Skip to content

Commit

Permalink
Merge pull request #2386 from desihub/trace_fix_improvements
Browse files Browse the repository at this point in the history
Trace fix improvements
  • Loading branch information
sbailey authored Nov 19, 2024
2 parents 94a2a20 + 083ca2b commit 1f75589
Show file tree
Hide file tree
Showing 2 changed files with 219 additions and 139 deletions.
23 changes: 11 additions & 12 deletions py/desispec/scripts/trace_shifts.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,14 @@ def fit_trace_shifts(image, args):

spectrum_filename = args.spectrum
if args.sky :
continuum_subtract = True
srch_file = "data/spec-sky.dat"
if not resources.files('desispec').joinpath(srch_file).is_file():
log.error("Cannot find sky spectrum file {:s}".format(srch_file))
raise RuntimeError("Cannot find sky spectrum file {:s}".format(srch_file))
spectrum_filename = resources.files('desispec').joinpath(srch_file)
elif args.arc_lamps :
continuum_subtract = False
srch_file = "data/spec-arc-lamps.dat"
if not resources.files('desispec').joinpath(srch_file).is_file():
log.error("Cannot find arc lamps spectrum file {:s}".format(srch_file))
Expand Down Expand Up @@ -196,7 +198,7 @@ def fit_trace_shifts(image, args):
x_for_dx,y_for_dx,dx,ex,fiber_for_dx,wave_for_dx = compute_dx_from_cross_dispersion_profiles(xcoef,ycoef,wavemin,wavemax, image=image, fibers=fibers, width=args.width, deg=args.degxy,image_rebin=args.ccd_rows_rebin)
if internal_wavelength_calib :
# measure y shifts
x_for_dy,y_for_dy,dy,ey,fiber_for_dy,wave_for_dy = compute_dy_using_boxcar_extraction(tset, image=image, fibers=fibers, width=args.width)
x_for_dy,y_for_dy,dy,ey,fiber_for_dy,wave_for_dy = compute_dy_using_boxcar_extraction(tset, image=image, fibers=fibers, width=args.width, continuum_subtract=continuum_subtract)
mdy = np.median(dy)
log.info("Subtract median(dy)={}".format(mdy))
dy -= mdy # remove median, because this is an internal calibration
Expand All @@ -216,17 +218,14 @@ def fit_trace_shifts(image, args):
degyy=args.degyy

# if any quadrant is masked, reduce to a single offset
hy=image.pix.shape[0]//2
hx=image.pix.shape[1]//2
allgood=True
allgood &= (np.sum((x_for_dx<hx)&(y_for_dx<hy))>0) # some data in this quadrant
allgood &= (np.sum((x_for_dx<hx)&(y_for_dx>hy))>0) # some data in this quadrant
allgood &= (np.sum((x_for_dx>hx)&(y_for_dx<hy))>0) # some data in this quadrant
allgood &= (np.sum((x_for_dx>hx)&(y_for_dx>hy))>0) # some data in this quadrant
allgood &= (np.sum((x_for_dy<hx)&(y_for_dy<hy))>0) # some data in this quadrant
allgood &= (np.sum((x_for_dy<hx)&(y_for_dy>hy))>0) # some data in this quadrant
allgood &= (np.sum((x_for_dy>hx)&(y_for_dy<hy))>0) # some data in this quadrant
allgood &= (np.sum((x_for_dy>hx)&(y_for_dy>hy))>0) # some data in this quadrant
hy = image.pix.shape[0] // 2
hx = image.pix.shape[1] // 2
allgood = True
for _curx, _cury in [(x_for_dx,y_for_dx),(x_for_dy, y_for_dy)]:
for curxop in [np.less, np.greater]:
for curyop in [np.less, np.greater]:
allgood &= np.any(curxop(_curx, hx) & curyop(_cury, hy))
# some data in this quadrant
if not allgood :
log.warning("No shift data for at least one quadrant of the CCD, falls back to deg=0 shift")
degxx=0
Expand Down
Loading

0 comments on commit 1f75589

Please sign in to comment.