Exemplo n.º 1
0
def test_extractor_on_zero_voltage():
    t = np.arange(0, 4000) * 2e-5

    v = np.zeros_like(t)
    i = np.zeros_like(t)

    ext = SpikeFeatureExtractor()
    ext.process(t, v, i)
Exemplo n.º 2
0
def test_extractor_on_sample_data(spike_test_pair):
    data = spike_test_pair

    t = data[:, 0]
    v = data[:, 1]

    ext = SpikeFeatureExtractor()
    spikes = ext.process(t=t, v=v, i=None)

    sx = SpikeTrainFeatureExtractor(start=0, end=t[-1])
    sx.process(t=t, v=v, i=None, spikes_df=spikes)
Exemplo n.º 3
0
def test_extractor_with_high_init_dvdt(spike_test_high_init_dvdt):
    data = spike_test_high_init_dvdt

    t = data[:, 0]
    v = data[:, 1]

    ext = SpikeFeatureExtractor()
    spikes = ext.process(t, v, i=None)

    expected_thresh_ind = np.array([11222, 16258, 24060])
    assert np.allclose(spikes["threshold_index"].values, expected_thresh_ind)
Exemplo n.º 4
0
def test_extractor_on_variable_time_step(spike_test_var_dt):
    data = spike_test_var_dt

    t = data[:, 0]
    v = data[:, 1]

    ext = SpikeFeatureExtractor()
    spikes = ext.process(t, v, i=None)

    expected_thresh_ind = np.array([73, 183, 314, 463, 616, 770])
    assert np.allclose(spikes["threshold_index"].values, expected_thresh_ind)
Exemplo n.º 5
0
def test_extractor_on_sample_data_with_i(spike_test_pair):
    data = spike_test_pair

    t = data[:, 0]
    v = data[:, 1]
    i = np.zeros_like(v)

    ext = SpikeFeatureExtractor()
    spikes = ext.process(t, v, i)

    sx = SpikeTrainFeatureExtractor(start=0, end=t[-1])
    sx.process(t, v, i, spikes)
Exemplo n.º 6
0
def test_extractor_wrong_inputs(spike_test_pair):
    data = spike_test_pair

    t = data[:, 0]
    v = data[:, 1]
    i = np.zeros_like(v)

    ext = SpikeFeatureExtractor()

    with pytest.raises(IndexError):
        ext.process([t], v, i)

    with pytest.raises(IndexError):
        ext.process([t], [v], i)

    with pytest.raises(ValueError):
        ext.process([t, t], [v], [i])

    with pytest.raises(ValueError):
        ext.process([t, t], [v, v], [i])
Exemplo n.º 7
0
def get_lsa_results(sweep_set, start_time, end_time, subthresh_min_amp=-500):
    spike_extractor = SpikeFeatureExtractor(start=start_time,
                                            end=end_time,
                                            filter=bessel_filter_khz)
    spike_train_extractor = SpikeTrainFeatureExtractor(start=start_time,
                                                       end=end_time,
                                                       baseline_interval=.05)

    # Create the analysis object
    lsa = LongSquareAnalysis(spx=spike_extractor,
                             sptx=spike_train_extractor,
                             subthresh_min_amp=subthresh_min_amp)
    lsa_results = lsa.analyze(sweep_set)
    return lsa_results
Exemplo n.º 8
0
nwb_file = os.path.join(os.path.dirname(os.getcwd()), "data",
                        "nwb2_H17.03.008.11.03.05.nwb")

# Create data set from the nwb file and find the short squares
data_set = create_data_set(nwb_file=nwb_file)

# Drop failed sweeps: sweeps with incomplete recording or failing QC criteria
drop_failed_sweeps(data_set)

short_square_table = data_set.filtered_sweep_table(stimuli=["Short Square"])
ssq_set = data_set.sweep_set(short_square_table.sweep_number)

# estimate the dv cutoff and threshold fraction
dv_cutoff, thresh_frac = estimate_adjusted_detection_parameters(
    ssq_set.v, ssq_set.t, 1.02, 1.021)

