fix: swap source/target grids in XsecRecord::Extract interpolation#1139
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The cross-section fit extraction in
XsecRecord::Extractwas passing the frequency grids tomake_lagsin 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 requestedf_griddiffered 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 thef_grid_activeanddata_f_grid_activearguments tolagrange_interp::make_lagsso weights interpolate from the catalog grid onto the requested grid.tests/python/xsec/xfit.py: Refactored the test into a parameterizedmain()covering the native grid (exact,atol=1e-36) plus downsampled (0.2x) and upsampled (1.2x)np.linspaceresampled 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
Extractwith the native grid see no change in behavior.