ibl_alignment_gui.loaders.data_loader

Classes

DataLoader

Abstract base class for loading processed data for the ibl_alignment_gui.

DataLoaderLocal

Data loader using local file system.

DataLoaderOne

Data loader using ONE.

FeatureLoader

Abstract base class for loading ephys atlas features.

FeatureLoaderOne

Feature loader using ONE.

SpikeGLXLoader

Abstract base class for loading SpikeGLX metadata and AP band snippets.

SpikeGLXLoaderLocal

SpikeGLX loader using local file system.

SpikeGLXLoaderOne

SpikeGLX loader using ONE.

class ibl_alignment_gui.loaders.data_loader.DataLoader[source]

Bases: ABC

Abstract base class for loading processed data for the ibl_alignment_gui.

Loads spikesorted and raw ephys data.

Subclasses must implement the follow abstract methods: - load_passive_data - load_raw_passive_data - load_ephys_data - load_spikes_data

filter_raw_by_chns(data)[source]

Filter ephys data to only include data relevant to channels present on selected shank.

Parameters:

data (dict) – Raw ephys data

Returns:

data – Filtered ephys data

Return type:

Bunch

filter_spikes_by_chns(spikes, clusters, channels)[source]

Filter spikes to only include data relevant to channels present on selected shank.

Return type:

tuple[Bunch[str, Any], Bunch[str, Any], Bunch[str, Any]]

Returns:

  • spikes (Bunch) – Filtered spikes data

  • clusters (Bunch) – Filtered clusters data

  • channels (Bunch) – Filtered channels data

static filter_spikes_by_fr(spikes, clusters, min_fr=0.013888888888888888)[source]

Remove low-firing clusters and filter spikes accordingly.

Parameters:
  • spikes (Bunch) – Spike data.

  • clusters (Bunch) – Cluster data.

  • min_fr (float) – Minimum firing rate in Hz.

Return type:

tuple[Bunch[str, Any], Bunch[str, Any]]

Returns:

  • spikes (Bunch) – Spikes data above fr threshold

  • clusters (Bunch) – Clusters data above fr threshold

get_data(shank_sites)[source]

Load all relevant data associated with the probe.

Parameters:

shank_sites (Bunch) – A Bunch object containing the channels that correspond to the shank

Returns:

data – A Bunch object containing spikes, clusters, channels, RMS and PSD data, and passive stimulus data.

Return type:

Bunch

get_passive_data()[source]

Load passive visual stimulus data including RF map, visual stimuli, and gabor events.

Return type:

tuple[Bunch[str, Any], Bunch[str, Any], Bunch[str, Any]]

Returns:

  • rf_data (Bunch) – RF map data including frames.

  • stim_data (Bunch) – Visual stimulus data.

  • vis_stim (Bunch) – Gabor event data for left and right gabors.

get_psd_data(band='LF')[source]

Load power spectral density data for specified band.

Only returns data on channels present on selected shank.

Parameters:

band (str) – Band type (‘AP’ or ‘LF’).

Returns:

psd_data – PSD data

Return type:

Bunch

get_rms_data(band='AP')[source]

Load RMS data for specified band.

Only returns data on channels present on selected shank.

Parameters:

band (str) – Band type (‘AP’ or ‘LF’).

Returns:

rms_data – RMS data

Return type:

Bunch

get_spikes_data()[source]

Load spike sorting data and optionally filter by minimum firing rate threshold.

Only returns data on channels present on selected shank.

Return type:

tuple[Bunch[str, Any], Bunch[str, Any], Bunch[str, Any]]

Returns:

  • spikes (Bunch) – spikes data

  • clusters (Bunch) – clusters data

  • channels (Bunch) – channels data

static load_data(load_function, *args, raise_message=None, raise_exception=<class 'one.alf.exceptions.ALFObjectNotFound'>, raise_error=False, **kwargs)[source]

Safely load data using a provided function.

Parameters:
  • load_function (Callable) – Function to load the data (e.g., ONE or alfio).

  • args (tuple) – Arguments for the loading function.

  • raise_message (str or None) – Message to log if an exception is raised.

  • raise_exception (Exception or ALFObjectNotFound) – Type of exception to catch.

  • raise_error (bool) – Whether to raise the exception after logging.

Returns:

The loaded data with an ‘exists’ flag.

Return type:

Bunch

abstractmethod load_ephys_data(alf_object, **kwargs)[source]

Abstract method to load ephys data.

Return type:

Bunch[str, Any]

abstractmethod load_passive_data(alf_object, **kwargs)[source]

Abstract method to load passive data.

Return type:

Bunch[str, Any]

abstractmethod load_raw_passive_data(alf_object, **kwargs)[source]

Abstract method to load raw passive data.

Return type:

Bunch[str, Any]

abstractmethod load_spikes_data(alf_object, attributes, **kwargs)[source]

Abstract method to load spike sorting data.

Return type:

Bunch[str, Any]

class ibl_alignment_gui.loaders.data_loader.DataLoaderLocal(data_paths)[source]

Bases: DataLoader

Data loader using local file system.

Data are loaded from files on disk. Uses a CollectionData object to resolve the paths for the different data directories.

Parameters:
  • probe_path (Path) – Root directory of probe data

  • collections (CollectionData) – Object containing subcollection paths for spike, ephys, task, raw_task, and metadata.

get_passive_data()[source]

Load passive data from local path.

Only attempts to load if both task_path and raw_task_path are defined.

Return type:

Bunch or None

load_ephys_data(alf_object, **kwargs)[source]