# detect spikes  in a given sweep number
sweep_number = 16
sweep = data_set.sweep(sweep_number)
ext = SpikeFeatureExtractor(dv_cutoff=dv_cutoff, thresh_frac=thresh_frac)
spikes = ext.process(t=sweep.t, v=sweep.v, i=sweep.i)

# and plot them
plt.plot(sweep.t, sweep.v)
plt.plot(spikes["peak_t"], spikes["peak_v"], 'r.')
plt.plot(spikes["threshold_t"], spikes["threshold_v"], 'k.')
plt.xlim(1.018, 1.028)
plt.xlabel('Time (s)')
plt.ylabel('Membrane potential (mV)')
plt.show()
Exemplo n.º 9
0
def long_square_analysis():
    # build the extractors
    spx = SpikeFeatureExtractor(start=0.27, end=1.27)
    spfx = SpikeTrainFeatureExtractor(start=0.27, end=1.27)
    return LongSquareAnalysis(spx, spfx, subthresh_min_amp=-100.0)
Exemplo n.º 10
0
# Download and access the experimental data from DANDI archive per instructions in the documentation
# Example below will use an nwb file provided with the package

nwb_file = os.path.join(
    os.path.dirname(os.getcwd()),
    "data",
    "nwb2_H17.03.008.11.03.05.nwb"
)

# Create data set from the nwb file and choose a sweeep
dataset = create_ephys_data_set(nwb_file=nwb_file)
sweep = dataset.sweep(sweep_number=39)

# Configure the extractor to just detect spikes in the middle of the step
ext = SpikeFeatureExtractor(start=1.25, end=1.75)
results = ext.process(t=sweep.t, v=sweep.v, i=sweep.i)

# Plot the results, showing two features of the detected spikes
plt.plot(sweep.t, sweep.v)
plt.plot(results["peak_t"], results["peak_v"], 'r.')
plt.plot(results["threshold_t"], results["threshold_v"], 'k.')

# Set the plot limits to highlight where spikes are and axis labels
plt.xlim(0.5, 2.5)
plt.xlabel("Time (s)")
plt.ylabel("Membrane potential (mV)")

# Show the analysis window on the plot
plt.axvline(1.25, linestyle="dotted", color="gray")
plt.axvline(1.75, linestyle="dotted", color="gray")
Exemplo n.º 11
0
# (treating the first sweep as representative)
stim_start_index, stim_end_index = get_stim_epoch(short_square_sweeps.i[0])
stim_start_time = short_square_sweeps.t[0][stim_start_index]
stim_end_time = short_square_sweeps.t[0][stim_end_index]

# Estimate the dv cutoff and threshold fraction
dv_cutoff, thresh_frac = estimate_adjusted_detection_parameters(
    short_square_sweeps.v,
    short_square_sweeps.t,
    stim_start_time,
    stim_start_time + 0.001
)

# Build the extractors
spfx = SpikeFeatureExtractor(
    start=stim_start_time, dv_cutoff=dv_cutoff, thresh_frac=thresh_frac
)
sptfx= SpikeTrainFeatureExtractor(start=stim_start_time, end=None)

# Run the analysis
short_square_analysis = ShortSquareAnalysis(spfx, sptfx)
results = short_square_analysis.analyze(short_square_sweeps)

# Plot the sweeps at the lowest amplitude that evoked the most spikes
for i, swp in enumerate(short_square_sweeps.sweeps):
    if i in results["common_amp_sweeps"].index:
        plt.plot(swp.t, swp.v, linewidth=0.5, color="steelblue")

# Set the plot limits to highlight where spikes are and axis labels
plt.xlim(stim_start_time - 0.05, stim_end_time + 0.05)
plt.xlabel("Time (s)")
Exemplo n.º 12
0
def test_extractors_no_values():

    SpikeFeatureExtractor()
    SpikeTrainFeatureExtractor(start=0, end=0)
