pipeline_transformed module

Reconstruct a pipeline’s spatial domain for LS → CCF mappings and apply ANTs transform chains to points/annotations.

The goal is to produce a SimpleITK stub image (no pixels) whose header (origin, spacing, direction) matches what the SmartSPIM processing pipeline would have produced for a given acquisition. This lets you convert Zarr voxel indices to the same anatomical coordinates that the transforms were trained in, and then compose the appropriate ANTs transforms to reach CCF.

Notes

  • All world coordinates are ITK LPS and millimeters.

  • SimpleITK direction matrices are 3×3 row-major tuples; columns are the world directions of index axes (i, j, k).

aind_zarr_utils.pipeline_transformed.base_and_pipeline_anatomical_stub(zarr_uri, metadata, processing_data, *, overlay_selector=OverlaySelector(rules=(OverlayRule(name='Fixed world image spacing (0.0144, 0.0144, 0.016)', spec=<SpecifierSet('<0.0.32, >=0.0.18')>, factory=<function _base_rules.<locals>.<lambda>>, start=None, end=None, predicate=None, rule_priority=55, group=None, stop_after=False), OverlayRule(name='anchor RAS corner to recorded bug point', spec=<SpecifierSet('>=0.0.18')>, factory=<function _base_rules.<locals>.<lambda>>, start=None, end=None, predicate=None, rule_priority=90, group=None, stop_after=False))), opened_zarr=None)[source]

Return both the base and pipeline-corrected anatomical SimpleITK stubs.

This convenience helper builds two lightweight (no pixel data) SimpleITK images representing (1) the uncorrected spatial header derived directly from the Zarr metadata and (2) the header after applying all pipeline overlays appropriate for the supplied processing metadata. It also returns the native voxel size (IJK dimensions) of the acquisition.

Parameters:
  • zarr_uri (str) – URI of the raw acquisition Zarr store used to derive the base header.

  • metadata (dict) – ND (instrument/acquisition) metadata consulted by overlay predicates.

  • processing_data (dict) – Processing metadata containing the pipeline version and process list used to select overlays.

  • overlay_selector (OverlaySelector) – Selector that resolves the ordered list of overlays to apply based on pipeline_version and acquisition metadata. Defaults to the global selector from get_selector().

  • opened_zarr (tuple[Node, dict] | None) – Pre-opened (image_node, zarr_meta) tuple. If provided, avoids an additional Zarr open; if None the Zarr is opened internally.

Return type:

tuple[Image, Image, tuple[int, int, int]]

Returns:

  • base_stub (sitk.Image) – SimpleITK stub image whose header reflects the original (uncorrected) spatial metadata.

  • pipeline_stub (sitk.Image) – SimpleITK stub image whose header reflects all pipeline overlay corrections (origin, spacing, direction).

  • native_size (tuple[int, int, int]) – The voxel dimensions (I, J, K) of the acquisition in index space.

Notes

  • Both returned images contain no pixel buffer; they are produced via AnatomicalHeader.as_sitk_stub() for header-only operations.

  • Use mimic_pipeline_zarr_to_anatomical_stub() if you only need the corrected stub.

  • Coordinates follow ITK LPS convention and spacing is in millimeters.

aind_zarr_utils.pipeline_transformed.mimic_pipeline_zarr_to_anatomical_stub(zarr_uri, metadata, processing_data, *, overlay_selector=OverlaySelector(rules=(OverlayRule(name='Fixed world image spacing (0.0144, 0.0144, 0.016)', spec=<SpecifierSet('<0.0.32, >=0.0.18')>, factory=<function _base_rules.<locals>.<lambda>>, start=None, end=None, predicate=None, rule_priority=55, group=None, stop_after=False), OverlayRule(name='anchor RAS corner to recorded bug point', spec=<SpecifierSet('>=0.0.18')>, factory=<function _base_rules.<locals>.<lambda>>, start=None, end=None, predicate=None, rule_priority=90, group=None, stop_after=False))), opened_zarr=None)[source]

Construct a SimpleITK stub matching pipeline spatial corrections.

