plot_traces.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. import matplotlib.gridspec as gridspec
  2. import matplotlib.pyplot as plt
  3. import pandas as pd
  4. import tools.pyrelacs as pr
  5. from tools.definitions import OUTPUT_FOLDER, HELPER_TABLE_FOLDER, PLOTS_FOLDER, STIMULATION_METADATA_RAW
  6. from tools.helper import get_times, get_traces
  7. path_to_raw_stimulus_file = OUTPUT_FOLDER+HELPER_TABLE_FOLDER+STIMULATION_METADATA_RAW
  8. stimulations = pd.read_csv(path_to_raw_stimulus_file, index_col="stimulation_id")
  9. print "# Plotting"
  10. path_to_plot_folder = OUTPUT_FOLDER+PLOTS_FOLDER
  11. for id, stimulation in stimulations.iterrows():
  12. print "Loading stimulation {}".format(id)
  13. times = get_times(stimulation)
  14. trace_infos = pr.get_available_traces(stimulation["recording"])
  15. traces = get_traces(stimulation)
  16. labels = ["{} [{}]".format(trace_info["identifier"], trace_info["unit"]) for trace_info in trace_infos]
  17. print "Plotting stimulation {}".format(id)
  18. fig = plt.figure(figsize=(9, 16))
  19. gs = gridspec.GridSpec(len(labels) + 1, 1)
  20. axes = [fig.add_subplot(gs[trace_idx, :]) for trace_idx in
  21. range(1, len(labels) + 1)]
  22. for ax, label, trace in zip(axes, labels, traces):
  23. ax.plot(times, trace)
  24. ax.axvline(0, color='k', ls='--', lw=2)
  25. ax.axvline(stimulation["stimulus_length"], color='k', ls='--', lw=2)
  26. ax.set_ylabel(label)
  27. fig.tight_layout()
  28. fig.savefig("{}/{}.png".format(path_to_plot_folder, id))
  29. plt.close(fig)
  30. print ""