Skip to content

fix: raw-flux latent + soft-fail magzero-required µJy - #463

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/flux-latents-raw
May 28, 2026
Merged

fix: raw-flux latent + soft-fail magzero-required µJy#463
Jammy2211 merged 1 commit into
mainfrom
feature/flux-latents-raw

Conversation

@Jammy2211

@Jammy2211 Jammy2211 commented May 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

total_galaxy_0_flux_mujy used to raise ValueError when its consumer enabled the
latent without passing magzero to AnalysisImaging. The raise fired post-fit
inside SearchUpdater._compute_latent_samples, killing the metric write of a
converged multi-hour search.

This PR adds a new raw-flux latent (total_galaxy_0_flux) that needs no
instrument inputs and ships default-on, and converts the existing _mujy
latent's raise into a NaN + once-per-process warning. The sibling change
for the lensing latents lives in PyAutoLabs/PyAutoLens#557 (linked once that PR is open).

API Changes

  • Added total_galaxy_0_flux(fit, magzero=None, xp=np) — raw integrated
    flux of galaxy 0 in the fit's image units; no instrument inputs required.
    Default-on in autogalaxy/config/latent.yaml.
  • Added module-level helper _maybe_magzero_warn(magzero, name) -> bool
    to dedupe the new soft-fail warning across the many fit evaluations in a
    search.
  • Behaviour change on total_galaxy_0_flux_mujy(fit, magzero=None, xp=np):
    no longer raises ValueError when magzero is None — returns xp.nan and
    emits a single logging.WARNING per latent name per process.
  • Default config change in autogalaxy/config/latent.yaml:
    total_galaxy_0_flux: true added; total_galaxy_0_flux_mujy stays false.

See full details below.

Test Plan

  • python -m pytest test_autogalaxy/imaging/model/test_latent.py -v — 13/13 pass
  • Full test_autogalaxy/ suite (subagent runs in CI commit)
  • Smoke test impact on autogalaxy_workspace — verified there are no callers of the removed raise in workspace scripts (separate workspace PR will demo the new latent in guides/units/flux.py)

Refs PyAutoLabs/PyAutoLens#556

Full API Changes (for automation & release notes)

Added

  • autogalaxy.imaging.model.latent.total_galaxy_0_flux(fit, magzero=None, xp=np) — raw image-unit sum of fit.galaxy_image_dict[fit.galaxies[0]].array. magzero accepted but ignored (uniform dispatcher context).
  • autogalaxy.imaging.model.latent._maybe_magzero_warn(magzero, name) — module-private helper. Returns True (and logs one WARNING) when magzero is None; False otherwise.
  • autogalaxy.imaging.model.latent._MAGZERO_WARNED — module-level set tracking which latent names have already warned in this process.

Removed

  • autogalaxy.imaging.model.latent.total_galaxy_0_flux_mujy no longer raises ValueError("magzero must be passed ...") on magzero=None. Callers that previously caught this ValueError will instead see xp.nan + a logging.WARNING record.

Changed Behaviour

  • total_galaxy_0_flux_mujy(fit, magzero=None, xp=np): same signature, but magzero=None now → (xp.nan, logger.warning(...)) instead of raise.
  • LATENT_FUNCTIONS registry now has 2 keys: total_galaxy_0_flux, total_galaxy_0_flux_mujy.

Default Config

  • autogalaxy/config/latent.yaml gains total_galaxy_0_flux: true. total_galaxy_0_flux_mujy: false is preserved.

Migration

  • No migration required for code that passes magzero (Euclid pipeline pattern unchanged).
  • Code that previously caught the ValueError: drop the catch; the value is now NaN.
  • Workspaces that want the µJy column auto-populated: enable total_galaxy_0_flux_mujy: true in their config/latent.yaml override AND construct AnalysisImaging(..., magzero=<value>).

🤖 Generated with Claude Code

`total_galaxy_0_flux_mujy` used to raise ValueError when its consumer enabled the latent without passing magzero to AnalysisImaging. The raise fired post-fit inside SearchUpdater._compute_latent_samples, killing the metric write of a converged search.

This commit:
  - adds total_galaxy_0_flux (raw image-unit sum, no instrument inputs)
    default-on in autogalaxy/config/latent.yaml
  - replaces the magzero raise with _maybe_magzero_warn, returning NaN +
    one warning per process per latent name
  - keeps total_galaxy_0_flux_mujy default-off (workspaces that pass
    magzero opt in via their own latent.yaml override)

Refs PyAutoLabs/PyAutoLens#556
@Jammy2211

Copy link
Copy Markdown
Collaborator Author

Workspace PR: PyAutoLabs/autolens_workspace#214

@Jammy2211

Copy link
Copy Markdown
Collaborator Author

Workspace PR: PyAutoLabs/autogalaxy_workspace#108

@Jammy2211

Copy link
Copy Markdown
Collaborator Author

Workspace PR: PyAutoLabs/autolens_workspace_test#133

@Jammy2211

Copy link
Copy Markdown
Collaborator Author

@Jammy2211
Jammy2211 merged commit 85a7cae into main May 28, 2026
6 checks passed
@Jammy2211
Jammy2211 deleted the feature/flux-latents-raw branch May 28, 2026 13:25
@Jammy2211 Jammy2211 removed the pending-release PR queued for the next release build label Sep 4, 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