plotShortStims.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. from brian2 import units
  2. from matplotlib import pyplot as plt
  3. import seaborn as sns
  4. import os
  5. from dirDefs import homeFolder
  6. import nixio
  7. from neoNIXIO import multiTag2SpikeTrain, dataArray2AnalogSignal, simpleFloat
  8. import quantities as qu
  9. from mplPars import mplPars
  10. sns.set(rc=mplPars)
  11. sns.axes_style('whitegrid')
  12. simSettleTime = 600 * units.ms
  13. #
  14. simStepSize = 0.1 * units.ms
  15. simDuration = 150 * units.ms
  16. inputParsNames = {
  17. 10: "tenMSPulse",
  18. 20: "twentyMSPulse",
  19. 30: "thirtyMSPulse",
  20. 40: "fortyMSPulse"
  21. }
  22. showBefore = 50 * units.ms
  23. showAfter = 50 * units.ms
  24. totalSimDur = simSettleTime + simDuration
  25. DLInt1ModelProps = "DLInt1Aynur"
  26. DLInt2ModelProps = "DLInt2Try2"
  27. DLInt1SynapsePropsE = 'DLInt1_syn_try2_e'
  28. # DLInt1SynapsePropsE = ""
  29. DLInt1SynapsePropsI = 'DLInt1_syn_try2_i'
  30. # DLInt1SynapsePropsI = ""
  31. DLInt2SynapseProps = 'DLInt2_syn_try2'
  32. # DLInt2SynapseProps = ""
  33. DLInt1DLInt2SynProps = "DLInt1_DLInt2_try1"
  34. # DLInt1DLInt2SynProps = ""
  35. DLInt1SynapseProps = "".join((DLInt1SynapsePropsE, DLInt1SynapsePropsI))
  36. opDir = os.path.join(homeFolder, DLInt1ModelProps + DLInt2ModelProps,
  37. DLInt1SynapseProps + DLInt2SynapseProps + DLInt1DLInt2SynProps)
  38. fig, axs = plt.subplots(nrows=2, ncols=len(inputParsNames), figsize=(14, 11.2),
  39. sharex='col')
  40. for ipInd, (ipVal, ipName) in enumerate(inputParsNames.items()):
  41. nixFile = os.path.join(opDir, ipName, 'SimResults.h5')
  42. nixFile = nixio.File.open(nixFile, nixio.FileMode.ReadOnly)
  43. blk = nixFile.blocks["Simulation Traces"]
  44. dlint1MemV = blk.data_arrays["DLInt1 MemV"]
  45. dlint1SpikesMT = blk.multi_tags["DLInt1 Spikes"]
  46. dlint2MemV = blk.data_arrays["DLInt2 MemV"]
  47. dlint2SpikesMT = blk.multi_tags["DLInt2 Spikes"]
  48. sinInput = blk.data_arrays["Input Vibration Signal"]
  49. joSpikesMT = blk.multi_tags["JO Spikes"]
  50. dlint1MemVAS = dataArray2AnalogSignal(dlint1MemV)
  51. dlint2MemVAS = dataArray2AnalogSignal(dlint2MemV)
  52. sinInputAS = dataArray2AnalogSignal(sinInput)
  53. dlint1SpikesST = multiTag2SpikeTrain(dlint1SpikesMT, sinInputAS.t_start, sinInputAS.t_stop)
  54. dlint2SpikesST = multiTag2SpikeTrain(dlint2SpikesMT, sinInputAS.t_start, sinInputAS.t_stop)
  55. joSpikesST = multiTag2SpikeTrain(joSpikesMT, sinInputAS.t_start, sinInputAS.t_stop)
  56. axs[0, ipInd].plot(simpleFloat(dlint1MemVAS.times / qu.ms),
  57. simpleFloat(dlint1MemVAS / qu.mV), 'b-')
  58. # mew needs setting for seaborn. https://github.com/mwaskom/seaborn/issues/644
  59. axs[0, ipInd].plot(simpleFloat(dlint1SpikesST.times / qu.ms),
  60. [4] * dlint1SpikesST.shape[0],
  61. 'b|', ms=8, mew=1)
  62. markerline, stemlines, baseline \
  63. = axs[0, ipInd].stem(simpleFloat(joSpikesST.times / qu.ms),
  64. [-40] * joSpikesST.shape[0],
  65. linefmt='r-.', markerfmt='None', basefmt='None',
  66. bottom=-60)
  67. plt.setp(stemlines, color=(0.5, 0.5, 0.5), lw=2)
  68. axs[0, ipInd].plot(simpleFloat(sinInputAS.times / qu.ms),
  69. simpleFloat(((5 * qu.um * sinInputAS) - 50 * qu.um) / qu.um)
  70. , 'k-')
  71. # axs[0, ipInd].set_xlim([(simSettleTime - showBefore) / units.ms,
  72. # (totalSimDur + showAfter) / units.ms])
  73. axs[0, ipInd].set_ylim([-60, 10])
  74. axs[0, ipInd].yaxis.tick_right()
  75. axs[1, ipInd].plot(simpleFloat(dlint2MemVAS.times / qu.ms),
  76. simpleFloat(dlint2MemVAS / qu.mV), 'b-')
  77. # mew needs setting for seaborn. https://github.com/mwaskom/seaborn/issues/644
  78. axs[1, ipInd].plot(simpleFloat(dlint2SpikesST.times / qu.ms),
  79. [4] * dlint2SpikesST.shape[0],
  80. 'b|', ms=8, mew=1)
  81. markerline, stemlines, baseline \
  82. = axs[1, ipInd].stem(simpleFloat(joSpikesST.times / qu.ms),
  83. [-40] * joSpikesST.shape[0],
  84. linefmt='r-.', markerfmt='None', basefmt='None',
  85. bottom=-60)
  86. plt.setp(stemlines, color=(0.5, 0.5, 0.5), lw=2)
  87. axs[1, ipInd].plot(simpleFloat(sinInputAS.times / qu.ms),
  88. simpleFloat(((5 * qu.um * sinInputAS) - 50 * qu.um) / qu.um)
  89. , 'k-')
  90. axs[1, ipInd].set_xlim([(simSettleTime - showBefore) / units.ms,
  91. (totalSimDur + showAfter) / units.ms])
  92. axs[1, ipInd].set_ylim([-60, 10])
  93. axs[1, ipInd].yaxis.tick_right()
  94. for ind in range(len(inputParsNames) - 1):
  95. axs[0, ind].set_yticks([])
  96. axs[1, ind].set_yticks([])
  97. for ipInd, (ipVal, ipName) in enumerate(inputParsNames.items()):
  98. axs[0, ipInd].set_title(ipVal)
  99. axs[0, 0].set_ylabel("DL-Int-1")
  100. axs[1, 0].set_ylabel("DL-Int-2")
  101. fig.tight_layout()
  102. fig.savefig(os.path.join(opDir, "shortStims.png"), dpi=300)