refactor: reduce magic in transform decorator#272
Merged
Conversation
The transform decorator now tracks is_transformed on the grid object itself instead of passing it through kwargs. Added rotate_back parameter for automatic back-rotation of deflection vectors. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This was referenced Apr 13, 2026
Clarify that rotate_back is needed when vector components are expressed in the profile's rotated frame, not unconditionally for all vectors. Document scalar, vector, and spin-2 transformation conventions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reduce the implicit "magic" in the
@aa.grid_dec.transformdecorator while keeping its DRY benefits. This is Phase 1+2 of the refactor described in #271.Phase 1: The
is_transformedflag now lives as a property on the grid object itself (grid.is_transformed) instead of being threaded through**kwargs. This makes transform state explicit, inspectable, and impossible to lose through missed kwarg propagation.Phase 2: Added
rotate_backparameter to@aa.grid_dec.transform(rotate_back=True). When enabled, the decorator automatically rotates vector outputs (e.g. deflection angles) back from the profile's reference frame to the observer frame — eliminating the need for deflection methods to manually callself.rotated_grid_from_reference_frame_from(...).API Changes
@aa.grid_dec.transformnow accepts an optionalrotate_back=Truekeyword argument. Existing usage without arguments is fully backward-compatible.grid.is_transformedis now a public readable/writable property on all grid objects (Grid2D,Grid2DIrregular,Grid1D).See full details below.
Test Plan
Full API Changes (for automation & release notes)
Added
AbstractNDArray.is_transformed— public property (getter/setter) exposing transform state on grid objectstransform(rotate_back=True)— optional parameter on the transform decorator for automatic back-rotation of vector outputsChanged Behaviour
@aa.grid_dec.transformnow reads/writesgrid.is_transformedinstead ofkwargs["is_transformed"]. The kwarg-based approach is no longer used.Migration
kwargs.get("is_transformed")to check transform stategrid.is_transformedto check transform state🤖 Generated with Claude Code