Repository navigation
Description
Overview
The scaling_relation workspace examples shipped in autolens_workspace#141 hardcode their luminosity lists. For production users with 20+ companion galaxies this is unworkable — they want a CSV with y,x,luminosity,redshift? columns alongside the centre JSONs. This task adds a typed galaxy_table reader/writer to PyAutoGalaxy and migrates the four scaling_relation workspace scripts onto it.
Plan
- Add
autogalaxy/galaxy/galaxy_table.pywithgalaxy_table_from_csv/galaxy_table_to_csvwrappingautoconf.csvable. Returns a smallGalaxyTabledataclass withcentres: Grid2DIrregular,luminosities: list[float],redshifts: list[float] | None. - Re-export via
autogalaxy/__init__.py(PyAutoLens picks it up transparently through its existing autogalaxy re-export chain). - Unit tests: round-trip, missing optional
redshiftcolumn, partial-redshift rejection (mirrorsautolens.point.datasetconvention), extra columns ignored, row order preserved, empty CSV. - Update both scaling_relation simulators to emit CSVs alongside JSONs (additive — JSONs stay for backward compat).
- Update both modeling scripts and
modeling_for_luminosities.pyto load luminosities from CSV.
Detailed implementation plan
Affected Repositories
- PyAutoGalaxy (primary, library)
- autolens_workspace (workspace consumer)
Work Classification
Both — library first via /start_library, workspace follow-up via /start_workspace.
Why PyAutoGalaxy
autoconf.csvableis intentionally generic row-I/O with no domain types and no autoarray dep — adding a galaxy schema there would push that dep down.- The
autolens.point.datasetprecedent (output_to_csv/list_from_csvforPointDataset) shows the pattern: typed CSV helpers live next to the typed object they describe.PointDatasetis lensing-only, so the helper lives in autolens. - A galaxy-population table (centres + luminosities + redshifts) is NOT lensing-specific — it's a galaxy concept. The queued
autogalaxy_extra_galaxies_audit.mdfollow-up wants the same helper. PyAutoGalaxy serves both autolens_workspace and autogalaxy_workspace from one home.
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| PyAutoGalaxy | main | clean |
| autolens_workspace | main | dirty (formatter reflows from prior task — re-stash before workspace worktree) |
Suggested branch: feature/scaling-relation-csv-loader
Worktree root: ~/Code/PyAutoLabs-wt/scaling-relation-csv-loader/
Implementation Steps
Library phase (PyAutoGalaxy)
-
autogalaxy/galaxy/galaxy_table.py(new)@dataclass GalaxyTablewithcentres: Grid2DIrregular,luminosities: List[float],redshifts: Optional[List[float]] = Nonegalaxy_table_from_csv(file_path) -> GalaxyTable— wrapsautoconf.csvable.list_from_csv; partial-redshift handling mirrors_group_redshiftinautolens/point/dataset.py:291galaxy_table_to_csv(centres, luminosities, file_path, redshifts=None)— wrapsautoconf.csvable.output_to_csv
-
autogalaxy/__init__.py— add 3 imports forGalaxyTable,galaxy_table_from_csv,galaxy_table_to_csv. Verifyal.galaxy_table_from_csvresolves via the existing autogalaxy → autolens re-export chain; if not, add explicit re-export inPyAutoLens/autolens/__init__.py. -
test_autogalaxy/galaxy/test_galaxy_table.py(new) — 8 tests covering round-trip with/without redshift, missing column, partial column, extra columns ignored, row order preserved, empty CSV, mismatched-length writer rejection.
Workspace phase (autolens_workspace)
-
scripts/imaging/features/scaling_relation/simulator.py— addal.galaxy_table_to_csv(...)calls writingextra_galaxies.csvandscaling_galaxies.csvalongside the existing centre JSONs. -
scripts/imaging/features/scaling_relation/modeling.py— replace hardcodedrelational_extras_luminosity_listwithal.galaxy_table_from_csv(...). Update prose. -
scripts/group/features/scaling_relation/simulator.py— same as (4) for the group dataset. -
scripts/group/features/scaling_relation/modeling.py— same as (5) forscaling_galaxies_luminosity_list. -
scripts/group/features/scaling_relation/modeling_for_luminosities.py— switch the output fromscaling_galaxies_luminosities.jsontoscaling_galaxies.csvusingal.galaxy_table_to_csv, since CSV is the format the downstream modeling.py now consumes.
Key Files
PyAutoGalaxy/autogalaxy/galaxy/galaxy_table.py— new modulePyAutoGalaxy/autogalaxy/__init__.py— add 3 exportsPyAutoGalaxy/test_autogalaxy/galaxy/test_galaxy_table.py— new testsautolens_workspace/scripts/imaging/features/scaling_relation/{simulator,modeling}.py— CSV emit + loadautolens_workspace/scripts/group/features/scaling_relation/{simulator,modeling,modeling_for_luminosities}.py— CSV emit + load
Reference reads (no edits)
PyAutoLens/autolens/point/dataset.py— typed-CSV-helper precedentPyAutoConf/autoconf/csvable.py— generic CSV I/O wrapped by the new helper
Out of scope
- autoconf / autoarray / autolens source changes (PyAutoLens auto-picks-up via autogalaxy chain; only add explicit re-export if discovered necessary during implementation)
- Sharing infrastructure with
autolens.point.dataset— the schemas differ enough that coupling would be premature - CSV migration for other workspace features (extra_galaxies, group/modeling.py, etc.)
- autogalaxy_workspace changes — the queued
autogalaxy_extra_galaxies_audit.mdfollow-up will consume the new helper as its own task - Notebook regeneration — separate
/generate_and_mergerun after merge
Original Prompt
Click to expand starting prompt
Extend scaling_relation examples with CSV loading via autoconf.csvable
Background
The two scaling_relation examples shipped by feature/scaling-relation-update (issue autolens_workspace#141) currently use hardcoded Python lists for the extra-galaxy / scaling-galaxy luminosities:
extra_galaxies_luminosity_list = [0.9, 0.9]
scaling_galaxies_luminosity_list = [0.45, 0.45]The centres are loaded from JSON files written by the simulators (extra_galaxies_centres.json, scaling_galaxies_centres.json), but the luminosities are not. That is fine for a tutorial of fixed length, but production users with 20+ galaxies want a single file describing the full population.
autoconf already provides a generic CSV reader/writer at autoconf/csvable.py:
output_to_csv(rows, file_path, headers=None)— write list-of-dicts or list-of-sequenceslist_from_csv(file_path)— read as ordered list-of-dicts
There is no autolens/autogalaxy-specific schema layer yet — autolens.point.dataset does this for its own format. We probably want a similar (very thin) schema layer for galaxy populations.
Goal
Both imaging/features/scaling_relation/modeling.py and group/features/scaling_relation/modeling.py should be able to drop a CSV like this in the dataset folder:
y,x,luminosity,redshift
3.5,2.5,0.9,0.5
-4.4,-5.0,0.9,0.5…and load centres + luminosities (+ optional redshifts) in one call. The hardcoded lists in the modeling scripts stay as a fallback path for the tutorial flow but the CSV path is shown alongside.
Proposed work
-
Decide where the schema layer lives. Two options:
- (a) Extend
autoconf/csvable.pywith a thin typed reader (e.g.galaxy_table_from_csv) returning(centres: Grid2DIrregular, luminosities: list[float], redshifts: list[float] | None). Pro: every workspace gets it. Con:autoconfdoes not depend onautoarray, so theGrid2DIrregularreturn type would push it down a dependency edge. - (b) Keep the schema layer in
autolens(orautoarray). Add e.g.al.util.galaxy_table_from_csvthat wrapsautoconf.csvable.list_from_csvand produces the typed outputs. Probably the right call.
- (a) Extend
-
Extend both simulators (
scripts/imaging/features/scaling_relation/...borrowsdataset/group/simple, so updatescripts/group/simulator.py; the newscripts/group/features/scaling_relation/simulator.pywrites its ownscaling_relationdataset) to also writeextra_galaxies.csvand/orscaling_galaxies.csvnext to the centre JSONs. Keep the JSON files for backward compatibility — the CSV is additive. -
Update both modeling scripts to load from the CSV instead of (or alongside) the JSON + hardcoded list. Show the CSV path as the primary modern flow; document the JSON-fallback inline for users on older datasets.
-
Tests.
test_autoconf/test_csvable.pyalready covers the generic round-trip. Add tests for the new schema layer (in whichever repo owns it), exercising:- missing optional column (
redshiftabsent →None) - extra columns (silently ignored)
- row order preserved
- empty file → empty population
- missing optional column (
Out of scope
- Refactoring the
autolens.point.datasetCSV layer to use this new helper. That should be a separate task —point.datasethas its own column conventions and we should not couple them. - Migrating other workspace features to CSV. This task is scoped to the two scaling_relation examples plus their simulators.
Reference reads
autoconf/csvable.py— generic CSV I/Oautolens.point.dataset— example of an existing CSV schema layerautolens_workspace/scripts/imaging/features/scaling_relation/modeling.py— current consumer (post issue Feature/adapt via fit #141)autolens_workspace/scripts/group/features/scaling_relation/{simulator,modeling}.py— current consumer (post issue Feature/adapt via fit #141)
Activity
Jammy2211 commentedon May 10, 2026
Library PR Created — 2026-05-10
PRs
Status
Workspace changes needed. Next: /start_workspace
API Changes
Purely additive — three new public symbols:
ag.GalaxyTable/al.GalaxyTable(dataclass with centres, luminosities, redshifts)ag.galaxy_table_from_csv(file_path) -> GalaxyTable(andal.alias)ag.galaxy_table_to_csv(centres, luminosities, file_path, redshifts=None) -> None(andal.alias)Test suite: PyAutoGalaxy 853/853 green, PyAutoLens 273/273 green.
Jammy2211 commentedon May 10, 2026
Smoke Test Results — 2026-05-10
All 7 smoke tests passed across autolens_workspace.
Workspace PR: PyAutoLabs/autolens_workspace#143
Jammy2211 commentedon May 10, 2026
Shipped — 2026-05-10
PRs
Summary
Added
autogalaxy.galaxy.galaxy_tableprovidingGalaxyTabledataclass plusgalaxy_table_from_csv/galaxy_table_to_csvthat wrapautoconf.csvable. Re-exported through autolens. Both scaling_relation simulators now emitextra_galaxies.csvandscaling_galaxies.csvnext to the centre JSONs; both modeling.py files show the CSV path (Option A, default) AND the original JSON-centres + hardcoded-list path (Option B, commented out) side by side so users see they have a choice.modeling_for_luminosities.pynow writesscaling_galaxies.csvdirectly so the chain into modeling.py needs no manual paste.Session Notes
autolens.point.dataset(the existing typed-CSV-helper precedent — lensing-specific so lives in autolens) plusautoconf.csvable(intentionally generic, no autoarray dep) confirmed PyAutoGalaxy is the right level: galaxy populations are a galaxy concept, not a configuration concept, and putting it in autogalaxy means the queued autogalaxy_workspace parity follow-up gets the same helper for free.autolens/__init__.pydoes explicitfrom autogalaxy.X import Ylines for every cross-library symbol — noimport *. So the helper required 3 imports in autogalaxy/init.py AND 3 in autolens/init.py. Easy to miss; verified withag.galaxy_table_from_csv is al.galaxy_table_from_csv(True).modeling_for_luminosities.pyoriginally wrotescaling_galaxies_luminosities.json(centres-less, modeler had to paste numbers). Switched it to writescaling_galaxies.csv(centres + luminosities) somodeling.pycan reload it directly via Option A — no manual copy/paste between the two scripts.