ibl_alignment_gui.loaders.geometry_loader

Functions

arrange_channels_into_banks

Arrange channel data into probe banks for visualization.

average_chns_at_same_depths

Average data across channels at the same depth.

pad_data_to_full_chn_map

Pad data to align with the full channel map, filling gaps with NaNs.

Classes

ChannelGeometry

Geometry class using spike sorting channel data.

Geometry

Abstract base class for splitting the sites on a probe per shank.

GeometryLoader

Abstract base class for loading probe geometry from metadata or channels.

GeometryLoaderLocal

Geometry loader using local file system.

GeometryLoaderOne

Geometry loader using the ONE API.

MetaGeometry

Geometry class using spikeglx ap metadata.

class ibl_alignment_gui.loaders.geometry_loader.ChannelGeometry(channels, shank_diff=100)[source]

Bases: Geometry

Geometry class using spike sorting channel data.

Here the sites correspond to the spike sorting channels.

Parameters:
  • channels (Bunch) – A Bunch object containing spike sorting channels data.

  • shank_diff (int) – The minimum difference in x coordinates to separate shanks.

class ibl_alignment_gui.loaders.geometry_loader.Geometry(x_coords, y_coords, chn_ind)[source]

Bases: ABC

Abstract base class for splitting the sites on a probe per shank.

Sites can either correspond to spike sorting channels or raw data electrodes.

Subclasses must implement the _get_n_shanks and _get_shank_groups methods.

Parameters:
  • x_coords (np.ndarray) – x coordinates of the sites

  • y_coords (np.ndarray) – y coordinates of the sites

  • chn_ind (ndarray) – Map of spike-sorting channels to raw data

split_sites_per_shank()[source]

Split the sites into shanks and store the results in self.shanks.

Channels are sorted according to the y coordinates.

Return type:

None

Each entry in self.shanks is a Bunch containing:
spikes_ind: np.ndarray

Indices of the sites that correspond to the spike sorting data.

raw_ind: np.ndarray

Indices of sites relative to raw data ordering.

site_coords: np.ndarray

(x, y) coordinates of the shank sites.

sites_min/ sites_max: float

Minimum and maximum y coordinate values.

sites_pitch: float

Minimum difference between y coordinates (sites spacing).

sites_full: np.ndarray

Full set of y coordinates covering the whole shank.

idx_full: np.ndarray

Indices of the actual y coordinates within sites_full.

n_banks: int

Number of banks in the shank.

class ibl_alignment_gui.loaders.geometry_loader.GeometryLoader[source]

Bases: ABC

Abstract base class for loading probe geometry from metadata or channels.

Subclasses must implement the load_meta_data and load_channels methods.

get_geometry()[source]

Load probe geometry from both the metadata and the channels.

get_sites_for_shank(shank_idx, sites=None)[source]

Get the sites information for a given shank.

By default, the site information from the electrodes (ap.metadata) is returned. If sites=’channels’, the site information for the channels is returned

Parameters:
  • shank_idx (int) – Index of the shank.

  • sites (str) – The origin of the site information

Returns:

Site information for the given shank.

Return type:

Bunch

abstractmethod load_channels(**kwargs)[source]

Load spike sorting channels data.

Return type:

Bunch[str, ndarray] | None

abstractmethod load_meta_data()[source]

Load probe metadata from spikeglx ap.meta file.

Return type:

Bunch[str, Any] | None

class ibl_alignment_gui.loaders.geometry_loader.GeometryLoaderLocal(data_paths)[source]

Bases: GeometryLoader

Geometry loader using local file system.

Parameters:
  • probe_path (Path) – A path to root folder containing the spike sorting and metadata collections.

  • collections (dloader.CollectionData) –

    A CollectionData instance specifying the folders relative to the rootpath that contain the spikesorting

    and metadata data.

load_channels(**kwargs)[source]

Load spike sorting channels data.

Returns:

A Bunch containing the channels data, or None if not found.

Return type:

Bunch or None

load_meta_data()[source]

Load probe metadata from spikeglx ap.meta file.

Returns:

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

Return type:

dict or None

class ibl_alignment_gui.loaders.geometry_loader.GeometryLoaderOne(insertion, one, session_path=None, probe_collection=None)[source]

Bases: GeometryLoader

Geometry loader using the ONE API.

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.

  • probe_collection (str or None) – The collection to the spike sorting data to load

load_channels(**kwargs)[source]

Load spike sorting channels data.

Returns:

A Bunch containing the channels data, or None if not found.

Return type:

Bunch or None

load_meta_data()[source]

Load probe metadata from spikeglx ap.meta file.

Returns:

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

Return type:

dict or None

class ibl_alignment_gui.loaders.geometry_loader.MetaGeometry(meta)[source]

Bases: Geometry

Geometry class using spikeglx ap metadata. Here the sites correspond to the electrode sites.

Parameters:

meta (Bunch) – A Bunch object containing spikeglx metadata

ibl_alignment_gui.loaders.geometry_loader.arrange_channels_into_banks(shank_geom, data, bnk_width=10)[source]

Arrange channel data into probe banks for visualization.

Channels are grouped by bank (x-coordinate). For each bank, channel values are aligned along the y-axis. If the spacing between channels does not match the expected spacing (self.chn_diff), gaps are filled with NaNs

Parameters:
  • shank_geom (Bunch) – A bunch containing channel geometry information for a shank, returned from Geometry.get_chns_for_shank().

  • data (np.ndarray) – 1D array of values per channel

  • bnk_width (int) – The width of each bank in the x dimension for visualization.

Return type:

tuple[ndarray, ndarray, ndarray]

Returns:

  • bnk_data (np.ndarray) – A 2D array with data organised into individual banks on the shank.

  • bnk_scale (np.ndarray) – Scale factor to apply along x and y axes

  • bnk_offset (list of np.ndarray) – Offset to apply along x and y axes.

ibl_alignment_gui.loaders.geometry_loader.average_chns_at_same_depths(shank_geom, data)[source]

Average data across channels at the same depth.

Parameters:
  • shank_geom (Bunch) – A bunch containing channel geometry information for a shank, returned from Geometry.get_chns_for_shank().

  • data (np.ndarray) – 2D array of data with shape (time or frequency x channels).

Returns:

2D array with averaged data across equivalent depths.

Return type:

np.ndarray

ibl_alignment_gui.loaders.geometry_loader.pad_data_to_full_chn_map(shank_geom, data)[source]

Pad data to align with the full channel map, filling gaps with NaNs.

Parameters:
  • shank_geom (Bunch) – A bunch containing channel geometry information for a shank, returned from Geometry.get_chns_for_shank().

  • data (np.ndarray) – 2D array of data with shape (time or frequency x channels).

Returns:

2D array padded to the full channel map.

Return type:

np.ndarray