예제 #1
0
def main(args=None):

    log = get_logger()
    if isinstance(args, (list, tuple, type(None))):
        args = parse(args)

    if isinstance(args, (list, tuple, type(None))):
        args = parse(args)

    if args.outfile is not None and len(args.infile) > 1:
        log.error(
            "Cannot specify single output file with multiple inputs, use --outdir option instead"
        )
        return 1

    if not os.path.isdir(args.outdir):
        log.info("Creating dir {}".format(args.outdir))
        os.makedirs(args.outdir)

    exptime = args.exptime
    if exptime is None:
        exptime = 1000.  # sec

    #- Generate obsconditions with args.program, then override as needed
    obsconditions = reference_conditions[args.program.upper()]
    if args.airmass is not None:
        obsconditions['AIRMASS'] = args.airmass
    if args.seeing is not None:
        obsconditions['SEEING'] = args.seeing
    if exptime is not None:
        obsconditions['EXPTIME'] = exptime
    if args.moonfrac is not None:
        obsconditions['MOONFRAC'] = args.moonfrac
    if args.moonalt is not None:
        obsconditions['MOONALT'] = args.moonalt
    if args.moonsep is not None:
        obsconditions['MOONSEP'] = args.moonsep

    log.info("Load SIMQSO model")
    model = SIMQSO(normfilter=args.norm_filter, nproc=1)

    decam_and_wise_filters = None
    if args.target_selection or args.mags:
        log.info("Load DeCAM and WISE filters for target selection sim.")
        decam_and_wise_filters = filters.load_filters('decam2014-g',
                                                      'decam2014-r',
                                                      'decam2014-z',
                                                      'wise2010-W1',
                                                      'wise2010-W2')

    footprint_healpix_weight = None
    footprint_healpix_nside = None
    if args.desi_footprint:
        if not 'DESIMODEL' in os.environ:
            log.error(
                "To apply DESI footprint, I need the DESIMODEL variable to find the file $DESIMODEL/data/footprint/desi-healpix-weights.fits"
            )
            sys.exit(1)
        footprint_filename = os.path.join(os.environ['DESIMODEL'], 'data',
                                          'footprint',
                                          'desi-healpix-weights.fits')
        if not os.path.isfile(footprint_filename):
            log.error(
                "Cannot find $DESIMODEL/data/footprint/desi-healpix-weights.fits"
            )
            sys.exit(1)
        pixmap = pyfits.open(footprint_filename)[0].data
        footprint_healpix_nside = 256  # same resolution as original map so we don't loose anything
        footprint_healpix_weight = load_pixweight(footprint_healpix_nside,
                                                  pixmap=pixmap)

    if args.seed is not None:
        np.random.seed(args.seed)

    # seeds for each healpix are themselves random numbers
    seeds = np.random.randint(2**32, size=len(args.infile))
    if args.balprob:
        bal = BAL()

    if args.nproc > 1:
        func_args = [ {"ifilename":filename , \
                       "args":args, "model":model , \
                       "obsconditions":obsconditions , \
                       "decam_and_wise_filters": decam_and_wise_filters , \
                       "footprint_healpix_weight": footprint_healpix_weight , \
                       "footprint_healpix_nside": footprint_healpix_nside , \
                       "seed":seeds[i]
                   } for i,filename in enumerate(args.infile) ]
        pool = multiprocessing.Pool(args.nproc)
        pool.map(_func, func_args)
    else:
        for i, ifilename in enumerate(args.infile):
            if args.balprob:
                simulate_one_healpix(ifilename,
                                     args,
                                     model,
                                     obsconditions,
                                     decam_and_wise_filters,
                                     footprint_healpix_weight,
                                     footprint_healpix_nside,
                                     seed=seeds[i],
                                     bal=bal)
            else:
                simulate_one_healpix(ifilename,
                                     args,
                                     model,
                                     obsconditions,
                                     decam_and_wise_filters,
                                     footprint_healpix_weight,
                                     footprint_healpix_nside,
                                     seed=seeds[i])