This fabricates a minimal image (no pixel data read) that reflects the spatial domain (spacing, direction, origin) the SmartSPIM pipeline would have produced after applying registered overlays and multiscale logic.

Parameters:
  • zarr_uri (str) – URI of the raw Zarr store.

  • metadata (dict) – ND metadata (instrument + acquisition) used by overlays.

  • processing_data (dict) – Processing metadata containing version / process list.

  • overlay_selector (OverlaySelector) – Selector used to obtain overlay sequence; defaults to the global selector.

  • opened_zarr (tuple[Node, dict] | None) – Pre-opened ZARR file (image_node, zarr_meta), by default None. If provided, this will be used instead of opening the ZARR file again.

Return type:

tuple[Image, tuple[int, int, int]]

Returns:

  • sitk.Image – Stub image with corrected spatial metadata.

  • tuple – The size of the image in IJK coordinates.

Raises:

ValueError – If the needed import process / version is absent.

aind_zarr_utils.pipeline_transformed.apply_pipeline_overlays_to_sitk(img, zarr_uri, processing_data, metadata, level=3, *, overlay_selector=OverlaySelector(rules=(OverlayRule(name='Fixed world image spacing (0.0144, 0.0144, 0.016)', spec=<SpecifierSet('<0.0.32, >=0.0.18')>, factory=<function _base_rules.<locals>.<lambda>>, start=None, end=None, predicate=None, rule_priority=55, group=None, stop_after=False), OverlayRule(name='anchor RAS corner to recorded bug point', spec=<SpecifierSet('>=0.0.18')>, factory=<function _base_rules.<locals>.<lambda>>, start=None, end=None, predicate=None, rule_priority=90, group=None, stop_after=False))), opened_zarr=None)[source]

Apply pipeline spatial overlays to a SimpleITK image header in-place.

Thin SimpleITK-typed shim around aind_zarr_utils.image.apply_pipeline_overlays().

See aind_zarr_utils.image.apply_pipeline_overlays() for parameter semantics. img’s spatial header is modified in place; pixel data is untouched.

Return type:

None

aind_zarr_utils.pipeline_transformed.mimic_pipeline_zarr_to_sitk(zarr_uri, metadata, processing_data, *, level=3, overlay_selector=OverlaySelector(rules=(OverlayRule(name='Fixed world image spacing (0.0144, 0.0144, 0.016)', spec=<SpecifierSet('<0.0.32, >=0.0.18')>, factory=<function _base_rules.<locals>.<lambda>>, start=None, end=None, predicate=None, rule_priority=55, group=None, stop_after=False), OverlayRule(name='anchor RAS corner to recorded bug point', spec=<SpecifierSet('>=0.0.18')>, factory=<function _base_rules.<locals>.<lambda>>, start=None, end=None, predicate=None, rule_priority=90, group=None, stop_after=False))), opened_zarr=None)[source]

Construct a SimpleITK image matching pipeline spatial corrections.

This fabricates a SimpleITK image that reflects the spatial domain (spacing, direction, origin) the SmartSPIM pipeline would have produced after applying registered overlays and multiscale logic.

Returns:

A new ANTs image instance reflecting the spatial domain.

Return type:

Image

aind_zarr_utils.pipeline_transformed.base_and_pipeline_zarr_to_sitk(zarr_uri, metadata, processing_data, *, level=3, overlay_selector=OverlaySelector(rules=(OverlayRule(name='Fixed world image spacing (0.0144, 0.0144, 0.016)', spec=<SpecifierSet('<0.0.32, >=0.0.18')>, factory=<function _base_rules.<locals>.<lambda>>, start=None, end=None, predicate=None, rule_priority=55, group=None, stop_after=False), OverlayRule(name='anchor RAS corner to recorded bug point', spec=<SpecifierSet('>=0.0.18')>, factory=<function _base_rules.<locals>.<lambda>>, start=None, end=None, predicate=None, rule_priority=90, group=None, stop_after=False))), opened_zarr=None)[source]

Construct both base and pipeline-corrected ANTs images from Zarr.

