1515
1616from __future__ import annotations
1717
18+ import logging
1819import os
1920from dataclasses import dataclass
2021from typing import TYPE_CHECKING , Any
2122
22- from aind_s3_cache .s3_cache import (
23- get_local_path_for_resource ,
24- )
23+ from aind_s3_cache .s3_cache import get_local_path_for_resource
2524from aind_s3_cache .uri_utils import as_pathlike , as_string , join_any
26-
2725from aind_zarr_utils .io .paths import _asset_from_zarr_pathlike
2826from aind_zarr_utils .io .processing import (
29- image_atlas_alignment_path_relative_from_processing ,
30- )
27+ _get_processing_pipeline_data ,
28+ image_atlas_alignment_path_relative_from_processing )
3129
3230if TYPE_CHECKING :
3331 from mypy_boto3_s3 import S3Client
3432
33+ logger = logging .getLogger (__name__ )
34+
3535
3636@dataclass (slots = True , frozen = True )
3737class TransformChain :
@@ -108,7 +108,7 @@ class TemplatePaths:
108108 )
109109}
110110
111- _PIPELINE_INDIVIDUAL_TRANSFORM_CHAINS : dict [int , TransformChain ] = {
111+ _KNOWN_INDIVIDUAL_TRANSFORM_CHAINS : dict [int , TransformChain ] = {
112112 3 : TransformChain (
113113 fixed = "template" ,
114114 moving = "individual" ,
@@ -125,6 +125,34 @@ class TemplatePaths:
125125 )
126126}
127127
128+ _PIPELINE_INDIVIDUAL_TRANSFORM_CHAINS : dict [int , TransformChain ] = {
129+ 3 : _KNOWN_INDIVIDUAL_TRANSFORM_CHAINS [3 ],
130+ 4 : _KNOWN_INDIVIDUAL_TRANSFORM_CHAINS [3 ],
131+ 5 : _KNOWN_INDIVIDUAL_TRANSFORM_CHAINS [3 ],
132+ }
133+
134+
135+ def _resolve_individual_transform_chain (
136+ pipeline_ver : int ,
137+ ) -> TransformChain :
138+ """Look up the individual (LS → template) transform chain for a pipeline major version.
139+
140+ Falls back to the latest known chain when the version is newer than
141+ anything registered.
142+ """
143+ chain = _PIPELINE_INDIVIDUAL_TRANSFORM_CHAINS .get (pipeline_ver )
144+ if chain is not None :
145+ return chain
146+ max_known = max (_PIPELINE_INDIVIDUAL_TRANSFORM_CHAINS )
147+ if pipeline_ver > max_known :
148+ logger .warning (
149+ f"No individual transform chain registered for pipeline "
150+ f"version { pipeline_ver } ; falling back to chain for version "
151+ f"{ max_known } . Results may not be accurate."
152+ )
153+ return _PIPELINE_INDIVIDUAL_TRANSFORM_CHAINS [max_known ]
154+ raise ValueError (f"No individual transform chain registered for pipeline version { pipeline_ver } " )
155+
128156
129157def pipeline_transforms (
130158 zarr_uri : str ,
@@ -169,9 +197,12 @@ def pipeline_transforms(
169197 bucket ,
170198 asset_pathlike / alignment_rel_path ,
171199 )
200+ pipeline = _get_processing_pipeline_data (processing_data )
201+ pipeline_ver = int (pipeline ["pipeline_version" ].split ("." )[0 ])
202+ transform_chain = _resolve_individual_transform_chain (pipeline_ver )
172203 individual_ants_paths = TemplatePaths (
173204 alignment_path ,
174- _PIPELINE_INDIVIDUAL_TRANSFORM_CHAINS [ 3 ] ,
205+ transform_chain ,
175206 )
176207 if template_base :
177208 template_ants_paths = TemplatePaths (
0 commit comments