ephyspy package
Subpackages
- ephyspy.allen_sdk package
- Submodules
- ephyspy.allen_sdk.ephys_extractor module
EphysCellFeatureExtractor
EphysCellFeatureExtractor.SAG_TARGET
EphysCellFeatureExtractor.SUBTHRESH_MAX_AMP
EphysCellFeatureExtractor.as_dict()
EphysCellFeatureExtractor.cell_features()
EphysCellFeatureExtractor.long_squares_features()
EphysCellFeatureExtractor.long_squares_stim_amps()
EphysCellFeatureExtractor.process()
EphysCellFeatureExtractor.ramps_features()
EphysCellFeatureExtractor.short_squares_features()
EphysSweepSetFeatureExtractor
cell_extractor_for_nwb()
extractor_for_nwb_sweeps()
fit_fi_slope()
input_resistance()
membrane_time_constant()
reset_long_squares_start()
- ephyspy.allen_sdk.ephys_features module
FeatureError
adaptation_index()
analyze_trough_details()
average_rate()
average_voltage()
calculate_dvdt()
check_thresholds_and_peaks()
detect_bursts()
detect_pauses()
detect_putative_spikes()
estimate_adjusted_detection_parameters()
filter_putative_spikes()
find_downstroke_indexes()
find_peak_indexes()
find_time_index()
find_trough_indexes()
find_upstroke_indexes()
find_widths()
fit_membrane_time_constant()
fit_prespike_time_constant()
get_isis()
has_fixed_dt()
latency()
norm_diff()
norm_sq_diff()
refine_threshold_indexes()
- Module contents
- ephyspy.features package
- Submodules
- ephyspy.features.base module
- ephyspy.features.spike_features module
- ephyspy.features.sweep_features module
APSweepFeature
NullSweepFeature
Sweep_AP_ADP
Sweep_AP_AHP
Sweep_AP_CV
Sweep_AP_FF
Sweep_AP_UDR
Sweep_AP_amp
Sweep_AP_amp_adapt
Sweep_AP_amp_adapt_avg
Sweep_AP_amp_slope
Sweep_AP_freq
Sweep_AP_freq_adapt
Sweep_AP_latency
Sweep_AP_peak
Sweep_AP_thresh
Sweep_AP_trough
Sweep_AP_width
Sweep_Burstiness
Sweep_ISI
Sweep_ISI_CV
Sweep_ISI_FF
Sweep_ISI_adapt
Sweep_ISI_adapt_avg
Sweep_Num_AP
Sweep_Num_bursts
Sweep_R_input
Sweep_Rebound
Sweep_Rebound_APs
Sweep_Rebound_area
Sweep_Rebound_avg
Sweep_Rebound_latency
Sweep_Sag
Sweep_Sag_area
Sweep_Sag_fraction
Sweep_Sag_ratio
Sweep_Sag_time
Sweep_Stim_amp
Sweep_Stim_end
Sweep_Stim_onset
Sweep_Tau
Sweep_V_baseline
Sweep_V_deflect
Sweep_V_plateau
Sweep_V_rest
Sweep_V_sag
Sweep_V_steady
Sweep_Wildness
available_sweep_features()
- ephyspy.features.sweepset_features module
APFeature
APsFeature
First5MedianFeature
HyperpolMedianFeature
MaxFeature
NullSweepSetFeature
ReboundFeature
SagFeature
SweepSet_AP_ADP
SweepSet_AP_AHP
SweepSet_AP_CV
SweepSet_AP_FF
SweepSet_AP_UDR
SweepSet_AP_amp
SweepSet_AP_amp_adapt
SweepSet_AP_amp_adapt_avg
SweepSet_AP_amp_slope
SweepSet_AP_freq
SweepSet_AP_freq_adapt
SweepSet_AP_latency
SweepSet_AP_peak
SweepSet_AP_thresh
SweepSet_AP_trough
SweepSet_AP_width
SweepSet_Burstiness
SweepSet_ISI
SweepSet_ISI_CV
SweepSet_ISI_FF
SweepSet_ISI_adapt
SweepSet_ISI_adapt_avg
SweepSet_Num_AP
SweepSet_Num_bursts
SweepSet_R_input
SweepSet_Rebound
SweepSet_Rebound_APs
SweepSet_Rebound_area
SweepSet_Rebound_avg
SweepSet_Rebound_latency
SweepSet_Rheobase
SweepSet_Sag
SweepSet_Sag_area
SweepSet_Sag_fraction
SweepSet_Sag_ratio
SweepSet_Sag_time
SweepSet_Slow_hyperpolarization
SweepSet_Tau
SweepSet_V_baseline
SweepSet_V_rest
SweepSet_Wildness
SweepSet_dfdI
available_sweepset_features()
- ephyspy.features.utils module
- Module contents
Submodules
ephyspy.analysis module
- ephyspy.analysis.plot_spike_feature(sweep: EphysSweep, ft: str, ax: Axes | None = None, **kwargs) Axes [source]
Plot spike feature by name.
- Parameters:
sweep (EphysSweep) – Sweep to plot the feature for.
ft (str) – Name of the feature to plot (all lowercase). Can plot all features that are included in the EphysSweep._spikes_df and all features in available_spike_features().
ax (Axes) – Matplotlib axes.
**kwargs – Additional kwargs are passed to the plotting function.
- Returns:
Matplotlib axes.
- Return type:
Axes
- ephyspy.analysis.plot_spike_features(sweep: EphysSweep, window: Tuple = [0.4, 0.45]) Tuple[Figure, Axes] [source]
Plot overview of the extracted spike features for a sweep.
- Parameters:
sweep (EphysSweep) – Sweep to plot the features for.
window (Tuple, optional) – Specific Time window to zoom in on a subset or single spikes to see more detail. Defaults to [0.4, 0.45].
- Returns:
Matplotlib figure and axes.
- Return type:
Tuple[Figure, Axes]
- ephyspy.analysis.plot_sweepset_diagnostics(sweepset: EphysSweepSet, figsize=(15, 14)) Tuple[Figure, Axes] [source]
Plot diagnostics overview for the whole sweepset.
This function is useful to diagnose outliers on the sweepset level.
- Parameters:
sweepset (EphysSweepSet) – sweepset to diagnose.
- Returns:
figure and axes with plot.
- Return type:
Fig, Axes
ephyspy.sweeps module
- class ephyspy.sweeps.EphysSweep(*args, metadata: Dict = {}, **kwargs)[source]
Bases:
EphysSweepFeatureExtractor
Wrapper around EphysSweepFeatureExtractor from the AllenSDK to support additional functionality.
Mainly it supports the addition of new spike features and metadata.
- metadata
Metadata for the sweep.
- Type:
dict
- added_spike_features
Dictionary of added spike features.
- Type:
dict
- features
Dictionary of sweep features. These should be SweepFeature instances.
- Type:
dict
- add_features(features: List[Any] | Dict[str, Any])[source]
Add features to the EphysSweep instance.
This function can be used to add spike or sweep features to an EphysSweep object. The added features can then be accessed via self.features or collectively computed via self.get_features().
- Parameters:
features (Union[List[Any], Dict[str, Any]]) – List of features to add.
- Raises:
TypeError – If feature is not of a known type.
- add_spike_feature(feature_name: str, feature_func: Callable)[source]
Add a new spike feature to the extractor.
- Parameters:
feature_name (str) – Name of the new feature.
feature_func (Callable) – Function to calculate the new feature.
- get_features(recompute: bool = False) Dict[str, float] [source]
Compute all features that have been added to the EphysSweep instance.
Includes all features that can be found in self.features.
- Parameters:
recompute (bool, optional) – Whether to force recomputation of the features. Defaults to False.
- Returns:
Dictionary of features and values.
- Return type:
Dict[str, float]
- plot(ax: Axes | None = None, show_stimulus: bool = False, **kwargs) Axes [source]
Plot the sweep.
If no axes object is provided, one will be created. It will have one or two subplots, depending on whether the stimulus is shown.
- Parameters:
ax (Axes, optional) – Matplotlib axes to plot on.
show_stimulus (bool, optional) – Whether to plot the stimulus. Defaults to False.
- Returns:
Matplotlib axes object.
- Return type:
Axes
- plot_feature(ft: str, ax: Axes | None = None, show_sweep: bool = True, **kwargs) Axes [source]
Plot any feature of the sweep by specifying its name.
- Parameters:
ft (str) – Name of the feature to plot. (all lower case)
ax (Axes, optional) – Matplotlib axes to plot on.
show_sweep (bool, optional) – Whether to plot V(t). Defaults to True.
- Returns:
Matplotlib axes object.
- Return type:
Axes
- plot_features(fts: List[str], ax: Axes | None = None, show_sweep: bool = True, **kwargs) Axes [source]
Plot multiple features of the sweep by specifying their names.
- Parameters:
fts (List[str]) – Names of the features to plot. (all lower case)
ax (Axes, optional) – Matplotlib axes to plot on.
show_sweep (bool, optional) – Whether to plot V(t). Defaults to True.
- Returns:
Matplotlib axes object.
- Return type:
Axes
- class ephyspy.sweeps.EphysSweepSet(t_set: List | ndarray | None = None, v_set: List | ndarray | None = None, i_set: List | ndarray | None = None, t_start: List | ndarray | float | None = None, t_end: List | ndarray | float | None = None, metadata: Dict = {}, *args, **kwargs)[source]
Bases:
EphysSweepSetFeatureExtractor
Wrapper around EphysSweepSetFeatureExtractor from the AllenSDK to support additional functionality.
t_set, v_set and i_set are optional and EphysSweepSet can also be initialized using an iterable of sweeps via the from_sweeps method. In this case all the metadata already needs to be contained in the sweeps.
- Parameters:
t_set (ndarray) – Time array for set of sweeps.
v_set (ndarray) – Voltage array for set of sweeps.
i_set (ndarray) – Current array for set of sweeps.
metadata (dict, optional) – Metadata for the sweep set. Defaults to None.
or (The metadata can be used to set hyperparameters for features) – store identifying information, such as cell id etc..
*args – Additional arguments for EphysSweepSetFeatureExtractor.
**kwargs – Additional keyword arguments for EphysSweepSetFeatureExtractor.
- metadata
Metadata for the sweep set.
- Type:
dict
- add_features(features: List[Any] | Dict[str, Any])[source]
Add features to the EphysSweepSet instance.
This function can be used to add spike sweep or sweepset features to an EphysSweepSet object. The added features can then be accessed via self.features or collectively computed via self.get_features().
Sweep features are passed to each sweep in the set and added there. Any sweep features needed in their computation are automatically added and handled by SweepSetFeature instances. This means they don’t necessarily need to be added manually.
- Parameters:
features (Union[List[Any], Dict[str, Any]]) – List of features to add.
- Raises:
TypeError – If feature is not of a known type.
- add_spike_feature(feature_name: str, feature_func: Callable)[source]
Add a new spike feature to the extractor.
Adds new spike feature to each EphysSweep instance.
- Parameters:
feature_name (str) – Name of the new feature.
feature_func (Callable) – Function to calculate the new feature.
- Raises:
TypeError – If feature is not of a known type.
- get_features(recompute: bool = False) Dict[str, float] [source]
Compute all features that have been added to the EphysSweepSet instance.
Includes all features that can be found in self.features.
- Parameters:
recompute (bool, optional) – Whether to force recomputation of the features. Defaults to False.
- Returns:
Dictionary of features and values.
- Return type:
Dict[str, float]
- get_sweep_features(recompute: bool = False) Dict[str, List[float]] [source]
Collect features on a sweep level.
This computes / looks up all features that have been computed at the sweep level and returns them as a dictionary of lists. Each list contains the values for the respective feature for each sweep, i.e. get_sweep_features()[feature_name][sweep_idx] returns the value of feature_name for the sweep_idx-th sweep.
- Parameters:
recompute (bool, optional) – Whether to force recomputation of the features. Defaults to False.
- Returns:
Dictionary of features and values.
- Return type:
Dict[str, List[float]]
- property i: ndarray
- plot(ax: Axes | None = None, show_stimulus: bool = False, **kwargs) Axes [source]
Plot all sweeps in the set.
If no axes object is provided, one will be created. It will have one or two subplots, depending on whether the stimulus is shown.
- Parameters:
ax (Axes, optional) – Matplotlib axes to plot on.
show_stimulus (bool, optional) – Whether to plot the stimulus. Defaults to False.
- Returns:
Matplotlib axes object.
- Return type:
Axes
- set_stimulus_amplitude_calculator(func: Callable)[source]
Set stimulus amplitude calculator for each sweep.
This is potentially only relevant for working with the AllenSDK and should not be needed for using ephyspy on its own.
- Parameters:
func (Callable) – Function to calculate stimulus amplitude.
- property t: ndarray
- property v: ndarray
ephyspy.utils module
- ephyspy.utils.fwhm(t: ndarray, v: ndarray, t_start: float, t_end: float) Tuple[float, float, float] [source]
Get full width at half maximum of a ap.
- Parameters:
t (ndarray) – time array.
v (ndarray) – voltage array.
t_start (float) – start time of ap.
t_end (float) – end time of ap.
- Returns:
- full width at half maximum,
time of half maximum upstroke, time of half maximum downstroke.
- Return type:
Tuple[float, float, float]
- ephyspy.utils.get_feature(name: str, data: EphysSweep | EphysSweepSet, **kwargs)[source]
Get feature by name.
This is a convenience function to compute features without having to import the feature classes or think about wether a feature is computed on a sweep or sweepset.
- Parameters:
name (str) – Name of feature.
data (EphysSweep or EphysSweepSet) – Data to compute feature on. This can be either a single sweep or a sweepset.
- Raises:
FeatureError – If feature is not available for data type.
- Returns:
Feature object.
- Return type:
Feature
- ephyspy.utils.has_spike_feature(sweep: EphysSweep, ft: str) bool [source]
Checks if sweep has a given spike feature.
First checks for _spikes_df attribute, which should get instantiated if spikes have already been processed. If not present process_spikes will be called. Then, if the feature is present in the _spikes_df and not all values are NaN, returns True.
- Parameters:
sweep (EphysSweep) – Sweep to check for existance of spike feature.
ft (str) – Spike feature to check for. Feature must be present in _spikes_df for a healthy spiking sweep.
- Returns:
Whether sweep has the given spike feature.
- Return type:
bool
- ephyspy.utils.parse_deps(deps_string: str) List[str] [source]
Parses docstring for feature dependencies.
If no dependencies are found, returns empty list. Special case of parse_func_doc_attrs.
- Parameters:
deps_string (str) – String to parse for dependencies.
- Returns:
List of dependencies.
- Return type:
List[str]
- ephyspy.utils.parse_desc(func: Callable) str [source]
Parses docstring for description.
If no description is found, returns empty string. Special case of parse_func_doc_attrs.
- Parameters:
func (Callable) – Function to parse docstring of.
- Returns:
Description of function.
- Return type:
str
- ephyspy.utils.parse_func_doc_attrs(func: Callable) Dict [source]
Parses docstrings for attributes.
Docstrings should have the following format: <Some text> attr: <attr text>. attr: <attr text>. … <Some more text>
IMPORTANT: EACH ATTRIBUTE MUST END WITH A “.”
- Parameters:
func (Callable) – Function to parse docstring of.
- Returns:
all attributes found in document string.
- Return type:
doc_attrs
- ephyspy.utils.relabel_line(ax: Axes, old_label: str, new_label: str)[source]
Rename line label in one given axes.
- ephyspy.utils.scatter_spike_ft(ft, sweep: EphysSweep, ax: Axes = None, selected_idxs=None, **kwargs) Axes [source]
- ephyspy.utils.unpack(dict: Dict, keys: str | Tuple[str, ...]) Any | Tuple[Any, ...] [source]
Unpack dict to tuple of values.
- ephyspy.utils.where_between(t, t0, tend)