Ejemplo n.º 1
0
def write_bricklist(ran_fn, bricklist_fn, south=False, nbricks=100, range_ebv=(0.002,0.15)):
    """Return brick list for ebv run."""
    bands = ['g','r','z']
    randoms = SimCatalog(ran_fn,columns=['photsys','brickname','ebv'] + ['nobs_%s' % b for b in bands])
    mask = randoms.photsys == ('S' if south else 'N')
    for b in bands: mask &= randoms.get('nobs_%s' % b)>0
    #mask &= randoms.maskbits == 0
    randoms = randoms[mask]
    step_ebv = (range_ebv[-1]-range_ebv[0])/nbricks
    with open(bricklist_fn,'w') as file:
        for ibrick in range(nbricks):
            min_ebv,max_ebv = ibrick*step_ebv + range_ebv[0],(ibrick+1)*step_ebv + range_ebv[0]
            mask = (randoms.ebv > min_ebv) & (randoms.ebv < max_ebv)
            if mask.any():
                file.write('%s\n' % randoms.brickname[mask][0])
            else:
                logger.info('No brick found in EBV interval %.3f - %.3f.' % (min_ebv,max_ebv))
Ejemplo n.º 2
0
def write_legacysurvey_randoms(input_fn, truth_fn, randoms_fn, bricknames=[], seed=None):
    """Build Obiwan randoms from legacysurvey randoms and truth table."""
    randoms = SimCatalog(input_fn)
    logger.info('Selecting randoms in %s' % bricknames)
    mask = np.in1d(randoms.brickname,bricknames)
    randoms = randoms[mask]
    randoms.rename('targetid','id')
    logger.info('Selected random catalog of size = %d.' % randoms.size)
    randoms.keep_columns('id','ra','dec','maskbits','photsys','brickname')

    for photsys in ['N','S']:
        truth = get_truth(truth_fn,south=photsys=='S')
        mask = randoms.photsys == photsys
        if mask.any():
            randoms.fill(sample_from_truth(randoms[mask],truth,seed=seed),index_self=mask,index_other=None)

    randoms.writeto(randoms_fn)
Ejemplo n.º 3
0
def get_truth(truth_fn, south=True):
    """Build truth table."""
    truth = SimCatalog(truth_fn)
    mask = (truth.g >= 22.) & (truth.g <= 24.)
    for b in ['g','r','z']:
        mask &= (~np.isnan(truth.get(b))) & (~np.isinf(truth.get(b)))
    logger.info('Target selection: %d/%d objects' % (mask.sum(),mask.size))
    truth = truth[mask]
    truth.rename('objid','id_truth')
    truth.rename('rhalf','shape_r')
    #truth.shape_r = 1e-5*truth.ones()
    truth.rename('hsc_mizuki_photoz_best','redshift')
    truth.sersic = truth.ones(dtype=int)
    truth.sersic[truth.type=='DEV'] = 4
    return truth
Ejemplo n.º 4
0
def get_truth(truth_fn, south=True):
    """Build truth table."""
    truth = SimCatalog(truth_fn)
    mask = isELG_colors(south=south,
                        gmarg=0.5,
                        grmarg=0.5,
                        rzmarg=0.5,
                        **{
                            '%sflux' % b: utils.mag2nano(truth.get(b))
                            for b in ['g', 'r', 'z']
                        })
    for b in ['g', 'r', 'z']:
        mask &= (~np.isnan(truth.get(b))) & (~np.isinf(truth.get(b)))
    logger.info('Target selection: %d/%d objects' % (mask.sum(), mask.size))
    truth = truth[mask]
    truth.rename('objid', 'id_truth')
    truth.rename('rhalf', 'shape_r')
    #truth.shape_r = 1e-5*truth.ones()
    truth.rename('hsc_mizuki_photoz_best', 'redshift')
    truth.sersic = truth.ones(dtype=int)
    truth.sersic[truth.type == 'DEV'] = 4
    return truth