Skip to content

Commit

Permalink
Merge branch 'develop' into specobjs_fracpos
Browse files Browse the repository at this point in the history
  • Loading branch information
kbwestfall authored Feb 6, 2025
2 parents 0872627 + 508c4b7 commit 06fb715
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 12 deletions.
3 changes: 3 additions & 0 deletions doc/releases/1.17.2dev.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ Datamodel Changes
Under-the-hood Improvements
---------------------------

- Updates the ``pypeit_trace_edges`` script to use ``lampoffflats``, if they're
provided by the pypeit file passed to the script.


Bug Fixes
---------
Expand Down
7 changes: 4 additions & 3 deletions pypeit/calibrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,10 +1052,12 @@ def get_slits(self, force:str=None):
# Perform a check on the files
self.check_calibrations(raw_trace_files)

# NOTE: self.msscattlight is *always* created after identifying the
# slits, meaning that it is redundant to pass the scattlight argument
# here.
traceImage = buildimage.buildimage_fromlist(self.spectrograph, self.det,
self.par['traceframe'], raw_trace_files,
bias=self.msbias, bpm=self.msbpm,
scattlight=self.msscattlight,
dark=self.msdark, calib_dir=self.calib_dir,
setup=setup, calib_id=calib_id)
if len(raw_lampoff_files) > 0:
Expand All @@ -1072,8 +1074,7 @@ def get_slits(self, force:str=None):
lampoff_flat = buildimage.buildimage_fromlist(self.spectrograph, self.det,
self.par['lampoffflatsframe'],
raw_lampoff_files, dark=self.msdark,
bias=self.msbias, scattlight=self.msscattlight,
bpm=self.msbpm)
bias=self.msbias, bpm=self.msbpm)
traceImage = traceImage.sub(lampoff_flat)

edges = edgetrace.EdgeTraceSet(traceImage, self.spectrograph, self.par['slitedges'],
Expand Down
46 changes: 37 additions & 9 deletions pypeit/scripts/trace_edges.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,27 @@ def main(args):
proc_par = rdx.par['calibrations']['traceframe']
# Slit tracing parameters
trace_par = rdx.par['calibrations']['slitedges']
# Use the bias frames to set the BPM
bpm_usebias = rdx.par['calibrations']['bpm_usebias']

# Get the bias files, if requested
bias_rows = rdx.fitstbl.find_frames('bias', calib_ID=int(group), index=True)
bias_files = rdx.fitstbl.frame_paths(bias_rows)
bias_files = rdx.fitstbl.find_frame_files('bias', calib_ID=int(group))
bias_par = rdx.par['calibrations']['biasframe']
if len(bias_files) == 0:
bias_files = None

# Get the dark files, if requested
dark_rows = rdx.fitstbl.find_frames('dark', calib_ID=int(group), index=True)
dark_files = rdx.fitstbl.frame_paths(dark_rows)
dark_files = rdx.fitstbl.find_frame_files('dark', calib_ID=int(group))
dark_par = rdx.par['calibrations']['darkframe']
if len(dark_files) == 0:
dark_files = None

# Lamp-off files
lampoff_files = rdx.fitstbl.find_frame_files('lampoffflats', calib_ID=int(group))
lampoff_par = rdx.par['calibrations']['lampoffflatsframe']
if len(lampoff_files) == 0:
lampoff_files = None

# Set the QA path
qa_path = rdx.qa_path
else:
Expand All @@ -131,12 +137,16 @@ def main(args):
par = spec.default_pypeit_par()
proc_par = par['calibrations']['traceframe']
trace_par = par['calibrations']['slitedges']
bpm_usebias = par['calibrations']['bpm_usebias']
bias_files = None
bias_par = None

dark_files = None
dark_par = None

lampoff_files = None
lampoff_par = None

# Set the QA path
qa_path = redux_path / 'QA'

Expand All @@ -149,31 +159,49 @@ def main(args):

calib_dir = redux_path / args.calib_dir
for det in detectors:
# Get the bias frame if requested

# Get the bias frame
if bias_files is None:
proc_par['process']['use_biasimage'] = False
msbias = None
else:
msbias = buildimage.buildimage_fromlist(spec, det, bias_par, bias_files)

# Get the dark frame if requested
# Get the bad-pixel mask
msbpm = spec.bpm(files[0], det, msbias=msbias if bpm_usebias else None)
# Save a copy
original_bpm = msbpm.copy()

# Get the dark frame
if dark_files is None:
proc_par['process']['use_darkimage'] = False
msdark = None
else:
msdark = buildimage.buildimage_fromlist(spec, det, dark_par, dark_files)

msbpm = spec.bpm(files[0], det)
msdark = buildimage.buildimage_fromlist(spec, det, dark_par, dark_files,
bias=msbias)

# Build the trace image
msbpm = original_bpm.copy() # Reset bpm
traceImage = buildimage.buildimage_fromlist(spec, det, proc_par, files, bias=msbias,
bpm=msbpm, dark=msdark, setup=setup,
calib_id=calib_id, calib_dir=calib_dir)

# Subtract the lamp-off flats, if they exist
if lampoff_files is not None:
msbpm = original_bpm.copy() # Reset bpm
lampoff_flat = buildimage.buildimage_fromlist(spec, det, lampoff_par,
lampoff_files, dark=msdark,
bias=msbias, bpm=msbpm)
traceImage = traceImage.sub(lampoff_flat)

# Trace the slit edges
t = time.perf_counter()
edges = edgetrace.EdgeTraceSet(traceImage, spec, trace_par, auto=True,
debug=args.debug, show_stages=args.show,
qa_path=qa_path)
if not edges.success:
msgs.warn(f'Edge tracing for detector {det} failed. Continuing...')
continue

msgs.info(f'Tracing for detector {det} finished in { time.perf_counter()-t:.1f} s.')
# Write the two calibration frames
Expand Down

0 comments on commit 06fb715

Please sign in to comment.