This fabricates an ANTs image that reflects the spatial domain (spacing, direction, origin) the SmartSPIM pipeline would have produced after applying registered overlays and multiscale logic.

Return type:

tuple[Image, Image]

Returns:

  • base_img (ants.core.ANTsImage) – The uncorrected ANTs image from the Zarr at the requested level.

  • pipeline_img (ants.core.ANTsImage) – A new ANTs image instance reflecting the spatial domain.

aind_zarr_utils.pipeline_transformed.apply_pipeline_overlays_to_ants(img, zarr_uri, processing_data, metadata, level=3, *, overlay_selector=OverlaySelector(rules=(OverlayRule(name='Fixed world image spacing (0.0144, 0.0144, 0.016)', spec=<SpecifierSet('<0.0.32, >=0.0.18')>, factory=<function _base_rules.<locals>.<lambda>>, start=None, end=None, predicate=None, rule_priority=55, group=None, stop_after=False), OverlayRule(name='anchor RAS corner to recorded bug point', spec=<SpecifierSet('>=0.0.18')>, factory=<function _base_rules.<locals>.<lambda>>, start=None, end=None, predicate=None, rule_priority=90, group=None, stop_after=False))), opened_zarr=None)[source]

Apply pipeline spatial overlays to an ANTs image header in-place.

Thin ANTs-typed shim around aind_zarr_utils.image.apply_pipeline_overlays(). The level > 0 SITK→ANTs convention conversion lives in aind_zarr_utils.image._to_ants_convention().

See aind_zarr_utils.image.apply_pipeline_overlays() for parameter semantics. img’s spatial header is modified in place; pixel data is untouched. The direction matrix is left unchanged (the conversion assumes the active overlays do not modify direction; this is true for the default rule set).

Return type:

None

aind_zarr_utils.pipeline_transformed.base_and_pipeline_zarr_to_ants(zarr_uri, metadata, processing_data, *, level=3, overlay_selector=OverlaySelector(rules=(OverlayRule(name='Fixed world image spacing (0.0144, 0.0144, 0.016)', spec=<SpecifierSet('<0.0.32, >=0.0.18')>, factory=<function _base_rules.<locals>.<lambda>>, start=None, end=None, predicate=None, rule_priority=55, group=None, stop_after=False), OverlayRule(name='anchor RAS corner to recorded bug point', spec=<SpecifierSet('>=0.0.18')>, factory=<function _base_rules.<locals>.<lambda>>, start=None, end=None, predicate=None, rule_priority=90, group=None, stop_after=False))), opened_zarr=None)[source]

Construct both base and pipeline-corrected ANTs images from Zarr.

This fabricates an ANTs image that reflects the spatial domain (spacing, direction, origin) the SmartSPIM pipeline would have produced after applying registered overlays and multiscale logic.

Return type:

tuple[ANTsImage, ANTsImage]

Returns:

  • base_img (ants.core.ANTsImage) – The uncorrected ANTs image from the Zarr at the requested level.

  • pipeline_img (ants.core.ANTsImage) – A new ANTs image instance reflecting the spatial domain.

aind_zarr_utils.pipeline_transformed.mimic_pipeline_zarr_to_ants(zarr_uri, metadata, processing_data, *, level=3, overlay_selector=OverlaySelector(rules=(OverlayRule(name='Fixed world image spacing (0.0144, 0.0144, 0.016)', spec=<SpecifierSet('<0.0.32, >=0.0.18')>, factory=<function _base_rules.<locals>.<lambda>>, start=None, end=None, predicate=None, rule_priority=55, group=None, stop_after=False), OverlayRule(name='anchor RAS corner to recorded bug point', spec=<SpecifierSet('>=0.0.18')>, factory=<function _base_rules.<locals>.<lambda>>, start=None, end=None, predicate=None, rule_priority=90, group=None, stop_after=False))), opened_zarr=None)[source]

Construct an ANTs image matching pipeline spatial corrections.

This fabricates an ANTs image that reflects the spatial domain (spacing, direction, origin) the SmartSPIM pipeline would have produced after applying registered overlays and multiscale logic.

