@@ -107,8 +107,11 @@ def write_simspec(meta, truth, expid, night, header=None, outfile=None):
107
107
outfile = '{}/simspec-{:08d}.fits' .format (outdir , expid )
108
108
109
109
#- Primary HDU is just a header from the input
110
+ header = desispec .io .util .fitsheader (header )
111
+ if 'DOSVER' not in header :
112
+ header ['DOSVER' ] = 'SIM'
110
113
hx = fits .HDUList ()
111
- hx .append (fits .PrimaryHDU (None , header = desispec . io . util . fitsheader ( header ) ))
114
+ hx .append (fits .PrimaryHDU (None , header = header ))
112
115
113
116
#- Object flux HDU (might not exist, e.g. for an arc)
114
117
if 'FLUX' in truth :
@@ -619,28 +622,29 @@ def read_basis_templates(objtype, subtype='', outwave=None, nspec=None,
619
622
log .info ('Reading {}' .format (infile ))
620
623
621
624
if objtype .upper () == 'QSO' :
622
- fx = fits .open (infile )
623
- format_version = _qso_format_version (infile )
624
- if format_version == 1 :
625
- flux = fx [0 ].data * 1E-17
626
- hdr = fx [0 ].header
627
- from desispec .io .util import header2wave
628
- wave = header2wave (hdr )
629
- meta = Table (fx [1 ].data )
630
- elif format_version == 2 :
631
- flux = fx ['SDSS_EIGEN' ].data .copy ()
632
- wave = fx ['SDSS_EIGEN_WAVE' ].data .copy ()
633
- meta = Table ([np .arange (flux .shape [0 ]),], names = ['PCAVEC' ,])
634
- else :
635
- raise IOError ('Unknown QSO basis template format version {}' .format (format_version ))
636
-
637
- fx .close ()
625
+ with fits .open (infile ) as fx :
626
+ format_version = _qso_format_version (infile )
627
+ if format_version == 1 :
628
+ flux = fx [0 ].data * 1E-17
629
+ hdr = fx [0 ].header
630
+ from desispec .io .util import header2wave
631
+ wave = header2wave (hdr )
632
+ meta = Table (fx [1 ].data )
633
+ elif format_version == 2 :
634
+ flux = fx ['SDSS_EIGEN' ].data .copy ()
635
+ wave = fx ['SDSS_EIGEN_WAVE' ].data .copy ()
636
+ meta = Table ([np .arange (flux .shape [0 ]),], names = ['PCAVEC' ,])
637
+ else :
638
+ raise IOError ('Unknown QSO basis template format version {}' .format (format_version ))
638
639
else :
639
640
flux , hdr = fits .getdata (infile , 0 , header = True )
640
641
meta = Table (fits .getdata (infile , 1 ))
641
642
wave = fits .getdata (infile , 2 )
642
643
643
644
if (objtype .upper () == 'WD' ) and (subtype != '' ):
645
+ if 'WDTYPE' not in meta .colnames :
646
+ raise RuntimeError ('Please upgrade to basis_templates >=2.3 to get WDTYPE support' )
647
+
644
648
keep = np .where (meta ['WDTYPE' ] == subtype .upper ())[0 ]
645
649
if len (keep ) == 0 :
646
650
log .warning ('Unrecognized white dwarf subtype {}!' .format (subtype ))
0 commit comments