bluecellulab 2.5.11__py3-none-any.whl → 2.6.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of bluecellulab might be problematic. Click here for more details.

@@ -35,7 +35,6 @@ def run_stimulus(
35
35
  stimulus: Stimulus,
36
36
  section: str,
37
37
  segment: float,
38
- duration: float,
39
38
  ) -> Recording:
40
39
  """Creates a cell and stimulates it with a given stimulus.
41
40
 
@@ -44,7 +43,6 @@ def run_stimulus(
44
43
  stimulus: The input stimulus to inject into the cell.
45
44
  section: Name of the section of cell where the stimulus is to be injected.
46
45
  segment: The segment of the section where the stimulus is to be injected.
47
- duration: The duration for which the simulation is to be run.
48
46
 
49
47
  Returns:
50
48
  The voltage-time recording at the specified location.
@@ -61,7 +59,7 @@ def run_stimulus(
61
59
  current_vector = neuron.h.Vector()
62
60
  current_vector.record(iclamp._ref_i)
63
61
  simulation = Simulation(cell)
64
- simulation.run(duration)
62
+ simulation.run(stimulus.stimulus_time)
65
63
  current = np.array(current_vector.to_python())
66
64
  voltage = cell.get_voltage_recording(neuron_section, segment)
67
65
  time = cell.get_time()
@@ -74,7 +72,6 @@ def apply_multiple_step_stimuli(
74
72
  cell: Cell,
75
73
  stimulus_name: StimulusName,
76
74
  amplitudes: Sequence[float],
77
- duration: float,
78
75
  section_name: str | None = None,
79
76
  segment: float = 0.5,
80
77
  n_processes: int | None = None,
@@ -85,7 +82,6 @@ def apply_multiple_step_stimuli(
85
82
  cell: The cell to which the stimuli are applied.
86
83
  stimulus_name: The name of the stimulus to apply.
87
84
  amplitudes: The amplitudes of the stimuli to apply.
88
- duration: The duration for which each stimulus is applied.
89
85
  section_name: Section name of the cell where the stimuli are applied.
90
86
  If None, the stimuli are applied at the soma[0] of the cell.
91
87
  segment: The segment of the section where the stimuli are applied.
@@ -116,7 +112,7 @@ def apply_multiple_step_stimuli(
116
112
  else:
117
113
  raise ValueError("Unknown stimulus name.")
118
114
 
119
- task_args.append((cell.template_params, stimulus, section_name, segment, duration))
115
+ task_args.append((cell.template_params, stimulus, section_name, segment))
120
116
 
121
117
  with IsolatedProcess(processes=n_processes) as pool:
122
118
  # Map expects a function and a list of argument tuples
@@ -39,38 +39,38 @@ class Stimulus(ABC):
39
39
  ax.set_title(self.__class__.__name__)
40
40
  return ax
41
41
 
42
- def plot_during_simulation(self, duration: float, ax=None, **kwargs):
43
- if ax is None:
44
- ax = plt.gca()
45
- # Create an array for the entire duration
46
- full_time = np.arange(0, duration, self.dt)
47
- full_current = np.zeros_like(full_time)
48
-
49
- # Replace the corresponding values with self.time and self.current
50
- indices = (self.time / self.dt).astype(int)
51
- full_current[indices] = self.current
52
-
53
- ax.plot(full_time, full_current, **kwargs)
54
- ax.set_xlabel("Time (ms)")
55
- ax.set_ylabel("Current (nA)")
56
- ax.set_title(self.__class__.__name__)
57
- ax.set_xlim(0, duration)
58
- return ax
59
-
60
42
  def __add__(self, other: Stimulus) -> CombinedStimulus:
61
43
  """Override + operator to concatenate Stimulus objects."""
62
44
  if self.dt != other.dt:
63
- raise ValueError("Stimulus objects must have the same dt to be concatenated")
64
- # shift other time
65
- other_time = other.time + self.time[-1] + self.dt
66
- combined_time = np.concatenate([self.time, other_time])
67
- # Concatenate the current arrays
68
- combined_current = np.concatenate([self.current, other.current])
69
- return CombinedStimulus(self.dt, combined_time, combined_current)
45
+ raise ValueError(
46
+ "Stimulus objects must have the same dt to be concatenated"
47
+ )
48
+ if len(self.time) == 0:
49
+ return CombinedStimulus(other.dt, other.time, other.current)
50
+ elif len(other.time) == 0:
51
+ return CombinedStimulus(self.dt, self.time, self.current)
52
+ else:
53
+ # shift other time
54
+ other_time = other.time + self.time[-1] + self.dt
55
+ combined_time = np.concatenate([self.time, other_time])
56
+ # Concatenate the current arrays
57
+ combined_current = np.concatenate([self.current, other.current])
58
+ return CombinedStimulus(self.dt, combined_time, combined_current)
59
+
60
+ def __eq__(self, other: object) -> bool:
61
+ if not isinstance(other, Stimulus):
62
+ return NotImplemented
63
+ else:
64
+ return (
65
+ np.allclose(self.time, other.time)
66
+ and np.allclose(self.current, other.current)
67
+ and self.dt == other.dt
68
+ )
70
69
 
71
70
 
72
71
  class CombinedStimulus(Stimulus):
73
72
  """Represents the Stimulus created by combining multiple stimuli."""
73
+
74
74
  def __init__(self, dt: float, time: np.ndarray, current: np.ndarray) -> None:
75
75
  super().__init__(dt)
76
76
  self._time = time
@@ -85,11 +85,12 @@ class CombinedStimulus(Stimulus):
85
85
  return self._current
86
86
 
87
87
 
88
- class EmptyStimulus(Stimulus):
88
+ class Empty(Stimulus):
89
89
  """Represents empty stimulus (all zeros) that has no impact on the cell.