Returns:

A new ANTs image instance reflecting the spatial domain.

Return type:

ANTsImage

aind_zarr_utils.pipeline_transformed.indices_to_ccf(annotation_indices, zarr_uri, metadata, processing_data, *, s3_client=None, anonymous=True, cache_dir=None, template_used='SmartSPIM-template_2024-05-16_11-26-14', template_base=None, opened_zarr=None)[source]

Convert voxel indices (LS space) directly into CCF coordinates.

Parameters:
  • annotation_indices (dict[str, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]]) – Mapping layer name → (N, 3) index array (z, y, x order expected by downstream conversion routine). Index arrays can contain continuous (floating-point) values for sub-voxel precision.

  • zarr_uri (str) – LS acquisition Zarr.

  • metadata (dict[str, Any]) – ND metadata needed for spatial corrections.

  • processing_data (dict) – Processing metadata.

  • s3_client (S3Client | None) – S3 client.

  • anonymous (bool) – Use unsigned access.

  • cache_dir (str | PathLike | None) – Resource cache directory.

  • template_used (str) – Template transform key.

  • template_base (str | PathLike | None) – Base path for the template transforms. If None, the default from _PIPELINE_TEMPLATE_TRANSFORMS will be used. Defaults to None.

  • opened_zarr (tuple[Node, dict] | None) – Pre-opened ZARR file (image_node, zarr_meta), by default None. If provided, this will be used instead of opening the ZARR file again.

Returns:

Mapping layer → (N, 3) array of anatomical CCF coordinates in LPS.

Return type:

dict[str, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]]

aind_zarr_utils.pipeline_transformed.neuroglancer_to_ccf(neuroglancer_data, zarr_uri, metadata, processing_data, *, layer_names=None, return_description=True, s3_client=None, anonymous=True, cache_dir=None, template_used='SmartSPIM-template_2024-05-16_11-26-14', template_base=None, opened_zarr=None)[source]

Convert Neuroglancer annotation JSON into CCF coordinates.

Parameters:
  • neuroglancer_data (dict) – Parsed Neuroglancer state JSON.

  • zarr_uri (str) – LS acquisition Zarr.

  • metadata (dict) – ND metadata.

  • processing_data (dict) – Processing metadata.

  • layer_names (str | list[str] | None) – Subset of annotation layer names to include; all if None.

  • return_description (bool) – Whether to include description lists in the second return value.

  • s3_client (S3Client | None) – S3 client.

  • anonymous (bool) – Use unsigned S3 access if True.

  • cache_dir (str | PathLike | None) – Cache directory for transform downloads.

  • template_used (str) – Template transform key.

  • template_base (str | PathLike | None) – Base path for the template transforms. If None, the default from _PIPELINE_TEMPLATE_TRANSFORMS will be used. Defaults to None.

  • opened_zarr (tuple[Node, dict] | None) – Pre-opened ZARR file (image_node, zarr_meta), by default None. If provided, this will be used instead of opening the ZARR file again.

Returns:

(annotation_points_ccf, descriptions) where descriptions is None if return_description is False.

Return type:

tuple[dict[str, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]], dict[str, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]] | None]

aind_zarr_utils.pipeline_transformed.ccf_to_indices(ccf_points, alignment_zarr_uri, metadata, processing_data, *, template_used='SmartSPIM-template_2024-05-16_11-26-14', template_base=None, opened_zarr=None, scale_unit='millimeter')[source]

Transform points from CCF space to continuous zarr indices.

This function applies the inverse of the registration pipeline, converting points from Allen CCF space back to the continuous (sub-index) indices of the zarr dataset, accounting for pipeline-specific domain corrections.

The transformation chain is: 1. CCF → Pipeline anatomical (via ANTs image transforms) 2. Pipeline anatomical → continuous indices (via pipeline stub)

