feat(galaxy): named-galaxy CSV reader/writer for full model round-trips#428
Merged
Conversation
Adds galaxy_model_csv with helpers that read/write named-galaxy CSVs keyed by a `galaxy` column and `profile_class` dispatch, alongside the existing galaxy_table.py (which keeps its narrow scaling-tier schema). Three family- level CSV schemas — mass, light, point — each with one row per (galaxy, attr_name, profile_class) tuple and sparse parameter columns. The join across families produces concrete Galaxy instances or af.Model[Galaxy] ready for non-linear search composition. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced May 19, 2026
Add a writer-side guard: each profile passed to galaxy_models_to_csv must have its class exposed in the family namespace declared by the call. Surfaces misuse like passing a SersicSph under family='mass' with a clear error rather than silently writing a wrong-family row that fails on read. Found while writing the workspace csv_api.py guide — passing a Galaxy dict containing both bulge + mass profiles to family='light' silently wrote dPIE rows into light.csv, which then failed on read as 'profile_class dPIEMassSph not found in light namespace'. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3 tasks
Collaborator
Author
|
Workspace PR: PyAutoLabs/autolens_workspace#189 |
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
Adds a CSV layer over the full galaxy model — names, profile classes, and constructor parameters — so cluster modelling scripts can store and reload an entire
af.CollectionofGalaxyobjects as a small set of human-editable CSVs. Sibling of the existinggalaxy_table.py(which keeps its narrowy, x, luminosityscaling-tier schema unchanged).Workspace integration follows in a separate PR on
autolens_workspace(issue PyAutoLabs/autolens_workspace#187) — this PR is library helpers + tests only.API Changes
Two new public dataclasses (
GalaxyModelRow,GalaxyModelTable) and four public functions (galaxy_models_to_csv,galaxy_models_from_csv,galaxies_from_csv_tables,galaxy_af_models_from_csv_tables). One CSV per profile family (mass/light/point); profile classes dispatch viagetattragainstautogalaxy.profiles.{mass,light.standard,point_sources}. Sparse columns supported — disparate profile classes can share one CSV.No breaking changes.
galaxy_table.pyis untouched.See full details below.
Test Plan
pytest test_autogalaxy/galaxy/test_galaxy_model_csv.py— 8 new tests cover single-family round-trip, sparse-column round-trip (dPIE + NFW), light family (Sersic + SersicCore), point family, cross-family join,af.Modelround-trip, redshift-consistency check, class-not-found error.pytest test_autogalaxy/galaxy/— 100 passing, no regressions.Full API Changes (for automation & release notes)
Added
autogalaxy.GalaxyModelRow— dataclass:galaxy: str, attr_name: str, profile_class: type, params: Dict[str, Any], redshift: Optional[float].autogalaxy.GalaxyModelTable— dataclass:rows: List[GalaxyModelRow], family: str.autogalaxy.galaxy_models_to_csv(profiles_by_galaxy, file_path, family, redshifts=None)— writes a family CSV with one row per (galaxy, attr_name) pair. Introspects each profile instance's constructor viainspect.signatureto discover the column set; sparse columns supported (different profile classes can share one CSV).autogalaxy.galaxy_models_from_csv(file_path, family)— reads a family CSV and dispatchesprofile_classagainstautogalaxy.profiles.{mass,light.standard,point_sources}forfamily ∈ {"mass", "light", "point"}respectively. Returns a typedGalaxyModelTable.autogalaxy.galaxies_from_csv_tables(*tables)— joins one or moreGalaxyModelTables on thegalaxycolumn and returnsDict[str, Galaxy]. Per-galaxy redshift consistency is enforced.autogalaxy.galaxy_af_models_from_csv_tables(*tables)— same as above but returnsDict[str, af.Model[Galaxy]]with concrete CSV values as fixedaf.Modeldefaults (ready to mutate selected params into priors).CSV schema
galaxy, attr_name, profile_class.centretuple param →y, xcolumns (precedent fromgalaxy_table.py).ell_comps) →<name>_0, <name>_1columns.redshiftcolumn for per-galaxy redshift (consistent across rows for the same galaxy or all blank).Module
autogalaxy/galaxy/galaxy_model_csv.py(~280 lines).autogalaxy/galaxy/galaxy_table.pyunchanged.🤖 Generated with Claude Code