Exemplo n.º 13
0
    stimuli=data_set.ontology.long_square_names)
long_square_sweeps = data_set.sweep_set(long_square_table.sweep_number)

# Select epoch corresponding to the actual recording from the sweeps
# and align sweeps so that the experiment would start at the same time
long_square_sweeps.select_epoch("recording")
long_square_sweeps.align_to_start_of_epoch("experiment")

# find the start and end time of the stimulus
# (treating the first sweep as representative)
stim_start_index, stim_end_index = get_stim_epoch(long_square_sweeps.i[0])
stim_start_time = long_square_sweeps.t[0][stim_start_index]
stim_end_time = long_square_sweeps.t[0][stim_end_index]

# build the extractors
spfx = SpikeFeatureExtractor(start=stim_start_time, end=stim_end_time)
sptfx = SpikeTrainFeatureExtractor(start=stim_start_time, end=stim_end_time)

# run the analysis and print out a few of the features
long_square_analysis = spa.LongSquareAnalysis(spfx,
                                              sptfx,
                                              subthresh_min_amp=-100.0)
data = long_square_analysis.analyze(long_square_sweeps)

fields_to_print = [
    'tau', 'v_baseline', 'input_resistance', 'vm_for_sag', 'fi_fit_slope',
    'sag', 'rheobase_i'
]

for field in fields_to_print:
    print("%s: %s" % (field, str(data[field])))
Exemplo n.º 14
0
# Download and access the experimental data from DANDI archive per instructions in the documentation
# Example below will use an nwb file provided with the package

nwb_file = os.path.join(
    os.path.dirname(os.getcwd()),
    "data",
    "nwb2_H17.03.008.11.03.05.nwb"
)

# Create data set from the nwb file and choose a sweeep
dataset = create_ephys_data_set(nwb_file=nwb_file)
sweep = dataset.sweep(sweep_number=39)

# Extract information about the spikes
ext = SpikeFeatureExtractor()
results = ext.process(t=sweep.t, v=sweep.v, i=sweep.i)

# Plot the results, showing two features of the detected spikes
plt.plot(sweep.t, sweep.v)
plt.plot(results["peak_t"], results["peak_v"], 'r.')
plt.plot(results["threshold_t"], results["threshold_v"], 'k.')

# Set the plot limits to highlight where spikes are and set axis labels
plt.xlim(0.5, 2.5)
plt.xlabel("Time (s)")
plt.ylabel("Membrane potential (mV)")

plt.show()

Exemplo n.º 15
0
# and align sweeps so that the experiment would start at the same time
ramp_sweeps.select_epoch("recording")
ramp_sweeps.align_to_start_of_epoch("experiment")

# Select epoch corresponding to the actual recording from the sweeps
# and align sweeps so that the experiment would start at the same time
ramp_sweeps.select_epoch("recording")
ramp_sweeps.align_to_start_of_epoch("experiment")

# find the start and end time of the stimulus
# (treating the first sweep as representative)
stim_start_index, stim_end_index = get_stim_epoch(ramp_sweeps.i[0])
stim_start_time = ramp_sweeps.t[0][stim_start_index]
stim_end_time = ramp_sweeps.t[0][stim_end_index]

spx = SpikeFeatureExtractor(start=stim_start_time, end=None)
sptfx = SpikeTrainFeatureExtractor(start=stim_start_time, end=None)

# Run the analysis
ramp_analysis = RampAnalysis(spx, sptfx)
results = ramp_analysis.analyze(ramp_sweeps)

# Plot the sweeps and the latency to the first spike of each
sns.set_style("white")
for swp in ramp_sweeps.sweeps:
    plt.plot(swp.t, swp.v, linewidth=0.5)
sns.rugplot(results["spiking_sweeps"]["latency"].values + stim_start_time)

# Set the plot limits to highlight where spikes are and axis labels
plt.xlim(stim_start_time, stim_end_time)
plt.xlabel("Time (s)")