forAi2017.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import nixio
  2. from dirDefs import homeFolder
  3. import os
  4. import seaborn as sns
  5. from mplPars import mplPars
  6. from brian2 import units
  7. from matplotlib import pyplot as plt
  8. from neoNIXIO import multiTag2SpikeTrain, dataArray2AnalogSignal, \
  9. simpleFloat, property2qu
  10. import quantities as qu
  11. from neo import AnalogSignal
  12. mplPars['xtick.labelsize'] = 10
  13. mplPars['ytick.labelsize'] = 10
  14. mplPars["text.usetex"] = False
  15. mplPars["font.sans-serif"] = "Arial"
  16. mplPars["axes.linewidth"] = 1
  17. sns.set(style="ticks", rc=mplPars)
  18. simSettleTime = 600 * units.ms
  19. # simStepSize = 0.1 * units.ms
  20. # simDuration = 150 * units.ms
  21. # # inputParsName = 'onePulse'
  22. # # inputParsName = 'twoPulse'
  23. # # inputParsName = 'threePulse'
  24. # inputParsName = "fortyMSPulse"
  25. # showBefore = 50 * units.ms
  26. # showAfter = 50 * units.ms
  27. simStepSize = 0.1 * units.ms
  28. simDuration = 450 * units.ms
  29. inputParsName = "pTShortInt33Dur16"
  30. # inputParsName = "pTShortInt100Dur16"
  31. showBefore = 75 * units.ms
  32. showAfter = -30 * units.ms
  33. # simStepSize = 0.1 * units.ms
  34. # simDuration = 1500 * units.ms
  35. # # inputParsName = 'oneSecondPulse'
  36. # # inputParsName = 'pulseTrainInt20Dur10'
  37. # inputParsName = 'pulseTrainInt20Dur16'
  38. # # inputParsName = 'pulseTrainInt33Dur10'
  39. # # inputParsName = 'pulseTrainInt33Dur16'
  40. # showBefore = 500 * units.ms
  41. # showAfter = 500 * units.ms
  42. DLInt1ModelProps = "DLInt1Aynur"
  43. DLInt1SynapsePropsE = 'DLInt1_syn_try2_e'
  44. # DLInt1SynapsePropsE = ""
  45. DLInt1SynapsePropsI = 'DLInt1_syn_try2_i'
  46. # DLInt1SynapsePropsI = ""
  47. DLInt1SynapseProps = "".join((DLInt1SynapsePropsE, DLInt1SynapsePropsI))
  48. DLInt2ModelProps = "DLInt2Try2"
  49. DLInt2SynapseProps = 'DLInt2_syn_try2'
  50. DLInt1DLInt2SynProps = "DLInt1_DLInt2_try1"
  51. opDir = os.path.join(homeFolder, DLInt1ModelProps + DLInt2ModelProps,
  52. DLInt1SynapseProps + DLInt2SynapseProps + DLInt1DLInt2SynProps,
  53. inputParsName)
  54. OPNixFile = os.path.join(opDir, 'simResults.h5')
  55. totalSimDur = simDuration + simSettleTime
  56. nixFile = nixio.File.open(OPNixFile, nixio.FileMode.ReadOnly)
  57. inputSec = nixFile.sections["Input Parameters"]
  58. simSettleTimeQu = property2qu(inputSec.props["simSettleTime"])
  59. blk = nixFile.blocks["Simulation Traces"]
  60. dlint1MemV = blk.data_arrays["DLInt1 MemV"]
  61. dlint1SpikesMT = blk.multi_tags["DLInt1 Spikes"]
  62. dlint2MemV = blk.data_arrays["DLInt2 MemV"]
  63. dlint2SpikesMT = blk.multi_tags["DLInt2 Spikes"]
  64. sinInput = blk.data_arrays["Input Vibration Signal"]
  65. joSpikesMT = blk.multi_tags["JO Spikes"]
  66. dlint1MemVAS = dataArray2AnalogSignal(dlint1MemV)
  67. dlint2MemVAS = dataArray2AnalogSignal(dlint2MemV)
  68. temp = dataArray2AnalogSignal(sinInput)
  69. sinInputAS = AnalogSignal(signal=15 * temp.magnitude,
  70. units=temp.units,
  71. t_start=temp.t_start,
  72. sampling_period=temp.sampling_period)
  73. sinInputAS = sinInputAS.reshape((sinInputAS.shape[0],))
  74. dlint1SpikesST = multiTag2SpikeTrain(dlint1SpikesMT, sinInputAS.t_start, sinInputAS.t_stop)
  75. dlint2SpikesST = multiTag2SpikeTrain(dlint2SpikesMT, sinInputAS.t_start, sinInputAS.t_stop)
  76. joSpikesST = multiTag2SpikeTrain(joSpikesMT, sinInputAS.t_start, sinInputAS.t_stop)
  77. # fig0, ax0 = plt.subplots(figsize=(2.5, 1.5))
  78. # fig1, ax1 = plt.subplots(figsize=(2.5, 1.5))
  79. # fig2, ax2 = plt.subplots(figsize=(2.5, 1.75))
  80. #
  81. fig0, ax0 = plt.subplots(figsize=(2.85, 1.5))
  82. fig1, ax1 = plt.subplots(figsize=(2.85, 1.5))
  83. fig2, ax2 = plt.subplots(figsize=(2.85, 1.75))
  84. ax0.plot(simpleFloat((dlint1MemVAS.times - simSettleTimeQu) / qu.ms),
  85. simpleFloat(dlint1MemVAS / qu.mV), 'k-', lw=0.4)
  86. ax1.plot(simpleFloat((dlint2MemVAS.times - simSettleTimeQu) / qu.ms),
  87. simpleFloat(dlint2MemVAS / qu.mV), 'k-', lw=0.4)
  88. ax2.plot(simpleFloat((sinInputAS.times - simSettleTimeQu) / qu.ms),
  89. simpleFloat(sinInputAS / qu.um), 'k-', lw=0.4)
  90. for ax in [ax0, ax1, ax2]:
  91. ax.set_xlim([(-showBefore) / units.ms,
  92. (simDuration + showAfter) / units.ms])
  93. # ax.yaxis.tick_right()
  94. ax.set_xticks([])
  95. ax.set_ylim([-50, 5])
  96. ax.set_yticks([-40, -20, 0])
  97. # ax.set_yticks([])
  98. for ax in [ax0, ax1]:
  99. markerline, stemlines, baseline \
  100. = ax.stem(simpleFloat((joSpikesST.times - simSettleTimeQu) / qu.ms),
  101. [-42] * joSpikesST.shape[0],
  102. linefmt='k-', markerfmt='None', basefmt='None',
  103. bottom=-50)
  104. plt.setp(stemlines, lw=0.4)
  105. markerline, stemlines, baseline \
  106. = ax2.stem(simpleFloat((joSpikesST.times - simSettleTimeQu) / qu.ms),
  107. [25] * joSpikesST.shape[0],
  108. linefmt='k-', markerfmt='None', basefmt='None',
  109. bottom=17)
  110. plt.setp(stemlines, lw=0.5)
  111. ax2.set_ylim([-20, 25])
  112. ax2.set_xticks([0, 100, 200, 300])
  113. for fig in [fig0, fig1, fig2]:
  114. fig.tight_layout()
  115. fig0.savefig(os.path.join(opDir, "DL-Int-1MemV.svg"), dpi=300,
  116. bbox_inches='tight', transparent=True)
  117. fig1.savefig(os.path.join(opDir, "DL-Int-2MemV.svg"), dpi=300,
  118. bbox_inches='tight', transparent=True)
  119. fig2.savefig(os.path.join(opDir, "InputSignal.svg"), dpi=300,
  120. bbox_inches='tight', transparent=True)