Optimize the aperture photometry operation#129
Open
jnation3406 wants to merge 5 commits into
Open
Conversation
capetillo
approved these changes
Jul 15, 2026
capetillo
left a comment
Contributor
There was a problem hiding this comment.
I think it looks okay but I'm confused if the ranking changed. Anyway, good job Jon & Fable
Cache per-frame WCS and aperture geometry for light-curve measurement
…photometry again. There are still further optimizations that can be done, but vectorizing the centroiding stuff, or by using a spatial hash for the cluster matching to only compute cluster angular distance for close clusters.
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.
The aperture photometry was killing the production pods with OOM when trying to do it with 10 QHY full frame images. This PR is mostly Claude implementing a few optimizations to prevent this:
I also threw in some optimization of the wcs and source catalog analysis task, to not load the unused pixel data into those tasks.
Claudes description of changes:
aperture_light_curve.py — the core restructure. generate_light_curve now takes local FITS paths instead of eagerly-loaded handlers, and runs in three phases: a metadata pass that validates frames reading only the SCI header and CAT table (no pixels), the candidate catalog build (headers only), then a streamed pixel pass (_measure_frame_pixels) that loads one frame as float32, measures the target plus every candidate on it, captures a downsampled preview, and releases the pixels before the next frame loads. FrameContext no longer has an .image field, and CAT rows are trimmed to the six columns the pipeline actually reads.
comparison_stars.py — the candidate-outer/frame-inner measurement loop (which forced all frames to coexist) is gone. candidate_stars_from_catalog builds candidates up front, the pixel pass measures them frame-by-frame, and select_comparison_stars is now pure math over the collected measurements, with identical drop/rank semantics.
photometry_diagnostics.py — overlays are drawn on a block-mean-downsampled FramePreview (capped at your 2000 px) captured during the pixel pass. That removes the GB-scale full-frame render temporaries and shrinks each frame's base64 JPEG in the operation output (and Redis, and the API response) from tens of MB to well under 1 MB. Small frames like the 80×80 test fixtures are untouched (scale 1.0).
aperture_photometry.py — operate() resolves inputs to file-cache paths via FileCache directly; no more list of eager InputDataHandlers each holding a decompressed frame.
centroiding.py:260 — removed the dtype=float upcast that would otherwise have silently copied the whole frame to float64 on every centroid call (once per candidate per frame).