-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtest.py
141 lines (106 loc) · 6.18 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import PyPNS
import matplotlib.pyplot as plt
import numpy as np
# ---------------------------------------------------------------------------
# --------------------------------- DEFINITION ------------------------------
# ---------------------------------------------------------------------------
# ----------------------------- simulation params ---------------------------
tStop=50
dt=0.0025
# ----------------------------- axon params ---------------------------
# diameters enlarged for quicker execution
myelinatedParameters = {'fiberD': {'distName': 'normal', 'params': (1.7, 0.4)}}
unmyelinatedParameters = {'fiberD': {'distName': 'normal', 'params': (1.0, 0.2)}}
segmentLengthAxon = 15
rdc = 0.2 # random direction component
# ----------------------------- bundle params -------------------------------
# set length of bundle and number of axons
bundleLength = 40000
nAxons = 1
# bundle guide
bundleGuide = PyPNS.createGeometry.get_bundle_guide_straight(bundleLength, segmentLengthAxon)
# ------------------------ intracellular stimulation params -----------------
# parameters of signals for stimulation
rectangularSignalParamsIntra = {'amplitude': 50., #50, # Pulse amplitude (mA)
'frequency': 20., # Frequency of the pulse (kHz)
'dutyCycle': 0.5, # Percentage stimulus is ON for one period (t_ON = duty_cyle*1/f)
'stimDur': 0.05, # Stimulus duration (ms)
'waveform': 'MONOPHASIC', # Type of waveform either "MONOPHASIC" or "BIPHASIC" symmetric
'delay': 0., # ms
# 'invert': True,
# 'timeRes': timeRes,
}
intraParameters = {'stimulusSignal': PyPNS.signalGeneration.rectangular(**rectangularSignalParamsIntra)}
# ------------------------- extracellular stimulation params -----------------
rectangularSignalParamsExtra = {'amplitude': 3000, # Pulse amplitude (nA)
'frequency': 1, # Frequency of the pulse (kHz)
'dutyCycle': 0.5, # Percentage stimulus is ON for one period (t_ON = duty_cyle*1/f)
'stimDur': 1., # Stimulus duration (ms)
'waveform': 'MONOPHASIC', # Type of waveform either "MONOPHASIC" or "BIPHASIC" symmetric
'delay': 0., # ms
# 'invert': True,
# 'timeRes': timeRes,
}
elecPosStim = PyPNS.createGeometry.circular_electrode(bundleGuide, positionAlongBundle=12500, radius=235,
numberOfPoles=2, poleDistance=1000)
extPotMechStim = PyPNS.Extracellular.precomputedFEM(bundleGuide) # , 'oil190Inner50Endoneurium')
extraParameters = {'stimulusSignal': PyPNS.signalGeneration.rectangular(**rectangularSignalParamsExtra),
'electrodePositions': elecPosStim,
'extPotMech': extPotMechStim}
# ----------------------------- recording params -------------------------------
recordingParametersNew = {'bundleGuide': bundleGuide,
'radius': 220,
'positionAlongBundle': bundleLength*0.5,
'numberOfPoles': 1,
'poleDistance': 1000,
}
electrodePoints = PyPNS.createGeometry.circular_electrode(**recordingParametersNew)
extracellularMechs = []
extracellularMechs.append(PyPNS.Extracellular.homogeneous(sigma=1))
extracellularMechs.append(PyPNS.Extracellular.precomputedFEM(bundleGuide))
extracellularMechs.append(PyPNS.Extracellular.analytic(bundleGuide))
# ------------------------------------------------------------------------------
# --------------------------- PyPNS object instantiation -----------------------
# ------------------------------------------------------------------------------
# set all properties of the bundle
bundleParameters = {'radius': 180, #um Radius of the bundle (match carefully to extracellular mechanism)
'randomDirectionComponent': rdc,
'bundleGuide': bundleGuide,
'numberOfAxons': nAxons, # Number of axons in the bundle
'pMyel': 1., # Percentage of myelinated fiber type A
'pUnmyel': 0., # Percentage of unmyelinated fiber type C
'paramsMyel': myelinatedParameters, # parameters for fiber type A
'paramsUnmyel': unmyelinatedParameters, # parameters for fiber type C
'tStop': tStop,
'timeRes': dt,
# 'saveI':True,
'saveV': False,
# 'numberOfSavedSegments': 50, # number of segments of which the membrane potential is saved to disk
}
# create the bundle with all properties of axons
bundle = PyPNS.Bundle(**bundleParameters)
# spiking through a single electrical stimulation
bundle.add_excitation_mechanism(PyPNS.StimIntra(**intraParameters))
bundle.add_excitation_mechanism(PyPNS.StimField(**extraParameters))
# add recording electrodes. One for each extracellular medium
for extracellularMech in extracellularMechs:
bundle.add_recording_mechanism(PyPNS.RecordingMechanism(electrodePoints, extracellularMech))
# ------------------------------------------------------------------------------
# -------------------------------- PyPNS calculation ---------------------------
# ------------------------------------------------------------------------------
# run the simulation
bundle.simulate()
PyPNS.save_bundle(bundle)
print('bundle saved.')
# ------------------------------------------------------------------------------
# -------------------------------- Result Plotting ----------------------------
# ------------------------------------------------------------------------------
plt.figure()
for i in range(len(bundle.recordingMechanisms)):
t, SFAPs = bundle.get_SFAPs_from_file(i)
plt.plot(t, SFAPs, label='recordingMechanism_%i'%i)
plt.legend()
plt.xlabel('time (ms)')
plt.ylabel('voltage (mV)')
plt.show()
bundle = None