def cat_fromflsk(cshcat_fn, nside, nonoise=False): """Load FLASK cosmic shear catalog and adds additional info """ cshcat = pd.read_parquet(cshcat_fn) # Shear if nonoise: cshcat['g1'] = cshcat['g1_true'] cshcat['g2'] = cshcat['g2_true'] cshcat.drop(['g1_true', 'g2_true'], axis=1, inplace=True) # Angular positions cshcat[f'ip{nside}'] = hu.HealPix('ring', nside).eq2pix(cshcat['ra'], cshcat['dec']) cshcat.drop(['ra', 'dec'], axis=1, inplace=True) # Extra information - here all simulated cshcat['R'] = np.ones(cshcat.shape[0]) cshcat['w'] = np.ones(cshcat.shape[0]) # # Apply corrections # cshcat['g1'] -= np.average(cshcat['g1'], weights=cshcat['w']) # cshcat['g2'] -= np.average(cshcat['g2'], weights=cshcat['w']) # Shape noise cshcat['varg'] = 0.5 * (cshcat['g1']**2 + cshcat['g2']**2) return cshcat
def _add_ipix(gclcat, nside): """ Adds IP'NSIDE' to a dataframe originally containing {ra, dec} """ hp = hu.HealPix('ring', nside) gclcat[f"ip{nside}"] = hp.eq2pix(gclcat.ra.values, gclcat.dec.values) return gclcat.drop(['ra', 'dec'], axis=1)
def read_partial_map(filename, ext=1, masked_val=MASKED_VAL, pix_col='PIXEL', val_col='SIGNAL'): f = fitsio.FITS(filename)[ext] nside = int(f.read_header()['NSIDE']) hpix = hu.HealPix("ring", nside) m = masked_val * np.ones(hpix.npix) m_data = f.read() m[m_data[pix_col]] = m_data[val_col] return hu.Map("ring", m)
def pixellise(self, ra, dec, observable, nside): import healpix_util as hu hpix = hu.HealPix('ring', nside) pixels = hpix.eq2pix(ra, dec) assert len(pixels) == len(observable) npix = hp.nside2npix(nside) notempty = np.unique(pixels) meanobs = np.zeros(npix) print "Averaging in %d (non empty) pixels" % len(notempty) for i in notempty: mask = (pixels == i) meanobs[i] = np.mean(observable[mask]) return meanobs
def ncmap_sample_positions(nc_map, ip_good, nside, fgoodmap, nside_up=4): """ Samples positions of galaxies inside a footprint from a number counts map """ ip_good_nest = hp.ring2nest(nside, ip_good) ipix_nest = [ rd.sample( range(ip_good_nest[i] * 4**nside_up, (ip_good_nest[i] + 1) * 4**nside_up), nc_map[i]) for i in range(len(ip_good)) ] ipix_nest = [ip for sub in ipix_nest for ip in sub] hpix = hu.HealPix('nest', nside * 2**nside_up) ra, dec = hpix.pix2eq(ipix_nest) return ra, dec
def gen_catalog_bin(ngal): """ Generate a random catalog for a single bin using healpy routines :param ngal: The number of galaxies per pixel :type ngal: :class:`lsssys.Map` :return: The right ascension and declination of the generated catalog :rtype: ``tuple`` of 2 :class:`numpy.ndarray` of ``float`` """ pix = np.where(ngal.data > 0.)[0] n_gal = ngal.data[pix].astype(int) highres_nside = ngal.nside * next_power_of_2(2 * n_gal.max()) pix_nest = hp.ring2nest(ngal.nside, pix) corners = np.array( [c.T for c in hp.boundaries(ngal.nside, pix_nest, nest=True)]) high_res_pix = np.concatenate([ np.random.choice(hp.query_polygon(highres_nside, corn, nest=True), n) for corn, n in zip(corners, n_gal) ]) hpix_highres = hu.HealPix("nest", highres_nside) return hpix_highres.pix2eq(high_res_pix)
def lnscat_addck(lnscat, flaskdir, nck=2, nz_lns=5, fgood_thold=0.0): """ Adds cookie-cut information to lnscat """ fgoodmap_fn = [ f"{flaskdir}/cookies/ck{ick+1}_desy3_goldv2p2p1.fits.gz" for ick in range(nck) ] nside = ft.read_header(fgoodmap_fn[0], 1)['nside'] assert nside == ft.read_header(fgoodmap_fn[1], 1)['nside'] npix = hp.nside2npix(nside) ipix = hu.HealPix('ring', nside).eq2pix(lnscat.ra, lnscat.dec) ck = np.zeros(lnscat.shape[0], dtype='i4') for ick in range(nck): fgmap = hp.read_map(fgoodmap_fn[ick], verbose=False) ip_good = np.arange(npix)[(fgmap > fgood_thold)] ck[np.in1d(ipix, ip_good)] = ick + 1 lnscat['ck'] = ck lnscat = lnscat[lnscat.ck > 0] return lnscat
data = ebf.read(datafile, '/') c = coord.Galactic(u=data['px'] * u.kpc, v=data['py'] * u.kpc, w=data['pz'] * u.kpc, U=data['vx'] * u.km / u.s, V=data['vy'] * u.km / u.s, W=data['vz'] * u.km / u.s, representation=coord.CartesianRepresentation, differential_cls=coord.CartesianDifferential) c.set_representation_cls(coord.SphericalRepresentation, s=coord.SphericalCosLatDifferential) #for visualizing all data on the sky nside = 128 hpixMap = hu.HealPix("ring", nside) pixnums = hpixMap.eq2pix(data['glon'], data['glat']) omap = np.bincount(pixnums, minlength=hpixMap.npix) mapSky = hp.mollview(np.log10(omap), return_projected_map=True) plt.savefig('pofd_allsky.pdf') #pmb = np.random.normal(loc=c.pm_b, scale=2) #pml = np.random.normal(loc=c.pm_l_cosb, scale=2) def matrixize(data, err): """ vectorize the 2 pieces of data into a 2D mean and 2D covariance matrix """ X = np.vstack(data).T Xerr = np.zeros(X.shape + X.shape[-1:])