diff --git a/python/desc/imsim/camera_readout.py b/python/desc/imsim/camera_readout.py index 531ba1a6..bcc5ccf7 100644 --- a/python/desc/imsim/camera_readout.py +++ b/python/desc/imsim/camera_readout.py @@ -461,6 +461,13 @@ def write_fits_file(self, outfile, overwrite=True, run_number=None, """ output = fits.HDUList(fits.PrimaryHDU()) output[0].header = self.eimage[0].header + # Since `.header` acts like an unordered dict when set like + # this, we need to re-insert the WCSAXES keyword to precede + # any other WCS keywords as stipulated in the FITS Standard, + # version 4.0, section 8.2. + wcsaxes = output[0].header['WCSAXES'] + del output[0].header['WCSAXES'] + output[0].header.insert(5, ('WCSAXES', wcsaxes, '')) if run_number is None: run_number = self.visit output[0].header['RUNNUM'] = str(run_number)