ibl_alignment_gui.loaders.histology_loader

Functions

download_histology_data

Download histology data from flatiron server if not already cached locally.

tif2nrrd

Convert a tif image to nrrd format if the nrrd does not already exist.

Classes

NrrdSliceLoader

SliceLoader for histology in the NRRD format.

SliceLoader

Abstract base class for loading histology slices.

class ibl_alignment_gui.loaders.histology_loader.NrrdSliceLoader(file_path, brain_atlas)[source]

Bases: SliceLoader

SliceLoader for histology in the NRRD format.

Parameters:
  • file_path (Path) – Directory containing .nrrd files.

  • brain_atlas (AllenAtlas) – Brain atlas for alignment.

get_paths()[source]

Load histology file paths with predefined color channel suffixes.

Return type:

None

load_volume(vol_path)[source]

Load a volume using AllenAtlas.

Parameters:

vol_path (Path) – A path to histology volume.

Returns:

Loaded image volume.

Return type:

np.ndarray

class ibl_alignment_gui.loaders.histology_loader.SliceLoader(file_path, brain_atlas)[source]

Bases: ABC

Abstract base class for loading histology slices.

Subclasses must implement the get_paths and load_volume methods.

Parameters:
  • file_path (Path) – Directory containing histology files.

  • brain_atlas (AllenAtlas) – Reference brain atlas.

abstractmethod get_paths()[source]

Locate and store relevant histology file paths in self.hist_paths.

Return type:

None

get_slice(xyz, vol, annotation=False)[source]

Extract a slice from a 3D volume using given coordinates.

Parameters:
  • xyz (np.ndarray) – Nx3 array of XYZ coordinates.

  • vol (np.ndarray) – 3D volume from which to extract a slice.

Returns:

A dictionary containing the 2D slice, scale, and offset.

Return type:

dict[str, np.ndarray]

get_slices(xyz)[source]

Generate slice images for CCF, annotation, and loaded histology.

Parameters:

xyz (np.ndarray) – n x 3 array of xyz coordinates.

Returns:

slices – A dictionary of dictionaries of image slices and metadata for each image type.

Return type:

dict[str, dict]

abstractmethod load_volume(vol_path)[source]

Load a 3D volume from a file.

Parameters:

vol_path (Path) – A path to the volume file.

Returns:

Loaded 3D image volume.

Return type:

np.ndarray

ibl_alignment_gui.loaders.histology_loader.download_histology_data(subject, laboratory)[source]

Download histology data from flatiron server if not already cached locally.

Parameters:
  • subject (str) – Subject name

  • laboratory (str) – Laboratory name

Return type:

tuple[list[Path], Path] | tuple[None, Path]

Returns:

  • path_to_files (list[Path] or None) – List of paths to downloaded or cached nrrd files, or None if not found.

  • cache_dir (Path) – Directory where files are cached.

ibl_alignment_gui.loaders.histology_loader.tif2nrrd(path_to_image)[source]

Convert a tif image to nrrd format if the nrrd does not already exist.

Parameters:

path_to_image (str or Path) – The path to the tif file.

Returns:

path_to_nrrd – The path to the nrrd file.

Return type:

Path