Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ is a design question for `foundation.md`, not a test to relax.

| Subpackage | Holds |
|---|---|
| `stages/` | One module per stage. The foundation's stages are one function, `run(job: JobContext) -> None`, run by `rapidpipe job local`/`job run`/`job submit`: `import_products` (stage `import`), `intake` (one SOC L2 ASDF file, read anonymously from a public source root when the run says so, converted by `dev`'s `build_fits_file` into its gzipped FITS, the pixels of `[intake] dq_mask_bits` NaN as commissioning #238 sets them, with its `exposures` and `l2files` rows, the row's `mjdmid` and the header's `MJD-AVG` the exposure's mid-time, the file's own or the middle of its start and end; under `[pixel_area_map] lookup` the row's `pixel_area_map` and the header's `PAMREF` hold the CRDS name of the file's pixel area map, from the file, CRDS's best reference or the store's index, null when none answers), `packet` (`dev`'s alerts package at schema 00.09: Avro packets with three RICE-compressed cutouts, forced photometry and Gaia matches, the object catalog and window read as they stand and recorded, and the packet index; the triggers are the set's xsources, with the xobjects and xmemberships, under `[packet] alert_catalog = "xsources"`, or its sources, objects and memberships under `"sources"`, cut to `[packet] max_alerts` by |S/N|; every flux in nJy, calibrated at assembly by its own image's `l2files.zptmag` and pixel area map, with `zeroPoint` and `pixelAreaFactor` on each record, the tables' fluxes left instrumental) `reference` (`dev`'s awaicgen coadd of the named `l2files`, with its SExtractor catalog and, under `[reference.psfcat] enabled`, its Photutils PSF-fit catalog made with the reference PSF `[difference] reference_psf` chooses: `refimages`, `refimimages`, `refimcatalogs`, `dev`'s quality measurements in `refimmeta`, and a measured PSF's 18 `psfs` rows; a status 0 reference is published with its binding refused) `difference` (`dev`'s subtraction of the named `l2files` row against the named `refimages` row with the science PSF and the reference PSF it measures on the resampled reference: SFFT, always run and the only differencer published, with ZOGY (skipped by `[difference.zogy] run_zogy = false`; its catalogs are diagnostics) and naive beside it as `dev` runs them: `diffimages`, the `sources` set (SFFT's positive and negative PSF-fit catalogs, scored by the in-process ONNX RuBR-AT classifier, through `[difference.sources_database_prefilter]`, uncapped unless `[difference] max_sources` says otherwise) and `dev`'s uncapped `xsources` from SFFT's two SExtractor catalogs (through `[difference.xsources_database_prefilter]`, scored the same way); then the association, crossmatch and statistics in one, its sources matched in memory against its dataset's objects of every run in each source's field and its neighbours as it read them, each founding in its own field: `objects` founded here and `memberships`, reconciled at publish; the same over its xsources, `dev`'s crossMatchXSources: `xobjects` and `xmemberships`) and `psf` (new science: one filter and SCA's science `psfs` row, reduced from the CRDS ePSF reference the L2 file names, fetched by name). A stage's exit, through `job run`: 0 success, 64 usage, 65 bad/missing input, 70 unclassified error, 75 retryable transient failure. The older `main(argv)` contract's `admit` and `finalize` were retired 2026-10-25. The run model's database stages (`register`, `load`, `maintain`, `crossmatch`, `statistics`, `prune`, `alerts`, `export`) were retired with its schema; the foundation plan's Part 5 ports their science (into `difference` and `packet`; the `associate` stage that first held it retired 2026-10-24). |
| `stages/` | One module per stage. The foundation's stages are one function, `run(job: JobContext) -> None`, run by `rapidpipe job local`/`job run`/`job submit`: `import_products` (stage `import`), `intake` (one SOC L2 ASDF file, read anonymously from a public source root when the run says so, converted by `dev`'s `build_fits_file` into its gzipped FITS, the pixels of `[intake] dq_mask_bits` NaN as commissioning #238 sets them, with its `exposures` and `l2files` rows, the row's `mjdmid` and the header's `MJD-AVG` the exposure's mid-time, the file's own or the middle of its start and end; under `[pixel_area_map] lookup` the row's `pixel_area_map` and the header's `PAMREF` hold the CRDS name of the file's pixel area map, from the file, CRDS's best reference or the store's index, null when none answers), `packet` (`dev`'s alerts package at schema 00.09: Avro packets with three RICE-compressed cutouts, forced photometry and Gaia matches, the object catalog and window read as they stand and recorded, and the packet index; the triggers are the set's xsources, with the xobjects and xmemberships, under `[packet] alert_catalog = "xsources"`, or its sources, objects and memberships under `"sources"`, cut to `[packet] max_alerts` by |S/N|; every flux in nJy, calibrated at assembly by its own image's `l2files.zptmag` and pixel area map, with `zeroPoint` and `pixelAreaFactor` on each record, the tables' fluxes left instrumental) `reference` (`dev`'s awaicgen coadd of the named `l2files`, with its SExtractor catalog and, under `[reference.psfcat] enabled`, its Photutils PSF-fit catalog made with the reference PSF `[difference] reference_psf` chooses: `refimages`, `refimimages`, `refimcatalogs`, `dev`'s quality measurements in `refimmeta`, and a measured PSF's 18 `psfs` rows; a status 0 reference is published with its binding refused) `difference` (`dev`'s subtraction of the named `l2files` row against the named `refimages` row with the science PSF and the reference PSF it measures on the resampled reference: SFFT, always run and the only differencer published, with ZOGY (skipped by `[difference.zogy] run_zogy = false`; its catalogs are diagnostics) and naive beside it as `dev` runs them: `diffimages`, with `dev`'s quality measurements and the gate's numbers in `diffimmeta`, the `sources` set (SFFT's positive and negative PSF-fit catalogs, scored by the in-process ONNX RuBR-AT classifier, through `[difference.sources_database_prefilter]`, uncapped unless `[difference] max_sources` says otherwise) and `dev`'s uncapped `xsources` from SFFT's two SExtractor catalogs (through `[difference.xsources_database_prefilter]`, scored the same way); then the association, crossmatch and statistics in one, its sources matched in memory against its dataset's objects of every run in each source's field and its neighbours as it read them, each founding in its own field: `objects` founded here and `memberships`, reconciled at publish; the same over its xsources, `dev`'s crossMatchXSources: `xobjects` and `xmemberships`) and `psf` (new science: one filter and SCA's science `psfs` row, reduced from the CRDS ePSF reference the L2 file names, fetched by name). A stage's exit, through `job run`: 0 success, 64 usage, 65 bad/missing input, 70 unclassified error, 75 retryable transient failure. The older `main(argv)` contract's `admit` and `finalize` were retired 2026-10-25. The run model's database stages (`register`, `load`, `maintain`, `crossmatch`, `statistics`, `prune`, `alerts`, `export`) were retired with its schema; the foundation plan's Part 5 ports their science (into `difference` and `packet`; the `associate` stage that first held it retired 2026-10-24). |
| `science/` | Pure algorithms and tool wrappers the stages call (`difference`, `reference`, `intake`, `load`, `crossmatch`, `statistics`, `alerts`, plus `spatial` for HEALPix/tessellation, `crds` (CRDS's best reference of a type for a detector and exposure start, asked by JSON-RPC), and `catalogs`: the external catalogs' copies, `store` (built once per release by `python -m rapidpipe.science.catalogs.store`: NED's object directory mirrored and re-cut, NED-LVS and Gaia DR3 ingested, or the Gaia layout from one table, and `ingest-ss`, one day of the MPC orbits propagated with kete under the `ss` root) and their cone `readers`; a run's `catalogs` row names a copy's prefix; `alerts.kona` is `dev`'s KONA, the solar-system predictions the packet stage matches from the `ss` day at or before the trigger and the L2 header's ephemeris; `alerts.calibration` is the nJy arithmetic, a zero point's scale and a pixel area map's value at a position). No stage, `launch` or CLI imports. |
| `products/` | Product identifiers and kinds (`ids.py`), storage layout (`storage.py`), the difference image's bits and source flags (`diffimage`), `filters`, and `spatial` (the pure HEALPix and tessellation derivations; `science.spatial` re-exports them). |
| `db/` | `connection.py` (one connection from the `PG*` environment, a secret or a parameter tree) and `ids.py` (ULIDs). |
Expand Down
49 changes: 49 additions & 0 deletions database/2026-12-04-diffimmeta.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
-- dev's DiffImMeta, a difference's quality measurements with the quality
-- gate's numbers beside them, written by each difference job (rapid_docs
-- decision-diffimmeta): the diffimmeta table, its indexes and
-- diffimmeta_official. schema.sql carries them for a fresh database; this
-- file brings an existing one to it, applied once, in one transaction, as
-- postgres. It only adds a table and a view, which reach the pipeline's roles
-- through the schema's default privileges (docs/foundation-smdc-step.md,
-- part 3 of the SMDC step). No row is backfilled: differences published
-- before it have none.

BEGIN;

CREATE TABLE diffimmeta (
pid integer PRIMARY KEY REFERENCES diffimages (pid),
job bigint NOT NULL REFERENCES jobs (id), -- the difference's job
nsexcatsources integer NOT NULL, -- rows of both SFFT SExtractor catalogs, before the prefilter
scalefacref real NOT NULL, -- gain-matching scale factor for the reference image
dxrmsfin real NOT NULL, -- gain-matching x astrometric uncertainty (final), measured
dyrmsfin real NOT NULL, -- gain-matching y astrometric uncertainty (final), measured
dxmedianfin real NOT NULL, -- gain-matching dx astrometric median offset (final)
dymedianfin real NOT NULL, -- gain-matching dy astrometric median offset (final)
field integer NOT NULL, -- Roman tessellation index of the difference image
hp6 integer NOT NULL, -- level-6 HEALPix index (NESTED) of the field's centre
hp9 integer NOT NULL, -- level-9 HEALPix index (NESTED) of the field's centre
fid smallint NOT NULL REFERENCES filters (fid),
sca smallint NOT NULL REFERENCES scas (sca),
n_xsources_read_positive integer, -- positive SExtractor rows before the edge cut and prefilter
n_xsources_prefiltered integer, -- positive xsources kept after the edge cut and prefilter
n_xsources_snr_gt20 integer, -- kept positive xsources with PSF-fit S/N above 20
usable_fraction real, -- difference pixels finite and covered, over all
registration_offset real, -- hypot(registration_dx_px, registration_dy_px) [pixels]
core_fraction real, -- median residual within 2.5 px of a star over its flux
ring_fraction real -- median residual 2.5 to 6 px from a star over its flux
);

CREATE INDEX diffimmeta_job_idx ON diffimmeta (job);
CREATE INDEX diffimmeta_field_idx ON diffimmeta (field);
CREATE INDEX diffimmeta_hp6_idx ON diffimmeta (hp6);
CREATE INDEX diffimmeta_hp9_idx ON diffimmeta (hp9);
CREATE INDEX diffimmeta_fid_idx ON diffimmeta (fid);
CREATE INDEX diffimmeta_sca_idx ON diffimmeta (sca);

CREATE VIEW diffimmeta_official AS
SELECT t.*, o.id AS binding, j.run
FROM diffimmeta t
JOIN official o ON o.closed_at IS NULL AND o.product = 'diffimages' AND o.job = t.job
JOIN jobs j ON j.id = t.job;

COMMIT;
3 changes: 3 additions & 0 deletions database/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ the pipeline imports.
`rapid_rebuild_pipeline` to `rapid_pipeline` in the adoption window (and
its rehearsal), dropping the retired login of that name; its header is the
whole procedure, the secret's commands and the test login included.
`2026-12-04-diffimmeta.sql` follows (the `diffimmeta` table and
`diffimmeta_official`, which the difference stage writes; no row
backfilled).

Applying one is one command, run by whoever merges the pull request that
adds it, from an Operator host, with no database login of their own: in a
Expand Down
Loading
Loading