@@ -714,15 +714,10 @@ def attachWavelengthSolution(self, adinputs=None, **params):
714714 # ADs, so just set the found transforms to empty and present
715715 # the warning at the end
716716 try :
717- if 'distortion_corrected' not in wcs .available_frames :
718- distortion_models = []
719- break
720- except AttributeError :
721- distortion_models = []
722- break
723-
724- m_distcorr = wcs .get_transform (wcs .input_frame ,
725- 'distortion_corrected' )
717+ m_distcorr = wcs .get_transform (wcs .input_frame ,
718+ 'distortion_corrected' )
719+ except CoordinateFrameError :
720+ m_distcorr = None
726721 distortion_models .append (m_distcorr )
727722
728723 try :
@@ -736,14 +731,6 @@ def attachWavelengthSolution(self, adinputs=None, **params):
736731 wave_frames .extend ([frame for frame in wcs .output_frame .frames
737732 if isinstance (frame , cf .SpectralFrame )])
738733
739- 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" )
743- if 'sq' in self .mode :
744- fail = True
745- continue
746-
747734 # Determine whether we're producing a single-extension AD
748735 # or keeping the number of extensions as-is
749736 if len_arc == 1 :
@@ -767,7 +754,8 @@ def attachWavelengthSolution(self, adinputs=None, **params):
767754 geotable = import_module ('.geometry_conf' , self .inst_lookups )
768755 transform .add_mosaic_wcs (ad , geotable )
769756 for ext in ad :
770- if 'mosaic' in ext .wcs .available_frames :
757+ if ('mosaic' in ext .wcs .available_frames and
758+ m_distcorr is not None ):
771759 ext .wcs .insert_frame ('mosaic' , m_distcorr ,
772760 cf .Frame2D (name = 'distortion_corrected' ))
773761
@@ -859,10 +847,12 @@ def attachWavelengthSolution(self, adinputs=None, **params):
859847 # No mosaicking, so we can just do a shift
860848 m_shift = (models .Shift ((ad_detsec .x1 - arc_detsec .x1 ) / xbin ) &
861849 models .Shift ((ad_detsec .y1 - arc_detsec .y1 ) / ybin ))
862- m_distcorr = m_shift | m_distcorr
850+ m_distcorr = (m_shift if m_distcorr is None else
851+ m_shift | m_distcorr )
863852
864- ad [0 ].wcs .insert_frame (ad [0 ].wcs .input_frame , m_distcorr ,
865- cf .Frame2D (name = 'distortion_corrected' ))
853+ if m_distcorr is not None :
854+ ad [0 ].wcs .insert_frame (ad [0 ].wcs .input_frame , m_distcorr ,
855+ cf .Frame2D (name = 'distortion_corrected' ))
866856
867857 if wave_model is None :
868858 log .warning (f"{ arc .filename } has no wavelength solution" )
@@ -887,11 +877,15 @@ def attachWavelengthSolution(self, adinputs=None, **params):
887877 # applying the distortion correction
888878 shifts = [c1 - c2 for c1 , c2 in zip (ext .detector_section (),
889879 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' ))
880+ if shifts .count (0 ) < len (shifts ):
881+ shift_model = (models .Shift (shifts [0 ] / xbin ) &
882+ models .Shift (shifts [1 ] / ybin ))
883+ dist_model = (shift_model if dist_model is None else
884+ shift_model | dist_model )
885+
886+ if dist_model is not None :
887+ ext .wcs .insert_frame (ad [0 ].wcs .input_frame , dist_model ,
888+ cf .Frame2D (name = 'distortion_corrected' ))
895889
896890 if wave_model is None :
897891 log .warning (f"{ arc .filename } extension { ext .id } has "
0 commit comments