justDLInt1.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import os
  2. import sys
  3. import seaborn as sns
  4. from brian2 import defaultclock, units
  5. from matplotlib import pyplot as plt
  6. from brian2.core.network import Network
  7. from dirDefs import homeFolder
  8. from models.neuronModels import VSNeuron, JOSpikes265, getSineInput
  9. from models.neurons import AdExp
  10. from models.synapses import exp2Syn, exp2SynStateInits
  11. from mplPars import mplPars
  12. from paramLists import synapsePropsList, inputParsList, AdExpPars
  13. sns.set(style="whitegrid", rc=mplPars)
  14. simSettleTime = 600 * units.ms
  15. # simStepSize = 0.1 * units.ms
  16. # simDuration = 150 * units.ms
  17. # # inputParsName = 'onePulse'
  18. # # inputParsName = 'twoPulse'
  19. # # inputParsName = 'threePulse'
  20. # # inputParsName = "tenMSPulse"
  21. # # inputParsName = "twentyMSPulse"
  22. # # inputParsName = "thirtyMSPulse"
  23. # inputParsName = "fortyMSPulse"
  24. # # inputParsName = "fiftyMSPulse"
  25. # showBefore = 50 * units.ms
  26. # showAfter = 10 * units.ms
  27. simStepSize = 0.1 * units.ms
  28. simDuration = 1500 * units.ms
  29. # inputParsName = 'pulseTrainInt20Dur10'
  30. # inputParsName = 'pulseTrainInt20Dur16'
  31. # inputParsName = 'pulseTrainInt33Dur16'
  32. # inputParsName = 'pulseTrainInt33Dur10'
  33. # inputParsName = 'oneSecondPulse'
  34. # inputParsName = 'pulseTrainInt50Dur10'
  35. inputParsName = 'pulseTrainInt50Dur16'
  36. # inputParsName = 'pulseTrainInt50Dur20'
  37. showBefore = 500 * units.ms
  38. showAfter = 500 * units.ms
  39. DLInt1ModelProps = "DLInt1Aynur"
  40. dlint1 = VSNeuron(**AdExp, inits=getattr(AdExpPars, DLInt1ModelProps), name='dlint1')
  41. dlint1.recordMembraneV()
  42. dlint1.recordSpikes()
  43. DLInt1SynapsePropsE = 'DLInt1_syn_try2_e'
  44. # DLInt1SynapsePropsE = ""
  45. DLInt1SynapsePropsI = 'DLInt1_syn_try2_i'
  46. # DLInt1SynapsePropsI = ""
  47. DLInt1SynapseProps = "-".join((DLInt1SynapsePropsE, DLInt1SynapsePropsI))
  48. # opDir = os.path.join(homeFolder, DLInt1ModelProps, DLInt1SynapseProps, inputParsName)
  49. opDir = "/tmp/justDLInt1"
  50. opFile = os.path.join(opDir, 'Traces.png')
  51. if os.path.isfile(opFile):
  52. ch = input('Results already exist at {}. Delete?(y/n):'.format(opFile))
  53. if ch == 'y':
  54. os.remove(opFile)
  55. else:
  56. sys.exit('User Abort!')
  57. elif not os.path.isdir(opDir):
  58. os.makedirs(opDir)
  59. inputPars = getattr(inputParsList, inputParsName)
  60. JO = JOSpikes265(nOutputs=1, simSettleTime=simSettleTime, **inputPars)
  61. if DLInt1SynapsePropsE:
  62. dlint1.addSynapse(synName="ExiJO", sourceNG=JO.JOSGG, **exp2Syn,
  63. synParsInits=getattr(synapsePropsList, DLInt1SynapsePropsE),
  64. synStateInits=exp2SynStateInits,
  65. sourceInd=0, destInd=0
  66. )
  67. if DLInt1SynapsePropsI:
  68. dlint1.addSynapse(synName="InhJO", sourceNG=JO.JOSGG, **exp2Syn,
  69. synParsInits=getattr(synapsePropsList, DLInt1SynapsePropsI),
  70. synStateInits=exp2SynStateInits,
  71. sourceInd=0, destInd=0
  72. )
  73. net = Network()
  74. net.add(JO.JOSGG)
  75. dlint1.addToNetwork(net)
  76. defaultclock.dt = simStepSize
  77. totalSimDur = simDuration + simSettleTime
  78. net.run(totalSimDur, report='text')
  79. simT, memV = dlint1.getMemVTrace()
  80. spikeTimes = dlint1.getSpikes()
  81. fig, axs = plt.subplots(nrows=2, figsize=(10, 6.25), sharex='col')
  82. axs[0].plot(simT / units.ms, memV / units.mV)
  83. spikesY = memV.min() + 1.05 * (memV.max() - memV.min())
  84. axs[0].plot(spikeTimes / units.ms, [spikesY / units.mV] * spikeTimes.shape[0], 'k^')
  85. axs[0].set_ylabel('DLInt1 \nmemV (mV)')
  86. axs[0].set_xlim([(simSettleTime - showBefore) / units.ms,
  87. (totalSimDur + showAfter) / units.ms])
  88. sineInput = getSineInput(simDur=simDuration, simStepSize=simStepSize,
  89. sinPulseDurs=inputPars['sinPulseDurs'],
  90. sinPulseStarts=inputPars['sinPulseStarts'],
  91. freq=265 * units.Hz, simSettleTime=simSettleTime)
  92. axs[1].plot(simT / units.ms, sineInput, 'r-', label='Vibration Input')
  93. axs[1].plot(JO.spikeTimes / units.ms, [sineInput.max() * 1.05] * len(JO.spikeTimes), 'k^',
  94. label='JO Spikes')
  95. axs[1].legend(loc='upper right')
  96. axs[1].set_xlabel('time (ms)')
  97. axs[1].set_ylabel('Vibration \nInput/JO\n Spikes')
  98. fig.tight_layout()
  99. fig.canvas.draw()
  100. # plt.show()
  101. fig.savefig(opFile, dpi=150)