desihub / desisim

DESI simulations
BSD 3-Clause "New" or "Revised" License
16 stars 22 forks source link

`BRICKNAME` doesn't exist in `quickspectra` output #451

Closed londumas closed 6 years ago

londumas commented 6 years ago

I create a fake quasar using desisim.templates.QSO(), then I expand it with quickspectra and I fit it using redrock. The code used to work, but it doesn't anymore on master. Do you know why BRICKNAME can't be found in the output file of quickspectra?

The error:

<me>@edison04:~/Run_programs/desi/redrock/Look_velocity_dispersion_redshift_fitting> rrdesi /scratch1/scratchdirs/<me>/desi/SIMQSO/master_10_again/qso-observed-spectra.fits --output /scratch1/scratchdirs/<me>/desi/SIMQSO/master_10_again/qso-rrdetail.h5 --zbest /scratch1/scratchdirs/<me>/desi/SIMQSO/master_10_again/qso-zbest.fits --archetypes $HOME/Programs/desi/code/redrock/py/redrock/archetypes/
Running on a NERSC login node- reducing number of processes to 4
Running with 4 processes
Loading targets...
Proc 0: Traceback (most recent call last):
Proc 0:   File "/global/homes/h/<me>/Programs/desi/code/redrock/py/redrock/external/desi.py", line 600, in rrdesi
    comm=comm, cache_Rcsr=True, cosmics_nsig=args.cosmics_nsig)
Proc 0:   File "/global/homes/h/<me>/Programs/desi/code/redrock/py/redrock/external/desi.py", line 289, in __init__
    bname = frow["BRICKNAME"]
Proc 0:   File "/global/common/software/desi/edison/desiconda/20180709-1.2.6-spec/conda/lib/python3.6/site-packages/astropy/table/row.py", line 46, in __getitem__
    return self._table.columns[item][self._index]
Proc 0:   File "/global/common/software/desi/edison/desiconda/20180709-1.2.6-spec/conda/lib/python3.6/site-packages/astropy/table/table.py", line 109, in __getitem__
    return OrderedDict.__getitem__(self, item)
Proc 0: KeyError: 'BRICKNAME'

Total run time: 0.2 seconds

The code:

import os
import subprocess
import matplotlib.pyplot as plt

import scipy as sp
import numpy.random
import scipy.constants

import astropy.io.fits as pyfits
from astropy.table import Table

import desispec.io
import desisim.io
import desisim.templates

obj = "qso"
simdir = os.getenv('SCRATCH') + '/desi/SIMQSO/master_10_again/'
specoutfile = simdir + obj +'-observed-spectra.fits'
zoutfile    = simdir + obj +'-zbest.fits'
soutfile    = simdir + obj +'-rrdetail.h5'
saveZTrue   = simdir + obj +'-ztrue.txt'

def create_spectra():

    nbObj = 1
    sp.random.seed(42)

    ### Create some spectra
    qso_maker = desisim.templates.QSO()
    flux, wave, meta, objmeta = qso_maker.make_templates(nmodel=nbObj,seed=42,lyaforest=True)
    #sp.savetxt(saveZTrue,meta['REDSHIFT'])

    ### Store them
    os.makedirs(simdir, exist_ok=True)
    infile = simdir + '/'+obj+'-input-spectra.fits'
    hdr = pyfits.Header()
    hdr['EXTNAME'] = 'WAVELENGTH'
    hdr['BUNIT'] = 'Angstrom'
    pyfits.writeto(infile, wave, header=hdr, overwrite=True)
    hdr['EXTNAME'] = 'FLUX'
    hdr['BUNIT'] = '10^-17 ergs/s/cm2/A'
    pyfits.append(infile, flux, header=hdr)
    hdr['EXTNAME'] = 'REDSHIFT'
    pyfits.append(infile, meta['REDSHIFT'], header=hdr)

    ### Apply DESI spect
    cmd  = ' quickspectra --input ' + infile
    cmd += ' --out-spectra ' + specoutfile
    cmd += ' --seeing 0.6'
    cmd += ' --exptime 1000'  ### Here is the exposure time
    cmd += ' --seed 42'
    cmd += ' --source-type '+obj
    print(cmd)
    #cmd = 'srun --time 30 --qos debug '+cmd
    subprocess.call(cmd, shell=True)

    ### Send redrock
    cmd  = ' rrdesi_mpi ' + specoutfile
    cmd += ' --output ' + soutfile
    cmd += ' --zbest ' + zoutfile
    cmd += ' --archetypes $HOME/Programs/desi/code/redrock/py/redrock/archetypes/'
    print(cmd)
    #cmd = 'srun --time 30 --qos debug '+cmd
    #srun = 'srun -A desi -N 1 -t 00:10:00 -C haswell --qos interactive'
    #cmd = '{srun} {cmd} --ncpu 32'.format(srun=srun, cmd=cmd)
    subprocess.call(cmd, shell=True)

    return

create_spectra()
sbailey commented 6 years ago

In a separate branch for other reasons I was about to remove BRICKNAME from the redrock zbest output, since if/when it exists, it is already contained in the FIBERMAP table and target catalogs against which we would match. Seems silly for redrock to crash on whether this column exists or not.

i.e. let's fix this by removing the requirement from redrock instead of adding that column to quickspectra.

londumas commented 6 years ago

@sbailey, Thanks for the answer. Do you want me to do it or you do it?

sbailey commented 6 years ago

@londumas please go ahead and make the change in redrock and submit a PR. I'm working on some other changes to how desispec pipeline + redrock work together when there are errors so you shouldn't wait for me.

sbailey commented 6 years ago

Fixed in desihub/redrock#157 by not requiring the BRICKNAME column anymore. Closing this ticket.