allensdk.ephys package

Submodules

allensdk.ephys.ephys_extractor module

class allensdk.ephys.ephys_extractor.EphysCellFeatureExtractor(ramps_ext, short_squares_ext, long_squares_ext, subthresh_min_amp=-100)[source]
SAG_TARGET = -100.0
SUBTHRESH_MAX_AMP = 0
as_dict()[source]

Create dict of cell features.

cell_features()[source]
long_squares_features(option=None)[source]
long_squares_stim_amps(option=None)[source]
process(keys=None)[source]

Processes features. Can take a specific key (or set of keys) to do a subset of processing.

ramps_features(all=False)[source]
short_squares_features()[source]
class allensdk.ephys.ephys_extractor.EphysSweepFeatureExtractor(t=None, v=None, i=None, start=None, end=None, filter=10.0, dv_cutoff=20.0, max_interval=0.005, min_height=2.0, min_peak=-30.0, thresh_frac=0.05, baseline_interval=0.1, baseline_detect_thresh=0.3, id=None)[source]

Feature calculation for a sweep (voltage and/or current time series).

as_dict()[source]

Create dict of features and spikes.

burst_metrics()[source]

Find bursts and return max “burstiness” index (normalized max rate in burst vs out).

Returns:

max_burstiness_index : max “burstiness” index across detected bursts

num_bursts : number of bursts detected

delay_metrics()[source]

Calculates ratio of latency to dominant time constant of rise before spike

Returns:

delay_ratio : ratio of latency to tau (higher means more delay)

tau : dominant time constant of rise before spike

estimate_sag(peak_width=0.005)[source]

Calculate the sag in a hyperpolarizing voltage response.

Parameters:peak_width : window width to get more robust peak estimate in sec (default 0.005)
Returns:sag : fraction that membrane potential relaxes back to baseline
estimate_time_constant()[source]

Calculate the membrane time constant by fitting the voltage response with a single exponential.

Returns:tau : membrane time constant in seconds
is_spike_feature_affected_by_clipping(key)[source]
pause_metrics()[source]

Estimate average number of pauses and average fraction of time spent in a pause

Attempts to detect pauses with a variety of conditions and averages results together.

Pauses that are consistently detected contribute more to estimates.

Returns:

avg_n_pauses : average number of pauses detected across conditions

avg_pause_frac : average fraction of interval (between start and end) spent in a pause

max_reliability : max fraction of times most reliable pause was detected given weights tested

n_max_rel_pauses : number of pauses detected with max_reliability

process_new_spike_feature(feature_name, feature_func, affected_by_clipping=False)[source]

Add new spike-level feature calculation function

The function should take this sweep extractor as its argument. Its results can be accessed by calling the method spike_feature(<feature_name>).

process_new_sweep_feature(feature_name, feature_func)[source]

Add new sweep-level feature calculation function

The function should take this sweep extractor as its argument. Its results can be accessed by calling the method sweep_feature(<feature_name>).

process_spikes()[source]

Perform spike-related feature analysis

set_stimulus_amplitude_calculator(function)[source]
spike_feature(key, include_clipped=False, force_exclude_clipped=False)[source]

Get specified feature for every spike.

Parameters:

key : feature name

include_clipped: return values for every identified spike, even when clipping means they will be incorrect/undefined

Returns:

spike_feature_values : ndarray of features for each spike

spike_feature_keys()[source]

Get list of every available spike feature.

spikes()[source]

Get all features for each spike as a list of records.

stimulus_amplitude()[source]
sweep_feature(key, allow_missing=False)[source]

Get sweep-level feature (key).

Parameters:

key : name of sweep-level feature

allow_missing : return np.nan if key is missing for sweep (default False)

Returns:

sweep_feature : sweep-level feature value

sweep_feature_keys()[source]

Get list of every available sweep-level feature.

voltage_deflection(deflect_type=None)[source]

Measure deflection (min or max, between start and end if specified).

Parameters:

deflect_type : measure minimal (‘min’) or maximal (‘max’) voltage deflection

If not specified, it will check to see if the current (i) is positive or negative between start and end, then choose ‘max’ or ‘min’, respectively If the current is not defined, it will default to ‘min’.

Returns:

deflect_v : peak

deflect_index : index of peak deflection

class allensdk.ephys.ephys_extractor.EphysSweepSetFeatureExtractor(t_set=None, v_set=None, i_set=None, start=None, end=None, filter=10.0, dv_cutoff=20.0, max_interval=0.005, min_height=2.0, min_peak=-30.0, thresh_frac=0.05, baseline_interval=0.1, baseline_detect_thresh=0.3, id_set=None)[source]
classmethod from_sweeps(sweep_list)[source]

Initialize EphysSweepSetFeatureExtractor object with a list of pre-existing sweep feature extractor objects.

process_spikes()[source]

Analyze spike features for all sweeps.

spike_feature_averages(key)[source]

Get nparray of average spike-level feature (key) for all sweeps

sweep_features(key, allow_missing=False)[source]

Get nparray of sweep-level feature (key) for all sweeps

Parameters:

key : name of sweep-level feature

allow_missing : return np.nan if key is missing for sweep (default False)

Returns:

sweep_feature : nparray of sweep-level feature values

sweeps()[source]

Get list of EphysSweepFeatureExtractor objects.

allensdk.ephys.ephys_extractor.cell_extractor_for_nwb(dataset, ramps, short_squares, long_squares, subthresh_min_amp=-100)[source]

Initialize EphysCellFeatureExtractor object from NWB data set

Parameters:

dataset : NwbDataSet

ramps : list of sweep numbers of ramp sweeps

short_squares : list of sweep numbers of short square sweeps

long_squares : list of sweep numbers of long square sweeps

allensdk.ephys.ephys_extractor.extractor_for_nwb_sweeps(dataset, sweep_numbers, fixed_start=None, fixed_end=None, dv_cutoff=20.0, thresh_frac=0.05)[source]
allensdk.ephys.ephys_extractor.fit_fi_slope(ext)[source]

Fit the rate and stimulus amplitude to a line and return the slope of the fit.

allensdk.ephys.ephys_extractor.input_resistance(ext)[source]

Estimate input resistance in MOhms, assuming all sweeps in passed extractor are hyperpolarizing responses.

allensdk.ephys.ephys_extractor.membrane_time_constant(ext)[source]

Average the membrane time constant values estimated from each sweep in passed extractor.

allensdk.ephys.ephys_extractor.reset_long_squares_start(when)[source]

allensdk.ephys.ephys_features module

exception allensdk.ephys.ephys_features.FeatureError[source]

Bases: exceptions.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:

v : numpy array of voltage time series in mV

t : numpy array of times in seconds

spike_indexes : numpy array of spike indexes

peak_indexes : numpy array of spike peak indexes

end : end of time window (optional)

filter : cutoff frequency for 4-pole low-pass Bessel filter in kHz (default 1)

heavy_filter : lower cutoff frequency for 4-pole low-pass Bessel filter in kHz (default 1)

thresh_frac : fraction 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)

tol : tolerance 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)

dvdt : pre-calculated time-derivative of voltage (optional)

Returns:

isi_types : numpy array of isi reset types (direct or detour)

fast_trough_indexes : numpy array of indexes at the start of the trough (i.e. end of the spike)

adp_indexes : numpy array of adp indexes (np.nan if there was no ADP in that ISI

slow_trough_indexes : numpy 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:

t : numpy array of times in seconds

spikes : numpy array of spike indexes

start : start of time window for spike detection

end : end of time window for spike detection

Returns:

avg_rate : average 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:

v : numpy array of voltage time series in mV

t : numpy array of times in seconds

start : start of time window for spike detection (optional, default None)

end : end of time window for spike detection (optional, default None)

Returns:

v_avg : average voltage

allensdk.ephys.ephys_features.calculate_dvdt(v, t, filter=None)[source]

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

Parameters:

v : numpy array of voltage time series in mV

t : numpy array of times in seconds

filter : cutoff frequency for 4-pole low-pass Bessel filter in kHz (optional, default None)

Returns:

dvdt : numpy 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)[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:

v : numpy array of voltage time series in mV

t : numpy array of times in seconds

spike_indexes : numpy array of spike indexes

peak_indexes : numpy array of indexes of spike peaks

upstroke_indexes : numpy array of indexes of spike upstrokes

max_interval : maximum allowed time between start of spike and time of peak in sec (default 0.005)

thresh_frac : fraction of average upstroke for threshold calculation (optional, default 0.05)

filter : cutoff frequency for 4-pole low-pass Bessel filter in kHz (optional, default 10)

dvdt : pre-calculated time-derivative of voltage (optional)

Returns:

spike_indexes : numpy array of modified spike indexes

peak_indexes : numpy array of modified spike peak indexes

upstroke_indexes : numpy array of modified spike upstroke indexes

clipped : numpy array of clippped 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:

isis : numpy array of n interspike intervals

isi_types : numpy array of n interspike interval types

fast_tr_v : numpy array of fast trough voltages for the n + 1 spikes of the train

fast_tr_t : numpy array of fast trough times for the n + 1 spikes of the train

slow_tr_v : numpy array of slow trough voltages for the n + 1 spikes of the train

slow_tr_t : numpy array of slow trough times for the n + 1 spikes of the train

thr_v : numpy array of threshold voltages for the n + 1 spikes of the train

tol : tolerance 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:

bursts : list 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:

isis : numpy array of interspike intervals

isi_types : numpy array of interspike interval types (‘direct’ or ‘detour’)

cost_weight : weight 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:

pauses : numpy 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:

v : numpy array of voltage time series in mV

t : numpy array of times in seconds

start : start of time window for spike detection (optional)

end : end of time window for spike detection (optional)

filter : cutoff frequency for 4-pole low-pass Bessel filter in kHz (optional, default 10)

dv_cutoff : minimum dV/dt to qualify as a spike in V/s (optional, default 20)

dvdt : pre-calculated time-derivative of voltage (optional)

Returns:

putative_spikes : numpy 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_set : list of numpy arrays of voltage time series in mV

t_set : list of numpy arrays of times in seconds

interval_start : start of analysis interval (sec)

interval_end : end of analysis interval (sec)

Returns:

new_dv_cutoff : adjusted dv/dt cutoff (V/s)

new_thresh_frac : adjusted 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)[source]
Filter out events that are unlikely to be spikes based on:
  • Height (threshold to peak)
  • Absolute peak level
Parameters:

v : numpy array of voltage time series in mV

t : numpy array of times in seconds

spike_indexes : numpy array of preliminary spike indexes

peak_indexes : numpy array of indexes of spike peaks

min_height : minimum acceptable height from threshold to peak in mV (optional, default 2)

min_peak : minimum acceptable absolute peak level in mV (optional, default -30)

Returns:

spike_indexes : numpy array of threshold indexes

peak_indexes : numpy 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:

v : numpy array of voltage time series in mV

t : numpy array of times in seconds

peak_indexes : numpy array of spike peak indexes

trough_indexes : numpy array of threshold indexes

clipped: boolean array - False if spike not clipped by edge of window

filter : cutoff frequency for 4-pole low-pass Bessel filter in kHz (optional, default 10)

dvdt : pre-calculated time-derivative of voltage (optional)

Returns:

downstroke_indexes : numpy array of downstroke indexes

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

Find indexes of spike peaks.

Parameters:

v : numpy array of voltage time series in mV

t : numpy array of times in seconds

spike_indexes : numpy array of preliminary spike indexes

end : end 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:

v : numpy array of voltage time series in mV

t : numpy array of times in seconds

spike_indexes : numpy array of spike indexes

peak_indexes : numpy array of spike peak indexes

end : end of time window (optional)

Returns:

trough_indexes : numpy 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:

v : numpy array of voltage time series in mV

t : numpy array of times in seconds

spike_indexes : numpy array of preliminary spike indexes

peak_indexes : numpy array of indexes of spike peaks

filter : cutoff frequency for 4-pole low-pass Bessel filter in kHz (optional, default 10)

dvdt : pre-calculated time-derivative of voltage (optional)

Returns:

upstroke_indexes : numpy 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:

v : numpy array of voltage time series in mV

t : numpy array of times in seconds

spike_indexes : numpy array of spike indexes

peak_indexes : numpy array of spike peak indexes

trough_indexes : numpy array of trough indexes

Returns:

widths : numpy 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:

v : numpy array of voltages in mV

t : numpy array of times in seconds

start : start of time window for exponential fit

end : end of time window for exponential fit

min_rsme: minimal acceptable root mean square error (default 1e-4)

Returns:

a, inv_tau, y0 : Coeffients 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:

v : numpy array of voltage time series in mV

t : numpy array of times in seconds

start : start of voltage rise (seconds)

spike_time : time of first spike (seconds)

dv_limit : dV/dt cutoff (default -0.001)

Shortens fit window if rate of voltage drop exceeds this limit

tau_limit : upper 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:

tau : dominant 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:

v : numpy array of voltage time series in mV

t : numpy array of times in seconds

upstroke_indexes : numpy array of indexes of spike upstrokes (for threshold target calculation)

thresh_frac : fraction of average upstroke for threshold calculation (optional, default 0.05)

filter : cutoff frequency for 4-pole low-pass Bessel filter in kHz (optional, default 10)

dvdt : pre-calculated time-derivative of voltage (optional)

Returns:

threshold_indexes : numpy array of threshold indexes

allensdk.ephys.extract_cell_features module

allensdk.ephys.extract_cell_features.extract_cell_features(data_set, ramp_sweep_numbers, short_square_sweep_numbers, long_square_sweep_numbers, subthresh_min_amp=None)[source]
allensdk.ephys.extract_cell_features.extract_sweep_features(data_set, sweeps_by_type)[source]
allensdk.ephys.extract_cell_features.get_ramp_stim_characteristics(i, t)[source]

Identify the start time and start index of a ramp sweep.

allensdk.ephys.extract_cell_features.get_square_stim_characteristics(i, t, no_test_pulse=False)[source]

Identify the start time, duration, amplitude, start index, and end index of a square stimulus. This assumes that there is a test pulse followed by the stimulus square.

allensdk.ephys.extract_cell_features.get_stim_characteristics(i, t, no_test_pulse=False)[source]

Identify the start time, duration, amplitude, start index, and end index of a general stimulus. This assumes that there is a test pulse followed by the stimulus square.

allensdk.ephys.extract_cell_features.mean_features_spike_zero(sweeps)[source]

Compute mean feature values for the first spike in list of extractors

allensdk.ephys.feature_extractor module

class allensdk.ephys.feature_extractor.EphysFeatureExtractor[source]

Bases: object

adaptation_index(spikes, stim_end)[source]
calculate_trough(spike, v, curr, t, next_idx)[source]
isicv(spikes)[source]
process_instance(name, v, curr, t, onset, dur, stim_name)[source]
push_summary(new_summary)[source]
score_feature_set(set_num)[source]
summarize(summary)[source]
class allensdk.ephys.feature_extractor.EphysFeatures(name)[source]

Bases: object

clone(param_dict)[source]
print_out()[source]

Module contents