Skip to content

Commit

Permalink
Allow EXTNAME=WAVE instead of WAVELENGTH
Browse files Browse the repository at this point in the history
  • Loading branch information
sbailey committed Oct 22, 2017
1 parent a508c89 commit 647ba01
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
7 changes: 5 additions & 2 deletions py/desisim/scripts/quickspectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,16 @@ def main(args=None):

if isfits :
log.info("Reading an input FITS file")
if not "WAVELENGTH" in hdulist :
if 'WAVELENGTH' in hdulist:
input_wave = hdulist["WAVELENGTH"].data
elif "WAVE" in hdulist:
input_wave = hdulist["WAVE"].data
else:
log.error("need an HDU with EXTNAME='WAVELENGTH' with a 1D array/image of wavelength in A in vacuum")
sys.exit(12)
if not "FLUX" in hdulist :
log.error("need an HDU with EXTNAME='FLUX' with a 1D or 2D array/image of flux in units of 10^-17 ergs/s/cm2/A")
sys.exit(12)
input_wave = hdulist["WAVELENGTH"].data
input_flux = hdulist["FLUX"].data
if input_wave.size != input_flux.shape[1] :
log.error("WAVELENGTH size {} != FLUX shape[1] = {} (NAXIS1 in fits)")
Expand Down
10 changes: 8 additions & 2 deletions py/desisim/simexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,14 @@ def simflat(flatfile, nspec=5000, nonuniform=False, exptime=10, testslit=False):

#- Trim to DESI wavelength ranges
#- TODO: is there an easier way to get these parameters?
wavemin = desimodel.io.load_throughput('b').wavemin
wavemax = desimodel.io.load_throughput('z').wavemax
try:
params = desimodel.io.load_desiparams()
wavemin = params['ccd']['b']['wavemin']
wavemax = params['ccd']['z']['wavemax']
except KeyError:
wavemin = desimodel.io.load_throughput('b').wavemin
wavemax = desimodel.io.load_throughput('z').wavemax

ii = (wavemin <= wave) & (wave <= wavemax)
wave = wave[ii]
sbflux = sbflux[ii]
Expand Down
22 changes: 17 additions & 5 deletions py/desisim/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,13 @@ def get_targets(nspec, program, tileid=None, seed=None, specify_targets=dict(),
true_objtype, target_objtype = sample_objtype(nspec, program)

#- Get DESI wavelength coverage
wavemin = desimodel.io.load_throughput('b').wavemin
wavemax = desimodel.io.load_throughput('z').wavemax
try:
params = desimodel.io.load_desiparams()
wavemin = params['ccd']['b']['wavemin']
wavemax = params['ccd']['z']['wavemax']
except KeyError:
wavemin = desimodel.io.load_throughput('b').wavemin
wavemax = desimodel.io.load_throughput('z').wavemax
dw = 0.2
wave = np.arange(round(wavemin, 1), wavemax, dw)
nwave = len(wave)
Expand Down Expand Up @@ -437,11 +442,18 @@ def sample_nz(objtype, n):

def _default_wave(wavemin=None, wavemax=None, dw=0.2):
'''Construct and return the default wavelength vector.'''

params = desimodel.io.load_desiparams()
if wavemin is None:
wavemin = desimodel.io.load_throughput('b').wavemin
try:
wavemin = params['ccd']['b']['wavemin']
except KeyError:
wavemin = desimodel.io.load_throughput('b').wavemin
if wavemax is None:
wavemax = desimodel.io.load_throughput('z').wavemax
try:
wavemax = params['ccd']['z']['wavemax']
except KeyError:
wavemax = desimodel.io.load_throughput('z').wavemax

wave = np.arange(round(wavemin, 1), wavemax, dw)

return wave

0 comments on commit 647ba01

Please sign in to comment.