Browse Source

added plotting of traces

Paul Pfeiffer 4 years ago
parent
commit
85f0784598
4 changed files with 39 additions and 3 deletions
  1. 2 2
      makefile
  2. 1 0
      scripts/check_folder_structure.py
  3. 34 0
      scripts/plot_traces.py
  4. 2 1
      scripts/tools/definitions.py

+ 2 - 2
makefile

@@ -1,4 +1,4 @@
-all: prepare_folder_structure extract_stimulations assign_protocols filter analyse_firing_rates analyse_persistent_activity
+all: prepare_folder_structure extract_stimulations assign_protocols filter analyse_firing_rates analyse_persistent_activity plot_traces
 
 prepare_folder_structure:
 	python scripts/check_folder_structure.py
@@ -19,7 +19,7 @@ analyse_persistent_activity:
 	python scripts/analyse_persistent_activity.py
 
 plot_traces:
-	python plot_traces.py
+	python scripts/plot_traces.py
 
 report:
 	python generate_report.py

+ 1 - 0
scripts/check_folder_structure.py

@@ -4,6 +4,7 @@ from tools.definitions import *
 def generate_folder_structure():
     os.mkdir(OUTPUT_FOLDER)
     os.mkdir(OUTPUT_FOLDER+HELPER_TABLE_FOLDER)
+    os.mkdir(OUTPUT_FOLDER+PLOTS_FOLDER)
 
 if not os.path.exists(OUTPUT_FOLDER):
     generate_folder_structure()

+ 34 - 0
scripts/plot_traces.py

@@ -0,0 +1,34 @@
+import matplotlib.gridspec as gridspec
+import matplotlib.pyplot as plt
+import pandas as pd
+import tools.pyrelacs as pr
+from tools.definitions import OUTPUT_FOLDER, HELPER_TABLE_FOLDER, PLOTS_FOLDER, STIMULATION_METADATA_RAW
+from tools.helper import get_times, get_traces
+
+path_to_raw_stimulus_file = OUTPUT_FOLDER+HELPER_TABLE_FOLDER+STIMULATION_METADATA_RAW
+stimulations = pd.read_csv(path_to_raw_stimulus_file, index_col="stimulation_id")
+
+print "# Plotting"
+path_to_plot_folder = OUTPUT_FOLDER+PLOTS_FOLDER
+
+for id, stimulation in stimulations.iterrows():
+    print "Loading stimulation {}".format(id)
+    times = get_times(stimulation)
+    trace_infos = pr.get_available_traces(stimulation["recording"])
+    traces = get_traces(stimulation)
+
+    labels = ["{} [{}]".format(trace_info["identifier"], trace_info["unit"]) for trace_info in trace_infos]
+    print "Plotting stimulation {}".format(id)
+    fig = plt.figure(figsize=(9, 16))
+    gs = gridspec.GridSpec(len(labels) + 1, 1)
+    axes = [fig.add_subplot(gs[trace_idx, :]) for trace_idx in
+            range(1, len(labels) + 1)]
+    for ax, label, trace in zip(axes, labels, traces):
+        ax.plot(times, trace)
+        ax.axvline(0,  color='k', ls='--', lw=2)
+        ax.axvline(stimulation["stimulus_length"], color='k', ls='--', lw=2)
+        ax.set_ylabel(label)
+    fig.tight_layout()
+    fig.savefig("{}/{}.png".format(path_to_plot_folder, id))
+    plt.close(fig)
+    print ""

+ 2 - 1
scripts/tools/definitions.py

@@ -3,7 +3,8 @@ METADATA_FOLDER = "metadata/"
 
 OUTPUT_FOLDER = "out/"
 HELPER_TABLE_FOLDER = "tables/"
+PLOTS_FOLDER = "plots"
 STIMULATION_METADATA_RAW = "stimulations_raw.csv"
 STIMULATION_METADATA_EXTENDED = "stimulations_analysed.csv"
 STIMULATION_METADATA_FILTERED = "stimulations_analysed_and_filtered.csv"
-PROTOCOL_BLACKLIST = "blacklist.csv"
+PROTOCOL_BLACKLIST = "blacklist.csv"