Skip to content

fix: swap source/target grids in XsecRecord::Extract interpolation#1139

Merged
olemke merged 2 commits into
atmtools:mainfrom
olemke:fix-xfit-interpolation
Jul 1, 2026
Merged

fix: swap source/target grids in XsecRecord::Extract interpolation#1139
olemke merged 2 commits into
atmtools:mainfrom
olemke:fix-xfit-interpolation

Conversation

@olemke

@olemke olemke commented Jun 30, 2026

Copy link
Copy Markdown
Member

The cross-section fit extraction in XsecRecord::Extract was passing the frequency grids to make_lags in the wrong order, so interpolation weights were computed from the output grid against the data grid rather than vice-versa. This produced incorrect spectral absorption coefficients whenever the requested f_grid differed from the catalog's native grid. Swapping the two arguments restores the intended interpolation direction, and the test now also exercises downsampled and upsampled grids to guard against regressions.

Changes

  • src/core/absorption/xsec_fit.cc: Swapped the f_grid_active and data_f_grid_active arguments to lagrange_interp::make_lags so weights interpolate from the catalog grid onto the requested grid.
  • tests/python/xsec/xfit.py: Refactored the test into a parameterized main() covering the native grid (exact, atol=1e-36) plus downsampled (0.2x) and upsampled (1.2x) np.linspace resampled grids (atol=1e-18), each with an adjusted stride to sample the same reference values.

Breaking Changes

None. The fix corrects a latent bug for non-native frequency grids; users already calling Extract with the native grid see no change in behavior.

olemke added 2 commits June 30, 2026 09:18
The make_lags call in XsecRecord::Extract had its grid arguments
swapped: the output grid (f_grid_active) was passed as the source
(xi) and the data grid (data_f_grid_active) as the target (xn).
This caused lags.indx to index into fit_result_active using the
wrong coordinate array, shifting the interpolated peak toward
higher frequencies as the output grid got coarser.

Swap the arguments so xi is the data grid (where fit_result_active
is defined) and xn is the output grid, keeping the peak position
independent of the output f_grid resolution.
Refactor the xsec/xfit regression test to exercise the native
grid plus downsampled (0.2x) and upsampled (1.2x) frequency
grids. The native case keeps the exact 1e-36 tolerance, while
the resampled cases use 1e-18 to account for np.linspace
interpolation error. Reference values are frozen as x_ref and
the check is factored into _check_grid.
@olemke olemke merged commit 22bd10e into atmtools:main Jul 1, 2026
9 checks passed
@olemke olemke deleted the fix-xfit-interpolation branch July 1, 2026 09:23
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.

1 participant