90
90
 
91
91
  This is required by some Stimuli that expect the cell to rest.
92
92
  """
93
+
93
94
  def __init__(self, dt: float, duration: float) -> None:
94
95
  super().__init__(dt)
95
96
  self.duration = duration
@@ -103,152 +104,286 @@ class EmptyStimulus(Stimulus):
103
104
  return np.zeros_like(self.time)
104
105
 
105
106
 
106
- class Step(Stimulus):
107
- def __init__(self, dt: float, start: float, end: float, amplitude: float) -> None:
107
+ class Flat(Stimulus):
108
+ def __init__(self, dt: float, duration: float, amplitude: float) -> None:
108
109
  super().__init__(dt)
109
- self.start = start
110
- self.end = end
110
+ self.duration = duration
111
111
  self.amplitude = amplitude
112
112
 
113
- @classmethod
114
- def threshold_based(
115
- cls,
116
- dt: float,
117
- threshold_current: float,
118
- threshold_percentage: float,
119
- start: float,
120
- end: float,
121
- post_wait: float,
122
- ) -> CombinedStimulus:
123
- amplitude = threshold_current * threshold_percentage / 100
124
- res = cls(dt, start, end, amplitude) + EmptyStimulus(dt, duration=post_wait)
125
- return res
126
-
127
113
  @property
128
114
  def time(self) -> np.ndarray:
129
- return np.arange(self.start, self.end, self.dt)
115
+ return np.arange(0.0, self.duration, self.dt)
130
116
 
131
117
  @property
132
118
  def current(self) -> np.ndarray:
133
119
  return np.full_like(self.time, self.amplitude)
134
120
 
135
121
 
136
- class Ramp(Stimulus):
122
+ class Slope(Stimulus):
137
123
  def __init__(
138
- self,
139
- dt: float,
140
- start: float,
141
- end: float,
142
- amplitude_start: float,
143
- amplitude_end: float,
124
+ self, dt: float, duration: float, amplitude_start: float, amplitude_end: float
144
125
  ) -> None:
145
126
  super().__init__(dt)
146
- self.start = start
147
- self.end = end
127
+ self.duration = duration
148
128
  self.amplitude_start = amplitude_start
149
129
  self.amplitude_end = amplitude_end
150
130
 
151
131
  @property
152
132
  def time(self) -> np.ndarray:
153
- return np.arange(self.start, self.end, self.dt)
133
+ return np.arange(0.0, self.duration, self.dt)
154
134
 
155
135
  @property
156
136
  def current(self) -> np.ndarray:
157
137
  return np.linspace(self.amplitude_start, self.amplitude_end, len(self.time))
158
138
 
159
139
 
140
+ class Step(Stimulus):
141
+
142
+ def __init__(self):
143
+ raise NotImplementedError(
144
+ "This class cannot be instantiated directly. "
145
+ "Please use the class methods 'amplitude_based' "
146
+ "or 'threshold_based' to create objects."
147
+ )
148
+
149
+ @classmethod
150
+ def amplitude_based(
151
+ cls,
152
+ dt: float,
153
+ pre_delay: float,
154
+ duration: float,
155
+ post_delay: float,
156
+ amplitude: float,
157
+ ) -> CombinedStimulus:
158
+ """Create a Step stimulus from given time events and amplitude.
159
+
160
+ Args:
161
+ dt: The time step of the stimulus.
162
+ pre_delay: The delay before the start of the step.
163
+ duration: The duration of the step.
164
+ post_delay: The time to wait after the end of the step.
165
+ amplitude: The amplitude of the step.
166
+ """
167
+ return (
168
+ Empty(dt, duration=pre_delay)
169
+ + Flat(dt, duration=duration, amplitude=amplitude)
170
+ + Empty(dt, duration=post_delay)
171
+ )
172
+
173
+ @classmethod
174
+ def threshold_based(
175
+ cls,
176
+ dt: float,
177
+ pre_delay: float,
178
+ duration: float,
179
+ post_delay: float,
180
+ threshold_current: float,
181
+ threshold_percentage: float,
182
+ ) -> CombinedStimulus:
183
+ """Creates a Step stimulus with respect to the threshold current.
184
+
185
+ Args:
186
+
187
+ dt: The time step of the stimulus.
188
+ pre_delay: The delay before the start of the step.
189
+ duration: The duration of the step.
190
+ post_delay: The time to wait after the end of the step.
191
+ threshold_current: The threshold current of the Cell.
192
+ threshold_percentage: Percentage of desired threshold_current amplification.
193
+ """
194
+ amplitude = threshold_current * threshold_percentage / 100
195
+ res = cls.amplitude_based(
196
+ dt,
197
+ pre_delay=pre_delay,
198
+ duration=duration,
199
+ post_delay=post_delay,
200
+ amplitude=amplitude,
201
+ )
202
+ return res
203
+
204
+
205
+ class Ramp(Stimulus):
206
+
207
+ def __init__(self):
208
+ raise NotImplementedError(
209
+ "This class cannot be instantiated directly. "
210
+ "Please use the class methods 'amplitude_based' "
211
+ "or 'threshold_based' to create objects."
212
+ )
213
+
214
+ @classmethod
215
+ def amplitude_based(
216
+ cls,
217
+ dt: float,
218
+ pre_delay: float,
219
+ duration: float,
220
+ post_delay: float,
221
+ amplitude: float,
222
+ ) -> CombinedStimulus:
223
+ """Create a Ramp stimulus from given time events and amplitudes.
224
+
225
+ Args:
226
+ dt: The time step of the stimulus.
227
+ pre_delay: The delay before the start of the ramp.
228
+ duration: The duration of the ramp.
229
+ post_delay: The time to wait after the end of the ramp.
230
+ amplitude: The final amplitude of the ramp.
231
+ """
232
+ return (
233
+ Empty(dt, duration=pre_delay)
234
+ + Slope(
235
+ dt,
236
+ duration=duration,
237
+ amplitude_start=0.0,
238
+ amplitude_end=amplitude,
239
+ )
240
+ + Empty(dt, duration=post_delay)
241
+ )
242
+
243
+ @classmethod
244
+ def threshold_based(
245
+ cls,
246
+ dt: float,
247
+ pre_delay: float,
248
+ duration: float,
249
+ post_delay: float,
250
+ threshold_current: float,
251
+ threshold_percentage: float,
252
+ ) -> CombinedStimulus:
253
+ """Creates a Ramp stimulus with respect to the threshold current.
254
+
255
+ Args:
256
+
257
+ dt: The time step of the stimulus.
258
+ pre_delay: The delay before the start of the ramp.
259
+ duration: The duration of the ramp.
260
+ post_delay: The time to wait after the end of the ramp.
261
+ threshold_current: The threshold current of the Cell.
262
+ threshold_percentage: Percentage of desired threshold_current amplification.
263
+ """
264
+ amplitude = threshold_current * threshold_percentage / 100
265
+ res = cls.amplitude_based(
266
+ dt,
267
+ pre_delay=pre_delay,
268
+ duration=duration,
269
+ post_delay=post_delay,
270
+ amplitude=amplitude,
271
+ )
272
+ return res
273
+
274
+
160
275
  class StimulusFactory:
161
276
  def __init__(self, dt: float):
162
277
  self.dt = dt
163
278
 
164
- def step(self, start: float, end: float, amplitude: float) -> Stimulus:
165
- return Step(self.dt, start, end, amplitude)
279
+ def step(
280
+ self, pre_delay: float, duration: float, post_delay: float, amplitude: float
281
+ ) -> Stimulus:
282
+ return Step.amplitude_based(
283
+ self.dt,
284
+ pre_delay=pre_delay,
285
+ duration=duration,
286
+ post_delay=post_delay,
287
+ amplitude=amplitude,
288
+ )
166
289
 
167
290
  def ramp(
168
- self, start: float, end: float, amplitude_start: float, amplitude_end: float
291
+ self, pre_delay: float, duration: float, post_delay: float, amplitude: float
169
292
  ) -> Stimulus:
170
- return Ramp(self.dt, start, end, amplitude_start, amplitude_end)
293
+ return Ramp.amplitude_based(
294
+ self.dt,
295
+ pre_delay=pre_delay,
296
+ duration=duration,
297
+ post_delay=post_delay,
298
+ amplitude=amplitude,
299
+ )
171
300
 
172
301
  def ap_waveform(
173
- self,
174
- threshold_current: float,
175
- threshold_percentage: float = 220.0,
176
- start: float = 250.0,
177
- end: float = 300.0,
178
- post_wait: float = 250.0,
302
+ self, threshold_current: float, threshold_percentage: float = 220.0
179
303
  ) -> Stimulus:
180
304
  """Returns the APWaveform Stimulus object, a type of Step stimulus.
181
305
 
182
306
  Args:
183
307
  threshold_current: The threshold current of the Cell.
184
308
  threshold_percentage: Percentage of desired threshold_current amplification.
185
- start: The start time of the step.
186
- end: The end time of the step.
187
- post_wait: The time to wait after the end of the step.
188
309
  """
310
+ pre_delay = 250.0
311
+ duration = 50.0
312
+ post_delay = 250.0
189
313
  return Step.threshold_based(
190
- self.dt, threshold_current, threshold_percentage, start, end, post_wait
314
+ self.dt,
315
+ pre_delay=pre_delay,
316
+ duration=duration,
317
+ post_delay=post_delay,
318
+ threshold_current=threshold_current,
319
+ threshold_percentage=threshold_percentage,
191
320
  )
192
321
 
193
322
  def idrest(
194
323
  self,
195
324
  threshold_current: float,
196
325
  threshold_percentage: float = 200.0,
197
- start: float = 250.0,
198
- end: float = 1600.0,
199
- post_wait: float = 250.0,
200
326
  ) -> Stimulus:
201
327
  """Returns the IDRest Stimulus object, a type of Step stimulus.
202
328
 
203
329
  Args:
204
330
  threshold_current: The threshold current of the Cell.
205
331
  threshold_percentage: Percentage of desired threshold_current amplification.
