Skip to content

Commit 55d3c35

Browse files
committed
refactor: port fixes on main to refactor branch
1 parent 129d6cc commit 55d3c35

2 files changed

Lines changed: 54 additions & 10 deletions

File tree

src/aind_zarr_utils/io/processing.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@
1010

1111
from __future__ import annotations
1212

13+
import logging
1314
from pathlib import PurePosixPath
1415
from typing import Any
1516

1617
from aind_zarr_utils.io.paths import _zarr_base_name_pathlike
1718

19+
logger = logging.getLogger(__name__)
20+
_KNOWN_GOOD_PIPELINE_VERSIONS = {3, 4, 5}
21+
1822

1923
def _get_processing_pipeline_data(
2024
processing_data: dict[str, Any],
@@ -42,8 +46,17 @@ def _get_processing_pipeline_data(
4246
if not ver_str:
4347
raise ValueError("Missing pipeline version")
4448
pipeline_ver = int(ver_str.split(".")[0])
45-
if pipeline_ver not in set((3, 4)):
46-
raise ValueError(f"Unsupported pipeline version: {pipeline_ver}")
49+
if pipeline_ver not in _KNOWN_GOOD_PIPELINE_VERSIONS:
50+
maxver = max(_KNOWN_GOOD_PIPELINE_VERSIONS)
51+
if pipeline_ver > maxver:
52+
logger.warning(
53+
f"Pipeline version {pipeline_ver} is greater than max "
54+
f"verified version {maxver}, results may not be accurate. "
55+
"File an issue at "
56+
"https://github.com/AllenNeuralDynamics/aind-zarr-utils/issues."
57+
)
58+
else:
59+
raise ValueError(f"Unsupported pipeline version: {pipeline_ver}")
4760
pipeline: dict[str, Any] = processing_data.get("processing_pipeline", {})
4861
return pipeline
4962

src/aind_zarr_utils/io/transforms.py

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@
1515

1616
from __future__ import annotations
1717

18+
import logging
1819
import os
1920
from dataclasses import dataclass
2021
from 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
2524
from aind_s3_cache.uri_utils import as_pathlike, as_string, join_any
26-
2725
from aind_zarr_utils.io.paths import _asset_from_zarr_pathlike
2826
from 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

3230
if TYPE_CHECKING:
3331
from mypy_boto3_s3 import S3Client
3432

33+
logger = logging.getLogger(__name__)
34+
3535

3636
@dataclass(slots=True, frozen=True)
3737
class 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

129157
def 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

Comments
 (0)