Skip to content

Commit ee2e091

Browse files
authored
Merge pull request #245 from NeuroML/experimental
To v1.0.9
2 parents 5a40aee + 4140b29 commit ee2e091

File tree

12 files changed

+1279
-987
lines changed

12 files changed

+1279
-987
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,5 @@ arm64
155155
*.neux
156156
/test_*plot*png
157157
/examples/plot.py
158+
/tests/utils/test_rotation.net.nml
159+
/tests/utils/test_rotation.net.png

examples/generate_if_curve.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
plot_voltage_traces=not nogui,
1717
plot_if=not nogui,
1818
plot_iv=not nogui,
19+
save_if_data_to="if_data.dat"
1920
)

pyneuroml/analysis/__init__.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,28 @@ def generate_current_vs_frequency_curve(
6060
segment_id: typing.Optional[str] = None,
6161
fraction_along: typing.Optional[float] = None
6262
):
63-
"""Generate current vs firing rate frequency curve for provided cell.
63+
"""Generate current vs firing rate frequency curves for provided cell.
64+
65+
It runs a number of simulations of the cell with different input currents,
66+
and generates the following metrics/graphs:
67+
68+
- sub-threshold potentials for all currents
69+
- F-I curve for the cell
70+
- membrane potential traces for each stimulus
71+
72+
Using the method arguments, these graphs and the data they are generated
73+
from may be enabled/disabled/saved.
74+
75+
When the I-F curve plotting is enabled, it also notes the spiking threshold
76+
current value in a file. Note that this value is simply the lowest input
77+
stimulus current at which spiking was detected, so should be taken as an
78+
approximate value. It does not, for example, implement a bisection based
79+
method to find the accurate spiking threshold current. This is also true
80+
for the I-F curves: the resolution is constrained by the values of the
81+
stimulus currents.
82+
83+
The various plotting related arguments to this method are passed on to
84+
:py:method`pynml.generate_plot`
6485
6586
:param nml2_file: name of NeuroML file containing cell definition
6687
:type nml2_file: str
@@ -303,6 +324,10 @@ def generate_current_vs_frequency_curve(
303324
volts_labels = []
304325
if_results = {}
305326
iv_results = {}
327+
328+
# arbitrarily large value to start with
329+
spike_threshold_current = float(math.inf)
330+
306331
for i in range(number_cells):
307332
t = np.array(results["t"]) * 1000
308333
v = np.array(results["%s[%i]/v" % (pop.id, i)]) * 1000
@@ -315,6 +340,7 @@ def generate_current_vs_frequency_curve(
315340
mm = max_min(v, t, delta=0, peak_threshold=spike_threshold_mV)
316341
spike_times = mm["maxima_times"]
317342
freq = 0.0
343+
318344
if len(spike_times) > 2:
319345
count = 0
320346
for s in spike_times:
@@ -323,6 +349,9 @@ def generate_current_vs_frequency_curve(
323349
):
324350
count += 1
325351
freq = 1000 * count / float(analysis_duration)
352+
if count > 0:
353+
if stims[i] < spike_threshold_current:
354+
spike_threshold_current = stims[i]
326355

327356
mean_freq = mean_spike_frequency(spike_times)
328357
logger.debug(
@@ -399,6 +428,8 @@ def generate_current_vs_frequency_curve(
399428
with open(save_if_data_to, "w") as if_file:
400429
for i in range(len(stims_pA)):
401430
if_file.write("%s\t%s\n" % (stims_pA[i], freqs[i]))
431+
with open(f"threshold_i_{save_if_data_to}", "w") as if_file:
432+
print(spike_threshold_current, file=if_file)
402433
if plot_iv:
403434
stims = sorted(iv_results.keys())
404435
stims_pA = [ii * 1000 for ii in sorted(iv_results.keys())]

pyneuroml/plot/Plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import typing
1313
import matplotlib
1414
import matplotlib.axes
15-
import plotly.graph_objects as go
1615

1716
logger = logging.getLogger(__name__)
1817
logger.setLevel(logging.INFO)
@@ -374,6 +373,7 @@ def generate_interactive_plot(
374373
Note: you can also save the file from the interactive web page.
375374
:type save_figure_to: str
376375
"""
376+
import plotly.graph_objects as go
377377
fig = go.Figure()
378378

379379
if len(xvalues) != len(yvalues):

0 commit comments

Comments
 (0)