Skip to content

Issue-223: Add the single-frame limit and the should-be-seen sort - #242

Open
ronisahajoo wants to merge 1 commit into
devfrom
feat/223-hunt-frame-limit
Open

ronisahajoo wants to merge 1 commit into
devfrom
feat/223-hunt-frame-limit

Conversation

@ronisahajoo

Copy link
Copy Markdown
Collaborator

Closes #223

What this adds

H4 audit stages A2 and A3 (A22.9.4), in backend/app/core/area/limits.py:

  • A2, frame limit: the 5σ point-source limit at a spot, from VARIANCE and the PSF (QR2 PSF cube, or QR3/DR1 EPSF table), as an AB magnitude at the WCS-WAVE wavelength. Tagged derived. A flagged spot or a missing input returns a reason, not a number.
  • A3, sort: each (rock, frame) pair is should_be_seen, marginal or too_faint with its margin, plus the rocks too faint in every frame. Tagged model_dependent.

It is a library module: nothing calls it yet. A1, A4, the join.py fixes and the blind search are not touched.

Testing

In backend, offline:

  • ruff check, ruff format --check and mypy pass.
  • pytest: 1909 passed, 5 skipped (sky images not baked or mirrored locally), 0 failed.
  • 35 tests in test_area_limits.py. Synthetic limits match the analytic value within 0.01 mag.
  • No cached fixture holds a PSF (Q-20), so those cutouts are tested to give no number, and real image data is run with a synthetic PSF. Real PSFs were checked by hand on one QR2, one QR3 and one DR1 cutout; this is not in the test suite.

Not run: a full docs link check and a Mermaid render of docs/uml/04-package.md (the UML edit is text inside one label).

Please check

  • Real frames look shallower than expected: median 5σ limits of about AB 18.2 to 18.4 on those three frames, against the inferred 18.8 to 19.2 in A22.9.4. Review found no bug that explains it. Not a V1 result.
  • Q-532 choices to confirm (Atish, Kevin). Main ones:
    • marginal runs from 3σ to 5σ [verify] (the spec gives no bound).
    • The limit can be optimistic: no background, confusion or calibration term, and no flux outside the PSF stamp.
    • A mostly masked PSF still gives a number if the spot itself is usable; the unused fraction is reported.
    • A1 must supply AB magnitudes at the frame's wavelength.
    • [verify] QR2 XCTR_n/YCTR_n count from 1, and whether the archive's PSF header error shows in them.
  • QR2 with the current cache: PSF is stripped, so the limit answers psf_missing until HN-5 fetches cutouts with the PSF kept.
  • Merge order: Issue-224: Row schemas and the synthetic hunts fixture #238 and Issue-222: Hunt refusal codes and API errors #239 edit the same decision files (Q-530, Q-531), so whoever merges later should expect conflicts. This PR takes Q-532.

🤖 Generated with Claude Code

H4 audit stages A2 and A3 (A22.9.4):
- limits.py: 5-sigma point-source limit at a spot from VARIANCE and the
  PSF (QR2 PSF cube or QR3/DR1 EPSF table), as an AB magnitude at the
  WCS-WAVE wavelength; a flagged spot or missing input gives a reason.
- Sort each (rock, frame) pair into should_be_seen, marginal or
  too_faint, and list the rocks too faint in every frame.
- Record the choices in Q-532 and the open [verify] items in A14.1.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@JoottunAtish JoottunAtish left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work. The PR does what #223 asks and nothing more. The maths is right, it refuses instead of guessing wherever it should, and the docs, decisions and UML are updated together. CI is green, and test_area_limits.py passes locally (35 passed). Approving.

What I checked:

  • Done when:
    • The synthetic limit matches the analytic 5σ value within 0.01 mag for both PSF and EPSF at four pixel phases, and a seeded noise test checks it against a real PSF fit.
    • The sort returns the three classes and the list of rocks too faint everywhere, and it is order-independent.
    • The V1 row is updated.
  • Data first: the limit comes from VARIANCE, the PSF and the WCS; 5σ and 3σ are recipe thresholds.
  • Provenance: FrameLimit is derived; the predictions and the sort are model_dependent.
  • Refusal: there are 11 NoLimit reasons, an unsortable pair keeps its reason, and a bad QR1/QR2 header is refused.
  • IDs: this PR takes Q-532, so nothing collides with #238 (Q-530) or #239 (Q-531).

Nits (non-blocking, fine as a follow-up)

  1. Thresholds and the gate hash (backend/app/core/area/limits.py:96-98). LimitConfig stays out of params_hash, but snr_limit and snr_marginal change the sort that the H4 gate reads. Under R-34, a threshold change must re-run the gate. Record in Q-532 that these thresholds go into the gate's input hash (or the run's method), so HN-5 wires it in.
  2. Is the QR2 PSF cube optical? (limits.py:231-262, Q-532 point 3). The code integrates the cube over each pixel. If IRSA's cube is already pixel-integrated, the pixel is counted twice and the limit comes out too shallow. Cite where IRSA says it is optical, or add a [verify].
  3. Magnitude systems in A22.9.4. Say whether the inferred 18.8–19.2 figure is V, Vega or AB. At 1–5 µm the AB−Vega offset is 1 to 3 mag, which alone could explain the gap from the measured 18.2–18.4. The 8925 Boattini line ("V 17.4, about 1.5 mag above the single-frame limit") also mixes V with this limit.
  4. Unchecked WCS shortcut (limits.py:271-276). The detector position assumes CRVAL1A/CRVAL2A = 0 and CDELT1A/CDELT2A = 1. That holds in every cached fixture, but a cheap check that refuses with psf_zone when they differ would close the gap.
  5. Zone-centre check (limits.py:251). The x-fastest check needs zone centres that match exactly along a row, so a tiny float difference in YCTR_n would refuse a good header. It fails safe; add a tolerance or a comment.
  6. no_limit:<reason> looks like a hunt code (limits.py:79,416). When HN-5 puts these into missing, they must go through #239's codes.py builders and the shared words file (Q-477), not be emitted raw. A separate limit_reason field on SortedPair would avoid the confusion. SortedPair could also carry expected_snr directly, to feed #238's row field.
  7. Status word for Q-532. It is "Open (built)" in the index and the topic file, but "(Proposed, Q-532)" in the A22.9.4 A3 row. Use one.
  8. A3.1 is out of date (docs/architecture/data-sources.md). Add EPSF/PSF to the "Extensions used" row. Also, keeping the 4 MB EPSF in the cache follows Q-20's code but goes against Q-20's size reason; flag it for Kevin before QR3 or DR1 runs fill the cache.

Merge note: this PR will conflict with #238 and #239 on the "Next free" line and the index rows in docs/decisions/README.md. Rebase whichever merges last. Q-532 still needs confirming, including the 3σ marginal bound.

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.

H4 audit: single-frame limit and the should-be-seen sort (stages A2 and A3)

2 participants