Browse Source

assign protocols works

Paul Pfeiffer 1 year ago
parent
commit
7f29c7fcf5
2 changed files with 39 additions and 2 deletions
  1. 2 2
      makefile
  2. 37 0
      scripts/extract_protocols.py

+ 2 - 2
makefile

@@ -6,8 +6,8 @@ check_folders:
 extract_stimulations: check_folders
 	python scripts/extract_stimulations.py
 
-assign_protocols:
-	python extract_protocols.py
+assign_protocols: check_folders
+	python scripts/extract_protocols.py
 
 filter:
 	python filter_stimulations.py

+ 37 - 0
scripts/extract_protocols.py

@@ -0,0 +1,37 @@
+import pandas as pd
+
+
+from tools.definitions import STIMULATION_METADATA_RAW, STIMULATION_METADATA_EXTENDED, OUTPUT_FOLDER, HELPER_TABLE_FOLDER
+
+
+
+def get_protocol_type(stimulation):
+    return "UP" if stimulation["pulse_offset"] > 0 else "DOWN"
+
+
+def get_pulse_number(stimulation):
+    length = stimulation["stimulus_length"]
+    period = stimulation["pulse_period"]
+    return int(length / period)
+
+
+def is_control(stim):
+    return stim["J"] == 0
+
+path_to_raw_stimulus_file = OUTPUT_FOLDER + HELPER_TABLE_FOLDER + STIMULATION_METADATA_RAW
+
+path_to_extended_stimulus_file = OUTPUT_FOLDER + HELPER_TABLE_FOLDER + STIMULATION_METADATA_EXTENDED
+
+print "# Assign protocol types"
+print "Go through stimulations in {} and determine pulse number and amplitude".format(path_to_raw_stimulus_file)
+
+stimulations = pd.read_csv(path_to_raw_stimulus_file, index_col="stimulation_id")
+stimulations["protocol_type"] = stimulations.apply(lambda stimulation: get_protocol_type(
+    stimulation), axis=1)
+stimulations["pulse_number"] = stimulations.apply(lambda stimulation: get_pulse_number(stimulation), axis=1)
+
+stimulations["is_control"] = stimulations.apply(lambda stim: is_control(stim), axis=1)
+
+stimulations.to_csv(path_or_buf=path_to_extended_stimulus_file)
+print "Stimulations with pulse information saved to {}".format(path_to_extended_stimulus_file)
+print ""