Parameters:
  • ccf_points (dict[str, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]]) – Mapping layer name → (N, 3) array of CCF coordinates in LPS order.

  • alignment_zarr_uri (str) – URI of the alignment zarr (channel used for registration).

  • metadata (dict) – Neural Dynamics metadata (metadata.nd.json).

  • processing_data (dict) – Processing pipeline metadata (processing.json).

  • template_used (str) – Template identifier. Default is “SmartSPIM-template_2024-05-16_11-26-14”.

  • template_base (str | PathLike | None) – Base path for template transforms. If None, uses default S3 location.

  • opened_zarr (tuple[Node, dict] | None) – Pre-opened zarr (image_node, zarr_meta). Avoids re-opening.

  • scale_unit (str) – Unit for anatomical coordinates. Default is “millimeter”.

Returns:

Mapping layer name → (N, 3) array of continuous indices in z,y,x order used by Neuroglancer

Return type:

dict[str, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]]

See also

indices_to_ccf

Forward transform from indices to CCF.

ccf_to_anatomical_auto_metadata

Convenience wrapper with auto metadata.

Notes

  • ANTs transforms output in pipeline anatomical space

  • Converts from pipeline space to LS space via shared index space

  • Returns coordinates in zarr z,y,x order (used by Neuroglancer)

  • Output coordinates match what Neuroglancer uses

Examples

>>> ccf_pts = {"layer1": np.array([[5000, 6000, 7000]])}  # CCF coords
>>> anatomical_pts = ccf_to_anatomical(
...     ccf_pts, alignment_zarr_uri, metadata, processing_data
... )
aind_zarr_utils.pipeline_transformed.ccf_to_indices_auto_metadata(ccf_points, zarr_uri, *, template_used='SmartSPIM-template_2024-05-16_11-26-14', **kwargs)[source]

Resolve pipeline metadata then convert CCF to indices.

Convenience wrapper that infers and loads metadata.nd.json and processing.json from the asset root, then delegates to ccf_to_indices.

Parameters:
  • ccf_points (dict[str, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]]) – Mapping layer name → (N, 3) array of CCF coordinates in LPS order.

  • zarr_uri (str) – URI of the acquisition zarr. Asset root will be inferred.

  • template_used (str) – Template identifier. Default is “SmartSPIM-template_2024-05-16_11-26-14”.

  • **kwargs (Any) – Forwarded to ccf_to_indices.

Returns:

Mapping layer name → (N, 3) array of continuous indices in z,y,x order (used by Neuroglancer).

Return type:

dict[str, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]]

See also

ccf_to_indices

Main function with explicit metadata parameters.

Examples

>>> ccf_pts = {"layer1": np.array([[5000, 6000, 7000]])}
>>> indices_pts = ccf_to_indices_auto_metadata(ccf_pts, zarr_uri)

Deprecated

Since 0.15, prefer Asset.from_zarr(zarr_uri).transform(...). This shim will be removed in a future release.

aind_zarr_utils.pipeline_transformed.neuroglancer_to_ccf_auto_metadata(neuroglancer_data, asset_uri=None, **kwargs)[source]

Resolve pipeline metadata files then convert annotations to CCF.

This is a convenience wrapper that infers the acquisition (LS) Zarr URI from a Neuroglancer state (image_sources), loads the accompanying metadata.nd.json and processing.json files located at the asset root, and then delegates to neuroglancer_to_ccf().

Parameters:
  • neuroglancer_data (dict) – Parsed Neuroglancer state JSON containing an image_sources section referencing at least one LS Zarr.

  • asset_uri (str | None) – Base URI for the asset containing the Zarr and metadata files. If None, the asset root is inferred from the Zarr URI in neuroglancer_data.

  • **kwargs (Any) – Forwarded keyword arguments accepted by neuroglancer_to_ccf().

Returns:

(annotation_points_ccf, descriptions) where annotation_points_ccf is a mapping layer -> (N,3) NDArray of CCF coordinates and descriptions is a mapping layer -> list of point descriptions or None if descriptions were not requested.

Return type:

tuple[dict[str, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]], dict[str, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]] | None]

