def test_v_and_t_are_arrays(): v = [0, 1, 2] t = [0, 1, 2] with pytest.raises(TypeError): ft.detect_putative_spikes(v, t) with pytest.raises(TypeError): ft.detect_putative_spikes(np.array(v), t)
def test_v_and_t_are_arrays(): v = [0, 1, 2] t = [0, 1, 2] with pytest.raises(TypeError): ft.detect_putative_spikes(v, t) with pytest.raises(TypeError): ft.detect_putative_spikes(np.array(v), t)
def test_detect_two_spikes(): data = np.loadtxt(os.path.join(path, "data/spike_test_pair.txt")) t = data[:, 0] v = data[:, 1] expected_spikes = np.array([728, 3386]) assert np.allclose(ft.detect_putative_spikes(v, t), expected_spikes)
def test_detect_two_spikes(): data = np.loadtxt(os.path.join(path, "data/spike_test_pair.txt")) t = data[:, 0] v = data[:, 1] expected_spikes = np.array([728, 3386]) assert np.allclose(ft.detect_putative_spikes(v, t), expected_spikes)
def test_detect_one_spike(): data = np.loadtxt(os.path.join(path, "data/spike_test_pair.txt")) t = data[:, 0] v = data[:, 1] expected_spikes = np.array([728]) assert np.allclose(ft.detect_putative_spikes(v[:3000], t[:3000]), expected_spikes)
def test_detect_one_spike(): data = np.loadtxt(os.path.join(path, "data/spike_test_pair.txt")) t = data[:, 0] v = data[:, 1] expected_spikes = np.array([728]) assert np.allclose(ft.detect_putative_spikes(v[:3000], t[:3000]), expected_spikes)
def get_spike_counts(self, voltage, neuron, cutoff): time = np.arange(1, 50001, step=1) * neuron.dt spike_indices = detect_putative_spikes(voltage, time, dv_cutoff=cutoff) spike_counts = len(spike_indices) return spike_indices, spike_counts
def test_biophysical_peri(): """ Test for backward compatibility of the perisomatic models """ subprocess.check_call(['nrnivmodl', 'modfiles/']) description = Config().load('manifest.json') utils = Utils(description) h = utils.h manifest = description.manifest morphology_path = manifest.get_path('MORPHOLOGY') utils.generate_morphology( morphology_path.encode('ascii', 'ignore').decode("utf-8")) utils.load_cell_parameters() stim = h.IClamp(h.soma[0](0.5)) stim.amp = 0.35 # Sweep 47 stim.delay = 1000.0 stim.dur = 1000.0 h.tstop = 3000.0 vec = utils.record_values() h.finitialize() h.run() junction_potential = description.data['fitting'][0]['junction_potential'] ms = 1.0e-3 output_data = (numpy.array(vec['v']) - junction_potential) # in mV output_times = numpy.array(vec['t']) * ms # in s output_path = 'output_voltage.dat' DatUtilities.save_voltage(output_path, output_data, output_times) num_spikes = len( ephys_features.detect_putative_spikes(output_data, output_times)) assert num_spikes == 27 # taken from the web app
def main(modelID): print "Loading parameters for model", modelID selection=raw_input('Would you like to download NWB data for model? [Y/N] ') if selection[0] == 'y' or selection[0] == 'Y': currModel = Model(modelID, cache_stim = True) if selection[0] == 'n' or selection[0] == 'N': currModel = Model(modelID, cache_stim = False) currModel.init_model() while(True): print "Initialized biophysical model", modelID print ''' Please select from the following options: 1 - Run test pulse on model 2 - Fit model parameter to data 3 - Display static neuron model 4 - Visualize model dynamics 5 - Quit ''' try: selection=int(raw_input('Please choose an option above: ')) except ValueError: print "Invalid selection." continue # test pulse example if selection == 1: # Run the model with a test pulse of the 'long square' type print "Running model with a long square current injection pulse of 210pA" output = currModel.long_square(0.21) currModel.plot_output() # fit parameter example elif selection == 2: if not currModel.bp.cache_stimulus: print "Current model was not instantiated with NWB data cached. Please reload the current model and cache experimental stimulus data." continue print "Fitting somatic sodium conductance for model", modelID, "to experimental data in sweep 41." print "Please be patient, this may take some time." # Define which section and which parameter to fit. # Here we'll fit the somatic sodium conductance. currModel.set_fit_section('soma', 0) currModel.set_parameter_to_fit('gbar_NaV') # Running the model with an NWB pulse as stimulus takes a # very long time because of the high sampling rate. # As a computationally-cheaper approximation for stimuli of # type Long Square pulse, we can rebuild the stimulus with the # default (lower) sampling rate in h.IClamp # currModel.run_nwb_pulse(41) # too slow output = currModel.long_square(0.21) # Set the experimental reference sweep and set up the variables for the objective function currModel.set_reference_sweep(ref_index=41) currModel.set_up_objective(measure='spike frequency') # Use SciPy's minimize functions to fit the specified parameter #results = minimize(currModel.objective_function, currModel.theta, method='Nelder-Mead', tol=1e-3) #results = minimize(currModel.objective_function, currModel.theta, method='Powell', tol=1e-3) #results = minimize(currModel.objective_function, currModel.theta, method='COBYLA', tol=1e-5) currModel.gradient_descent(alpha=0.00005, epsilon=0.001, threshold=0.01, max_cycles=1000) currModel.plot_fit() output = currModel.long_square(0.21) currModel.plot_output() times = np.array(output['t'])/1000 spikes = detect_putative_spikes(np.array(output['v']), times, 0.1, 1.1) avg_rate = currModel.average_rate_from_delays(times, spikes, 0.1, 1.1) print "spike rate for theta of", currModel.theta, ":", avg_rate # static visualization example elif selection == 3: run_visualization(currModel) elif selection == 4: run_visualization(currModel, show_simulation_dynamics = True) elif selection == 5: quit() else: print "Invalid selection." continue
def test_size_mismatch(): v = np.array([0, 1, 2]) t = np.array([0, 1]) with pytest.raises(ft.FeatureError): ft.detect_putative_spikes(v, t)
def test_detect_no_spikes(): data = np.loadtxt(os.path.join(path, "data/spike_test_pair.txt")) t = data[:, 0] v = np.zeros_like(t) assert len(ft.detect_putative_spikes(v, t)) == 0
def test_size_mismatch(): v = np.array([0, 1, 2]) t = np.array([0, 1]) with pytest.raises(ft.FeatureError): ft.detect_putative_spikes(v, t)
def test_detect_no_spikes(): data = np.loadtxt(os.path.join(path, "data/spike_test_pair.txt")) t = data[:, 0] v = np.zeros_like(t) assert len(ft.detect_putative_spikes(v, t)) == 0