Skip to content

Cache per-frame WCS and aperture geometry for light-curve measurement#130

Merged
jnation3406 merged 1 commit into
fix/optimize_aperture_photometryfrom
fix/optimise-for-cpu
Jul 16, 2026
Merged

Cache per-frame WCS and aperture geometry for light-curve measurement#130
jnation3406 merged 1 commit into
fix/optimize_aperture_photometryfrom
fix/optimise-for-cpu

Conversation

@sfoale

@sfoale sfoale commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Add FrameGeometry (fits_metadata), built once per frame, holding the cached WCS plus the aperture/annulus radii in pixels, and thread it through _measure_target and measure_candidate_on_frame. WCS builds drop from ~4 per candidate to ~2 per frame.

Testing on the NGC7331 in rp data set on my machine confirmed that the results are identical but run time falls from 72s to 16s.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes aperture-photometry/light-curve generation by caching per-frame WCS and pixel-space aperture geometry and by streaming full-resolution pixel data one frame at a time, reducing repeated FITS/WCS work and peak memory usage while keeping outputs identical.

Changes:

  • Introduces FrameGeometry (cached WCS + aperture/annulus radii in pixels) and threads it through target/candidate measurement paths.
  • Streams SCI pixel data per frame via _load_frame_image / _measure_frame_pixels and adds a downsampled FramePreview for diagnostics overlays (avoids reloading pixels for rendering).
  • Adds get_fits_header and updates analysis endpoints/tests to avoid decompressing large compressed SCI images when only metadata is needed.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
datalab/datalab_session/utils/photometry_diagnostics.py Adds FramePreview + downsampled preview generation; overlays now draw on previews instead of full-res images.
datalab/datalab_session/utils/fits_metadata.py Adds FrameGeometry and frame_geometry() to cache WCS and pixel radii per frame.
datalab/datalab_session/utils/file_utils.py Adds get_fits_header() to read headers without forcing SCI decompression; clarifies get_hdu() behavior.
datalab/datalab_session/utils/comparison_stars.py Refactors comparison selection to operate on pre-measured per-frame measurements; measurement uses cached FrameGeometry.
datalab/datalab_session/utils/centroiding.py Avoids forced float64 conversion to prevent copying full frames per centroid call.
datalab/datalab_session/utils/aperture_light_curve.py Major refactor to validate metadata without pixels, then stream per-frame pixel measurement; builds diagnostics previews; reduces CAT-column retention.
datalab/datalab_session/tests/test_operations.py Updates operation tests for new FileCache usage and generate_light_curve(fits_paths=...) API.
datalab/datalab_session/tests/test_aperture_photometry.py Updates tests to use FITS paths; adds tests for streaming pixel loading and preview scaling/overlay behavior.
datalab/datalab_session/data_operations/aperture_photometry.py Resolves FITS paths via FileCache and passes fits_paths into generate_light_curve.
datalab/datalab_session/analysis/wcs.py Uses get_fits_header() to avoid decompressing SCI image data for WCS inspection.
datalab/datalab_session/analysis/source_catalog.py Avoids loading SCI pixel data by using get_fits_dimensions() instead of sci_hdu.data.shape.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread datalab/datalab_session/utils/photometry_diagnostics.py
@jnation3406
jnation3406 changed the base branch from main to fix/optimize_aperture_photometry July 16, 2026 23:51

@jnation3406 jnation3406 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.

Looks good other than some duplication of the wcs helper functions. I'm going to merge it into my branch and continue adding to it there.

@jnation3406
jnation3406 merged commit fef55b5 into fix/optimize_aperture_photometry Jul 16, 2026
4 checks passed
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.

3 participants