Skip to content

Commit

Permalink
Merge pull request #2205 from desihub/test_fallback_on_dark_fof
Browse files Browse the repository at this point in the history
Test fallback on dark fof
  • Loading branch information
sbailey committed Mar 29, 2024
2 parents 1eee6dc + cc36a43 commit 56784f9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
36 changes: 28 additions & 8 deletions py/desispec/ccdcalib.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,8 +822,8 @@ def compare_dark(preprocfile1, preprocfile2, ny=8, nx=40):
"""Compare preprocessed dark images based on different dark models
Args:
preprocfile1: filepath to bias model made from OBSTYPE=ZERO exposures
preprocfile2: filepath to bias model made from OBSTYPE=ZERO exposures
preprocfile1: filepath to preprocessed (i.e. dark subtracted) DARK image
preprocfile2: filepath to preprocessed (i.e. dark subtracted) DARK image
Options:
ny (even int): number of patches in y (row) direction
Expand All @@ -850,10 +850,22 @@ def compare_dark(preprocfile1, preprocfile2, ny=8, nx=40):
log.critical(msg)
raise ValueError(msg)

#- calculate differences per-amp, thus //2
ny_groups = ny//2
nx_groups = nx//2

#- calculate differences per-amp
readout_mode = get_readout_mode(preprochdr1)
if readout_mode == '4Amp':
ny_groups = ny//2
nx_groups = nx//2
elif readout_mode == '2AmpLeftRight':
ny_groups = ny
nx_groups = nx//2
elif readout_mode == '2AmpUpDown':
ny_groups = ny//2
nx_groups = nx
else:
msg = f'Unknown {readout_mode=}'
log.critical(msg)
raise ValueError(msg)

median_diff1 = list()
median_diff2 = list()

Expand Down Expand Up @@ -884,8 +896,16 @@ def compare_dark(preprocfile1, preprocfile2, ny=8, nx=40):
#- put back into 2D array by amp
d1 = median_diff1
d2 = median_diff2
mdiff1 = np.vstack([np.hstack([d1[2],d1[3]]), np.hstack([d1[0],d1[2]])])
mdiff2 = np.vstack([np.hstack([d2[2],d2[3]]), np.hstack([d2[0],d2[2]])])

if readout_mode == '4Amp':
mdiff1 = np.vstack([np.hstack([d1[2],d1[3]]), np.hstack([d1[0],d1[2]])])
mdiff2 = np.vstack([np.hstack([d2[2],d2[3]]), np.hstack([d2[0],d2[2]])])
elif readout_mode == '2AmpLeftRight':
mdiff1 = np.hstack([d1[0], d1[1]])
mdiff2 = np.hstack([d2[0], d2[1]])
elif readout_mode == '2AmpUpDown':
mdiff1 = np.vstack([d1[0], d1[1]])
mdiff2 = np.vstack([d2[0], d2[1]])

assert mdiff1.shape == (ny,nx)
assert mdiff2.shape == (ny,nx)
Expand Down
4 changes: 2 additions & 2 deletions py/desispec/io/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def read_raw(filename, camera, fibermapfile=None, fill_header=None, **kwargs):
if 'FIBER' in fibermap.dtype.names : # not the case in early teststand data

## Mask fibers
cfinder = CalibFinder([header,primary_header])
cfinder = CalibFinder([header,primary_header],fallback_on_dark_not_found=kwargs['fallback_on_dark_not_found'] if 'fallback_on_dark_not_found' in kwargs.keys() else False)
fibers = fibermap['FIBER'].data
for k in ["BROKENFIBERS","BADCOLUMNFIBERS","LOWTRANSMISSIONFIBERS"] :
log.debug("{}={}".format(k,cfinder.badfibers([k])))
Expand All @@ -283,7 +283,7 @@ def read_raw(filename, camera, fibermapfile=None, fill_header=None, **kwargs):
log.info("Propagate ccdmask.BADREADNOISE to fibermap FIBERSTATUS")

if cfinder is None :
cfinder = CalibFinder([header,primary_header])
cfinder = CalibFinder([header,primary_header],fallback_on_dark_not_found=kwargs['fallback_on_dark_not_found'] if 'fallback_on_dark_not_found' in kwargs.keys() else False)

psf_filename = cfinder.findfile("PSF")
tset = desispec.io.read_xytraceset(psf_filename)
Expand Down
6 changes: 3 additions & 3 deletions py/desispec/scripts/qproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def main(args=None):

if args.psf is None :
if cfinder is None :
cfinder = CalibFinder([image.meta,primary_header])
cfinder = CalibFinder([image.meta,primary_header],fallback_on_dark_not_found=args.fallback_on_dark_not_found)
args.psf = cfinder.findfile("PSF")
log.info(" Using PSF {}".format(args.psf))

Expand Down Expand Up @@ -272,7 +272,7 @@ def main(args=None):

if args.input_fiberflat is None :
if cfinder is None :
cfinder = CalibFinder([image.meta,primary_header])
cfinder = CalibFinder([image.meta,primary_header],fallback_on_dark_not_found=args.fallback_on_dark_not_found)
try :
args.input_fiberflat = cfinder.findfile("FIBERFLAT")
except KeyError as e :
Expand All @@ -294,7 +294,7 @@ def main(args=None):

if args.fluxcalib :
if cfinder is None :
cfinder = CalibFinder([image.meta,primary_header])
cfinder = CalibFinder([image.meta,primary_header],fallback_on_dark_not_found=args.fallback_on_dark_not_found)
# check for flux calib
if cfinder.haskey("FLUXCALIB") :
fluxcalib_filename = cfinder.findfile("FLUXCALIB")
Expand Down

0 comments on commit 56784f9

Please sign in to comment.