extract_protocols.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import pandas as pd
  2. from tools.definitions import STIMULATION_METADATA_RAW, STIMULATION_METADATA_EXTENDED, OUTPUT_FOLDER, HELPER_TABLE_FOLDER
  3. def get_protocol_type(stimulation):
  4. return "UP" if stimulation["pulse_offset"] > 0 else "DOWN"
  5. def get_pulse_number(stimulation):
  6. length = stimulation["stimulus_length"]
  7. period = stimulation["pulse_period"]
  8. return int(length / period)
  9. def is_control(stim):
  10. return stim["J"] == 0
  11. path_to_raw_stimulus_file = OUTPUT_FOLDER + HELPER_TABLE_FOLDER + STIMULATION_METADATA_RAW
  12. path_to_extended_stimulus_file = OUTPUT_FOLDER + HELPER_TABLE_FOLDER + STIMULATION_METADATA_EXTENDED
  13. print "# Assign protocol types"
  14. print "Go through stimulations in {} and determine pulse number and amplitude".format(path_to_raw_stimulus_file)
  15. stimulations = pd.read_csv(path_to_raw_stimulus_file, index_col="stimulation_id")
  16. stimulations["protocol_type"] = stimulations.apply(lambda stimulation: get_protocol_type(
  17. stimulation), axis=1)
  18. stimulations["pulse_number"] = stimulations.apply(lambda stimulation: get_pulse_number(stimulation), axis=1)
  19. stimulations["is_control"] = stimulations.apply(lambda stim: is_control(stim), axis=1)
  20. stimulations.to_csv(path_or_buf=path_to_extended_stimulus_file)
  21. print "Stimulations with pulse information saved to {}".format(path_to_extended_stimulus_file)
  22. print ""