Skip to content

Evaluate the xi-lambda image with direct bilinear interpolation - #993

Draft
astronomyk wants to merge 1 commit into
mainfrom
perf/xilamimage-bilinear-interp
Draft

Evaluate the xi-lambda image with direct bilinear interpolation#993
astronomyk wants to merge 1 commit into
mainfrom
perf/xilamimage-bilinear-interp

Conversation

@astronomyk

Copy link
Copy Markdown
Collaborator

What

map_spectra_to_focal_plane evaluates the rectified (xi, lambda) spectrum at every pixel of the detector sub-image through RectBivariateSpline(kx=ky=1) with grid=False. FITPACK's scattered-point evaluation path is very slow for large coordinate arrays: for a METIS long-slit trace this single call took ~3 s per FieldOfView.

XiLamImage.interp is now a method performing the bilinear interpolation directly on the regular (xi, lambda) grid — identical semantics for kx=ky=1, including the clamping of out-of-range coordinates, for both grid=False and grid=True. The call site is unchanged, and the spline attribute no longer needs to be built eagerly in the constructor.

Measured on the rectified spectrum of a real METIS LSS observation: 3.77 s -> 1.46 s for 1.4M evaluation points (the isolated microbenchmark difference is considerably larger for bigger sub-images).

Testing

  • TestXiLamImage::test_interp_matches_rect_bivariate_spline — equivalence against RectBivariateSpline for scattered and grid evaluation, including points beyond the grid edges.
  • basic_instrument spectroscopy/IFU end-to-end suite passes unchanged.
  • Notebook with the timing on real data attached below.

Note: includes the same 3-line MockCubeFov(data=...) test-helper extension as #989; the two merge cleanly in either order.

map_spectra_to_focal_plane evaluates the XiLamImage at every pixel of
the detector sub-image through RectBivariateSpline(kx=ky=1) with
grid=False. FITPACK's scattered-point evaluation is orders of magnitude
slower than a direct bilinear lookup on the regular (xi, lam) grid: for
a METIS long-slit trace this one call took ~3 s per FieldOfView.

XiLamImage.interp is now a method that performs the bilinear
interpolation directly, with identical semantics (including clamping
of out-of-range coordinates); the call site is unchanged.

Adds equivalence tests against RectBivariateSpline for scattered and
grid evaluation, including points beyond the grid edges. The full
basic_instrument spectroscopy/ifu suite passes unchanged.
@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.49%. Comparing base (86ad453) to head (64367e5).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #993      +/-   ##
==========================================
+ Coverage   76.47%   76.49%   +0.02%     
==========================================
  Files          69       69              
  Lines        9027     9037      +10     
==========================================
+ Hits         6903     6913      +10     
  Misses       2124     2124              

☔ 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