ephyspy package

Subpackages

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.

clear_features()[source]

Clear all features.

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

process_spikes()[source]

Perform spike-related feature analysis, which includes added spike features not part of the original AllenSDK implementation.

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.

clear_features()[source]

Clear all features.

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.is_baseclass(base_name: str, obj: object) bool[source]
ephyspy.utils.is_spike_feature(ft: Any) bool[source]
ephyspy.utils.is_sweep_feature(ft: Any) bool[source]
ephyspy.utils.is_sweepset_feature(ft: Any) bool[source]
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.remove_mpl_artist_by_label(ax: Axes, legend_handle: str) Axes[source]
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)

Module contents