@@ -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 ())]
0 commit comments