206
- start: The start time of the step.
207
- end: The end time of the step.
208
- post_wait: The time to wait after the end of the step.
209
332
  """
333
+ pre_delay = 250.0
334
+ duration = 1350.0
335
+ post_delay = 250.0
210
336
  return Step.threshold_based(
211
- self.dt, threshold_current, threshold_percentage, start, end, post_wait
337
+ self.dt,
338
+ pre_delay=pre_delay,
339
+ duration=duration,
340
+ post_delay=post_delay,
341
+ threshold_current=threshold_current,
342
+ threshold_percentage=threshold_percentage,
212
343
  )
213
344
 
214
345
  def iv(
215
346
  self,
216
347
  threshold_current: float,
217
348
  threshold_percentage: float = -40.0,
218
- start: float = 250.0,
219
- end: float = 3250.0,
220
- post_wait: float = 250.0,
221
349
  ) -> Stimulus:
222
350
  """Returns the IV Stimulus object, a type of Step stimulus.
223
351
 
224
352
  Args:
225
353
  threshold_current: The threshold current of the Cell.
226
354
  threshold_percentage: Percentage of desired threshold_current amplification.
227
- start: The start time of the step.
228
- end: The end time of the step.
229
- post_wait: The time to wait after the end of the step.
230
355
  """
356
+ pre_delay = 250.0
357
+ duration = 3000.0
358
+ post_delay = 250.0
231
359
  return Step.threshold_based(
232
- self.dt, threshold_current, threshold_percentage, start, end, post_wait
360
+ self.dt,
361
+ pre_delay=pre_delay,
362
+ duration=duration,
363
+ post_delay=post_delay,
364
+ threshold_current=threshold_current,
365
+ threshold_percentage=threshold_percentage,
233
366
  )
234
367
 
235
368
  def fire_pattern(
236
369
  self,
237
370
  threshold_current: float,
238
371
  threshold_percentage: float = 200.0,
239
- start: float = 250.0,
240
- end: float = 3850.0,
241
- post_wait: float = 250.0,
242
372
  ) -> Stimulus:
243
373
  """Returns the FirePattern Stimulus object, a type of Step stimulus.
