plotDLInt1DLInt2SynEffect.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import nixio
  2. from matplotlib import pyplot as plt
  3. from brian2 import units
  4. from dirDefs import homeFolder
  5. import os
  6. from neoNIXIO import dataArray2AnalogSignal, multiTag2SpikeTrain, simpleFloat
  7. from mplPars import mplPars
  8. import seaborn as sns
  9. import quantities as qu
  10. sns.set(rc=mplPars)
  11. simSettleTime = 600 * units.ms
  12. simStepSize = 0.1 * units.ms
  13. simDuration = 450 * units.ms
  14. totalSimDur = simSettleTime + simDuration
  15. IntDurs = [
  16. (20, 10),
  17. (20, 16),
  18. (33, 10),
  19. (33, 16),
  20. (33, 20),
  21. (50, 10),
  22. (50, 16),
  23. (50, 20),
  24. (100, 10),
  25. (100, 16),
  26. (100, 20)
  27. ]
  28. pulseInts = sorted(set([x[0] for x in IntDurs]))
  29. pulseDurs = sorted(set([x[1] for x in IntDurs]))
  30. showBefore = 75 * units.ms
  31. showAfter = -30 * units.ms
  32. DLInt1ModelProps = "DLInt1Aynur"
  33. DLInt2ModelProps = "DLInt2Try2"
  34. DLInt1SynapsePropsE = 'DLInt1_syn_try2_e'
  35. # DLInt1SynapsePropsE = ""
  36. DLInt1SynapsePropsI = 'DLInt1_syn_try2_i'
  37. # DLInt1SynapsePropsI = ""
  38. DLInt1SynapseProps = "".join((DLInt1SynapsePropsE, DLInt1SynapsePropsI))
  39. DLInt2SynapseProps = 'DLInt2_syn_try2'
  40. # DLInt2SynapseProps = ""
  41. DLInt1DLInt2SynProps = "DLInt1_DLInt2_try1"
  42. # DLInt1DLInt2SynProps = ""
  43. DLInt1SynapseProps = "".join((DLInt1SynapsePropsE, DLInt1SynapsePropsI))
  44. opDir = os.path.join(homeFolder, DLInt1ModelProps + DLInt2ModelProps,
  45. DLInt1SynapseProps + DLInt2SynapseProps + DLInt1DLInt2SynProps)
  46. fig1, axs1 = plt.subplots(nrows=len(pulseDurs), ncols=len(pulseInts),
  47. figsize=(14, 11.2), sharex='col')
  48. fig2, axs2 = plt.subplots(nrows=len(pulseDurs), ncols=len(pulseInts),
  49. figsize=(14, 11.2), sharex='col')
  50. for IntDur in IntDurs:
  51. pulseInt = IntDur[0]
  52. pulseDur = IntDur[1]
  53. inputParsName = 'pTShortInt{:2d}Dur{:2d}'.format(pulseInt, pulseDur)
  54. opDirWith = os.path.join(homeFolder, DLInt1ModelProps + DLInt2ModelProps,
  55. DLInt1SynapseProps + DLInt2SynapseProps + DLInt1DLInt2SynProps,
  56. inputParsName)
  57. OPNixFileWith = os.path.join(opDirWith, 'SimResults.h5')
  58. opDirWithout = os.path.join(homeFolder, DLInt1ModelProps + DLInt2ModelProps,
  59. DLInt1SynapseProps + DLInt2SynapseProps,
  60. inputParsName)
  61. OPNixFileWithout = os.path.join(opDirWithout, 'SimResults.h5')
  62. nixFile = nixio.File.open(OPNixFileWith, nixio.FileMode.ReadOnly)
  63. blk = nixFile.blocks["Simulation Traces"]
  64. dlint1MemV = blk.data_arrays["DLInt1 MemV"]
  65. dlint1SpikesMT = blk.multi_tags["DLInt1 Spikes"]
  66. dlint2MemV = blk.data_arrays["DLInt2 MemV"]
  67. dlint2SpikesMT = blk.multi_tags["DLInt2 Spikes"]
  68. sinInput = blk.data_arrays["Input Vibration Signal"]
  69. joSpikesMT = blk.multi_tags["JO Spikes"]
  70. dlint1MemVAS = dataArray2AnalogSignal(dlint1MemV)
  71. dlint2MemVAS = dataArray2AnalogSignal(dlint2MemV)
  72. sinInputAS = dataArray2AnalogSignal(sinInput)
  73. dlint1SpikesST = multiTag2SpikeTrain(dlint1SpikesMT, sinInputAS.t_start, sinInputAS.t_stop)
  74. dlint2SpikesST = multiTag2SpikeTrain(dlint2SpikesMT, sinInputAS.t_start, sinInputAS.t_stop)
  75. joSpikesST = multiTag2SpikeTrain(joSpikesMT, sinInputAS.t_start, sinInputAS.t_stop)
  76. nixFileWithout = nixio.File.open(OPNixFileWithout, nixio.FileMode.ReadOnly)
  77. blkWithout = nixFileWithout.blocks["Simulation Traces"]
  78. dlint2MemVWithout = blkWithout.data_arrays["DLInt2 MemV"]
  79. dlint2SpikesMTWithout = blkWithout.multi_tags["DLInt2 Spikes"]
  80. dlint2MemVASWithout = dataArray2AnalogSignal(dlint2MemVWithout)
  81. dlint2SpikesSTWithout = multiTag2SpikeTrain(dlint2SpikesMTWithout,
  82. sinInputAS.t_start, sinInputAS.t_stop)
  83. rowInd = pulseDurs.index(pulseDur)
  84. colInd = pulseInts.index(pulseInt)
  85. axs1[rowInd, colInd].plot(simpleFloat(dlint1MemVAS.times / qu.ms),
  86. simpleFloat(dlint1MemVAS / qu.mV), 'b-', lw=1)
  87. # mew needs setting for seaborn. https://github.com/mwaskom/seaborn/issues/644
  88. axs1[rowInd, colInd].plot(simpleFloat(dlint1SpikesST.times / qu.ms),
  89. [4] * dlint1SpikesST.shape[0],
  90. 'b|', ms=8, mew=1)
  91. axs1[rowInd, colInd].plot(simpleFloat(sinInputAS.times / qu.ms),
  92. simpleFloat(-50 + (sinInputAS * 5) / qu.um)
  93. , 'k-', lw=1)
  94. axs1[rowInd, colInd].set_xlim([(simSettleTime - showBefore) / units.ms,
  95. (totalSimDur + showAfter) / units.ms])
  96. axs2[rowInd, colInd].plot(simpleFloat(dlint2MemVAS.times / qu.ms),
  97. simpleFloat(dlint2MemVAS / qu.mV), 'b-', lw=1)
  98. axs2[rowInd, colInd].plot(simpleFloat(dlint2MemVASWithout.times / qu.ms),
  99. simpleFloat(-45 + (dlint2MemVASWithout / qu.mV)),
  100. 'r-', lw=1)
  101. axs2[rowInd, colInd].plot(simpleFloat(dlint2SpikesST.times / qu.ms),
  102. [12] * dlint2SpikesST.shape[0],
  103. 'b|', ms=8, mew=1)
  104. axs2[rowInd, colInd].plot(simpleFloat(dlint2SpikesSTWithout.times / qu.ms),
  105. [6] * dlint2SpikesSTWithout.shape[0],
  106. 'r|', ms=8, mew=1)
  107. axs2[rowInd, colInd].plot(simpleFloat(sinInputAS.times / qu.ms),
  108. simpleFloat(-105 + (sinInputAS * 7.5) / qu.um)
  109. , 'k-', lw=1)
  110. axs2[rowInd, colInd].set_xlim([(simSettleTime - showBefore) / units.ms,
  111. (totalSimDur + showAfter) / units.ms])
  112. for rowInd in range(axs1.shape[0]):
  113. for colInd in range(axs1.shape[1]):
  114. ax = axs1[rowInd, colInd]
  115. ax.set_ylim([-60, 10])
  116. ax.yaxis.tick_right()
  117. ax.set_yticklabels([""] * len(ax.get_yticks()))
  118. ax.set_xticklabels([""] * len(ax.get_xticks()))
  119. for rowInd in range(axs2.shape[0]):
  120. for colInd in range(axs2.shape[1]):
  121. ax = axs2[rowInd, colInd]
  122. ax.set_ylim([-120, 20])
  123. ax.yaxis.tick_right()
  124. ax.set_yticklabels([""] * len(ax.get_yticks()))
  125. ax.set_xticklabels([""] * len(ax.get_xticks()))
  126. for ind, val in enumerate(pulseInts):
  127. axs1[0, ind].set_title(str(val))
  128. axs2[0, ind].set_title(str(val))
  129. for ind, val in enumerate(pulseDurs):
  130. axs1[ind, 0].set_ylabel(str(val))
  131. axs2[ind, 0].set_ylabel(str(val))
  132. fig1.tight_layout()
  133. fig2.tight_layout()
  134. fig1.savefig(os.path.join(opDir, 'DLInt1Summary.png'), dpi=150)
  135. fig2.savefig(os.path.join(opDir, 'DLInt2Summary.png'), dpi=150)