Skip to content

Commit 5ddc119

Browse files
committed
enh: add 2 new convenience functions to retrieve spike features. fix doc versioning. prepare for 0.0.6 release.
1 parent 7fdc561 commit 5ddc119

File tree

3 files changed

+130
-18
lines changed

3 files changed

+130
-18
lines changed

docs/conf.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@
1010

1111
sys.path.insert(0, os.path.abspath("../"))
1212

13+
NAME = "ephyspy"
14+
about = {}
15+
here = os.path.abspath(os.path.dirname("../"))
16+
project_slug = NAME.lower().replace("-", "_").replace(" ", "_")
17+
with open(os.path.join(here, project_slug, "__version__.py")) as f:
18+
exec(f.read(), about)
1319

1420
project = "EphysPy"
1521
copyright = "2023, Jonas Beck"
1622
author = "Jonas Beck"
17-
release = "0.0.05"
23+
release = about["__version__"]
1824

1925
# -- General configuration ---------------------------------------------------
2026
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

ephyspy/sweeps.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import numpy as np
2323
from matplotlib.pyplot import Axes
2424
from numpy import ndarray
25+
from pandas import DataFrame
2526

2627
import ephyspy.allen_sdk.ephys_extractor as efex
2728
from ephyspy.allen_sdk.ephys_extractor import (
@@ -151,6 +152,21 @@ def get_features(self, recompute: bool = False) -> Dict[str, float]:
151152
for k, ft in self.features.items()
152153
}
153154

155+
def get_spike_features(self, recompute: bool = False) -> DataFrame:
156+
"""Compute all spike features that have been added to the `EphysSweep` instance.
157+
158+
Includes all features that can be found in `self.added_spike_features`.
159+
160+
Args:
161+
recompute (bool, optional): Whether to force recomputation of the
162+
features. Defaults to False.
163+
164+
Returns:
165+
DataFrame: DataFrame of features and values."""
166+
if not hasattr(self, "_spikes_df") or recompute:
167+
self.process_spikes()
168+
return self._spikes_df
169+
154170
def clear_features(self):
155171
"""Clear all features."""
156172
self.spikes_df = None
@@ -459,6 +475,25 @@ def get_sweep_features(self, recompute: bool = False) -> Dict[str, List[float]]:
459475
LD = [sw.get_features(recompute=recompute) for sw in self.sweeps()]
460476
return {k: [dic[k] for dic in LD] for k in LD[0]}
461477

478+
def get_spike_features(self, recompute: bool = False) -> List[DataFrame]:
479+
"""Collect spike features on a sweep level.
480+
481+
This computes / looks up all spike features that have been computed at
482+
the sweep level and returns them as a list of dataframes. Each dataframe
483+
contains the values for the respective feature for each spike, i.e.
484+
`get_spike_features()[sweep_idx][feature_name]` returns the values of
485+
`feature_name` for the `sweep_idx`-th sweep.
486+
487+
Args:
488+
recompute (bool, optional): Whether to force recomputation of the
489+
features. Defaults to False.
490+
491+
Returns:
492+
Dict[str, List[float]]: Dictionary of features and values.
493+
"""
494+
dfs = [sw.get_spike_features(recompute=recompute) for sw in self.sweeps()]
495+
return dfs
496+
462497
def plot(
463498
self, ax: Optional[Axes] = None, show_stimulus: bool = False, **kwargs
464499
) -> Axes:

0 commit comments

Comments
 (0)