ibl_alignment_gui.loaders.histology_loader
Functions
|
Pick the right SliceLoader by inspecting the histology directory. |
Download histology data from flatiron server if not already cached locally. |
|
Return the appropriate SliceLoader for the given folder. |
|
Convert a tif image to nrrd format if the nrrd does not already exist. |
Classes
Dict of histology slice Bunches that loads channels from disk on first access. |
|
SliceLoader for histology in the NRRD format. |
|
Abstract base class for loading histology slices. |
|
SliceLoader for histology in TIFF format (e.g. brainreg outputs). |
- class ibl_alignment_gui.loaders.histology_loader.LazySliceDict(eager_data, lazy_callbacks)[source]
Bases:
dictDict of histology slice Bunches that loads channels from disk on first access.
Eager entries (CCF, Annotation) are populated immediately. Lazy entries (histology channels) are stored as
Noneplaceholders until a key is accessed, at which point the registered callback loads and caches the slice.
- class ibl_alignment_gui.loaders.histology_loader.NrrdSliceLoader(file_path, brain_atlas)[source]
Bases:
SliceLoaderSliceLoader for histology in the NRRD format.
- Parameters:
file_path (Path) – Directory containing .nrrd files.
brain_atlas (AllenAtlas) – Brain atlas for alignment.
- class ibl_alignment_gui.loaders.histology_loader.SliceLoader(file_path, brain_atlas)[source]
Bases:
ABCAbstract 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_slices(xyz)[source]
Generate slice images for CCF, annotation, and histology channels.
CCF and Annotation are computed immediately (atlas arrays are already in memory). Histology channel volumes are loaded from disk only when their key is first accessed in the returned dict.
- Parameters:
xyz (np.ndarray) – n x 3 array of xyz coordinates along the probe track.
- Returns:
Keys: ‘CCF’, ‘Annotation’, and one key per entry in hist_paths. Each value is a Bunch with ‘slice’ (2D array), ‘scale’, and ‘offset’.
- Return type:
- class ibl_alignment_gui.loaders.histology_loader.TiffSliceLoader(file_path, brain_atlas)[source]
Bases:
SliceLoaderSliceLoader for histology in TIFF format (e.g. brainreg outputs).
Detects brainreg’s standard
C0(green) /C1(red) channel suffixes first, then falls back to the NRRD loader’sGR/RDsubstring rules so manually-named TIFFs also load.- Parameters:
file_path (Path) – Directory containing
.tif/.tifffiles.brain_atlas (AllenAtlas) – Brain atlas for alignment.
- get_paths()[source]
Locate histology TIFFs and store paths keyed by display label.
- Return type:
None
- load_volume(vol_path)[source]
Load a TIFF and reorient to AllenAtlas (AP, ML, DV) convention.
- Parameters:
vol_path (Path) – A path to a histology TIFF volume.
- Returns:
Loaded volume with shape
(AP, ML, DV)ready for slicing bySliceLoader.get_slice().- Return type:
np.ndarray
Notes
Brainreg’s
downsampled_standard_brain_C*.tiffare 25 µm isotropic in Allen CCF space, withsitk.GetArrayFromImageaxis order(AP, DV, ML). The AllenAtlas convention is(AP, ML, DV), so a single axis swap suffices — no flips required.
- 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.make_slice_loader(file_path, brain_atlas, space='ccf')[source]
Return the appropriate SliceLoader for the given folder.
- Parameters:
file_path (Path or None) – Folder containing histology files. When None, no histology volumes are loaded and only the atlas template and annotation slices are available.
brain_atlas (BrainAtlas) – Brain atlas passed to the loader (used directly by NrrdSliceLoader; ignored by AnatomicalSliceLoader which builds its own atlas from the folder files).
space ({'ccf', 'anatomical'}) – Which loader to use. ‘ccf’ returns a NrrdSliceLoader operating in Allen CCF space; ‘anatomical’ returns an AnatomicalSliceLoader operating in the original image space. Matches the
histology.spacefield in the alignment YAML.
- Returns:
NrrdSliceLoader for ‘ccf’, AnatomicalSliceLoader for ‘anatomical’. A NrrdSliceLoader with no histology volumes when
file_pathis None.- Return type: