Skip to content

Trace shifts updates#2669

Draft
segasai wants to merge 2 commits into
mainfrom
trace_shifts_extraction_fix
Draft

Trace shifts updates#2669
segasai wants to merge 2 commits into
mainfrom
trace_shifts_extraction_fix

Conversation

@segasai

@segasai segasai commented Mar 15, 2026

Copy link
Copy Markdown
Contributor

While investigating the persistent wavelength offsets in the psfs saved in EXTOFF,
I looked at the trace_shifts code and there are couple of small things that may need addressing. In the end the effect from those are tiny.

  • One change is that the hw variable was used for both x and y when creating the LSF to convolve the external spectrum with. Previously hw was potentially very large (when the external spectrum had small wavelength sampling).
  • Another change is using several fibers to compute the dy/dwavelength rather than using the central fiber ( the spread of slopes is ~0.5 %, so the effect of this is small)

@sbailey

sbailey commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

@julienguy please review this PR for inclusion in Matterhorn.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates wavelength-offset (external spectrum cross-correlation) handling in desispec.trace_shifts, aiming to reduce tiny systematic biases in the reference-spectrum convolution and make dy/dλ estimation less sensitive to a single fiber.

Changes:

  • Add an explicit width parameter to _prepare_ref_spectrum() and use it to set the cross-dispersion (x-axis) integration window when building the LSF kernel.
  • Compute dy/dλ using an average over multiple fibers instead of only a single “central” fiber.
  • Minor logging formatting updates for readability.
Comments suppressed due to low confidence (1)

py/desispec/trace_shifts.py:672

  • _prepare_ref_spectrum() now takes a new width parameter, but the docstring Arguments/Returns section doesn't mention what width represents or how it affects the convolution. Please update the docstring to document width (boxcar extraction width in pixels, and that hw_x=width//2 is used for cross-dispersion integration) so callers know how to keep extraction and reference LSF consistent.
def _prepare_ref_spectrum(ref_wave, ref_spectrum, psf, wave, mflux, nfibers, width=7):
    """
    Prepare the reference spectrum to be used for wavelength offset
    determination. Here we convolve it to the right LSF and rescale it
    to match the measured flux.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +882 to +883
n_fibers_for_psf = 20
fibers_for_psf_evaluation = np.linspace(0, flux.shape[0]-1, n_fibers_for_psf).astype(int) # flux.shape[0] //2
Comment on lines 911 to +915
dwave_list = np.append(dwave_list, dwave)
dwave_err_list = np.append(dwave_err_list, err)
y_for_dy=np.append(y_for_dy,y)
log.info(f"wave = {bin_wave}A , y={y}, measured dwave = {dwave} +- {err} A")
y_for_dy=np.append(y_for_dy,y) # this is only used for printing
log.info(f"wave = {bin_wave:.3f}A , y={y:.3f}, measured "
f"dwave = {dwave:.3f} +- {err:.3f} A")
Comment on lines 867 to +871
flux, ivar, wave = resample_boxcar_frame(qframe.flux, qframe.ivar, qframe.wave, oversampling=oversampling)

mflux, mivar, flux = _continuum_subtract_median(flux, ivar, continuum_win=oversampling*9)

ref_wave, ref_spectrum = _prepare_ref_spectrum(ref_wave, ref_spectrum, psf, wave, mflux, len(ivar))
ref_wave, ref_spectrum = _prepare_ref_spectrum(ref_wave, ref_spectrum, psf, wave, mflux, len(ivar), width=width)
@sbailey

sbailey commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

From the data telecon discussion, we agree that this update is small enough that we won't include it in Matterhorn, due to the risk of messing up some corner case. I'm going to move this to a draft PR so that we don't accidentally merge it.

@sbailey sbailey marked this pull request as draft March 20, 2026 18:09
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.

3 participants