FrequencyDomainSpikeAnalysisResult#
- class neurodent.results.FrequencyDomainSpikeAnalysisResult(result_sas: list[SortingAnalyzer] = None, result_mne: RawArray = None, spike_indices: list[ndarray] = None, detection_params: dict = None, animal_id: str = None, genotype: str = None, animal_day: str = None, bin_folder_name: str = None, metadata: RecordingMetadata = None, channel_names: list[str] = None)[source]#
Bases:
objectWrapper for frequency-domain spike detection results.
This class mirrors the SpikeAnalysisResult interface to ensure compatibility with existing WindowAnalysisResult.read_sars_spikes() infrastructure.
- __init__(result_sas: list[SortingAnalyzer] = None, result_mne: RawArray = None, spike_indices: list[ndarray] = None, detection_params: dict = None, animal_id: str = None, genotype: str = None, animal_day: str = None, bin_folder_name: str = None, metadata: RecordingMetadata = None, channel_names: list[str] = None) None[source]#
Initialize FrequencyDomainSpikeAnalysisResult.
- Parameters:
result_sas (
list[si.SortingAnalyzer], optional) – SpikeInterface SortingAnalyzers for compatibilityresult_mne (
mne.io.RawArray, optional) – MNE RawArray with spike annotationsspike_indices (
list[np.ndarray], optional) – Raw spike detection results per channeldetection_params (
dict, optional) – Parameters used for spike detectionanimal_id (
str, optional) – Identifier for the animalgenotype (
str, optional) – Genotype of animalanimal_day (
str, optional) – Recording day identifierbin_folder_name (
str, optional) – Binary folder namemetadata (
RecordingMetadata, optional) – Recording metadatachannel_names (
list[str], optional) – List of channel names
- property path_safe_animal_id: str#
Slugified
animal_idfor filesystem paths.See
WindowAnalysisResult.path_safe_animal_idfor the convention.
- property path_safe_animal_day: str#
Slugified
animal_dayfor filesystem paths.
- property path_safe_save_stem: str#
Canonical filename stem
{animal_id}-{genotype}-{animal_day}, slugified.Use this whenever building the directory or filename for this FDSAR’s on-disk artifacts; it consolidates the three identifier reads into one slugified call so callers don’t have to reconstruct the format string.
- classmethod from_detection_results(spike_indices_per_channel: list[ndarray], recording: si.BaseRecording, detection_params: dict, animal_id: str = None, genotype: str = None, animal_day: str = None, bin_folder_name: str = None, metadata: RecordingMetadata = None)[source]#
Create FrequencyDomainSpikeAnalysisResult from raw detection outputs.
- Parameters:
spike_indices_per_channel – List of spike sample indices per channel
recording – SpikeInterface recording. Traces are read directly from this object (zero-copy) to build SortingAnalyzers.
detection_params – Parameters used for detection
animal_id – Identifier for the animal
genotype – Genotype of animal
animal_day – Recording day identifier
bin_folder_name – Binary folder name
metadata – Recording metadata
- Returns:
Initialized result object
- Return type:
- convert_to_mne(chunk_duration_s: float = 60, save_raw=True, multiprocess_mode: Literal['dask', 'serial'] = 'serial') RawArray[source]#
Convert SortingAnalyzers to MNE RawArray.
- Parameters:
chunk_duration_s (
float, optional) – Duration in seconds of each chunk read during conversion. Smaller values reduce peak RAM; larger values improve throughput. Defaults to 60.save_raw – Whether to save the result internally
multiprocess_mode – Whether to use Dask for parallel per-channel conversion. Defaults to “serial”.
- Returns:
MNE RawArray with spike annotations
- Return type:
mne.io.RawArray
- save_fif_and_json(folder: str | Path, convert_to_mne=True, make_folder=True, save_abbrevs=False, overwrite=False, multiprocess_mode: Literal['dask', 'serial'] = 'serial', chunk_duration_s: float = 60)[source]#
Archive frequency domain spike analysis result as fif and json files. Mirrors the SpikeAnalysisResult.save_fif_and_json interface.
The filename stem is always
path_safe_save_stem(slugified{animal_id}-{genotype}-{animal_day}). The previousslugify_filebasekwarg was removed — the unsafe (un-slugified) form was never the right answer for any real caller.- Parameters:
folder – Destination folder to save results
convert_to_mne – If True, convert to MNE if needed
make_folder – If True, create folder if it doesn’t exist
save_abbrevs – If True, save abbreviations as channel names
overwrite – If True, overwrite existing files
multiprocess_mode – Whether to use Dask for parallel conversion. Defaults to “serial”.
chunk_duration_s (
float, optional) – Duration in seconds of each chunk read when converting SortingAnalyzers to a NumPy trace array. Smaller values reduce peak RAM at the cost of more I/O round-trips; larger values improve throughput on high-memory systems. Only used whenresult_mneisNoneandconvert_to_mneisTrue. Defaults to 60.
- classmethod load_fif_and_json(folder: str | Path)[source]#
Load FrequencyDomainSpikeAnalysisResult from fif and json files. Mirrors the SpikeAnalysisResult.load_fif_and_json interface.
- Parameters:
folder – Folder containing the saved files
- Returns:
Loaded result object
- Return type:
- plot_spike_averaged_traces(tmin=-0.5, tmax=0.5, baseline=None, save_dir=None, animal_id=None, save_epoch=True)[source]#
Plot spike-triggered averages for each channel.
Based on plot_spike_evoked_by_channel from the pipeline script.
- Parameters:
tmin – Start time for epochs (seconds)
tmax – End time for epochs (seconds)
baseline – Baseline correction period
save_dir – Directory to save plots and epoch data
animal_id – Animal identifier for filenames
save_epoch – Whether to save epoch data
- Returns:
Spike counts per channel, keyed by channel index
- Return type:
dict
- get_spike_counts_per_channel() list[int][source]#
Get spike counts per channel.
- Returns:
Number of detected spikes per channel
- Return type:
list
- static convert_sas_to_mne(sas: list[SortingAnalyzer], chunk_duration_s: float = 60, multiprocess_mode: Literal['dask', 'serial'] = 'serial') RawArray[source]#
Convert a list of SortingAnalyzers to a MNE RawArray.
- Parameters:
sas (
list[si.SortingAnalyzer]) – The list of SortingAnalyzers to convertchunk_duration_s (
float, optional) – Duration in seconds of each chunk read during conversion. Defaults to 60.multiprocess_mode (
Literal["dask", "serial"], optional) – Whether to use Dask for parallel per-channel conversion. Defaults to “serial”.
- Returns:
The converted RawArray, with spikes labeled as annotations
- Return type:
mne.io.RawArray
- static convert_sa_to_np(sa: SortingAnalyzer, chunk_duration_s: float = 60, multiprocess_mode: Literal['dask', 'serial'] = 'serial') ndarray[source]#
Convert a SortingAnalyzer to a numpy array of traces.
- Parameters:
sa (
si.SortingAnalyzer) – The SortingAnalyzer to convert. Must have only 1 channel.chunk_duration_s (
float, optional) – Duration in seconds of each chunk read during conversion. Defaults to 60.multiprocess_mode (
Literal["dask", "serial"], optional) – Whether to use Dask for parallel per-chunk reads. Defaults to “serial”. Note: avoid using “dask” when this method is already called fromconvert_sas_to_mnein Dask mode, as that parallelizes across channels and nested Dask may not improve performance.
- Returns:
The converted traces
- Return type:
np.ndarray