Skip to content

Commit 316b071

Browse files
committed
allow attachWavelengthSolution() to progress without a distortion model (since there may be no lines in some GNIRS XD orders)
1 parent 755053a commit 316b071

1 file changed

Lines changed: 23 additions & 18 deletions

File tree

geminidr/core/primitives_spect.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -715,15 +715,15 @@ def attachWavelengthSolution(self, adinputs=None, **params):
715715
# the warning at the end
716716
try:
717717
if 'distortion_corrected' not in wcs.available_frames:
718-
distortion_models = []
719-
break
718+
m_distcorr = None # because this is used in later code
719+
distortion_models.append(None)
720720
except AttributeError:
721721
distortion_models = []
722722
break
723-
724-
m_distcorr = wcs.get_transform(wcs.input_frame,
725-
'distortion_corrected')
726-
distortion_models.append(m_distcorr)
723+
else:
724+
m_distcorr = wcs.get_transform(wcs.input_frame,
725+
'distortion_corrected')
726+
distortion_models.append(m_distcorr)
727727

728728
try:
729729
wave_model = am.get_named_submodel(wcs.forward_transform,
@@ -737,9 +737,7 @@ def attachWavelengthSolution(self, adinputs=None, **params):
737737
if isinstance(frame, cf.SpectralFrame)])
738738

739739
if not distortion_models:
740-
log.warning("Could not find a 'distortion_corrected' frame "
741-
f"in arc {arc.filename} extension {ext.id} - "
742-
"continuing")
740+
log.warning("Problem with one or more WCS objects - continuing")
743741
if 'sq' in self.mode:
744742
fail = True
745743
continue
@@ -767,7 +765,8 @@ def attachWavelengthSolution(self, adinputs=None, **params):
767765
geotable = import_module('.geometry_conf', self.inst_lookups)
768766
transform.add_mosaic_wcs(ad, geotable)
769767
for ext in ad:
770-
if 'mosaic' in ext.wcs.available_frames:
768+
if ('mosaic' in ext.wcs.available_frames and
769+
m_distcorr is not None):
771770
ext.wcs.insert_frame('mosaic', m_distcorr,
772771
cf.Frame2D(name='distortion_corrected'))
773772

@@ -859,10 +858,12 @@ def attachWavelengthSolution(self, adinputs=None, **params):
859858
# No mosaicking, so we can just do a shift
860859
m_shift = (models.Shift((ad_detsec.x1 - arc_detsec.x1) / xbin) &
861860
models.Shift((ad_detsec.y1 - arc_detsec.y1) / ybin))
862-
m_distcorr = m_shift | m_distcorr
861+
m_distcorr = (m_shift if m_distcorr is None else
862+
m_shift | m_distcorr)
863863

864-
ad[0].wcs.insert_frame(ad[0].wcs.input_frame, m_distcorr,
865-
cf.Frame2D(name='distortion_corrected'))
864+
if m_distcorr is not None:
865+
ad[0].wcs.insert_frame(ad[0].wcs.input_frame, m_distcorr,
866+
cf.Frame2D(name='distortion_corrected'))
866867

867868
if wave_model is None:
868869
log.warning(f"{arc.filename} has no wavelength solution")
@@ -887,11 +888,15 @@ def attachWavelengthSolution(self, adinputs=None, **params):
887888
# applying the distortion correction
888889
shifts = [c1 - c2 for c1, c2 in zip(ext.detector_section(),
889890
ext_arc.detector_section())]
890-
dist_model = (models.Shift(shifts[0] / xbin) &
891-
models.Shift(shifts[1] / ybin)) | dist_model
892-
893-
ext.wcs.insert_frame(ad[0].wcs.input_frame, dist_model,
894-
cf.Frame2D(name='distortion_corrected'))
891+
if shifts.count(0) < len(shifts):
892+
shift_model = (models.Shift(shifts[0] / xbin) &
893+
models.Shift(shifts[1] / ybin))
894+
dist_model = (shift_model if dist_model is None else
895+
shift_model | dist_model)
896+
897+
if dist_model is not None:
898+
ext.wcs.insert_frame(ad[0].wcs.input_frame, dist_model,
899+
cf.Frame2D(name='distortion_corrected'))
895900

896901
if wave_model is None:
897902
log.warning(f"{arc.filename} extension {ext.id} has "

0 commit comments

Comments
 (0)