8
8
from bluecellulab .stimulus import StimulusFactory
9
9
from bluecellulab .tools import calculate_rheobase
10
10
from bluecellulab .analysis .inject_sequence import run_stimulus
11
- from bluecellulab .analysis .plotting import plot_iv_curve
11
+ from bluecellulab .analysis .plotting import plot_iv_curve , plot_fi_curve
12
12
13
13
14
- def compute_plot_iv_curve (cell , stim_start = 100.0 , duration = 500.0 , post_delay = 100.0 , threshold_voltage = - 30 , nb_bins = 11 ):
15
- """Compute and plot the IV curve from a given cell by injecting a
16
- predefined range of currents.
14
+ def compute_plot_iv_curve (cell ,
15
+ injecting_section = "soma[0]" ,
16
+ injecting_segment = 0.5 ,
17
+ recording_section = "soma[0]" ,
18
+ recording_segment = 0.5 ,
19
+ stim_start = 100.0 ,
20
+ duration = 500.0 ,
21
+ post_delay = 100.0 ,
22
+ threshold_voltage = - 30 ,
23
+ nb_bins = 11 ):
24
+ """Compute and plot the Current-Voltage (I-V) curve for a given cell by
25
+ injecting a range of currents.
26
+
27
+ This function evaluates the relationship between the injected current amplitude and the resulting
28
+ steady-state membrane potential of a neuronal cell model. Currents are injected at a specified section
29
+ and segment, and the steady-state voltage at the recording location is used to construct the I-V curve.
17
30
18
31
Args:
19
- cell (bluecellulab.cell.Cell): The initialized cell model.
20
- stim_start (float): Start time for current injection (in ms). Default is 100.0 ms.
21
- duration (float): Duration of current injection (in ms). Default is 500.0 ms.
22
- post_delay (float): Delay after the stimulation ends (in ms). Default is 100.0 ms.
23
- nb_bins (int): Number of current injection levels. Default is 11.
32
+ cell (bluecellulab.cell.Cell): The initialized BlueCelluLab cell model.
33
+ injecting_section (str, optional): The name of the section where the stimulus is injected.
34
+ Default is "soma[0]".
35
+ injecting_segment (float, optional): The position along the injecting section (0.0 to 1.0)
36
+ where the stimulus is applied. Default is 0.5.
37
+ recording_section (str, optional): The name of the section where the voltage is recorded.
38
+ Default is "soma[0]".
39
+ recording_segment (float, optional): The position along the recording section (0.0 to 1.0)
40
+ where the voltage is recorded. Default is 0.5.
41
+ stim_start (float, optional): The start time of the current injection (in ms). Default is 100.0 ms.
42
+ duration (float, optional): The duration of the current injection (in ms). Default is 500.0 ms.
43
+ post_delay (float, optional): The delay after the stimulation ends before the simulation stops
44
+ (in ms). Default is 100.0 ms.
45
+ threshold_voltage (float, optional): The voltage threshold (in mV) for detecting a steady-state
46
+ response. Default is -30 mV.
47
+ nb_bins (int, optional): The number of discrete current levels between 0 and the maximum current.
48
+ Default is 11.
24
49
25
50
Returns:
26
51
tuple: A tuple containing:
27
- - list_amp (np.ndarray): The predefined injected step current levels (nA).
28
- - steady_states (np.ndarray): The corresponding steady-state voltages (mV).
52
+ - list_amp (np.ndarray): The injected current amplitudes (nA).
53
+ - steady_states (np.ndarray): The corresponding steady-state voltages (mV) recorded at the
54
+ specified location.
55
+
56
+ Raises:
57
+ ValueError: If the cell object is invalid, the specified sections/segments are not found, or if
58
+ the simulation results are inconsistent.
29
59
"""
30
- rheobase = calculate_rheobase (cell )
60
+ rheobase = calculate_rheobase (cell = cell , section = injecting_section , segx = injecting_segment )
31
61
32
62
list_amp = np .linspace (rheobase - 2 , rheobase - 0.1 , nb_bins ) # [nA]
33
63
34
64
steps = []
35
65
times = []
36
66
voltages = []
37
67
# inject step current and record voltage response
68
+ stim_factory = StimulusFactory (dt = 0.1 )
38
69
for amp in list_amp :
39
- stim_factory = StimulusFactory (dt = 0.1 )
40
70
step_stimulus = stim_factory .step (pre_delay = stim_start , duration = duration , post_delay = post_delay , amplitude = amp )
41
- recording = run_stimulus (cell .template_params , step_stimulus , section = "soma[0]" , segment = 0.5 )
71
+ recording = run_stimulus (cell .template_params ,
72
+ step_stimulus ,
73
+ section = injecting_section ,
74
+ segment = injecting_segment ,
75
+ recording_section = recording_section ,
76
+ recording_segment = recording_segment )
42
77
steps .append (step_stimulus )
43
78
times .append (recording .time )
44
79
voltages .append (recording .voltage )
@@ -57,7 +92,86 @@ def compute_plot_iv_curve(cell, stim_start=100.0, duration=500.0, post_delay=100
57
92
steady_state = features_results [0 ]['steady_state_voltage_stimend' ]
58
93
steady_states .append (steady_state )
59
94
60
- # plot I-V curve
61
- plot_iv_curve (list_amp , steady_states )
95
+ plot_iv_curve (list_amp ,
96
+ steady_states ,
97
+ injecting_section = injecting_section ,
98
+ injecting_segment = injecting_segment ,
99
+ recording_section = recording_section ,
100
+ recording_segment = recording_segment )
62
101
63
102
return np .array (list_amp ), np .array (steady_states )
103
+
104
+
105
+ def compute_plot_fi_curve (cell ,
106
+ injecting_section = "soma[0]" ,
107
+ injecting_segment = 0.5 ,
108
+ recording_section = "soma[0]" ,
109
+ recording_segment = 0.5 ,
110
+ stim_start = 100.0 ,
111
+ duration = 500.0 ,
112
+ post_delay = 100.0 ,
113
+ max_current = 0.8 ,
114
+ nb_bins = 11 ):
115
+ """Compute and plot the Frequency-Current (F-I) curve for a given cell by
116
+ injecting a range of currents.
117
+
118
+ This function evaluates the relationship between injected current amplitude and the firing rate
119
+ of a neuronal cell model. Currents are injected at a specified section and segment, and the number
120
+ of spikes recorded in the specified recording location is used to construct the F-I curve.
121
+
122
+ Args:
123
+ cell (bluecellulab.cell.Cell): The initialized BlueCelluLab cell model.
124
+ injecting_section (str, optional): The name of the section where the stimulus is injected.
125
+ Default is "soma[0]".
126
+ injecting_segment (float, optional): The position along the injecting section (0.0 to 1.0)
127
+ where the stimulus is applied. Default is 0.5.
128
+ recording_section (str, optional): The name of the section where spikes are recorded.
129
+ Default is "soma[0]".
130
+ recording_segment (float, optional): The position along the recording section (0.0 to 1.0)
131
+ where spikes are recorded. Default is 0.5.
132
+ stim_start (float, optional): The start time of the current injection (in ms). Default is 100.0 ms.
133
+ duration (float, optional): The duration of the current injection (in ms). Default is 500.0 ms.
134
+ post_delay (float, optional): The delay after the stimulation ends before the simulation stops
135
+ (in ms). Default is 100.0 ms.
136
+ max_current (float, optional): The maximum amplitude of the injected current (in nA).
137
+ Default is 0.8 nA.
138
+ nb_bins (int, optional): The number of discrete current levels between 0 and `max_current`.
139
+ Default is 11.
140
+
141
+ Returns:
142
+ tuple: A tuple containing:
143
+ - list_amp (np.ndarray): The injected current amplitudes (nA).
144
+ - spike_count (np.ndarray): The corresponding spike counts for each current amplitude.
145
+
146
+ Raises:
147
+ ValueError: If the cell object is invalid or the specified sections/segments are not found.
148
+ """
149
+ rheobase = calculate_rheobase (cell = cell , section = injecting_section , segx = injecting_segment )
150
+
151
+ list_amp = np .linspace (rheobase , max_current , nb_bins ) # [nA]
152
+ steps = []
153
+ spikes = []
154
+ # inject step current and record spike response
155
+ stim_factory = StimulusFactory (dt = 0.1 )
156
+ for amp in list_amp :
157
+ step_stimulus = stim_factory .step (pre_delay = stim_start , duration = duration , post_delay = post_delay , amplitude = amp )
158
+ recording = run_stimulus (cell .template_params ,
159
+ step_stimulus ,
160
+ section = injecting_section ,
161
+ segment = injecting_segment ,
162
+ recording_section = recording_section ,
163
+ recording_segment = recording_segment ,
164
+ enable_spike_detection = True )
165
+ steps .append (step_stimulus )
166
+ spikes .append (recording .spike )
167
+
168
+ spike_count = [len (spike ) for spike in spikes ]
169
+
170
+ plot_fi_curve (list_amp ,
171
+ spike_count ,
172
+ injecting_section = injecting_section ,
173
+ injecting_segment = injecting_segment ,
174
+ recording_section = recording_section ,
175
+ recording_segment = recording_segment )
176
+
177
+ return np .array (list_amp ), np .array (spike_count )
0 commit comments