Raises:
  • ValueError – If no image sources can be found in neuroglancer_data.

  • Deprecated

  • ----------

  • Since 0.15, prefer

  • Asset.from_neuroglancer(ng).transform(Points.from_neuroglancer(ng), to=Space.CCF_MM)`

  • This shim will be removed in a future release.

aind_zarr_utils.pipeline_transformed.swc_data_to_zarr_indices(swc_point_dict, zarr_uri, swc_point_order='zyx', swc_point_units='micrometer', opened_zarr=None)[source]

Convert SWC coordinates to zarr indices.

Parameters:
  • swc_point_dict (dict[str, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]]) – Dictionary containing SWC points for a set of neurons. Keys are neuron IDs and values are (N, 3) arrays of SWC point coordinates.

  • zarr_uri (str) – URI of the LS acquisition Zarr.

  • processing_data (dict) – Processing metadata with pipeline version and process list.

  • swc_point_order (str) – Order of the zarr coordinates in the input arrays. Default is ‘zyx’.

  • swc_point_units (str) – Units of the input coordinates. Default is ‘microns’.

  • opened_zarr (tuple[Node, dict] | None) – Pre-opened ZARR file (image_node, zarr_meta), by default None. If provided, this will be used instead of opening the ZARR file again.

Returns:

Mapping neuron ID → (N, 3) array of integer zarr indices (rounded from continuous coordinates).

Return type:

dict[str, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]]

aind_zarr_utils.pipeline_transformed.swc_data_to_ccf(swc_point_dict, alignment_zarr_uri, metadata, processing_data, *, swc_point_order='zyx', swc_point_units='micrometer', opened_zarr=None, **kwargs)[source]

Convert SWC annotations to CCF coordinates.

Converts SWC coordinates to zarr indices and then converts these indices to CCF coordinates. This function requires the Zarr URI and metadata to be provided explicitly.

Parameters:
  • swc_point_dict (dict[str, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]]) – Dictionary containing SWC points for a set of neurons. Keys are neuron IDs and values are (N, 3) arrays of SWC point coordinates.

  • alignment_zarr_uri (str) – URI of the LS acquisition Zarr.

  • metadata (dict[str, Any]) – ND metadata with acquisition information.

  • processing_data (dict[str, Any]) – Processing metadata with pipeline version and process list.

  • swc_point_order (str) – Order of the zarr coordinates in the input arrays. Default is ‘zyx’.

  • swc_point_units (str) – Units of the input coordinates. Default is ‘microns’.

  • opened_zarr (tuple[Node, dict] | None) – Pre-opened ZARR file (image_node, zarr_meta), by default None. If provided, this will be used instead of opening the ZARR file again.

  • **kwargs (Any) – Forwarded keyword arguments accepted by indices_to_ccf().

Returns:

Mapping neuron ID → (N, 3) array of anatomical CCF coordinates in LPS.

Return type:

dict[str, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]]

aind_zarr_utils.pipeline_transformed.swc_data_to_ccf_auto_metadata(swc_point_dict, asset_uri, swc_point_order='zyx', swc_point_units='micrometer', **kwargs)[source]

Resolve pipeline metadata files then convert SWC annotations to CCF.

This is a convenience wrapper that infers the location of and loads the accompanying metadata.nd.json and processing.json files located at the asset root, and then delegates to swc_data_to_ccf().

Parameters:
  • swc_point_dict (dict[str, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]]) – Dictionary containing SWC points for a set of neurons. Keys are neuron IDs and values are (N, 3) arrays of SWC point coordinates.

  • asset_uri (str) – Base URI for the asset containing the Zarr and metadata files.

  • swc_point_order (str) – Order of the zarr coordinates in the input arrays. Default is ‘zyx’.

  • swc_point_units (str) – Units of the input coordinates. Default is ‘microns’.

  • **kwargs (Any) – Forwarded keyword arguments accepted by indices_to_ccf().

Return type:

dict[str, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]]

Returns:

  • dict[str, NDArray] – Mapping neuron ID → (N, 3) array of anatomical CCF coordinates in LPS.

  • Deprecated

  • ———-

  • Since 0.15, prefer Asset.from_root(asset_uri).transform(...).

  • This shim will be removed in a future release.

aind_zarr_utils.pipeline_transformed.indices_to_ccf_auto_metadata(annotation_indices, zarr_uri, **kwargs)[source]

Resolve pipeline metadata files then convert indices to CCF.

This is a convenience wrapper that infers the location of and loads the accompanying metadata.nd.json and processing.json files from the asset root (inferred from the Zarr URI), and then delegates to indices_to_ccf().

Parameters:
  • annotation_indices (dict[str, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]]) – Mapping layer name → (N, 3) index array (z, y, x order expected by downstream conversion routine). Index arrays can contain continuous (floating-point) values for sub-voxel precision.

  • zarr_uri (str) – URI of the acquisition Zarr file that the indices reference. The asset root will be inferred from this URI to locate metadata files.

  • **kwargs (Any) – Forwarded keyword arguments accepted by indices_to_ccf().

Returns:

Mapping layer → (N, 3) array of anatomical CCF coordinates in LPS.

Return type:

dict[str, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]]

See also

indices_to_ccf

The underlying function that performs the transformation.

neuroglancer_to_ccf_auto_metadata

Similar wrapper for Neuroglancer data.

swc_data_to_ccf_auto_metadata

Similar wrapper for SWC data.

Examples

Convert annotation indices to CCF coordinates:

>>> indices = {
...     "layer1": np.array([[100, 200, 300], [150, 250, 350]]),
...     "layer2": np.array([[50, 100, 150]])
... }
>>> ccf_coords = indices_to_ccf_auto_metadata(
...     indices,
...     zarr_uri="s3://aind-open-data/dataset_123/image.zarr"
... )

Deprecated

Since 0.15, prefer Asset.from_zarr(zarr_uri).transform(Points(annotation_indices, Space.ZARR_INDICES), to=Space.CCF_MM). This shim will be removed in a future release.

Overview

The pipeline_transformed module contains the legacy explicit-metadata functions for reconstructing a SmartSPIM pipeline spatial domain and applying ANTs transform chains. New user code should prefer Asset and Points:

from aind_zarr_utils import Asset, Points, Space

asset = Asset.from_zarr("s3://bucket/dataset/image.ome.zarr/0")
points = Points.from_neuroglancer(ng_state)
ccf = asset.transform(points, to=Space.CCF_MM)

Legacy Workflow

The explicit transformation pipeline still follows these steps:

  1. Reconstruct a SimpleITK stub matching the pipeline coordinate system.

  2. Resolve individual-to-template and template-to-CCF transform chains.

  3. Apply ANTs transforms to point arrays.

  4. Return Allen CCF coordinates.

Legacy Examples

Create a pipeline-compatible stub image:

from aind_zarr_utils.pipeline_transformed import mimic_pipeline_zarr_to_anatomical_stub

stub, native_size_ijk = mimic_pipeline_zarr_to_anatomical_stub(
    zarr_uri,
    zarr_metadata,
    processing_metadata,
)

Transform Neuroglancer annotations to CCF:

from aind_zarr_utils.pipeline_transformed import neuroglancer_to_ccf

ccf_points, descriptions = neuroglancer_to_ccf(
    neuroglancer_data=ng_state,
    zarr_uri=zarr_uri,
    zarr_metadata=zarr_metadata,
    processing_metadata=processing_metadata,
    template_used="SmartSPIM-template_2024-05-16_11-26-14",
)

Manual transform-chain application:

from aind_zarr_utils.pipeline_transformed import (
    indices_to_ccf,
    pipeline_point_transforms_local_paths,
    pipeline_transforms,
)

individual_paths, template_paths = pipeline_transforms(
    zarr_uri,
    processing_metadata,
)

local_paths, inverted = pipeline_point_transforms_local_paths(
    zarr_uri,
    processing_metadata,
    cache_dir="/tmp/transforms",
)

ccf_points = indices_to_ccf(
    {"region1": annotation_indices},
    zarr_metadata,
    zarr_uri,
    processing_metadata,
    template_used="SmartSPIM-template_2024-05-16_11-26-14",
)