Source code for desisim.scripts.newarc

from __future__ import absolute_import, division, print_function
import sys, os
import argparse
import datetime
import time
import warnings

import numpy as np
import astropy.table
# See
import astropy.time
from import fits
import astropy.units as u

import desisim.simexp
import desiutil.depend

def parse(options=None):

    if 'DESI_ROOT' in os.environ:
        _default_arcfile = os.path.join(os.getenv('DESI_ROOT'),
            'spectro', 'templates', 'calib', 'v0.4', 'arc-lines-average-in-vacuum-from-winlight-20170118.fits')
        _default_arcfile = None

    #- Required
    parser.add_argument('--expid', type=int, help="exposure ID")
    parser.add_argument('--night', type=str, help="YEARMMDD")

    #- Optional
    parser.add_argument('--arcfile', type=str, help="input arc calib spec file",
    parser.add_argument('--simspec', type=str, help="output simspec file")
    parser.add_argument('--fibermap', type=str, help="output fibermap file")
    parser.add_argument('--outdir', type=str, help="output directory")
    parser.add_argument('--nspec', type=int, default=5000, help="number of spectra to include")
    parser.add_argument('--nonuniform', action='store_true', help="Include calibration screen non-uniformity")
    parser.add_argument('--clobber', action='store_true', help="overwrite any pre-existing output files")

    if len(sys.argv) == 1:

    if options is None:
        args = parser.parse_args()
        args = parser.parse_args(options)

    if args.simspec is None:
        args.simspec ='simspec', args.night, args.expid,

    if args.fibermap is None:
        #- put in same directory as simspec by default
        filedir = os.path.dirname(os.path.abspath(args.simspec))
        filename = os.path.basename('fibermap', args.night, args.expid))
        args.fibermap = os.path.join(filedir, filename)

    return args

[docs]def main(args=None): ''' TODO: document Note: this bypasses specsim since we don't have an arclamp model in surface brightness units; we only have electrons on the CCD ''' import desiutil.log log = desiutil.log.get_logger() from desiutil.iers import freeze_iers freeze_iers() if isinstance(args, (list, tuple, type(None))): args = parse(args)'reading arc data from {}'.format(args.arcfile)) arcdata = wave, phot, fibermap = \ desisim.simexp.simarc(arcdata, nspec=args.nspec, nonuniform=args.nonuniform)'Writing {}'.format(args.fibermap)) fibermap.meta['NIGHT'] = args.night fibermap.meta['EXPID'] = args.expid fibermap.meta['EXTNAME'] = 'FIBERMAP' fibermap.write(args.fibermap, overwrite=args.clobber) #- TODO: explain bypassing header = fits.Header() desiutil.depend.add_dependencies(header) header['EXPID'] = args.expid header['NIGHT'] = args.night header['FLAVOR'] = 'arc' header['DOSVER'] = 'SIM' header['EXPTIME'] = 5 #- TODO: add exptime support #- TODO: DATE-OBS on night instead of now tx = astropy.time.Time(datetime.datetime(*time.gmtime()[0:6])) header['DATE-OBS'] = tx.utc.isot, wave, phot, header, fibermap, overwrite=args.clobber)