Skip to content

feat(AdaptImages): rotate cached mesh grid with DatasetModel transforms#416

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/dataset-model-grid-rotation
May 15, 2026
Merged

feat(AdaptImages): rotate cached mesh grid with DatasetModel transforms#416
Jammy2211 merged 1 commit into
mainfrom
feature/dataset-model-grid-rotation

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

  • AdaptImages.updated_via_instance_from now accepts a dataset_model and applies its grid_offset + grid_rotation_angle to every entry in galaxy_name_image_plane_mesh_grid_dict via the new Grid2DIrregular.subtracted_and_rotated_from helper.
  • AnalysisDataset.adapt_images_via_instance_from plumbs dataset_model and xp through to that method.
  • AnalysisImaging.fit_from passes the per-iteration dataset_model into it.
  • config/priors/dataset_model.yaml gains a grid_rotation_angle entry (default Constant 0.0, matching the existing grid_offset_* entries).

Why

This is the actual fix for @qiuhan06's "weird source reconstruction" on his dev_Q prototype. On main, the cached adapt mesh-grid was never being shifted by grid_offset, let alone rotated. For multi-band fits with an adaptive pixelization (Hilbert / KMeans), the cached mesh sits in the original image-plane frame while FitDataset.grids correctly shifts/rotates the data grid — the two end up in different frames and the source reconstruction is genuinely misaligned. See PyAutoLens#511 for the full Phase-0 reproduction.

Depends on

PyAutoArray#312 (adds the grid_rotation_angle field + subtracted_and_rotated_from methods). CI will be red on this PR until that one merges.

API Changes

  • AdaptImages.updated_via_instance_from(instance, dataset_model=None, mask=None, galaxies=None, xp=np) — new dataset_model and xp kwargs.
  • AnalysisDataset.adapt_images_via_instance_from(instance, dataset_model=None, galaxies=None, xp=np) — new dataset_model and xp kwargs.

Test plan

  • python -m pytest test_autogalaxy/ — 873 tests pass on this branch
  • 3 new chi^2=0 self-consistency tests in test_simulate_and_fit_imaging.py:
    • test__perfect_fit__sim_offset_centre__fit_with_dataset_model_grid_offset__chi_squared_zero
    • test__perfect_fit__sim_rotated_ellipse__fit_with_dataset_model_grid_rotation__chi_squared_zero
    • test__perfect_fit__sim_offset_and_rotated__fit_with_dataset_model_offset_and_rotation__chi_squared_zero

Each one simulates a profile with offset/rotated parameters and fits with an identity-frame profile + matching DatasetModelchi_squared is asserted pytest.approx(0.0, abs=1e-4). These guard against any future regression of the latent mesh-grid misalignment bug.

Refs PyAutoLens#511.

The image-plane mesh grid cached in galaxy_name_image_plane_mesh_grid_dict
now follows the same shift+rotate transform that FitDataset.grids applies
to the data grid, so adaptive pixelization fits stay aligned in multi-band
work. Also plumbs dataset_model + xp through adapt_images_via_instance_from
and adds a grid_rotation_angle prior to config/priors/dataset_model.yaml.

This is the actual fix for the source-reconstruction misalignment in
@qiuhan06's dev_Q prototype; he had it correct but never re-tested it.

Adds 3 chi^2=0 simulate-and-fit tests in test_simulate_and_fit_imaging.py
covering offset-only, rotation-only, and combined cases.

Refs PyAutoLens#511, PyAutoArray#312.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Jammy2211 Jammy2211 merged commit bc360c0 into main May 15, 2026
6 of 8 checks passed
@Jammy2211 Jammy2211 deleted the feature/dataset-model-grid-rotation branch May 15, 2026 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant