ibl_alignment_gui.loaders.histology_loader
Functions
|
Pick the right SliceLoader by inspecting the histology directory. |
Build a BrainAtlasAnatomical from the registration pipeline NRRD files in histology_path. |
|
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
SliceLoader for histology registered in original anatomical (non-CCF) space. |
|
Paths to the NRRD files produced by the histology registration pipeline. |
|
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.AnatomicalSliceLoader(file_path, brain_atlas)[source]
Bases:
SliceLoaderSliceLoader for histology registered in original anatomical (non-CCF) space.
Expects a folder produced by the histology registration pipeline containing:
ccf_in_*.nrrd,labels_in_*.nrrd,histology_registration_pipeline.nrrd,histology_registration.nrrd, and optionallyEx_*_Em_*.nrrdchannel files.The BrainAtlasAnatomical built from these files works in the physical space of the anatomical images (mm, RAS). Coordinates passed to
get_slicesmust therefore be in that same anatomical physical space, not in Allen CCF space.- Parameters:
file_path (Path) – Folder containing the registration pipeline NRRD outputs.
brain_atlas (BrainAtlas) – Unused; accepted to satisfy the SliceLoader interface and the
make_slice_loaderfactory signature.
- class ibl_alignment_gui.loaders.histology_loader.ImageSpacePaths(atlas_image_path, atlas_labels_path, pipeline_image_path, histology_image_path, other_channel_paths=<factory>)[source]
Bases:
objectPaths to the NRRD files produced by the histology registration pipeline.
All of the files live in a single folder.
- atlas_image_pathPath
CCF template warped into anatomical space (
ccf_in_*.nrrd).- atlas_labels_pathPath
CCF labels warped into anatomical space (
labels_in_*.nrrd).- pipeline_image_pathPath
Pipeline reference image used by the registration (
histology_registration_pipeline.nrrd).- histology_image_pathPath
Main registered histology channel (
histology_registration.nrrd).- other_channel_pathslist[Path]
Any additional fluorescence channels matching
Ex_*_Em_*.nrrd.
-
atlas_image_path:
Path
-
atlas_labels_path:
Path
- classmethod from_folder(input_path)[source]
Discover all required files in input_path and return an ImageSpacePaths.
Raises StopIteration if any required file is missing.
- Return type:
-
histology_image_path:
Path
-
other_channel_paths:
list[Path]
-
pipeline_image_path:
Path
- 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.build_anatomical_atlas(histology_path)[source]
Build a BrainAtlasAnatomical from the registration pipeline NRRD files in histology_path.
- Parameters:
histology_path (Path) – Folder containing
ccf_in_*.nrrd,labels_in_*.nrrd, andhistology_registration_pipeline.nrrd.- Return type:
- 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: