Skip to content

Commit 2ec990c

Browse files
authored
Merge pull request #214 from desihub/fixtests
Fix test failures
2 parents b1aecf8 + 804a713 commit 2ec990c

File tree

5 files changed

+33
-23
lines changed

5 files changed

+33
-23
lines changed

.travis.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ env:
5050
- DESISIM_TESTDATA_VERSION=0.3.3
5151
- SPECLITE_VERSION=0.5
5252
- SPECSIM_VERSION=v0.6
53-
- SPECTER_VERSION=0.6.0
54-
- DESISPEC_VERSION=0.12.0
55-
- DESITARGET_VERSION=0.8.1
53+
- SPECTER_VERSION=0.7.0
54+
- DESISPEC_VERSION=0.13.1
55+
- DESITARGET_VERSION=0.9.0
5656
# - DESIMODEL_VERSION=trunk
5757
- DESI_LOGLEVEL=DEBUG
5858
- MAIN_CMD='python setup.py'
@@ -63,7 +63,7 @@ env:
6363
# These packages will always be installed.
6464
- PIP_DEPENDENCIES=""
6565
# These packages will only be installed if we really need them.
66-
- PIP_ALL_DEPENDENCIES="speclite==${SPECLITE_VERSION} coveralls"
66+
- PIP_ALL_DEPENDENCIES="speclite==${SPECLITE_VERSION} coveralls fitsio"
6767
# These pip packages need to be installed in a certain order, so we
6868
# do that separately from the astropy/ci-helpers scripts.
6969
- DESIHUB_PIP_DEPENDENCIES="desiutil=${DESIUTIL_VERSION}"

py/desisim/io.py

+21-17
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,11 @@ def write_simspec(meta, truth, expid, night, header=None, outfile=None):
107107
outfile = '{}/simspec-{:08d}.fits'.format(outdir, expid)
108108

109109
#- 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'
110113
hx = fits.HDUList()
111-
hx.append(fits.PrimaryHDU(None, header=desispec.io.util.fitsheader(header)))
114+
hx.append(fits.PrimaryHDU(None, header=header))
112115

113116
#- Object flux HDU (might not exist, e.g. for an arc)
114117
if 'FLUX' in truth:
@@ -619,28 +622,29 @@ def read_basis_templates(objtype, subtype='', outwave=None, nspec=None,
619622
log.info('Reading {}'.format(infile))
620623

621624
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))
638639
else:
639640
flux, hdr = fits.getdata(infile, 0, header=True)
640641
meta = Table(fits.getdata(infile, 1))
641642
wave = fits.getdata(infile, 2)
642643

643644
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+
644648
keep = np.where(meta['WDTYPE'] == subtype.upper())[0]
645649
if len(keep) == 0:
646650
log.warning('Unrecognized white dwarf subtype {}!'.format(subtype))

py/desisim/lya_spectra.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def get_spectra(lyafile, nqso=None, wave=None, templateid=None, normfilter='sdss
5151
nqso = len(h)-1
5252
templateid = np.arange(nqso)
5353
else:
54-
templateid = np.array(templateid)
54+
templateid = np.asarray(templateid)
5555
nqso = len(templateid)
5656

5757
if rand is None:

py/desisim/pixsim.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def xyslice2header(xyslice):
266266

267267
if preproc:
268268
log.debug('Running preprocessing at {}'.format(asctime()))
269-
image = desispec.preproc.preproc(rawpix, header)
269+
image = desispec.preproc.preproc(rawpix, header, primary_header=simspec.header)
270270
else:
271271
log.debug('Skipping preprocessing')
272272
image = Image(np.zeros(rawpix.shape), np.zeros(rawpix.shape), meta=header)
@@ -346,6 +346,9 @@ def _project(args):
346346
try:
347347
psf, wave, phot, specmin = args
348348
nspec = phot.shape[0]
349+
if phot.shape[-1] != wave.shape[-1]:
350+
raise ValueError('phot.shape {} vs. wave.shape {} mismatch'.format(phot.shape, wave.shape))
351+
349352
xyrange = psf.xyrange( [specmin, specmin+nspec], wave )
350353
img = psf.project(wave, phot, specmin=specmin, xyrange=xyrange)
351354
return (xyrange, img)
@@ -356,6 +359,7 @@ def _project(args):
356359
print('ERROR in _project', psf.wmin, psf.wmax, wave[0], wave[-1], phot.shape, specmin)
357360
traceback.print_exc()
358361
print('-'*60)
362+
359363
raise e
360364

361365
#- Move this into specter itself?

py/desisim/test/test_lya.py

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ def test_read_lya(self):
3434
self.assertEqual(flux.shape[0], self.nspec)
3535
self.assertEqual(wave.shape[0], flux.shape[1])
3636
self.assertEqual(len(meta), self.nspec)
37+
templateid = [0,1,2]
38+
nqso = len(templateid)
3739

3840
flux, wave, meta = lya_spectra.get_spectra(self.infile, templateid=templateid,
3941
wave=self.wave, seed=self.seed)

0 commit comments

Comments
 (0)