Пример #1
0
def get_truth(truth_fn, south=True):
    """Build truth table."""
    logger.info('Reading truth file %s',truth_fn)
    truth = SimCatalog(truth_fn)
    mask = get_maskbit(truth)
    mask = get_mask_depth(truth)
    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','gfiber']})[0]
    for b in ['g','r','z','gfiber']:
        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]
    return truth
Пример #2
0
def get_grid_in_brick(survey, brickname, rng=None, seed=None):

    brick = survey.get_brick_by_name(brickname)
    brickwcs = wcs_for_brick(brick)
    W, H, pixscale = brickwcs.get_width(), brickwcs.get_height(
    ), brickwcs.pixel_scale()

    if rng is None:
        logger.info('Using seed = %d', seed)
        rng = np.random.RandomState(seed=seed)

    logger.info('Generating grid for %s' % brickname)

    offset = rng.uniform(0., 1., size=2)
    side = 144  # 60*0.262 = 15.72 arcsec
    # for HexGrid spacing is defined as radius... here we rather want space along x and y, so divide by correct factor
    # we also alternate start of horizontal lines depending on brick column, to allow for better transition between bricks
    grid = HexGrid(spacing=side / (2. * np.tan(np.pi / 6)),
                   shape=(W, H),
                   shift=brick.brickcol % 2)
    grid.positions += offset + side / 2  # we add random pixel fraction offset, then side/2 because grid.positions start at 0
    positions = grid._mask(grid.positions)

    catalog = SimCatalog(size=positions.shape[0])
    catalog.bx, catalog.by = positions.T

    catalog.ra, catalog.dec = brickwcs.pixelxy2radec(catalog.bx, catalog.by)
    catalog.id = catalog.index()
    catalog.brickname = catalog.full(brickname)
    mask_primary = (catalog.ra >= brick.ra1) * (catalog.ra < brick.ra2) * (
        catalog.dec >= brick.dec1) * (catalog.dec < brick.dec2)

    return catalog[mask_primary]
Пример #3
0
def get_legacysurvey_randoms(randoms_fn,
                             truth_fn,
                             bricknames=[],
                             rng=None,
                             seed=None):
    """Build legacysim catalog of injected sources from legacysurvey randoms and truth table."""
    if not isinstance(randoms_fn, list): randoms_fn = [randoms_fn]
    randoms = 0
    for fn in randoms_fn:
        logger.info('Reading randoms file %s', fn)
        randoms += SimCatalog(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
        logger.info('Found %d randoms in %s.', mask.sum(), photsys)
        if mask.any():
            randoms.fill(sample_from_truth(randoms[mask],
                                           truth,
                                           rng=rng,
                                           seed=seed),
                         index_self=mask,
                         index_other=None)

    return randoms
Пример #4
0
def write_bricklist(filename='bricklist.txt',south=False):
    dirname = '/global/cfs/cdirs/desi/survey/catalogs/SV3/LSS'
    targets = SimCatalog(os.path.join(dirname,'dark_targets.fits'))
    photsys = 'S' if south else 'N'
    with open(filename,'w') as file:
        for brickname in np.unique(targets.brickname[targets.photsys == photsys]):
            file.write('{}\n'.format(brickname))
Пример #5
0
def get_truth(truth_fn, south=True):
    """Build truth table."""
    logger.info('Reading truth file %s',truth_fn)
    truth = SimCatalog(truth_fn)
    snr = {b: truth.get('flux_%s' % b) * np.sqrt(truth.get('flux_ivar_%s' % b)) for b in ['g','r','z']}
    mask = truth.get('hsc_object_id') >= 0
    mask &= notinELG_mask(maskbits=truth.maskbits,gsnr=snr['g'],rsnr=snr['r'],zsnr=snr['z'],gnobs=truth.nobs_g,rnobs=truth.nobs_r,znobs=truth.nobs_z)
    mask &= get_mask_depth(truth)
    mask &= get_mask_ts(truth,south=south,gmarg=0.5,grmarg=0.5,rzmarg=0.5)
    for b in ['g','r','z','gfiber']:
        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]
    return truth
Пример #6
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)))
    mask &= truth.rhalf < 5.
    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