Skip to content

refactor: reduce magic in transform decorator#272

Merged
Jammy2211 merged 2 commits intomainfrom
feature/transform-decorator
Apr 13, 2026
Merged

refactor: reduce magic in transform decorator#272
Jammy2211 merged 2 commits intomainfrom
feature/transform-decorator

Conversation

@Jammy2211
Copy link
Copy Markdown
Collaborator

Summary

Reduce the implicit "magic" in the @aa.grid_dec.transform decorator while keeping its DRY benefits. This is Phase 1+2 of the refactor described in #271.

Phase 1: The is_transformed flag 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_back parameter 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 call self.rotated_grid_from_reference_frame_from(...).

API Changes

  • @aa.grid_dec.transform now accepts an optional rotate_back=True keyword argument. Existing usage without arguments is fully backward-compatible.
  • grid.is_transformed is now a public readable/writable property on all grid objects (Grid2D, Grid2DIrregular, Grid1D).

See full details below.

Test Plan

  • 725 PyAutoArray tests pass
  • 834 PyAutoGalaxy tests pass (including 12 new regression tests)
  • Exact numerical regression values locked in for Isothermal, NFW, PowerLaw
Full API Changes (for automation & release notes)

Added

  • AbstractNDArray.is_transformed — public property (getter/setter) exposing transform state on grid objects
  • transform(rotate_back=True) — optional parameter on the transform decorator for automatic back-rotation of vector outputs

Changed Behaviour

  • @aa.grid_dec.transform now reads/writes grid.is_transformed instead of kwargs["is_transformed"]. The kwarg-based approach is no longer used.

Migration

  • Before: kwargs.get("is_transformed") to check transform state
  • After: grid.is_transformed to check transform state
  • No action needed for most users — the decorator handles this internally

🤖 Generated with Claude Code

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>
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>
@Jammy2211 Jammy2211 merged commit 81c368b into main Apr 13, 2026
4 checks passed
@Jammy2211 Jammy2211 deleted the feature/transform-decorator branch April 13, 2026 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant