allensdk.ephys.ephys_features module

exception allensdk.ephys.ephys_features.FeatureError[source]

Bases: Exception

Generic Python-exception-derived object raised by feature detection functions.

allensdk.ephys.ephys_features.adaptation_index(isis)[source]

Calculate adaptation index of isis.

allensdk.ephys.ephys_features.analyze_trough_details(v, t, spike_indexes, peak_indexes, clipped=None, end=None, filter=10.0, heavy_filter=1.0, term_frac=0.01, adp_thresh=0.5, tol=0.5, flat_interval=0.002, adp_max_delta_t=0.005, adp_max_delta_v=10.0, dvdt=None)[source]

Analyze trough to determine if an ADP exists and whether the reset is a ‘detour’ or ‘direct’

Parameters:
vnumpy array of voltage time series in mV
tnumpy array of times in seconds
spike_indexesnumpy array of spike indexes
peak_indexesnumpy array of spike peak indexes
endend of time window (optional)
filtercutoff frequency for 4-pole low-pass Bessel filter in kHz (default 1)
heavy_filterlower cutoff frequency for 4-pole low-pass Bessel filter in kHz (default 1)
thresh_fracfraction of average upstroke for threshold calculation (optional, default 0.05)
adp_thresh: minimum dV/dt in V/s to exceed to be considered to have an ADP (optional, default 1.5)
toltolerance for evaluating whether Vm drops appreciably further after end of spike (default 1.0 mV)
flat_interval: if the trace is flat for this duration, stop looking for an ADP (default 0.002 s)
adp_max_delta_t: max possible ADP delta t (default 0.005 s)
adp_max_delta_v: max possible ADP delta v (default 10 mV)
dvdtpre-calculated time-derivative of voltage (optional)
Returns:
isi_typesnumpy array of isi reset types (direct or detour)
fast_trough_indexesnumpy array of indexes at the start of the trough (i.e. end of the spike)
adp_indexesnumpy array of adp indexes (np.nan if there was no ADP in that ISI
slow_trough_indexesnumpy array of indexes at the minimum of the slow phase of the trough

(if there wasn’t just a fast phase)

allensdk.ephys.ephys_features.average_rate(t, spikes, start, end)[source]

Calculate average firing rate during interval between start and end.

Parameters:
tnumpy array of times in seconds
spikesnumpy array of spike indexes
startstart of time window for spike detection
endend of time window for spike detection
Returns:
avg_rateaverage firing rate in spikes/sec
allensdk.ephys.ephys_features.average_voltage(v, t, start=None, end=None)[source]

Calculate average voltage between start and end.

Parameters:
vnumpy array of voltage time series in mV
tnumpy array of times in seconds
startstart of time window for spike detection (optional, default None)
endend of time window for spike detection (optional, default None)
Returns:
v_avgaverage voltage
allensdk.ephys.ephys_features.calculate_dvdt(v, t, filter=None)[source]

Low-pass filters (if requested) and differentiates voltage by time.

Parameters:
vnumpy array of voltage time series in mV
tnumpy array of times in seconds
filtercutoff frequency for 4-pole low-pass Bessel filter in kHz (optional, default None)
Returns:
dvdtnumpy array of time-derivative of voltage (V/s = mV/ms)
allensdk.ephys.ephys_features.check_thresholds_and_peaks(v, t, spike_indexes, peak_indexes, upstroke_indexes, end=None, max_interval=0.005, thresh_frac=0.05, filter=10.0, dvdt=None, tol=1.0)[source]

Validate thresholds and peaks for set of spikes

Check that peaks and thresholds for consecutive spikes do not overlap Spikes with overlapping thresholds and peaks will be merged.

Check that peaks and thresholds for a given spike are not too far apart.

Parameters:
vnumpy array of voltage time series in mV
tnumpy array of times in seconds
spike_indexesnumpy array of spike indexes
peak_indexesnumpy array of indexes of spike peaks
upstroke_indexesnumpy array of indexes of spike upstrokes
max_intervalmaximum allowed time between start of spike and time of peak in sec (default 0.005)
thresh_fracfraction of average upstroke for threshold calculation (optional, default 0.05)
filtercutoff frequency for 4-pole low-pass Bessel filter in kHz (optional, default 10)
dvdtpre-calculated time-derivative of voltage (optional)
toltolerance for returning to threshold in mV (optional, default 1)
Returns:
spike_indexesnumpy array of modified spike indexes
peak_indexesnumpy array of modified spike peak indexes
upstroke_indexesnumpy array of modified spike upstroke indexes
clippednumpy array of clipped status of spikes
allensdk.ephys.ephys_features.detect_bursts(isis, isi_types, fast_tr_v, fast_tr_t, slow_tr_v, slow_tr_t, thr_v, tol=0.5, pause_cost=1.0)[source]

Detect bursts in spike train.

Parameters:
isisnumpy array of n interspike intervals
isi_typesnumpy array of n interspike interval types
fast_tr_vnumpy array of fast trough voltages for the n + 1 spikes of the train
fast_tr_tnumpy array of fast trough times for the n + 1 spikes of the train
slow_tr_vnumpy array of slow trough voltages for the n + 1 spikes of the train
slow_tr_tnumpy array of slow trough times for the n + 1 spikes of the train
thr_vnumpy array of threshold voltages for the n + 1 spikes of the train
toltolerance for the difference in slow trough voltages and thresholds (default 0.5 mV)

Used to identify “delay” interspike intervals that occur within a burst

Returns:
burstslist of bursts

Each item in list is a tuple of the form (burst_index, start, end) where burst_index is a comparison index between the highest instantaneous rate within the burst vs the highest instantaneous rate outside the burst. start is the index of the first ISI of the burst, and end is the ISI index immediately following the burst.

allensdk.ephys.ephys_features.detect_pauses(isis, isi_types, cost_weight=1.0)[source]

Determine which ISIs are “pauses” in ongoing firing.

Pauses are unusually long ISIs with a “detour reset” among “direct resets”.

Parameters:
isisnumpy array of interspike intervals
isi_typesnumpy array of interspike interval types (‘direct’ or ‘detour’)
cost_weightweight for cost function for calling an ISI a pause

Higher cost weights lead to fewer ISIs identified as pauses. The cost function also depends on the difference between the duration of the “pause” ISIs and the average duration and standard deviation of “non-pause” ISIs.

Returns:
pausesnumpy array of indices corresponding to pauses in isis
allensdk.ephys.ephys_features.detect_putative_spikes(v, t, start=None, end=None, filter=10.0, dv_cutoff=20.0)[source]

Perform initial detection of spikes and return their indexes.

Parameters:
vnumpy array of voltage time series in mV
tnumpy array of times in seconds
startstart of time window for spike detection (optional)
endend of time window for spike detection (optional)
filtercutoff frequency for 4-pole low-pass Bessel filter in kHz (optional, default 10)
dv_cutoffminimum dV/dt to qualify as a spike in V/s (optional, default 20)
dvdtpre-calculated time-derivative of voltage (optional)
Returns:
putative_spikesnumpy array of preliminary spike indexes
allensdk.ephys.ephys_features.estimate_adjusted_detection_parameters(v_set, t_set, interval_start, interval_end, filter=10)[source]

Estimate adjusted values for spike detection by analyzing a period when the voltage changes quickly but passively (due to strong current stimulation), which can result in spurious spike detection results.

Parameters:
v_setlist of numpy arrays of voltage time series in mV
t_setlist of numpy arrays of times in seconds
interval_startstart of analysis interval (sec)
interval_endend of analysis interval (sec)
Returns:
new_dv_cutoffadjusted dv/dt cutoff (V/s)
new_thresh_fracadjusted fraction of avg upstroke to find threshold
allensdk.ephys.ephys_features.filter_putative_spikes(v, t, spike_indexes, peak_indexes, min_height=2.0, min_peak=-30.0, filter=10.0, dvdt=None)[source]
Filter out events that are unlikely to be spikes based on:
  • Voltage failing to go down between peak and the next spike’s threshold

  • Height (threshold to peak)

  • Absolute peak level

Parameters:
vnumpy array of voltage time series in mV
tnumpy array of times in seconds
spike_indexesnumpy array of preliminary spike indexes
peak_indexesnumpy array of indexes of spike peaks
min_heightminimum acceptable height from threshold to peak in mV (optional, default 2)
min_peakminimum acceptable absolute peak level in mV (optional, default -30)
filtercutoff frequency for 4-pole low-pass Bessel filter in kHz (optional, default 10)
dvdtpre-calculated time-derivative of voltage (optional)
Returns:
spike_indexesnumpy array of threshold indexes
peak_indexesnumpy array of peak indexes
allensdk.ephys.ephys_features.find_downstroke_indexes(v, t, peak_indexes, trough_indexes, clipped=None, filter=10.0, dvdt=None)[source]

Find indexes of minimum voltage (troughs) between spikes.

Parameters:
vnumpy array of voltage time series in mV
tnumpy array of times in seconds
peak_indexesnumpy array of spike peak indexes
trough_indexesnumpy array of threshold indexes
clipped: boolean array - False if spike not clipped by edge of window
filtercutoff frequency for 4-pole low-pass Bessel filter in kHz (optional, default 10)
dvdtpre-calculated time-derivative of voltage (optional)
Returns:
downstroke_indexesnumpy array of downstroke indexes
allensdk.ephys.ephys_features.find_peak_indexes(v, t, spike_indexes, end=None)[source]

Find indexes of spike peaks.

Parameters:
vnumpy array of voltage time series in mV
tnumpy array of times in seconds
spike_indexesnumpy array of preliminary spike indexes
endend of time window for spike detection (optional)
allensdk.ephys.ephys_features.find_time_index(t, t_0)[source]

Find the index value of a given time (t_0) in a time series (t).

allensdk.ephys.ephys_features.find_trough_indexes(v, t, spike_indexes, peak_indexes, clipped=None, end=None)[source]

Find indexes of minimum voltage (trough) between spikes.

Parameters:
vnumpy array of voltage time series in mV
tnumpy array of times in seconds
spike_indexesnumpy array of spike indexes
peak_indexesnumpy array of spike peak indexes
endend of time window (optional)
Returns:
trough_indexesnumpy array of threshold indexes
allensdk.ephys.ephys_features.find_upstroke_indexes(v, t, spike_indexes, peak_indexes, filter=10.0, dvdt=None)[source]

Find indexes of maximum upstroke of spike.

Parameters:
vnumpy array of voltage time series in mV
tnumpy array of times in seconds
spike_indexesnumpy array of preliminary spike indexes
peak_indexesnumpy array of indexes of spike peaks
filtercutoff frequency for 4-pole low-pass Bessel filter in kHz (optional, default 10)
dvdtpre-calculated time-derivative of voltage (optional)
Returns:
upstroke_indexesnumpy array of upstroke indexes
allensdk.ephys.ephys_features.find_widths(v, t, spike_indexes, peak_indexes, trough_indexes, clipped=None)[source]

Find widths at half-height for spikes.

Widths are only returned when heights are defined

Parameters:
vnumpy array of voltage time series in mV
tnumpy array of times in seconds
spike_indexesnumpy array of spike indexes
peak_indexesnumpy array of spike peak indexes
trough_indexesnumpy array of trough indexes
Returns:
widthsnumpy array of spike widths in sec
allensdk.ephys.ephys_features.fit_membrane_time_constant(v, t, start, end, min_rsme=0.0001)[source]

Fit an exponential to estimate membrane time constant between start and end

Parameters:
vnumpy array of voltages in mV
tnumpy array of times in seconds
startstart of time window for exponential fit
endend of time window for exponential fit
min_rsme: minimal acceptable root mean square error (default 1e-4)
Returns:
a, inv_tau, y0Coeffients of equation y0 + a * exp(-inv_tau * x)
returns np.nan for values if fit fails
allensdk.ephys.ephys_features.fit_prespike_time_constant(v, t, start, spike_time, dv_limit=-0.001, tau_limit=0.3)[source]

Finds the dominant time constant of the pre-spike rise in voltage

Parameters:
vnumpy array of voltage time series in mV
tnumpy array of times in seconds
startstart of voltage rise (seconds)
spike_timetime of first spike (seconds)
dv_limitdV/dt cutoff (default -0.001)

Shortens fit window if rate of voltage drop exceeds this limit

tau_limitupper bound for slow time constant (seconds, default 0.3)

If the slower time constant of a double-exponential fit is twice that of the faster and exceeds this limit, the faster one will be considered the dominant one

Returns:
taudominant time constant (seconds)
allensdk.ephys.ephys_features.get_isis(t, spikes)[source]

Find interspike intervals in sec between spikes (as indexes).

allensdk.ephys.ephys_features.has_fixed_dt(t)[source]

Check that all time intervals are identical.

allensdk.ephys.ephys_features.latency(t, spikes, start)[source]

Calculate time to the first spike.

allensdk.ephys.ephys_features.norm_diff(a)[source]

Calculate average of (a[i] - a[i+1]) / (a[i] + a[i+1]).

allensdk.ephys.ephys_features.norm_sq_diff(a)[source]

Calculate average of (a[i] - a[i+1])^2 / (a[i] + a[i+1])^2.

allensdk.ephys.ephys_features.refine_threshold_indexes(v, t, upstroke_indexes, thresh_frac=0.05, filter=10.0, dvdt=None)[source]

Refine threshold detection of previously-found spikes.

Parameters:
vnumpy array of voltage time series in mV
tnumpy array of times in seconds
upstroke_indexesnumpy array of indexes of spike upstrokes (for threshold target calculation)
thresh_fracfraction of average upstroke for threshold calculation (optional, default 0.05)
filtercutoff frequency for 4-pole low-pass Bessel filter in kHz (optional, default 10)
dvdtpre-calculated time-derivative of voltage (optional)
Returns:
threshold_indexesnumpy array of threshold indexes