Skip to content

Commit

Permalink
Merge pull request #214 from desihub/fixtests
Browse files Browse the repository at this point in the history
Fix test failures
  • Loading branch information
moustakas authored Mar 4, 2017
2 parents b1aecf8 + 804a713 commit 2ec990c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 23 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ env:
- DESISIM_TESTDATA_VERSION=0.3.3
- SPECLITE_VERSION=0.5
- SPECSIM_VERSION=v0.6
- SPECTER_VERSION=0.6.0
- DESISPEC_VERSION=0.12.0
- DESITARGET_VERSION=0.8.1
- SPECTER_VERSION=0.7.0
- DESISPEC_VERSION=0.13.1
- DESITARGET_VERSION=0.9.0
# - DESIMODEL_VERSION=trunk
- DESI_LOGLEVEL=DEBUG
- MAIN_CMD='python setup.py'
Expand All @@ -63,7 +63,7 @@ env:
# These packages will always be installed.
- PIP_DEPENDENCIES=""
# These packages will only be installed if we really need them.
- PIP_ALL_DEPENDENCIES="speclite==${SPECLITE_VERSION} coveralls"
- PIP_ALL_DEPENDENCIES="speclite==${SPECLITE_VERSION} coveralls fitsio"
# These pip packages need to be installed in a certain order, so we
# do that separately from the astropy/ci-helpers scripts.
- DESIHUB_PIP_DEPENDENCIES="desiutil=${DESIUTIL_VERSION}"
Expand Down
38 changes: 21 additions & 17 deletions py/desisim/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,11 @@ def write_simspec(meta, truth, expid, night, header=None, outfile=None):
outfile = '{}/simspec-{:08d}.fits'.format(outdir, expid)

#- Primary HDU is just a header from the input
header = desispec.io.util.fitsheader(header)
if 'DOSVER' not in header:
header['DOSVER'] = 'SIM'
hx = fits.HDUList()
hx.append(fits.PrimaryHDU(None, header=desispec.io.util.fitsheader(header)))
hx.append(fits.PrimaryHDU(None, header=header))

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

if objtype.upper() == 'QSO':
fx = fits.open(infile)
format_version = _qso_format_version(infile)
if format_version == 1:
flux = fx[0].data * 1E-17
hdr = fx[0].header
from desispec.io.util import header2wave
wave = header2wave(hdr)
meta = Table(fx[1].data)
elif format_version == 2:
flux = fx['SDSS_EIGEN'].data.copy()
wave = fx['SDSS_EIGEN_WAVE'].data.copy()
meta = Table([np.arange(flux.shape[0]),], names=['PCAVEC',])
else:
raise IOError('Unknown QSO basis template format version {}'.format(format_version))

fx.close()
with fits.open(infile) as fx:
format_version = _qso_format_version(infile)
if format_version == 1:
flux = fx[0].data * 1E-17
hdr = fx[0].header
from desispec.io.util import header2wave
wave = header2wave(hdr)
meta = Table(fx[1].data)
elif format_version == 2:
flux = fx['SDSS_EIGEN'].data.copy()
wave = fx['SDSS_EIGEN_WAVE'].data.copy()
meta = Table([np.arange(flux.shape[0]),], names=['PCAVEC',])
else:
raise IOError('Unknown QSO basis template format version {}'.format(format_version))
else:
flux, hdr = fits.getdata(infile, 0, header=True)
meta = Table(fits.getdata(infile, 1))
wave = fits.getdata(infile, 2)

if (objtype.upper() == 'WD') and (subtype != ''):
if 'WDTYPE' not in meta.colnames:
raise RuntimeError('Please upgrade to basis_templates >=2.3 to get WDTYPE support')

keep = np.where(meta['WDTYPE'] == subtype.upper())[0]
if len(keep) == 0:
log.warning('Unrecognized white dwarf subtype {}!'.format(subtype))
Expand Down
2 changes: 1 addition & 1 deletion py/desisim/lya_spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get_spectra(lyafile, nqso=None, wave=None, templateid=None, normfilter='sdss
nqso = len(h)-1
templateid = np.arange(nqso)
else:
templateid = np.array(templateid)
templateid = np.asarray(templateid)
nqso = len(templateid)

if rand is None:
Expand Down
6 changes: 5 additions & 1 deletion py/desisim/pixsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def xyslice2header(xyslice):

if preproc:
log.debug('Running preprocessing at {}'.format(asctime()))
image = desispec.preproc.preproc(rawpix, header)
image = desispec.preproc.preproc(rawpix, header, primary_header=simspec.header)
else:
log.debug('Skipping preprocessing')
image = Image(np.zeros(rawpix.shape), np.zeros(rawpix.shape), meta=header)
Expand Down Expand Up @@ -346,6 +346,9 @@ def _project(args):
try:
psf, wave, phot, specmin = args
nspec = phot.shape[0]
if phot.shape[-1] != wave.shape[-1]:
raise ValueError('phot.shape {} vs. wave.shape {} mismatch'.format(phot.shape, wave.shape))

xyrange = psf.xyrange( [specmin, specmin+nspec], wave )
img = psf.project(wave, phot, specmin=specmin, xyrange=xyrange)
return (xyrange, img)
Expand All @@ -356,6 +359,7 @@ def _project(args):
print('ERROR in _project', psf.wmin, psf.wmax, wave[0], wave[-1], phot.shape, specmin)
traceback.print_exc()
print('-'*60)

raise e

#- Move this into specter itself?
Expand Down
2 changes: 2 additions & 0 deletions py/desisim/test/test_lya.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def test_read_lya(self):
self.assertEqual(flux.shape[0], self.nspec)
self.assertEqual(wave.shape[0], flux.shape[1])
self.assertEqual(len(meta), self.nspec)
templateid = [0,1,2]
nqso = len(templateid)

flux, wave, meta = lya_spectra.get_spectra(self.infile, templateid=templateid,
wave=self.wave, seed=self.seed)
Expand Down

0 comments on commit 2ec990c

Please sign in to comment.