Skip to content

feat(weak): add scripts/weak/fit.py tutorial (PyAutoLens #524) - #188

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/weak-fit
May 19, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/weak-fit

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Adds a new tutorial scripts/weak/fit.py demonstrating the al.FitWeak class shipped in PyAutoLens PR #525. Workspace follow-up to step 3 of the weak-lensing series.

The tutorial walks through:

  1. Building a WeakDataset inline (matching the simulator's seed=1 / 200-galaxy / σ=0.3 setup so the script is self-contained).
  2. Visualising the dataset via aplt.subplot_weak_dataset.
  3. Constructing a model Tracer with hand-picked parameters close to the truth (a real workflow would use a non-linear search — that's step 4 of the series).
  4. Building al.FitWeak, printing chi_squared, noise_normalization, log_likelihood, and relating the chi-squared value to the 2 * n_galaxies degrees of freedom.
  5. Saving the 2×2 fit subplot mosaic via aplt.subplot_fit_weak.

Test Plan

  • python scripts/weak/fit.py runs end-to-end (verified locally — chi_squared = 437.5 for 400 DoF, within 1σ of expected; writes both PNGs to dataset/weak/simple/).
  • No new TODO markers introduced.
  • Script follows the same __Section__ notebook-cell docstring convention as simulator.py.

Known issue surfaced

al.from_json("dataset/weak/simple/dataset.json") fails to deserialise a WeakDataset — VectorYX2DIrregular.__init__() raises missing 1 required positional argument: 'values'. The tutorial works around it by rebuilding the dataset inline rather than loading the simulator's JSON output. Fixing the deserializer is out of scope for this PR (separate PyAutoGalaxy/PyAutoLens library task).

Cross-reference

🤖 Generated with Claude Code

New workspace tutorial demonstrating `al.FitWeak` on the shear catalogue
produced by scripts/weak/simulator.py. The script:

1. Builds the dataset inline (matching simulator.py's seed=1 / 200-galaxy /
   noise_sigma=0.3 setup) so the tutorial is self-contained.
2. Visualises the dataset via `aplt.subplot_weak_dataset`.
3. Builds a model `Tracer` with hand-picked parameters close to the
   simulator's truth.
4. Constructs a `FitWeak`, prints `chi_squared`, `noise_normalization` and
   `log_likelihood`, and notes the relation between chi-squared and the
   `2 * n_galaxies` degrees of freedom.
5. Saves the 2x2 fit subplot mosaic via `aplt.subplot_fit_weak`.

Workspace follow-up to PyAutoLens #525 (step 3 of the weak-lensing series,
issue #524). End-to-end run on this branch reports chi_squared = 437.5 for
400 DoF — well within 1-sigma of the expected value, confirming the fit
matches shape-noise expectations.

Side note: `al.from_json(dataset.json)` for a `WeakDataset` is broken
(`VectorYX2DIrregular.__init__() missing 1 required positional argument:
'values'`). The tutorial works around it by rebuilding the dataset inline;
fixing the deserializer is a separate library task.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label May 19, 2026
@Jammy2211
Jammy2211 merged commit d5db8ff into main May 19, 2026
6 checks passed
@Jammy2211
Jammy2211 deleted the feature/weak-fit branch May 19, 2026 09:28
@Jammy2211 Jammy2211 removed the pending-release PR queued for the next release build label Oct 7, 2026
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