matroxel / roman_imsim

MIT License
10 stars 4 forks source link

Make DATE-OBS format match the FITS (ISO) standard. #25

Open wmwv opened 6 months ago

wmwv commented 6 months ago

tl;dr

Use Time().datetime.isoformat() instead of str(Time().datetime)

Details

The DATE-OBS as defined in https://github.com/matroxel/roman_imsim/blob/864357c8d088164b9662007f2ebe50e23243368e/roman_imsim/sca.py#L131

is calculated as

str(Time(self.mjd,format='mjd').datetime)

But that does not generate ISO-compliant DATE-OBS, which is formally what the FITS standard specifies. E.g., the current code generates dates with a space ' ' instead of a 'T' between the DATE and the TIME: such as 2029-12-01 06:01:26.400000' instead of '2029-12-01T06:01:26.400000'.

Section 9.1.1 of https://fits.gsfc.nasa.gov/standard40/fits_standard40aa-le.pdf

I suggest using

Time(self.mjd,format='mjd').datetime.isoformat()

to correctly generate ISO-formate datetime strings for the FITS headers.

wmwv commented 6 months ago

Here's the relevant code from the LSSTDESC imSim. This also makes sure to write the datetime in TAI intead of UTC.

https://github.com/search?q=repo%3ALSSTDESC%2FimSim%20DATE-OBS&type=code

wmwv commented 1 month ago

@matroxel Is this something that can be fixed before the next runs?

wmwv commented 1 month ago

To be a little more comprehensive, fitsverify doesn't like the format of DATE-OBS and the location of WCSAXES

https://heasarc.gsfc.nasa.gov/docs/software/ftools/fitsverify/

fitsverify RomanTDS/images/simple_model/H158/33338/Roman_TDS_simple_model_H158_33338_17.fits.gz

              fitsverify 4.20 (CFITSIO V4.020)
              --------------------------------

File: RomanTDS/images/simple_model/H158/33338/Roman_TDS_simple_model_H158_33338_17.fits.gz

4 Header-Data Units in this file.

=================== HDU 1: Primary Array ===================

*** Error:   Keyword #7, DATE-OBS: (from CFITSIO error stack:)
             input date string has illegal format (ffs2dt):
             2029-10-22 02:36:57.600000

*** Error:   WCSAXES keyword #52 appears after other WCS keyword CTYPE1 #13

 64 header keywords

 Null data array; NAXIS = 0

=================== HDU 2: Image Exten. ====================

*** Error:   Keyword #10, DATE-OBS: (from CFITSIO error stack:)
             input date string has illegal format (ffs2dt):
             2029-10-22 02:36:57.600000

*** Error:   WCSAXES keyword #55 appears after other WCS keyword CTYPE1 #16

 69 header keywords

SCI (1) 64-bit double precision pixels,  2 axes (4088 x 4088),

=================== HDU 3: Image Exten. ====================

*** Error:   Keyword #10, DATE-OBS: (from CFITSIO error stack:)
             input date string has illegal format (ffs2dt):
             2029-10-22 02:36:57.600000

*** Error:   WCSAXES keyword #55 appears after other WCS keyword CTYPE1 #16

 69 header keywords

ERR (1) 32-bit floating point pixels,  2 axes (4088 x 4088),

=================== HDU 4: Image Exten. ====================

*** Error:   Keyword #12, DATE-OBS: (from CFITSIO error stack:)
             input date string has illegal format (ffs2dt):
             2029-10-22 02:36:57.600000

*** Error:   WCSAXES keyword #57 appears after other WCS keyword CTYPE1 #18

 71 header keywords

DQ (1) 32-bit integer pixels,  2 axes (4088 x 4088),

++++++++++++++++++++++ Error Summary  ++++++++++++++++++++++

 HDU#  Name (version)       Type             Warnings  Errors
 1                          Primary Array    0         2
 2     SCI (1)              Image Array      0         2
 3     ERR (1)              Image Array      0         2
 4     DQ (1)               Image Array      0         2

**** Verification found 0 warning(s) and 8 error(s). ****