Skip to content

Vectorise the wavelength resampling in XiLamImage - #989

Draft
astronomyk wants to merge 1 commit into
mainfrom
perf/xilamimage-vectorised-resampling
Draft

Vectorise the wavelength resampling in XiLamImage#989
astronomyk wants to merge 1 commit into
mainfrom
perf/xilamimage-vectorised-resampling

Conversation

@astronomyk

Copy link
Copy Markdown
Collaborator

What

For every spatial row across the slit width (eta), the XiLamImage constructor built a full 2-D RectBivariateSpline over the cube plane — and then evaluated it exactly at the xi grid points, so the spline degenerated to plain 1-D linear interpolation along the wavelength axis.

The loop now interpolates directly, vectorised over all xi rows at once (searchsorted-based gather). Out-of-range wavelengths are clamped to the boundary values — exactly what a degree-1 RectBivariateSpline does (verified: FITPACK clamps, it does not extrapolate).

Measured on the cube of a real METIS LSS observation: 6.06 s -> 1.54 s per FieldOfView with max |difference| = 0.0; for METIS LMS the same construction runs 28 times per observation.

Testing

  • TestXiLamImage::test_image_matches_rect_bivariate_spline_reference — equivalence against the previous spline-per-row computation on random cube data, including the clamped edge region.
  • basic_instrument spectroscopy/IFU end-to-end suite passes unchanged.
  • A notebook with the old-vs-new timing and equality check on a real METIS LSS cube is attached below.

The per-eta loop built a full 2D RectBivariateSpline over each cube
plane and evaluated it exactly at the xi knot positions, i.e. the
spline degenerated to independent 1D linear interpolation along the
wavelength axis. Replace it with a direct searchsorted-based linear
interpolation over all xi rows at once. Out-of-range wavelengths are
clamped to the boundary values, exactly as the degree-1 spline did.

For a METIS LSS field of view this removes ~1.7 s of spline
construction per FieldOfView; for METIS LMS the loop runs 28 times
per observation.

Adds an equivalence test against the previous spline-based computation
on random cube data (including the clamped edge region). The full
basic_instrument spectroscopy/ifu suite passes unchanged.
@codecov

codecov Bot commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.46%. Comparing base (beb191d) to head (873f21f).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #989   +/-   ##
=======================================
  Coverage   76.46%   76.46%           
=======================================
  Files          69       69           
  Lines        9025     9026    +1     
=======================================
+ Hits         6901     6902    +1     
  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.

@teutoburg teutoburg moved this to 🏗 In progress in ScopeSim-development Aug 24, 2026
@teutoburg teutoburg added the performance Execution speed or memory consumtion label Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Execution speed or memory consumtion

Projects

Status: 🏗 In progress

Development

Successfully merging this pull request may close these issues.

2 participants