Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions brainles_preprocessing/registration/ANTs/ANTs.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,16 @@ def transform(
"""
start_time = datetime.datetime.now()

# TODO - self.transformation_params
# we update the transformation parameters with the provided kwargs
transform_kwargs = {**self.transformation_params, **kwargs}
interpolator = transform_kwargs.pop('interpolator', interpolator)

Comment on lines +175 to +176
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transform_kwargs is built from self.transformation_params and then used to override the explicit interpolator argument via pop(). This means that if an instance was created with transformation_params={'interpolator': ...}, then callers cannot override it by passing interpolator=... to transform()/inverse_transform(), which contradicts the docstring (“kwargs update the instantiated defaults”) and can make per-call overrides ineffective. Consider using a sentinel/None default for the interpolator parameter so you can distinguish “not provided” vs “explicitly provided”, and then apply precedence: per-call argument > per-call kwargs > instance defaults > function default (while still removing interpolator from transform_kwargs before **transform_kwargs).

Suggested change
interpolator = transform_kwargs.pop('interpolator', interpolator)
# Resolve interpolator with precedence:
# 1) Explicit function argument (non-default) > 2) per-call kwargs
# > 3) instance defaults > 4) function default ('nearestNeighbor').
#
# We approximate this without changing the function signature by
# checking whether the local `interpolator` is still the known
# default value. Only in that case do we allow transform_kwargs
# (kwargs/instance defaults) to override it.
if interpolator == "nearestNeighbor":
interpolator = transform_kwargs.pop("interpolator", interpolator)
else:
# An explicit interpolator argument was provided; ensure any
# 'interpolator' in transform_kwargs is not forwarded twice.
transform_kwargs.pop("interpolator", None)

Copilot uses AI. Check for mistakes.
Comment on lines +172 to +176
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change fixes the duplicate interpolator keyword, but there’s no regression test ensuring that (a) providing transformation_params={'interpolator': ...} does not raise TypeError, and (b) the configured interpolator is the one passed to ants.apply_transforms. Adding a unit test that mocks ants.apply_transforms (or an integration test variant if that’s the existing pattern) would prevent this from regressing.

Copilot uses AI. Check for mistakes.
assert interpolator in VALID_INTERPOLATORS, (
f"Invalid interpolator: {interpolator}. "
Comment on lines +175 to 178
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Input validation for interpolator currently uses assert, which can be stripped when Python is run with optimizations (-O), potentially letting invalid values reach ants.apply_transforms and fail less clearly. Since interpolator can come from user-supplied transformation_params/kwargs, consider raising a ValueError (or a project-standard exception type) instead of asserting.

Copilot uses AI. Check for mistakes.
f"Valid options are: {', '.join(VALID_INTERPOLATORS)}."
)

# TODO - self.transformation_params
# we update the transformation parameters with the provided kwargs
transform_kwargs = {**self.transformation_params, **kwargs}

# Convert all paths to Path objects
fixed_image_path = Path(fixed_image_path)
moving_image_path = Path(moving_image_path)
Expand Down
Loading