Load ephys data from local path.

Return type:

Bunch

load_passive_data(alf_object, **kwargs)[source]

Load passive data from local path.

Return type:

Bunch

load_raw_passive_data(alf_object, **kwargs)[source]

Load raw passive data from local path.

Return type:

Bunch or None

load_spikes_data(alf_object, attributes, **kwargs)[source]

Load spike sorting data from local path.

Return type:

Bunch

class ibl_alignment_gui.loaders.data_loader.DataLoaderOne(insertion, one, session_path=None, spike_collection=None)[source]

Bases: DataLoader

Data loader using ONE.

Data are downloaded using Alyx/ ONE.

Parameters:
  • insertion (dict) – Dictionary representing a probe insertion (must include ‘session’ and ‘name’).

  • one (ONE) – An ONE instance used to access data.

  • session_path (Path or None) – Path to the session folder. If None, it is resolved using the eid via one.eid2path.

  • spike_collection (str or None) – Spike sorting algorithm to load (e.g. ‘pykilosort’, ‘iblsorter’).

get_spike_sorting_path()[source]

Determine the path to the spike sorting output.

Returns:

probe_path – A Path to the spike sorting folder for the probe.

Return type:

Path

load_ephys_data(alf_object, **kwargs)[source]

Load ephys data using ONE.

Return type:

Bunch

load_passive_data(alf_object, **kwargs)[source]

Load passive data using ONE.

Return type:

Bunch

load_raw_passive_data(alf_object, **kwargs)[source]

Load raw passive data using ONE.

Return type:

Bunch

load_spikes_data(alf_object, attributes, **kwargs)[source]

Load spike sorting data using ONE.

Return type:

Bunch

class ibl_alignment_gui.loaders.data_loader.FeatureLoader[source]

Bases: ABC

Abstract base class for loading ephys atlas features.

abstractmethod load_features()[source]

Abstract method to load ephys atlas features.

Return type:

Bunch[str, Any]

class ibl_alignment_gui.loaders.data_loader.FeatureLoaderOne(insertion, one, session_path=None)[source]

Bases: FeatureLoader

Feature loader using ONE.

Loads feature from ephys feature table.

download_features(fname, save_path)[source]

Download the latest ephys atlas features from S3.

Parameters:
  • fname (str) – Filename to download

  • save_path (Path) – A path to save the downloaded file

Return type:

None

load_features()[source]

Load ephys atlas features from ONE.

Returns:

feature_data – A Bunch containing a dataFrame containing ephys atlas features for the probe.

Return type:

Bunch

class ibl_alignment_gui.loaders.data_loader.SpikeGLXLoader(save_path=None)[source]

Bases: ABC

Abstract base class for loading SpikeGLX metadata and AP band snippets.

Subclasses must implement the follow abstract methods: - load_meta_data - load_ap_data

Parameters:

save_path (Path or None) – Directory where cached snippet data will be saved.

get_meta_data()[source]

Load and parse metadata for the AP band.

Returns:

A Bunch containing geometry info and an ‘exists’ flag.

Return type:

Bunch

static get_time_snippets(sr, n=3, pad=200)[source]

Return n time points across the file duration, excluding pad seconds from start and end.

Parameters:
  • sr (spikeglx.Reader or Streamer) – The raw data reader

  • n (int) – Number of time points to extract.

  • pad (int) – Time (seconds) to exclude from beginning and end.

Returns:

Array of time points in seconds.

Return type:

np.ndarray

abstractmethod load_ap_data()[source]

Abstract method to return a SpikeGLX reader or Streamer object.

Return type:

Reader | Streamer | None

load_ap_snippets(twin=1)[source]

Load AP snippets centered around selected time points.

Also computes channel quality metrics across snippets to detect dead, noisy and outside channels.

Parameters:

twin (float) – Time window in seconds for each snippet.

Returns:

data – Snippets of raw data for three timepoints in addition to metadata (exists, fs).

Return type:

Bunch

abstractmethod load_meta_data()[source]

Abstract method to load AP metadata.

Return type:

dict | None

class ibl_alignment_gui.loaders.data_loader.SpikeGLXLoaderLocal(meta_path)[source]

Bases: SpikeGLXLoader

SpikeGLX loader using local file system.

Parameters:
  • probe_path (Path) – Root directory of probe data

  • meta_collection (str) – Name of subfolder containing meta and binary files.

load_ap_data()[source]

Load binary AP data from local path.

Returns:

A spikeglx.Reader instance to load the raw data, or None if not found.

Return type:

spikeglx.Reader or None

load_meta_data()[source]

Load AP metadata from local path.

Returns:

A dict containing the spikeglx AP band metadata, or None if not found.

Return type:

dict or None

class ibl_alignment_gui.loaders.data_loader.SpikeGLXLoaderOne(insertion, one, session_path=None, force=False)[source]

Bases: SpikeGLXLoader

SpikeGLX loader using ONE.

Raw data is streamed via ONE

Parameters:
  • insertion (dict) – Dictionary representing a probe insertion (must include ‘session’ and ‘name’).

  • one (ONE) – An ONE instance used to access data.

  • session_path (Path or None) – Path to the session folder. If None, it is resolved using the eid via one.eid2path.

  • force (bool) – If True, forces removal of cached data before streaming.

load_ap_data()[source]

Load AP data using ONE.

Returns:

A streamer object for AP band.

Return type:

Streamer

load_meta_data()[source]

Load AP metadata using ONE.

Returns:

A dict containing the spikeglx AP band metadata, or None if not found.

Return type:

dict or None