def sample_from_truth(randoms, truth, rng=None, seed=None): """Sample random photometry from truth table.""" if rng is None: logger.info('Using seed = %d', seed) rng = np.random.RandomState(seed=seed) ind = rng.randint(low=0, high=truth.size, size=randoms.size) for field in [ 'objid', 'g', 'r', 'z', 'gfiber', 'rfiber', 'zfiber', 'shape_r', 'sersic', 'shape_ba', 'shape_phi', 'hsc_object_id', 'hsc_demp_photoz_best', 'hsc_mizuki_photoz_best' ]: randoms.set(field, truth.get(field)[ind]) for b in ['g', 'r', 'z']: transmission = 10**(-0.4 * randoms.get_extinction(b, camera='DES')) randoms.set('mw_transmission_%s' % b, transmission) flux = utils.mag2nano(randoms.get(b)) * transmission randoms.set('flux_%s' % b, flux) randoms.shape_phi = rng.uniform(0., np.pi, randoms.size) randoms.shape_e1, randoms.shape_e2 = utils.get_shape_e1_e2( randoms.get('shape_ba'), randoms.shape_phi) seed = rng.randint(int(2**32 - 1)) randoms.fill_legacysim(seed=seed) return randoms
def get_mask_ts(catalog, priority='all', **kwargs): mask_low, mask_high = isELG_colors( **{ '%sflux' % b: utils.mag2nano(catalog.get(b)) for b in ['g', 'r', 'z', 'gfiber'] }, **kwargs) if priority == 'low': return mask_low if priority == 'high': return mask_high return (mask_low | mask_high)
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
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
def sample_from_truth(randoms, truth, rng=None, seed=None): """Sample random photometry from truth table.""" if rng is None: logger.info('Using seed = %d', seed) rng = np.random.RandomState(seed=seed) ind = rng.randint(low=0, high=truth.size, size=randoms.size) for field in ['id_truth', 'g', 'r', 'z', 'shape_r', 'sersic', 'redshift']: randoms.set(field, truth.get(field)[ind]) for b in ['g', 'r', 'z']: transmission = 10**(-0.4 * randoms.get_extinction(b, camera='DES')) randoms.set('mw_transmission_%s' % b, transmission) flux = utils.mag2nano(randoms.get(b)) * transmission randoms.set('flux_%s' % b, flux) ba = rng.uniform(0.2, 1., size=randoms.size) phi = rng.uniform(0, np.pi, size=randoms.size) randoms.shape_e1, randoms.shape_e2 = utils.get_shape_e1_e2(ba, phi) randoms.fill_legacysim(seed=seed) return randoms