Skip to content

Commit

Permalink
Merge pull request #245 from NeuroML/experimental
Browse files Browse the repository at this point in the history
To v1.0.9
  • Loading branch information
pgleeson authored Aug 9, 2023
2 parents 5a40aee + 4140b29 commit ee2e091
Show file tree
Hide file tree
Showing 12 changed files with 1,279 additions and 987 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,5 @@ arm64
*.neux
/test_*plot*png
/examples/plot.py
/tests/utils/test_rotation.net.nml
/tests/utils/test_rotation.net.png
1 change: 1 addition & 0 deletions examples/generate_if_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
plot_voltage_traces=not nogui,
plot_if=not nogui,
plot_iv=not nogui,
save_if_data_to="if_data.dat"
)
33 changes: 32 additions & 1 deletion pyneuroml/analysis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,28 @@ def generate_current_vs_frequency_curve(
segment_id: typing.Optional[str] = None,
fraction_along: typing.Optional[float] = None
):
"""Generate current vs firing rate frequency curve for provided cell.
"""Generate current vs firing rate frequency curves for provided cell.
It runs a number of simulations of the cell with different input currents,
and generates the following metrics/graphs:
- sub-threshold potentials for all currents
- F-I curve for the cell
- membrane potential traces for each stimulus
Using the method arguments, these graphs and the data they are generated
from may be enabled/disabled/saved.
When the I-F curve plotting is enabled, it also notes the spiking threshold
current value in a file. Note that this value is simply the lowest input
stimulus current at which spiking was detected, so should be taken as an
approximate value. It does not, for example, implement a bisection based
method to find the accurate spiking threshold current. This is also true
for the I-F curves: the resolution is constrained by the values of the
stimulus currents.
The various plotting related arguments to this method are passed on to
:py:method`pynml.generate_plot`
:param nml2_file: name of NeuroML file containing cell definition
:type nml2_file: str
Expand Down Expand Up @@ -303,6 +324,10 @@ def generate_current_vs_frequency_curve(
volts_labels = []
if_results = {}
iv_results = {}

# arbitrarily large value to start with
spike_threshold_current = float(math.inf)

for i in range(number_cells):
t = np.array(results["t"]) * 1000
v = np.array(results["%s[%i]/v" % (pop.id, i)]) * 1000
Expand All @@ -315,6 +340,7 @@ def generate_current_vs_frequency_curve(
mm = max_min(v, t, delta=0, peak_threshold=spike_threshold_mV)
spike_times = mm["maxima_times"]
freq = 0.0

if len(spike_times) > 2:
count = 0
for s in spike_times:
Expand All @@ -323,6 +349,9 @@ def generate_current_vs_frequency_curve(
):
count += 1
freq = 1000 * count / float(analysis_duration)
if count > 0:
if stims[i] < spike_threshold_current:
spike_threshold_current = stims[i]

mean_freq = mean_spike_frequency(spike_times)
logger.debug(
Expand Down Expand Up @@ -399,6 +428,8 @@ def generate_current_vs_frequency_curve(
with open(save_if_data_to, "w") as if_file:
for i in range(len(stims_pA)):
if_file.write("%s\t%s\n" % (stims_pA[i], freqs[i]))
with open(f"threshold_i_{save_if_data_to}", "w") as if_file:
print(spike_threshold_current, file=if_file)
if plot_iv:
stims = sorted(iv_results.keys())
stims_pA = [ii * 1000 for ii in sorted(iv_results.keys())]
Expand Down
2 changes: 1 addition & 1 deletion pyneuroml/plot/Plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import typing
import matplotlib
import matplotlib.axes
import plotly.graph_objects as go

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
Expand Down Expand Up @@ -374,6 +373,7 @@ def generate_interactive_plot(
Note: you can also save the file from the interactive web page.
:type save_figure_to: str
"""
import plotly.graph_objects as go
fig = go.Figure()

if len(xvalues) != len(yvalues):
Expand Down
Loading

0 comments on commit ee2e091

Please sign in to comment.