244
374
 
245
375
  Args:
246
376
  threshold_current: The threshold current of the Cell.
247
377
  threshold_percentage: Percentage of desired threshold_current amplification.
248
- start: The start time of the step.
249
- end: The end time of the step.
250
- post_wait: The time to wait after the end of the step.
251
378
  """
379
+ pre_delay = 250.0
380
+ duration = 3600.0
381
+ post_delay = 250.0
252
382
  return Step.threshold_based(
253
- self.dt, threshold_current, threshold_percentage, start, end, post_wait
383
+ self.dt,
384
+ pre_delay=pre_delay,
385
+ duration=duration,
386
+ post_delay=post_delay,
387
+ threshold_current=threshold_current,
388
+ threshold_percentage=threshold_percentage,
254
389
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bluecellulab
3
- Version: 2.5.11
3
+ Version: 2.6.0
4
4
  Summary: Biologically detailed neural network simulations and analysis.
5
5
  Author: Blue Brain Project, EPFL
6
6
  License: Apache2.0
@@ -15,7 +15,7 @@ bluecellulab/type_aliases.py,sha256=DvgjERv2Ztdw_sW63JrZTQGpJ0x5uMTFB5hcBHDb0WA,
15
15
  bluecellulab/utils.py,sha256=SbOOkzw1YGjCKV3qOw0zpabNEy7V9BRtgMLsQJiFRq4,1526
16
16
  bluecellulab/verbosity.py,sha256=T0IgX7DrRo19faxrT4Xzb27gqxzoILQ8FzYKxvUeaPM,1342
17
17
  bluecellulab/analysis/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
- bluecellulab/analysis/inject_sequence.py,sha256=sL8G01uYzPohLkh1BT_8op2vHbSFx1_MlRgj2dY1cWs,4944
18
+ bluecellulab/analysis/inject_sequence.py,sha256=qr3N1tQX4avvKzFBT0L7W6LnSgk2y_P_7Yhy0UjlGmk,4769
19
19
  bluecellulab/cell/__init__.py,sha256=Sbc0QOsJ8E7tSwf3q7fsXuE_SevBN6ZmoCVyyU5zfII,208
20
20
  bluecellulab/cell/cell_dict.py,sha256=PVmZsjhZ9jp3HC-8QmdFqp-crAcVMSVeLWujcOPLlpo,1346
21
21
  bluecellulab/cell/core.py,sha256=MtrVQAxT82dc9uQuWZyTQfc6Oczrnc_y_9hcyBqUT7w,31467
@@ -58,13 +58,13 @@ bluecellulab/simulation/parallel.py,sha256=xmlIelxYNct-vGhPip7_vF9gwyehdpomYB8kf
58
58
  bluecellulab/simulation/simulation.py,sha256=I__cZwV_A8I7XSefn6aJDBA_jXCI3E35-pCNCLUsnvo,6206
59
59
  bluecellulab/stimulus/__init__.py,sha256=DgIgVaSyR-URf3JZzvO6j-tjCerzvktuK-ep8pjMRPQ,37
60
60
  bluecellulab/stimulus/circuit_stimulus_definitions.py,sha256=uij_s44uNdmMwMLGmTHSRgmp9K9B_vvHHshX6YPJNJU,15686
61
- bluecellulab/stimulus/factory.py,sha256=AOby3Sp2g8BJsRccz3afazfCyysyWIgLtcliWlyeiu0,8097
61
+ bluecellulab/stimulus/factory.py,sha256=cjnMqFx-Y31kV1XHvkSbGI2f1OpEawU3Wg_cLqcIyRc,11883
62
62
  bluecellulab/synapse/__init__.py,sha256=RW8XoAMXOvK7OG1nHl_q8jSEKLj9ZN4oWf2nY9HAwuk,192
63
63
  bluecellulab/synapse/synapse_factory.py,sha256=YkvxbdGF-u-vxYdbRNTlX-9AtSC_3t_FQRFhybwzgrk,6805
64
64
  bluecellulab/synapse/synapse_types.py,sha256=4gne-hve2vq1Lau-LAVPsfLjffVYqAYBW3kCfC7_600,16871
65
- bluecellulab-2.5.11.dist-info/AUTHORS.txt,sha256=EDs3H-2HXBojbma10psixk3C2rFiOCTIREi2ZAbXYNQ,179
66
- bluecellulab-2.5.11.dist-info/LICENSE,sha256=xOouu1gC1GGklDxkITlaVl60I9Ab860O-nZsFbWydvU,11749
67
- bluecellulab-2.5.11.dist-info/METADATA,sha256=rE7_kRYFnhuy1_9tiArH9zPRCYt2F5SmiIXbnO3GOZo,7026
68
- bluecellulab-2.5.11.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
69
- bluecellulab-2.5.11.dist-info/top_level.txt,sha256=VSyEP8w9l3pXdRkyP_goeMwiNA8KWwitfAqUkveJkdQ,13
70
- bluecellulab-2.5.11.dist-info/RECORD,,
65
+ bluecellulab-2.6.0.dist-info/AUTHORS.txt,sha256=EDs3H-2HXBojbma10psixk3C2rFiOCTIREi2ZAbXYNQ,179
66
+ bluecellulab-2.6.0.dist-info/LICENSE,sha256=xOouu1gC1GGklDxkITlaVl60I9Ab860O-nZsFbWydvU,11749
67
+ bluecellulab-2.6.0.dist-info/METADATA,sha256=X-XmGZmXo-FZIe6H5r0qIs-VBJnTN0zNVOXNVuiLW0M,7025
68
+ bluecellulab-2.6.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
69
+ bluecellulab-2.6.0.dist-info/top_level.txt,sha256=VSyEP8w9l3pXdRkyP_goeMwiNA8KWwitfAqUkveJkdQ,13
70
+ bluecellulab-2.6.0.dist-info/RECORD,,