feat(AdaptImages): rotate cached mesh grid with DatasetModel transforms#416
Merged
Conversation
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>
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
AdaptImages.updated_via_instance_fromnow accepts adataset_modeland applies itsgrid_offset+grid_rotation_angleto every entry ingalaxy_name_image_plane_mesh_grid_dictvia the newGrid2DIrregular.subtracted_and_rotated_fromhelper.AnalysisDataset.adapt_images_via_instance_fromplumbsdataset_modelandxpthrough to that method.AnalysisImaging.fit_frompasses the per-iterationdataset_modelinto it.config/priors/dataset_model.yamlgains agrid_rotation_angleentry (defaultConstant 0.0, matching the existinggrid_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 bygrid_offset, let alone rotated. For multi-band fits with an adaptive pixelization (Hilbert / KMeans), the cached mesh sits in the original image-plane frame whileFitDataset.gridscorrectly 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_anglefield +subtracted_and_rotated_frommethods). 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)— newdataset_modelandxpkwargs.AnalysisDataset.adapt_images_via_instance_from(instance, dataset_model=None, galaxies=None, xp=np)— newdataset_modelandxpkwargs.Test plan
python -m pytest test_autogalaxy/— 873 tests pass on this branchtest_simulate_and_fit_imaging.py:test__perfect_fit__sim_offset_centre__fit_with_dataset_model_grid_offset__chi_squared_zerotest__perfect_fit__sim_rotated_ellipse__fit_with_dataset_model_grid_rotation__chi_squared_zerotest__perfect_fit__sim_offset_and_rotated__fit_with_dataset_model_offset_and_rotation__chi_squared_zeroEach one simulates a profile with offset/rotated parameters and fits with an identity-frame profile + matching
DatasetModel—chi_squaredis assertedpytest.approx(0.0, abs=1e-4). These guard against any future regression of the latent mesh-grid misalignment bug.Refs PyAutoLens#511.