ephyspy.features package
Submodules
ephyspy.features.base module
- class ephyspy.features.base.BaseFeature(data: EphysSweep | None = None, compute_at_init: bool = True, name: str | None = None)[source]
Bases:
ABC
Base class for all electrophysiological features.
This class defines the interface for all electrophysiological features. All sweep features should inherit from this class, and must implement a _compute and _data_init method. The _compute method should return the feature value and optionally save diagnostic information for later debugging to self._diagnostics. The _data_init method should be used to set the self.data attribute, and add the feature to the self.data.features.
The description of the feature should contain a short description of the feature, and a list of dependencies. The dependencies should be listed as a comma separated list of feature names. It is parsed and can be displayed but has no functional use for now. Furthermore, the units of the feature should be specified. If the feature is unitless, the units should be set to “/”.
The docstring should have the following format:
‘’’<Some Text>
description: <Short description of the feature>. depends on: <Comma separated list of dependencies>. units: <Units of the feature>.
<Some more text>’’’
BaseFeature`s can also implement a _plot method, that displays the diagnostic information or the feature itself. If the feature cannot be displayed in a V(t) or I(t) plot, instead the `plot method should be overwritten directly. This is because plot wraps _plot adds additional functionality ot it.
- property diagnostics: Dict[str, Any]
- ensure_correct_hyperparams()[source]
Ensure that parameters passed with the data are used in computation.
Both EphysSweep and EphysSweepSet can come with metadata attached. This metadata can be used to set default values for hyperparameters of features. This method ensures that these hyperparameters are used in computation. It should be called in _data_init after setting the self.data attribute.
- get_diagnostics(recompute: bool = False) Dict[str, Any] [source]
Get diagnostic information about how a feature was computed.
This method returns any intermediary results obtained during computation of the feature that has been stored in _diagnostics. If the feature is not yet computed, it will be computed first.
- Parameters:
recompute – If True, recompute the feature even if it is already computed.
- Returns:
A dictionary with diagnostic information about the feature computation.
- get_value(recompute: bool = False, store_diagnostics: bool = True) float [source]
Get the value of the feature.
Allows to force recomputation of the feature and toggle whether diagnostic information should be stored.
- Parameters:
recompute – If True, recompute the feature even if it is already computed.
store_diagnostics – If True, store any additional information about the feature computation in the _diagnostics attribute.
- Returns:
The value of the feature.
- plot(*args, ax: Axes | None = None, show_sweep: bool = False, show_stimulus: bool = False, sweep_kwargs: Dict[str, Any] | None = {'alpha': 0.5, 'color': 'grey'}, **kwargs) Axes [source]
Adds additional kwargs and functionality to BaseFeature._plot`.
Before calling BaseFeature._plot, this function checks if the feature is a stimulus feature and if so, ensures the feature is plotteed onto the stimulus axis. Additionally along with every feature, the sweep can be plotted. Same goes for the stimulus.
If no axis is provided one is created. This function can be (and should be overwritten) if the feature cannot be displayed on top of the unterlying sweep.
- Parameters:
self (BaseFeature) – Feature to plot. Needs to have a plot method.
*args – Additional arguments to pass to self.plot.
ax (Optional[Axes], optional) – Axes to plot on.
show_sweep (bool, optional) – Whether to plot the sweep. Defaults to False.
show_stimulus (bool, optional) – Whether to plot the stimulus. Defaults to False.
kwargs – Additional kwargs to pass to self.plot.
- Returns:
Axes of plot.
- Return type:
Axes
- recompute() float [source]
Convencience method to recompute the feature.
This method is equivalent to calling get_value with recompute=True and store_diagnostics=True.
- Returns:
The value of the feature.
- property value: Any
- class ephyspy.features.base.SpikeFeature(data: EphysSweep | None = None, compute_at_init: bool = True, name: str | None = None)[source]
Bases:
BaseFeature
Base class for all spike level electrophysiological features.
All spike features should inherit from this class, and must implement the _compute method. The _compute method should return the feature value and optionally save diagnostic information for later debugging to self._diagnostics.
Compared to SweepFeature, SpikeFeature behaves slightly differently. Firstly, since spike features are computed on the spike level, results come in the form of a vector, where each entry corresponds to a spike. Similar to before this vector is stored in the _value attribute. However, because the handling the spike features is left to the AllenSDK’s process_spikes, they SpikeFeature just provides an interface to the _spikes_df attribute of the underlying EphysSweep object. Secondly, the spike features in the AllenSDK are defined in a functional manner. This means the __call__ method of SpikeFeature provides the required functional interface to be able to compute spike features with EphysSweep.process_spikes, while being able to provide additional functionality to the spike feature class.
Currently, no diagnostics or recursive feature lookup is supported for spike features! For now this class mainly just acts as a feature function.
The description of the feature should contain a short description of the feature, and a list of dependencies. The dependencies should be listed as a comma separated list of feature names. It is parsed and can be displayed but has no functional use for now. Furthermore, the units of the feature should be specified. If the feature is unitless, the units should be set to “/”.
The docstring should have the following format:
‘’’<Some Text>
description: <Short description of the feature>. depends on: <Comma separated list of dependencies>. units: <Units of the feature>.
<Some more text>’’’
All computed features are added to the underlying EphysSweep object, and can be accessed via lookup_spike_feature. The methods will first check if the feature is already computed, and if not, instantiate and compute it. Any dependencies already computed will be reused, unless recompute=True is passed.
SpikeFeature`s can also implement a _plot method, the feature. If the feature cannot be displayed in a V(t) or I(t) plot, instead the `plot method should be overwritten directly. This is because plot wraps _plot adds additional functionality ot it.
- get_diagnostics(recompute: bool = False)[source]
Overwrite get_diagnostics to return None.
Diagnostics is currently not supported for spike features.
- lookup_spike_feature(feature_name: str, recompute: bool = False) ndarray [source]
Look up a spike level feature and return its value.
This method will first check if the feature is already computed, and if not, compute all spike level features using process_spikes from the underlying EphysSweep object, and then instantiate and compute the feature.
- Parameters:
feature_name – Name of the feature to look up.
recompute – If True, recompute the feature even if it is already computed.
- Returns:
The value of the feature for each detected spike.
- class ephyspy.features.base.SweepFeature(data: EphysSweep | None = None, compute_at_init: bool = True, name: str | None = None)[source]
Bases:
BaseFeature
Base class for all sweep level electrophysiological features.
All sweep features should inherit from this class, and must implement the _compute method. The _compute method should return the feature value and optionally save diagnostic information for later debugging to self._diagnostics.
The description of the feature should contain a short description of the feature, and a list of dependencies. The dependencies should be listed as a comma separated list of feature names. It is parsed and can be displayed but has no functional use for now. Furthermore, the units of the feature should be specified. If the feature is unitless, the units should be set to “/”.
The docstring should have the following format:
‘’’<Some Text>
description: <Short description of the feature>. depends on: <Comma separated list of dependencies>. units: <Units of the feature>.
<Some more text>’’’
All computed features are added to the underlying EphysSweep object, and can be accessed via lookup_sweep_feature or lookup_spike_feature. The methods will first check if the feature is already computed, and if not, instantiate and compute it. This works recursively, so that features can depend on other features as long as they are looked up with lookup_sweep_feature or lookup_spike_feature. Hence any feature can be computed at any point, without having to compute any dependencies first. Any dependencies already computed will be reused, unless recompute=True is passed.
SweepFeature`s can also implement a _plot method, that displays the diagnostic information or the feature itself. If the feature cannot be displayed in a V(t) or I(t) plot, instead the `plot method should be overwritten directly. This is because plot wraps _plot adds additional functionality ot it.
- lookup_spike_feature(feature_name: str, recompute: bool = False) ndarray [source]
Look up a spike level feature and return its value.
This method will first check if the feature is already computed, and if not, compute all spike level features using process_spikes from the underlying EphysSweep object, and then instantiate and compute the feature.
- Parameters:
feature_name – Name of the feature to look up.
recompute – If True, recompute the feature even if it is already computed.
- Returns:
The value of the feature for each detected spike.
- lookup_sweep_feature(feature_name: str, recompute: bool = False, return_value: bool = True) float | SweepFeature [source]
Look up a sweep level feature and return its value.
This method will first check if the feature is already computed, and if not, instantiate and compute it. This works as long as the feature can be found via fetch_available_fts. Works recursively, so that features can depend on other features as long as they are looked up with lookup_sweep_feature or lookup_spike_feature.
- Parameters:
feature_name – Name of the feature to look up.
recompute – If True, recompute the feature even if it is already computed.
return_value – If True, return the value of the feature. Otherwise return the feature object.
- Returns:
The feature or the value of the feature depending on return_value.
- Raises:
FeatureError – If the feature is not found via fetch_available_fts.
- class ephyspy.features.base.SweepSetFeature(SwFt: SweepFeature, data: EphysSweepSet | None = None, compute_at_init: bool = True, name: str | None = None)[source]
Bases:
SweepFeature
Base class for sweepset level features that are computed from a EphysSweepSet. Wraps around any SweepFeature derived feature and extends it to the sweepset level.
This class mostly acts like an SweepFeature and implements the same basic functionalities. See Documentation of SweepFeature for defails. Most importantly it also allows to recursively look up dependend features and compute them if necessary. This can be done on the spike, sweep and sweepset level. On the sweep level, instead of returning just a float however, lookup_sweep_feature will return a vector of feature values, where each entry corresponds to a sweep in the sweepset. Since all computation is done on the sweep level, all features are also stored with along with each sweep.
All sweepset features should inherit from this class, and must implement the _select and _aggregate method. The _select method takes a vector of feature values and return a subset of these values based on a selection criterion (e.g. return all values that are larger than 0). The _aggregate method also takes a vector of feature values and aggregates them into a single value (e.g. return the mean of all values). Together the _select and _aggregate methods are able to compute representative values for every feature that can also be computed on the sweep level.
In cases where the feature cannot directly be computed as an aggregate of the corresponding sweep feature, the _compute method can be overwritten. In this case the inheriting class should instantiate the SweepSetFeature super with AbstractSweepFeature. Similar to SweepFeature, the _compute method should then return the value of the feature.
Other SweepSetFeatures can also be used in the computation of other features by using the lookup_sweepset_feature method.
The description of the sweepset feature should contain a short description of the feature, and a list of dependencies. The dependencies should be listed as a comma separated list of feature names. It is parsed and can be displayed but has no functional use. Furthermore, the units of the feature should be specified. If the feature is unitless, the units should be set to “/”.
The docstring should have the following format:
‘’’<Some Text>
description: <Short description of the feature>. depends on: <Comma separated list of dependencies>. units: <Units of the feature>.
<Some more text>’’’
All computed features are added to the underlying EphysSweepSet object, and can be accessed the get_features().
- property dataset
Proxy for self.data at the sweepset level.
- property features
List values for all computed features.
- lookup_sweep_feature(feature_name: str, recompute: bool = False, return_value: bool = True) ndarray [source]
Lookup feature for each sweep and return the results as a vector.
- Parameters:
feature_name – Name of the feature to lookup.
recompute – If True, recompute the feature even if it is already has been computed previously.
return_value – If True, return the value of the feature, otherwise return the feature object.
- Returns:
Vector of feature values or feature objects.
- lookup_sweepset_feature(feature_name: str, recompute: bool = False, return_value: bool = True) float | SweepSetFeature [source]
Lookup feature for the sweepset and return the result.
Analogous to lookup_sweep_feature, on the sweep level, but for sweepset level features.
- Parameters:
feature_name – Name of the feature to lookup.
recompute – If True, recompute the feature even if it is already has been computed previously.
return_value – If True, return the value of the feature, otherwise return the feature object.
- Returns:
Feature value.
ephyspy.features.spike_features module
- class ephyspy.features.spike_features.Spike_AP_ADP(data=None, compute_at_init=True)[source]
Bases:
SpikeFeature
Extract spike level after depolarization feature.
depends on: adp_v, fast_trough_v. description: v_adp - v_fast_trough. units: mV.
- class ephyspy.features.spike_features.Spike_AP_AHP(data=None, compute_at_init=True)[source]
Bases:
SpikeFeature
Extract spike level after hyperpolarization feature.
depends on: threshold_v, fast_trough_v. description: v_fast_trough - threshold_v. units: mV.
- class ephyspy.features.spike_features.Spike_AP_UDR(data=None, compute_at_init=True)[source]
Bases:
SpikeFeature
Extract spike level ap udr feature.
depends on: upstroke, downstroke. description: upstroke / downstroke. For details on how upstroke, downstroke are computed see AllenSDK. units: /.
- class ephyspy.features.spike_features.Spike_AP_amp(data=None, compute_at_init=True)[source]
Bases:
SpikeFeature
Extract spike level peak height feature.
depends on: threshold_v, peak_v. description: v_peak - threshold_v. units: mV.
- class ephyspy.features.spike_features.Spike_AP_downstroke(data=None, compute_at_init=True)[source]
Bases:
SpikeFeature
Extract spike level downstroke feature.
depends on: /. description: downstroke of AP. units: mV.
- class ephyspy.features.spike_features.Spike_AP_fast_trough(data=None, compute_at_init=True)[source]
Bases:
SpikeFeature
Extract spike level fast trough feature.
depends on: /. description: fast trough of AP. units: mV.
- class ephyspy.features.spike_features.Spike_AP_peak(data=None, compute_at_init=True)[source]
Bases:
SpikeFeature
Extract spike level peak feature.
depends on: peak_v. description: max voltage of AP. units: mV.
- class ephyspy.features.spike_features.Spike_AP_slow_trough(data=None, compute_at_init=True)[source]
Bases:
SpikeFeature
Extract spike level slow trough feature.
depends on: /. description: slow trough of AP. units: mV.
- class ephyspy.features.spike_features.Spike_AP_thresh(data=None, compute_at_init=True)[source]
Bases:
SpikeFeature
Extract spike level ap threshold feature.
depends on: threshold_v. description: For details on how AP thresholds are computed see AllenSDK. units: mV.
- class ephyspy.features.spike_features.Spike_AP_trough(data=None, compute_at_init=True)[source]
Bases:
SpikeFeature
Extract spike level ap trough feature.
depends on: through_v. description: For details on how AP troughs are computed see AllenSDK. units: mV.
- class ephyspy.features.spike_features.Spike_AP_upstroke(data=None, compute_at_init=True)[source]
Bases:
SpikeFeature
Extract spike level upstroke feature.
depends on: /. description: upstroke of AP. units: mV.
- class ephyspy.features.spike_features.Spike_AP_width(data=None, compute_at_init=True)[source]
Bases:
SpikeFeature
Extract spike level ap width feature.
depends on: width. description: full width half max of AP. units: s.
- class ephyspy.features.spike_features.Spike_ISI(data=None, compute_at_init=True)[source]
Bases:
SpikeFeature
Extract spike level inter-spike-interval feature.
depends on: threshold_t. description: The distance between subsequent spike thresholds. isi at the
first index is nan since isi[t+1] = threshold_t[t+1] - threshold_t[t].
units: s.
- ephyspy.features.spike_features.available_spike_features(compute_at_init: bool = False, store_diagnostics: bool = False) Dict[str, SpikeFeature] [source]
Return a dictionary of all implemented spike features.
Looks for all classes that inherit from SpikeFeature and returns a dictionary of all available features. If compute_at_init is True, the features are computed at initialization.
- Parameters:
compute_at_init (bool, optional) – If True, the features are computed at initialization. Defaults to False.
store_diagnostics (bool, optional) – If True, the features are computed with diagnostics. Defaults to False.
- Returns:
Dictionary of all available spike features.
- Return type:
dict[str, SpikeFeature]
ephyspy.features.sweep_features module
- class ephyspy.features.sweep_features.APSweepFeature(data=None, compute_at_init=True, ft_name: str | None = None, ap_selector: Callable | None = None, ft_aggregator: Callable | None = None)[source]
Bases:
SweepFeature
Extract sweep level AP feature.
description: Action potential feature to represent a sweep.
- class ephyspy.features.sweep_features.NullSweepFeature(data=None, compute_at_init=True, name=None)[source]
Bases:
SweepFeature
Dummy sweep level feature.
Dummy feature that can be used as a placeholder to compute sweepset level features using SweepSetFeature if no sweep level feature for it is available.
depends on: /. description: Only the corresponding sweepset level feature exsits. units: /.
- class ephyspy.features.sweep_features.Sweep_AP_ADP(data=None, compute_at_init=True, ap_selector: Callable | None = None, ft_aggregator: Callable | None = None)[source]
Bases:
APSweepFeature
Extract sweep level Afterdepolarization feature.
depends on: /. description: Afterdepolarization (ADP) for representative AP. Difference between the ADP and the fast trough. units: mV.
- class ephyspy.features.sweep_features.Sweep_AP_AHP(data=None, compute_at_init=True, ap_selector: Callable | None = None, ft_aggregator: Callable | None = None)[source]
Bases:
APSweepFeature
Extract sweep level Afterhyperpolarization feature.
depends on: /. description: Afterhyperpolarization (AHP) for representative AP. Difference between the fast trough and the threshold. units: mV.
- class ephyspy.features.sweep_features.Sweep_AP_CV(data=None, compute_at_init=True)[source]
Bases:
SweepFeature
Extract sweep level AP amplitude coefficient of variation (CV) feature.
depends on: ap_amp. description: Std(ap_amp) / Mean(ap_amp). units: /.
- class ephyspy.features.sweep_features.Sweep_AP_FF(data=None, compute_at_init=True)[source]
Bases:
SweepFeature
Extract sweep level AP amplitude Fano factor feature.
depends on: ap_amp. description: Var(ap_amp) / Mean(ap_amp). units: mV.
- class ephyspy.features.sweep_features.Sweep_AP_UDR(data=None, compute_at_init=True, ap_selector: Callable | None = None, ft_aggregator: Callable | None = None)[source]
Bases:
APSweepFeature
Extract sweep level Upstroke-to-downstroke ratio feature.
depends on: /. description: Upstroke-to-downstroke ratio for representative AP. units: /.
- class ephyspy.features.sweep_features.Sweep_AP_amp(data=None, compute_at_init=True, ap_selector: Callable | None = None, ft_aggregator: Callable | None = None)[source]
Bases:
APSweepFeature
Extract sweep level AP amplitude feature.
depends on: /. description: AP amplitude for representative AP. units: mV.
- class ephyspy.features.sweep_features.Sweep_AP_amp_adapt(data=None, compute_at_init=True)[source]
Bases:
SweepFeature
Extract sweep level AP amplitude adaptation index feature.
depends on: ap_amp. description: /. units: mV/s.
- class ephyspy.features.sweep_features.Sweep_AP_amp_adapt_avg(data=None, compute_at_init=True)[source]
Bases:
SweepFeature
Extract sweep level average AP amplitude adaptation index feature.
depends on: ap_amp. description: /. units: /.
- class ephyspy.features.sweep_features.Sweep_AP_amp_slope(data=None, compute_at_init=True)[source]
Bases:
SweepFeature
Extract sweep level spike count feature.
depends on: stim_onset, stim_end. description: spike amplitude adaptation as the slope of a linear fit v_peak(t_peak) during the stimulus interval. units: mV/s.
- class ephyspy.features.sweep_features.Sweep_AP_freq(data=None, compute_at_init=True)[source]
Bases:
SweepFeature
Extract sweep level spike rate feature.
depends on: numap. description: # peaks during stimulus / stimulus duration. units: Hz.
- class ephyspy.features.sweep_features.Sweep_AP_freq_adapt(data=None, compute_at_init=True)[source]
Bases:
SweepFeature
Extract sweep level spike frequency adaptation feature.
depends on: stim_onset, stim_end, num_ap. description: ratio of spikes in second and first half half of stimulus interval, if there is at least 5 spikes in total. units: /.
- class ephyspy.features.sweep_features.Sweep_AP_latency(data=None, compute_at_init=True)[source]
Bases:
SweepFeature
Extract sweep level ap_latency feature.
depends on: stim_onset. description: time of first spike after stimulus onset. units: s.
- class ephyspy.features.sweep_features.Sweep_AP_peak(data=None, compute_at_init=True, ap_selector: Callable | None = None, ft_aggregator: Callable | None = None)[source]
Bases:
APSweepFeature
Extract sweep level AP peak feature.
depends on: /. description: AP peak for representative AP. units: mV.
- class ephyspy.features.sweep_features.Sweep_AP_thresh(data=None, compute_at_init=True, ap_selector: Callable | None = None, ft_aggregator: Callable | None = None)[source]
Bases:
APSweepFeature
Extract sweep level AP threshold feature.
depends on: /. description: AP threshold for representative AP. units: mV.
- class ephyspy.features.sweep_features.Sweep_AP_trough(data=None, compute_at_init=True, ap_selector: Callable | None = None, ft_aggregator: Callable | None = None)[source]
Bases:
APSweepFeature
Extract sweep level AP trough feature.
depends on: /. description: AP trough for representative AP. units: mV.
- class ephyspy.features.sweep_features.Sweep_AP_width(data=None, compute_at_init=True, ap_selector: Callable | None = None, ft_aggregator: Callable | None = None)[source]
Bases:
APSweepFeature
Extract sweep level AP width feature.
depends on: /. description: AP width for representative AP. units: s.
- class ephyspy.features.sweep_features.Sweep_Burstiness(data=None, compute_at_init=True)[source]
Bases:
SweepFeature
Extract sweep level burstiness feature.
depends on: num_ap. description: max “burstiness” index across detected bursts. units: /.
- class ephyspy.features.sweep_features.Sweep_ISI(data=None, compute_at_init=True, ap_selector: Callable | None = None, ft_aggregator: Callable | None = None)[source]
Bases:
APSweepFeature
Extract sweep level ISI ratio feature.
depends on: /. description: Median interspike interval. units: /.
- class ephyspy.features.sweep_features.Sweep_ISI_CV(data=None, compute_at_init=True)[source]
Bases:
SweepFeature
Extract sweep level inter-spike-interval (ISI) coefficient of variation (CV) feature.
depends on: ISIs. description: Std(ISIs) / Mean(ISIs). units: /.
- class ephyspy.features.sweep_features.Sweep_ISI_FF(data=None, compute_at_init=True)[source]
Bases:
SweepFeature
Extract sweep level inter-spike-interval (ISI) Fano factor feature.
depends on: ISIs. description: Var(ISIs) / Mean(ISIs). units: s.
- class ephyspy.features.sweep_features.Sweep_ISI_adapt(data=None, compute_at_init=True)[source]
Bases:
SweepFeature
Extract sweep level inter-spike-interval (ISI) adaptation index feature.
depends on: ISIs. description: /. units: /.
- class ephyspy.features.sweep_features.Sweep_ISI_adapt_avg(data=None, compute_at_init=True)[source]
Bases:
SweepFeature
Extract sweep level average inter-spike-interval (ISI) adaptation index feature.
depends on: ISIs. description: /. units: /.
- class ephyspy.features.sweep_features.Sweep_Num_AP(data=None, compute_at_init=True)[source]
Bases:
SweepFeature
Extract sweep level spike count feature.
depends on: stim_onset, stim_end. description: # peaks during stimulus. units: /.
- class ephyspy.features.sweep_features.Sweep_Num_bursts(data=None, compute_at_init=True)[source]
Bases:
SweepFeature
Extract sweep level number of bursts feature.
depends on: num_ap. description: Number of detected bursts. units: /.
- class ephyspy.features.sweep_features.Sweep_R_input(data=None, compute_at_init=True)[source]
Bases:
SweepFeature
Extract sweep level input resistance feature.
depends on: stim_amp, v_deflect, v_baseline. description: sweep level input resistance as (v_deflect - v_baseline / current). Should not be used for cell level feature. units: MOhm.
- class ephyspy.features.sweep_features.Sweep_Rebound(data=None, compute_at_init=True, T_rebound=0.3)[source]
Bases:
SweepFeature
Extract sweep level rebound feature.
depends on: v_baseline, stim_end. description: V_max during stimulus_end and stimulus_end + T_rebound - V_baseline. units: mV.
- class ephyspy.features.sweep_features.Sweep_Rebound_APs(data=None, compute_at_init=True, T_rebound=0.3)[source]
Bases:
SweepFeature
Extract sweep level number of rebounding spikes feature.
depends on: stim_end. description: number of spikes during stimulus_end and stimulus_end + T_rebound. units: /.
- class ephyspy.features.sweep_features.Sweep_Rebound_area(data=None, compute_at_init=True, T_rebound=0.3)[source]
Bases:
SweepFeature
Extract sweep level rebound area feature.
depends on: v_baseline, stim_end. description: area between rebound curve and baseline voltage from stimulus_end to stimulus_end + T_rebound. units: mV*s.
- class ephyspy.features.sweep_features.Sweep_Rebound_avg(data=None, compute_at_init=True, T_rebound=0.3)[source]
Bases:
SweepFeature
Extract sweep level average rebound feature.
depends on: v_baseline, stim_end. description: average voltage between stimulus_end and stimulus_end + T_rebound - baseline voltage. units: mV.
- class ephyspy.features.sweep_features.Sweep_Rebound_latency(data=None, compute_at_init=True, T_rebound=0.3)[source]
Bases:
SweepFeature
Extract sweep level rebound latency feature.
depends on: v_baseline, stim_end. description: duration from stimulus_end to when the voltage reaches above baseline for the first time. t_rebound = t_off + rebound_latency. units: s.
- class ephyspy.features.sweep_features.Sweep_Sag(data=None, compute_at_init=True, peak_width=0.005)[source]
Bases:
SweepFeature
Extract sweep level sag feature.
depends on: v_sag. description: magnitude of the depolarization peak. units: mV.
- class ephyspy.features.sweep_features.Sweep_Sag_area(data=None, compute_at_init=True)[source]
Bases:
SweepFeature
Extract sweep level sag area feature.
depends on: v_deflect, stim_onset, stim_end. description: area under the sag. units: mV*s.
- class ephyspy.features.sweep_features.Sweep_Sag_fraction(data=None, compute_at_init=True, peak_width=0.005)[source]
Bases:
SweepFeature
Extract sweep level sag fraction feature.
depends on: /. description: fraction that membrane potential relaxes back to baseline. units: /.
- class ephyspy.features.sweep_features.Sweep_Sag_ratio(data=None, compute_at_init=True)[source]
Bases:
SweepFeature
Extract sweep level sag ratio feature.
depends on: /. description: ratio of steady state voltage decrease to the largest voltage decrease. units: /.
- class ephyspy.features.sweep_features.Sweep_Sag_time(data=None, compute_at_init=True)[source]
Bases:
SweepFeature
Extract sweep level sag duration feature.
depends on: v_deflect, stim_onset, stim_end. description: duration of the sag. units: s.
- class ephyspy.features.sweep_features.Sweep_Stim_amp(data=None, compute_at_init=True)[source]
Bases:
SweepFeature
Extract sweep level stimulus ampltiude feature. depends on: /. description: maximum amplitude of stimulus. units: pA.
- class ephyspy.features.sweep_features.Sweep_Stim_end(data=None, compute_at_init=True)[source]
Bases:
SweepFeature
Extract sweep level stimulus end feature.
depends on: /. description: time of stimulus end. units: s.
- class ephyspy.features.sweep_features.Sweep_Stim_onset(data=None, compute_at_init=True)[source]
Bases:
SweepFeature
Extract sweep level stimulus onset feature.
depends on: /. description: time of stimulus onset. units: s.
- class ephyspy.features.sweep_features.Sweep_Tau(data=None, compute_at_init=True)[source]
Bases:
SweepFeature
Extract sweep level time constant feature.
depends on: v_baseline, stim_onset. description: time constant of exponential fit to voltage deflection. units: s.
- class ephyspy.features.sweep_features.Sweep_V_baseline(data=None, compute_at_init=True)[source]
Bases:
SweepFeature
Extract sweep level baseline voltage feature.
depends on: stim_onset. description: average voltage in baseline_interval (in s) before stimulus onset. units: mV.
- class ephyspy.features.sweep_features.Sweep_V_deflect(data=None, compute_at_init=True)[source]
Bases:
SweepFeature
Extract sweep level voltage deflection feature.
depends on: stim_end. description: average voltage during last 100 ms of stimulus. units: mV.
- class ephyspy.features.sweep_features.Sweep_V_plateau(data=None, compute_at_init=True, T_plateau=0.1)[source]
Bases:
SweepFeature
Extract sweep level plataeu voltage feature.
depends on: stim_end. description: average voltage during the plateau. units: mV.
- class ephyspy.features.sweep_features.Sweep_V_rest(data=None, compute_at_init=True, dc_offset=0)[source]
Bases:
SweepFeature
Extract sweep level resting potential feature.
depends on: v_baseline, r_input, dc_offset. description: v_rest = v_baseline - r_input*dc_offset. units: mV.
- class ephyspy.features.sweep_features.Sweep_V_sag(data=None, compute_at_init=True, peak_width=0.005)[source]
Bases:
SweepFeature
Extract sweep level sag voltage feature.
depends on: v_deflect, v_baseline. description: Average voltage around max deflection. units: mV.
- class ephyspy.features.sweep_features.Sweep_V_steady(data=None, compute_at_init=True)[source]
Bases:
SweepFeature
Extract sweep level hyperpol steady state feature.
depends on: stim_end. description: hyperpol steady state voltage. units: /.
- class ephyspy.features.sweep_features.Sweep_Wildness(data=None, compute_at_init=True)[source]
Bases:
SweepFeature
Extract sweep level wildness feature.
depends on: /. description: Wildness is the number of spikes that occur outside of the stimulus interval. units: /.
- ephyspy.features.sweep_features.available_sweep_features(compute_at_init: bool = False, store_diagnostics: bool = False) Dict[str, SweepFeature] [source]
Return a dictionary of all implemented sweep features.
Looks for all classes that inherit from SweepFeature and returns a dictionary of all available features. If compute_at_init is True, the features are computed at initialization.
- Parameters:
compute_at_init (bool, optional) – If True, the features are computed at initialization. Defaults to False.
store_diagnostics (bool, optional) – If True, the features are computed with diagnostics. Defaults to False.
- Returns:
Dictionary of all available spike features.
- Return type:
dict[str, SweepFeature]
ephyspy.features.sweepset_features module
- class ephyspy.features.sweepset_features.APFeature(feature, data=None, compute_at_init=True)[source]
Bases:
SweepSetFeature
Obtain sweepset level single AP feature.
This includes the following features: - AP threshold - AP amplitude - AP width - AP peak - AP trough - AP afterhyperpolarization (AHP) - AP afterdepolarization (ADP) - AP upstroke-to-downstroke ratio (UDR)
- class ephyspy.features.sweepset_features.APsFeature(feature, data=None, compute_at_init=True)[source]
Bases:
SweepSetFeature
Obtain sweepset level spiking related feature.
This includes the following features: - number of spikes - spike frequency - spike frequency adaptation (SFA) - spike amplitude slope - ISI fano factor - ISI AP fano factor - ISI CV - AP CV
- class ephyspy.features.sweepset_features.First5MedianFeature(feature, data=None, compute_at_init=True)[source]
Bases:
SweepSetFeature
Obtain sweepset level median feature.
This includes the following features: - burstiness - ISI adaptation - average ISI adaptation - AP amplitude adaptation - average AP amplitude adaptation
- class ephyspy.features.sweepset_features.HyperpolMedianFeature(feature, data=None, compute_at_init=True)[source]
Bases:
SweepSetFeature
Obtain sweepset level hyperpolarization feature.
- class ephyspy.features.sweepset_features.MaxFeature(feature, data=None, compute_at_init=True)[source]
Bases:
SweepSetFeature
Obtain sweepset level maximum feature.
This includes the following features: - number of bursts - wildness
- class ephyspy.features.sweepset_features.NullSweepSetFeature(data=None, compute_at_init=True)[source]
Bases:
SweepSetFeature
- class ephyspy.features.sweepset_features.ReboundFeature(feature, data=None, compute_at_init=True)[source]
Bases:
SweepSetFeature
Obtain sweepset level rebound related feature.
This includes the following features: - rebound - rebound APs - rebound latency - average rebound - rebound area
- class ephyspy.features.sweepset_features.SagFeature(feature, data=None, compute_at_init=True)[source]
Bases:
SweepSetFeature
Obtain sweepset level sag related feature.
This includes the following features: - sag - sag area - sag time - sag ratio - sag fraction
- class ephyspy.features.sweepset_features.SweepSet_AP_ADP(data=None, compute_at_init=True)[source]
Bases:
APFeature
- class ephyspy.features.sweepset_features.SweepSet_AP_AHP(data=None, compute_at_init=True)[source]
Bases:
APFeature
- class ephyspy.features.sweepset_features.SweepSet_AP_CV(data=None, compute_at_init=True)[source]
Bases:
APsFeature
- class ephyspy.features.sweepset_features.SweepSet_AP_FF(data=None, compute_at_init=True)[source]
Bases:
APsFeature
- class ephyspy.features.sweepset_features.SweepSet_AP_UDR(data=None, compute_at_init=True)[source]
Bases:
APFeature
- class ephyspy.features.sweepset_features.SweepSet_AP_amp(data=None, compute_at_init=True)[source]
Bases:
APFeature
- class ephyspy.features.sweepset_features.SweepSet_AP_amp_adapt(data=None, compute_at_init=True)[source]
Bases:
First5MedianFeature
- class ephyspy.features.sweepset_features.SweepSet_AP_amp_adapt_avg(data=None, compute_at_init=True)[source]
Bases:
First5MedianFeature
- class ephyspy.features.sweepset_features.SweepSet_AP_amp_slope(data=None, compute_at_init=True)[source]
Bases:
APsFeature
- class ephyspy.features.sweepset_features.SweepSet_AP_freq(data=None, compute_at_init=True)[source]
Bases:
APsFeature
- class ephyspy.features.sweepset_features.SweepSet_AP_freq_adapt(data=None, compute_at_init=True)[source]
Bases:
APsFeature
- class ephyspy.features.sweepset_features.SweepSet_AP_latency(data=None, compute_at_init=True)[source]
Bases:
SweepSetFeature
Obtain sweepset level AP latency feature.
- class ephyspy.features.sweepset_features.SweepSet_AP_peak(data=None, compute_at_init=True)[source]
Bases:
APFeature
- class ephyspy.features.sweepset_features.SweepSet_AP_thresh(data=None, compute_at_init=True)[source]
Bases:
APFeature
- class ephyspy.features.sweepset_features.SweepSet_AP_trough(data=None, compute_at_init=True)[source]
Bases:
APFeature
- class ephyspy.features.sweepset_features.SweepSet_AP_width(data=None, compute_at_init=True)[source]
Bases:
APFeature
- class ephyspy.features.sweepset_features.SweepSet_Burstiness(data=None, compute_at_init=True)[source]
Bases:
First5MedianFeature
- class ephyspy.features.sweepset_features.SweepSet_ISI(data=None, compute_at_init=True)[source]
Bases:
APsFeature
- class ephyspy.features.sweepset_features.SweepSet_ISI_CV(data=None, compute_at_init=True)[source]
Bases:
APsFeature
- class ephyspy.features.sweepset_features.SweepSet_ISI_FF(data=None, compute_at_init=True)[source]
Bases:
APsFeature
- class ephyspy.features.sweepset_features.SweepSet_ISI_adapt(data=None, compute_at_init=True)[source]
Bases:
First5MedianFeature
- class ephyspy.features.sweepset_features.SweepSet_ISI_adapt_avg(data=None, compute_at_init=True)[source]
Bases:
First5MedianFeature
- class ephyspy.features.sweepset_features.SweepSet_Num_AP(data=None, compute_at_init=True)[source]
Bases:
APsFeature
- class ephyspy.features.sweepset_features.SweepSet_Num_bursts(data=None, compute_at_init=True)[source]
Bases:
First5MedianFeature
- class ephyspy.features.sweepset_features.SweepSet_R_input(data=None, compute_at_init=True)[source]
Bases:
SweepSetFeature
Obtain sweepset level r_input feature.
- plot(*args, ax: Axes | None = None, **kwargs) Axes [source]
Adds additional kwargs and functionality to BaseFeature._plot`.
Before calling BaseFeature._plot, this function checks if the feature is a stimulus feature and if so, ensures the feature is plotteed onto the stimulus axis. Additionally along with every feature, the sweep can be plotted. Same goes for the stimulus.
If no axis is provided one is created. This function can be (and should be overwritten) if the feature cannot be displayed on top of the unterlying sweep.
- Parameters:
self (BaseFeature) – Feature to plot. Needs to have a plot method.
*args – Additional arguments to pass to self.plot.
ax (Optional[Axes], optional) – Axes to plot on.
show_sweep (bool, optional) – Whether to plot the sweep. Defaults to False.
show_stimulus (bool, optional) – Whether to plot the stimulus. Defaults to False.
kwargs – Additional kwargs to pass to self.plot.
- Returns:
Axes of plot.
- Return type:
Axes
- class ephyspy.features.sweepset_features.SweepSet_Rebound(data=None, compute_at_init=True)[source]
Bases:
ReboundFeature
- class ephyspy.features.sweepset_features.SweepSet_Rebound_APs(data=None, compute_at_init=True)[source]
Bases:
SweepSetFeature
Obtain sweepset level rebound APs feature.
- class ephyspy.features.sweepset_features.SweepSet_Rebound_area(data=None, compute_at_init=True)[source]
Bases:
ReboundFeature
- class ephyspy.features.sweepset_features.SweepSet_Rebound_avg(data=None, compute_at_init=True)[source]
Bases:
ReboundFeature
- class ephyspy.features.sweepset_features.SweepSet_Rebound_latency(data=None, compute_at_init=True)[source]
Bases:
ReboundFeature
- class ephyspy.features.sweepset_features.SweepSet_Rheobase(data=None, compute_at_init=True, dc_offset=0)[source]
Bases:
SweepSetFeature
Obtain sweepset level rheobase feature.
- plot(*args, ax: Axes | None = None, **kwargs) Axes [source]
Adds additional kwargs and functionality to BaseFeature._plot`.
Before calling BaseFeature._plot, this function checks if the feature is a stimulus feature and if so, ensures the feature is plotteed onto the stimulus axis. Additionally along with every feature, the sweep can be plotted. Same goes for the stimulus.
If no axis is provided one is created. This function can be (and should be overwritten) if the feature cannot be displayed on top of the unterlying sweep.
- Parameters:
self (BaseFeature) – Feature to plot. Needs to have a plot method.
*args – Additional arguments to pass to self.plot.
ax (Optional[Axes], optional) – Axes to plot on.
show_sweep (bool, optional) – Whether to plot the sweep. Defaults to False.
show_stimulus (bool, optional) – Whether to plot the stimulus. Defaults to False.
kwargs – Additional kwargs to pass to self.plot.
- Returns:
Axes of plot.
- Return type:
Axes
- class ephyspy.features.sweepset_features.SweepSet_Sag(data=None, compute_at_init=True)[source]
Bases:
SagFeature
- class ephyspy.features.sweepset_features.SweepSet_Sag_area(data=None, compute_at_init=True)[source]
Bases:
SagFeature
- class ephyspy.features.sweepset_features.SweepSet_Sag_fraction(data=None, compute_at_init=True)[source]
Bases:
SagFeature
- class ephyspy.features.sweepset_features.SweepSet_Sag_ratio(data=None, compute_at_init=True)[source]
Bases:
SagFeature
- class ephyspy.features.sweepset_features.SweepSet_Sag_time(data=None, compute_at_init=True)[source]
Bases:
SagFeature
- class ephyspy.features.sweepset_features.SweepSet_Slow_hyperpolarization(data=None, compute_at_init=True)[source]
Bases:
SweepSetFeature
Obtain sweepset level slow_hyperpolarization feature.
- class ephyspy.features.sweepset_features.SweepSet_Tau(data=None, compute_at_init=True)[source]
Bases:
HyperpolMedianFeature
- class ephyspy.features.sweepset_features.SweepSet_V_baseline(data=None, compute_at_init=True)[source]
Bases:
HyperpolMedianFeature
- class ephyspy.features.sweepset_features.SweepSet_V_rest(data=None, compute_at_init=True)[source]
Bases:
HyperpolMedianFeature
- class ephyspy.features.sweepset_features.SweepSet_Wildness(data=None, compute_at_init=True)[source]
Bases:
MaxFeature
- class ephyspy.features.sweepset_features.SweepSet_dfdI(data=None, compute_at_init=True)[source]
Bases:
SweepSetFeature
Obtain sweepset level dfdI feature.
- plot(*args, ax: Axes | None = None, **kwargs) Axes [source]
Adds additional kwargs and functionality to BaseFeature._plot`.
Before calling BaseFeature._plot, this function checks if the feature is a stimulus feature and if so, ensures the feature is plotteed onto the stimulus axis. Additionally along with every feature, the sweep can be plotted. Same goes for the stimulus.
If no axis is provided one is created. This function can be (and should be overwritten) if the feature cannot be displayed on top of the unterlying sweep.
- Parameters:
self (BaseFeature) – Feature to plot. Needs to have a plot method.
*args – Additional arguments to pass to self.plot.
ax (Optional[Axes], optional) – Axes to plot on.
show_sweep (bool, optional) – Whether to plot the sweep. Defaults to False.
show_stimulus (bool, optional) – Whether to plot the stimulus. Defaults to False.
kwargs – Additional kwargs to pass to self.plot.
- Returns:
Axes of plot.
- Return type:
Axes
- ephyspy.features.sweepset_features.available_sweepset_features(compute_at_init: bool = False, store_diagnostics: bool = False) Dict[str, SweepSetFeature] [source]
Return a dictionary of all implemented sweepset features.
Looks for all classes that inherit from SweepSetFeature and returns a dictionary of all available features. If compute_at_init is True, the features are computed at initialization.
- Parameters:
compute_at_init (bool, optional) – If True, the features are computed at initialization. Defaults to False.
store_diagnostics (bool, optional) – If True, the features are computed with diagnostics. Defaults to False.
- Returns:
Dictionary of all available spike features.
- Return type:
dict[str, SweepSetFeature]
ephyspy.features.utils module
- exception ephyspy.features.utils.FeatureError[source]
Bases:
ValueError
Error raised when a feature is unknown.
- ephyspy.features.utils.fetch_available_fts() List[str] [source]
Fetch all available features.
Returns a list of all available feature functions and classes that are either part of the EphysPy package or have been registered as custom features with register_custom_feature.
- Returns:
List of all available features.
- Return type:
List[str]
Warning
If a custom feature has the same name as a feature that is part of EphysPy, a warning is raised.
- ephyspy.features.utils.get_sweep_burst_metrics(sweep: EphysSweep) Tuple[ndarray, ndarray, ndarray] [source]
Calculate burst metrics for a sweep.
Uses EphysExtractor’s _process_bursts() method to calculate burst metrics. Handles case where no bursts are found.
- Parameters:
sweep (EphysSweep) – Sweep to calculate burst metrics for.
- Returns:
- returns burst index, burst start index,
burst end index.
- Return type:
Tuple[ndarray, ndarray, ndarray]
- ephyspy.features.utils.get_sweep_sag_idxs(sag_instance: Any, recompute: bool = False, store_diagnostics=False) ndarray [source]
determine idxs in a sweep that are part of the sag.
description: all idxs below steady state and during stimulus.
- Parameters:
feature (EphysSweep) – sag_feature object.
- Returns:
boolean array with length of sweep.t; where sag.
- ephyspy.features.utils.has_rebound(feature: Any, T_rebound: float = 0.3) bool [source]
Check if sweep rebounds.
description: rebound if voltage exceeds baseline after stimulus offset.
- Parameters:
feature (SweepFeature) – Feature to check for rebound.
T_rebound (float, optional) – Time window after stimulus offset in which rebound can occur. Defaults to 0.3.
- Returns:
True if sweep rebounds.
- Return type:
bool
- ephyspy.features.utils.has_spikes(sweep: EphysSweep) bool [source]
Check if sweep has spikes.
- Parameters:
sweep (EphysSweep) – Sweep to check.
- Returns:
True if sweep has spikes.
- Return type:
bool
- ephyspy.features.utils.has_stimulus(data: EphysSweep | EphysSweepSet) bool | ndarray [source]
Check if sweep has stimulus that is non-zero.
- Parameters:
data (EphysSweep or EphysSweepSet) – Sweep or sweepset to check.
- Returns:
True if sweep has stimulus.
- Return type:
bool
- ephyspy.features.utils.is_depol(data: EphysSweep | EphysSweepSet) bool | ndarray [source]
Check if sweep is depolarizing, i.e. if the stimulus > 0.
- Parameters:
data (EphysSweep or EphysSweepSet) – Sweep or sweepset to check.
- Returns:
True if sweep is depolarizing.
- Return type:
bool
- ephyspy.features.utils.is_hyperpol(data: EphysSweep | EphysSweepSet) bool | ndarray [source]
Check if sweep is hyperpolarizing, i.e. if the stimulus < 0.
- Parameters:
data (EphysSweep or EphysSweepSet) – Sweep or sweepset to check.
- Returns:
True if sweep is hyperpolarizing.
- Return type:
bool
- ephyspy.features.utils.median_idx(d: DataFrame | ndarray) int | slice [source]
Get index of median value in a DataFrame.
If median is unique return index, otherwise return all indices that are closest to the median. If dataframe is empty or all nan return slice(0).
- Parameters:
d (Union[DataFrame, ndarray]) – DataFrame or ndarray to get median index from.
- Returns:
- Index of median value or slice(0) if d is empty or
all nan.
- Return type:
Union[int, slice]
- ephyspy.features.utils.register_custom_feature(Feature: Callable | SweepSetFeature | SweepFeature)[source]
Add a custom feature class that inherits from SweepFeature or from SweepSetFeature. This makes the feature available to all the the EphysPy functionalities such as recursive computation of all dependend features that are called with lookup_X_feature, where X can be spike, sweep or sweepset.
- Parameters:
Feature – Feature class to be added to EphysPy ecosystem. Feature must inherit from either SweepFeature or SweesetFeature.
- ephyspy.features.utils.where_stimulus(data: EphysSweep | EphysSweepSet) bool | ndarray [source]
Checks where the stimulus is non-zero.
Checks where stimulus is non-zero for a single sweep or each sweep in a sweepset.
- Parameters:
data (EphysSweep or EphysSweepSet) – Sweep or sweepset to check.
- Returns:
True if stimulus is non-zero.
- Return type:
bool