Skip to content

Resample all LMS cube planes in one step - #995

Draft
astronomyk wants to merge 1 commit into
mainfrom
perf/lms-cube-resampling
Draft

Resample all LMS cube planes in one step#995
astronomyk wants to merge 1 commit into
mainfrom
perf/lms-cube-resampling

Conversation

@astronomyk

Copy link
Copy Markdown
Collaborator

What

The FieldOfView branch of MetisLMSSpectralTraceList.apply_to built a fresh RectBivariateSpline(kx=1, ky=1) over the field-of-view plane for every wavelength plane of the cube and evaluated it at the slice's (yfov, xfov) coordinates. Those sample coordinates depend only on the slice geometry — they are identical for every plane — so with ~2,500–7,000 planes (depending on !SIM.spectral.spectral_bin_width) and 28 slices this meant up to ~200,000 spline constructions per observation. In a profiled LMS run this loop accounted for the bulk of observe().

The new module function interpolate_cube_planes(fovcube, yfov, xfov) computes the bilinear indices and weights once per slice and gathers all planes in a single vectorised expression. Coordinates outside the plane are clamped to the edges, exactly as RectBivariateSpline does.

End-to-end check (full lms mode, point source, identical inputs, separate processes): observe() wall time 386.5 s -> 108.6 s, with the detector image identical to the last digit (sum 1617362510.5459003, max 193.6031494140625 on both). The like-for-like loop comparison on one slice of the real cube is 10x (2.89 s -> 0.29 s, x28 slices per observation).

Testing

  • TestInterpolateCubePlanes::test_matches_spline_per_plane_reference — exact equivalence against the per-plane spline evaluation on random data, including sample coordinates beyond the plane edges (clamping behaviour).
  • A notebook with the full LMS observation and the like-for-like timing on the real cube is attached below.

The FieldOfView branch of MetisLMSSpectralTraceList.apply_to built a
fresh RectBivariateSpline over the FoV plane for every wavelength
plane of the cube and evaluated it at the slice coordinates. Those
sample coordinates depend only on the slice geometry and are identical
for every plane, so with thousands of planes and 28 slices this meant
up to ~200k spline constructions per observation; in a profiled LMS
run the loop accounted for the bulk of observe().

New module function interpolate_cube_planes computes the bilinear
indices and weights once and gathers all planes in a single vectorised
expression. Out-of-plane coordinates are clamped to the edges, exactly
as RectBivariateSpline does.

Adds an equivalence test against the per-plane spline evaluation,
including coordinates beyond the plane edges.
@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 76.51%. Comparing base (86ad453) to head (8ffc9c9).

Files with missing lines Patch % Lines
scopesim/effects/metis_lms_trace_list.py 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #995      +/-   ##
==========================================
+ Coverage   76.47%   76.51%   +0.04%     
==========================================
  Files          69       69              
  Lines        9027     9032       +5     
==========================================
+ Hits         6903     6911       +8     
+ Misses       2124     2121       -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant