Skip to main content

feature_calculators.BaseFeatureCalculator

feature_calculators.BaseFeatureCalculator(name, neuropixel_version=1)

Abstract base class for source-specific feature calculators.

Concrete subclasses implement the source-dependent loaders: raw AP/LF snippets, geometry, channel metadata, and available durations. The base class then performs the shared feature-computation workflow.

Args: name (str): Human-readable recording identifier. It is used as pid in new OOP output manifests. neuropixel_version (int): Neuropixels version passed to ibldsp destriping and compute_features_from_raw.

Attributes: name (str): Human-readable recording identifier. neuropixel_version (int): Neuropixels version used for destriping.

Note: It owns live reader objects, caches, and arrays; validation is handled at method boundaries where the relevant data are available.

Methods

Name Description
available_duration Return available AP and LF recording durations in seconds.
compute_denoised_features Compute features on snippets spread over the recording, then aggregate and denoise them.
compute_snippet Compute features for one snippet using the shared raw-array engine.
enrich_channel_metadata Optionally enrich channel metadata before writing channels.pqt.
get_destriped_snippet Return raw and destriped AP/LF data for debugging.
load_channel_metadata Load channel metadata for aggregation and feature-table enrichment.
load_geometry Load channel geometry for ibldsp.
load_raw_snippet Load raw AP/LF voltage for one snippet.
output_directory_params Build parameters passed to setup_output_directory.

available_duration

feature_calculators.BaseFeatureCalculator.available_duration()

Return available AP and LF recording durations in seconds.

Returns: tuple[float | None, float | None]: (duration_ap, duration_lf). A value is None when that stream is absent or unknown.

compute_denoised_features

feature_calculators.BaseFeatureCalculator.compute_denoised_features(
    n_snippets=5,
    duration_ap=5.0,
    duration_lf=5.0,
    options=None,
    n_jobs=1,
)

Compute features on snippets spread over the recording, then aggregate and denoise them.

The start times come from get_snippet_start_times with its defaults (stratified, 5 minute margins); use it and compute_aggregated_features directly to choose the margin, method or windows.

Args: n_snippets (int): Number of snippets. duration_ap (float): AP duration of each snippet in seconds. duration_lf (float): LF duration of each snippet in seconds. options (FeatureComputationOptions, optional): Options of every snippet computation. n_jobs (int): Snippets computed in parallel.

Returns: pd.DataFrame: Aggregated and denoised features indexed by (pid, channel), with the snippet windows and code versions in df.attrs (see aggregate_snippets).

compute_snippet

feature_calculators.BaseFeatureCalculator.compute_snippet(window, options=None)

Compute features for one snippet using the shared raw-array engine.

Args: window (SnippetWindow): Snippet window to compute. options (FeatureComputationOptions, optional): Feature, output, cache, trajectory, and scratch options.

Returns: FeatureComputationResult: Feature table, computed/cached feature families, provenance, output paths, and aggregation manifest metadata.

Raises: ValueError: If the requested window or feature family is invalid.

enrich_channel_metadata

feature_calculators.BaseFeatureCalculator.enrich_channel_metadata(
    channels,
    options,
)

Optionally enrich channel metadata before writing channels.pqt.

Args: channels (pd.DataFrame): Channel metadata loaded by the subclass. options (FeatureComputationOptions): Current computation options.

Returns: pd.DataFrame: Enriched channel metadata. The base implementation returns channels unchanged.

Raises: ValueError: If trajectory data are required but unavailable.

get_destriped_snippet

feature_calculators.BaseFeatureCalculator.get_destriped_snippet(
    window,
    options=None,
    channel_labels=None,
)

Return raw and destriped AP/LF data for debugging.

Args: window (SnippetWindow): Time window to read and destripe. options (DestripeOptions, optional): Destriping options. Defaults to the calculator’s standard options. channel_labels (np.ndarray, optional): Precomputed bad-channel labels. When omitted, labels are loaded from channel metadata or detected from the AP snippet.

Returns: DestripedSnippet: Raw snippet, destriped arrays, geometry, and labels.

load_channel_metadata

feature_calculators.BaseFeatureCalculator.load_channel_metadata()

Load channel metadata for aggregation and feature-table enrichment.

Returns: pd.DataFrame: Channel metadata keyed by a "channel" column. At minimum, this should include "axial_um" and "lateral_um" when geometry is available.

load_geometry

feature_calculators.BaseFeatureCalculator.load_geometry()

Load channel geometry for ibldsp.

Returns: dict[str, np.ndarray]: Geometry with at least "x" and "y" arrays. Subclasses should include "sample_shift", "shank", "row", and "col" when available.

load_raw_snippet

feature_calculators.BaseFeatureCalculator.load_raw_snippet(window)

Load raw AP/LF voltage for one snippet.

Args: window (SnippetWindow): Time window to read.

Returns: RawSnippet: Raw AP/LF arrays shaped (channels, samples) in volts and their sampling frequencies.

Raises: ValueError: If the requested window cannot be read.

output_directory_params

feature_calculators.BaseFeatureCalculator.output_directory_params(
    window,
    output_dir,
)

Build parameters passed to setup_output_directory.

Args: window (SnippetWindow): Snippet window being computed. output_dir (Path | None): Output root directory.

Returns: dict[str, Any]: Parameters using self.name as the OOP pid.