forked from chlubba/PyPNS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
136 lines (100 loc) · 5.96 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
import PNPy
import matplotlib.pyplot as plt
import numpy as np
# ---------------------------------------------------------------------------
# --------------------------------- DEFINITION ------------------------------
# ---------------------------------------------------------------------------
# ----------------------------- simulation params ---------------------------
tStop=100
dt=0.0025
# ----------------------------- axon params ---------------------------
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 = 5
# bundle guide
bundleGuide = PNPy.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': PNPy.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 = PNPy.createGeometry.circular_electrode(bundleGuide, positionAlongBundle=12500, radius=235,
numberOfPoles=2, poleDistance=1000)
extPotMechStim = PNPy.Extracellular.precomputedFEM(bundleGuide) # , 'oil190Inner50Endoneurium')
extraParameters = {'stimulusSignal': PNPy.signalGeneration.rectangular(**rectangularSignalParamsExtra),
'electrodePositions': elecPosStim,
'extPotMech': extPotMechStim}
# ----------------------------- recording params -------------------------------
recordingParametersNew = {'bundleGuide': bundleGuide,
'radius': 220,
'positionAlongBundle': bundleLength*0.5,
'numberOfPoles': 1,
'poleDistance': 1000,
}
electrodePoints = PNPy.createGeometry.circular_electrode(**recordingParametersNew)
extracellularMechs = []
extracellularMechs.append(PNPy.Extracellular.homogeneous(sigma=1))
extracellularMechs.append(PNPy.Extracellular.precomputedFEM(bundleGuide))
extracellularMechs.append(PNPy.Extracellular.analytic(bundleGuide))
# ------------------------------------------------------------------------------
# --------------------------- PNPy 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': .5, # Percentage of myelinated fiber type A
'pUnmyel': .5, # 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 = PNPy.Bundle(**bundleParameters)
# spiking through a single electrical stimulation
bundle.add_excitation_mechanism(PNPy.StimIntra(**intraParameters))
bundle.add_excitation_mechanism(PNPy.StimField(**extraParameters))
# add recording electrodes. One for each extracellular medium
for extracellularMech in extracellularMechs:
bundle.add_recording_mechanism(PNPy.RecordingMechanism(electrodePoints, extracellularMech))
# ------------------------------------------------------------------------------
# -------------------------------- PNPy calculation ---------------------------
# ------------------------------------------------------------------------------
# run the simulation
bundle.simulate()
PNPy.save_bundle(bundle)
print 'bundle saved.'
# ------------------------------------------------------------------------------
# -------------------------------- Result Plotting ----------------------------
# ------------------------------------------------------------------------------
t, SFAPs = bundle.get_SFAPs_from_file(0)
plt.plot(t, SFAPs)
plt.show()
bundle = None