예제 #2
0
def main(args=None):

    log = get_logger()
    if isinstance(args, (list, tuple, type(None))):
        args = parse(args)

    if args.outfile is not None and len(args.infile)>1 :
        log.error("Cannot specify single output file with multiple inputs, use --outdir option instead")
        return 1

    if not os.path.isdir(args.outdir) :
        log.info("Creating dir {}".format(args.outdir))
        os.makedirs(args.outdir)

    if args.mags:
        log.warning('--mags is deprecated; please use --bbflux instead')
        args.bbflux = True

    exptime = args.exptime
    if exptime is None :
        exptime = 1000. # sec
        if args.eboss:
            exptime = 1000. # sec (added here in case we change the default)

    #- Generate obsconditions with args.program, then override as needed
    obsconditions = reference_conditions[args.program.upper()]
    if args.airmass is not None:
        obsconditions['AIRMASS'] = args.airmass
    if args.seeing is not None:
        obsconditions['SEEING'] = args.seeing
    if exptime is not None:
        obsconditions['EXPTIME'] = exptime
    if args.moonfrac is not None:
        obsconditions['MOONFRAC'] = args.moonfrac
    if args.moonalt is not None:
        obsconditions['MOONALT'] = args.moonalt
    if args.moonsep is not None:
        obsconditions['MOONSEP'] = args.moonsep

    if args.no_simqso:
        log.info("Load QSO model")
        model=QSO()
    else:
        log.info("Load SIMQSO model")
        #lya_simqso_model.py is located in $DESISIM/py/desisim/scripts/.
        #Uses a different emmision lines model than the default SIMQSO. 
        #We will update this soon to match with the one used in select_mock_targets. 
        model=SIMQSO(nproc=1,sqmodel='lya_simqso_model')
    decam_and_wise_filters = None
    bassmzls_and_wise_filters = None
    if args.target_selection or args.bbflux :
        log.info("Load DeCAM and WISE filters for target selection sim.")
        # ToDo @moustakas -- load north/south filters
        decam_and_wise_filters = filters.load_filters('decam2014-g', 'decam2014-r', 'decam2014-z',
                                                      'wise2010-W1', 'wise2010-W2')
        bassmzls_and_wise_filters = filters.load_filters('BASS-g', 'BASS-r', 'MzLS-z',
                                                     'wise2010-W1', 'wise2010-W2')

    footprint_healpix_weight = None
    footprint_healpix_nside  = None
    if args.desi_footprint :
        if not 'DESIMODEL' in os.environ :
            log.error("To apply DESI footprint, I need the DESIMODEL variable to find the file $DESIMODEL/data/footprint/desi-healpix-weights.fits")
            sys.exit(1)
        footprint_filename=os.path.join(os.environ['DESIMODEL'],'data','footprint','desi-healpix-weights.fits')
        if not os.path.isfile(footprint_filename):
            log.error("Cannot find $DESIMODEL/data/footprint/desi-healpix-weights.fits")
            sys.exit(1)
        pixmap=pyfits.open(footprint_filename)[0].data
        footprint_healpix_nside=256 # same resolution as original map so we don't loose anything
        footprint_healpix_weight = load_pixweight(footprint_healpix_nside, pixmap=pixmap)

    if args.gamma_kms_zfit and not args.zbest:
       log.info("Setting --zbest to true as required by --gamma_kms_zfit")
       args.zbest = True

    if args.extinction:
       sfdmap= SFDMap()
    else:
       sfdmap=None

    if args.balprob:
        bal=BAL()
    else:
        bal=None

    if args.eboss:
        eboss = { 'footprint':FootprintEBOSS(), 'redshift':RedshiftDistributionEBOSS() }
    else:
        eboss = None

    if args.nproc > 1:
        func_args = [ {"ifilename":filename , \
                       "args":args, "model":model , \
                       "obsconditions":obsconditions , \
                       "decam_and_wise_filters": decam_and_wise_filters , \
                       "bassmzls_and_wise_filters": bassmzls_and_wise_filters , \
                       "footprint_healpix_weight": footprint_healpix_weight , \
                       "footprint_healpix_nside": footprint_healpix_nside , \
                       "bal":bal,"sfdmap":sfdmap,"eboss":eboss \
                   } for i,filename in enumerate(args.infile) ]
        pool = multiprocessing.Pool(args.nproc)
        pool.map(_func, func_args)
    else:
        for i,ifilename in enumerate(args.infile) :
            simulate_one_healpix(ifilename,args,model,obsconditions,
                    decam_and_wise_filters,bassmzls_and_wise_filters,
                    footprint_healpix_weight,footprint_healpix_nside,
                    bal=bal,sfdmap=sfdmap,eboss=eboss)