Trace shifts updates#2669
Conversation
over biger window across dispersion
|
@julienguy please review this PR for inclusion in Matterhorn. |
There was a problem hiding this comment.
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
widthparameter 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.
| 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 |
| 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") |
| 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) |
|
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. |
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.