def main(args, comm=None): if comm.rank == 0: import healpy as hp # --- only rank 0 # read data, randoms, and templates data = ft.read(args.data_path) nside = 1024 ngal = hp.read_map(args.hpmap_path) nran = make_hp(nside, data['hpix'], 1.0) # mocks do not have completeness mask = make_hp(nside, data['hpix'], 1.0) > 0.5 sysm = np.zeros((12 * nside * nside, data['features'].shape[1])) print(sysm.shape) sysm[data['hpix'], :] = data['features'] if args.selection is not None: s_ = ft.read(args.selection) selection_fn = make_hp(nside, s_['hpix'], np.median(s_['weight'], axis=1)) #.mean(axis=1)) print(np.percentile(selection_fn[mask], [0, 1, 99, 100])) else: selection_fn = None else: ngal = None nran = None mask = None sysm = None selection_fn = None ngal = comm.bcast(ngal, root=0) nran = comm.bcast(nran, root=0) mask = comm.bcast(mask, root=0) sysm = comm.bcast(sysm, root=0) selection_fn = comm.bcast(selection_fn, root=0) cls_list = get_cl( ngal, nran, mask, selection_fn=selection_fn, systematics=sysm, njack=0, cross_only=False, is_delta=True) # don't compute Css for mocks & mocks are delta if comm.rank == 0: output_dir = os.path.dirname(args.output_path) if not os.path.exists(output_dir): print(f'creating {output_dir}') os.makedirs(output_dir) np.save(args.output_path, cls_list)
def d2dl(d): nside = 1024 ng = make_hp(nside, d['hpix'], d['label']) fr = make_hp(nside, d['hpix'], d['fracgood']) ms = fr > 0.0 dl = make_overdensity(ng, fr, ms) return fr, dl
def main(args, comm=None): if comm.rank == 0: # --- only rank 0 # read data, randoms, and templates data = ft.read(args.data_path) nside = 256 ngal = make_hp(nside, data['hpix'], data['label']) nran = make_hp(nside, data['hpix'], data['fracgood']) mask = make_hp(nside, data['hpix'], 1.0) > 0.5 sysm = np.zeros((12 * nside * nside, data['features'].shape[1])) print(sysm.shape) sysm[data['hpix'], :] = data['features'] if args.selection is not None: s_ = ft.read(args.selection) selection_fn = make_hp(nside, s_['hpix'], np.median(s_['weight'], axis=1)) #.mean(axis=1)) print(np.percentile(selection_fn[mask], [0, 1, 99, 100])) else: selection_fn = None else: ngal = None nran = None mask = None sysm = None selection_fn = None ngal = comm.bcast(ngal, root=0) nran = comm.bcast(nran, root=0) mask = comm.bcast(mask, root=0) sysm = comm.bcast(sysm, root=0) selection_fn = comm.bcast(selection_fn, root=0) cls_list = get_cl(ngal, nran, mask, selection_fn=selection_fn, systematics=sysm, njack=0) if comm.rank == 0: output_dir = os.path.dirname(args.output_path) if not os.path.exists(output_dir): print(f'creating {output_dir}') os.makedirs(output_dir) np.save(args.output_path, cls_list)
def main(ns, comm=None): if comm.rank == 0: for (key, value) in ns.__dict__.items(): print(f'{key:15s} : {value}') # get list of windows windows = glob(os.path.join(ns.hpmap_dir, '*.fits')) print(f'# windows: {len(windows)}') # read imaging maps data = ft.read(ns.data_path) frac = make_hp(nside, data['hpix'], data['fracgood']) mask = make_hp(nside, data['hpix'], 1.0) > 0.5 else: windows = None frac = None mask = None windows = comm.bcast(windows, root=0) frac = comm.bcast(frac, root=0) mask = comm.bcast(mask, root=0) start, end = split_NtoM(len(windows), comm.size, comm.rank) cl = [] for i in range(start, end + 1): t0 = time() w_i = hp.read_map(windows[i], verbose=False, dtype=np.float64) #w_i = w_i / np.mean(w_i[mask]) #w_i = w_i.clip(0.5, 2.0) w_i = (w_i / w_i[mask].mean()) - 1.0 cl_i = anafast(w_i, frac, mask)['cl'] t1 = time() if comm.rank == 0: print(f'rank-{comm.rank} finished {i} in {t1-t0} sec') cl.append(cl_i) comm.Barrier() cl = comm.gather(cl, root=0) if comm.rank == 0: cl = np.array(cl) print(cl.shape) lmax = cl.shape[-1] cl = np.concatenate(cl.reshape(-1, lmax).flatten()) np.save(ns.output_path, cl, allow_pickle=False)
def main(args, comm=None): if comm.rank == 0: import healpy as hp # --- only rank 0 # read data, randoms, and templates data = ft.read(args.data_path) nside = 256 #ngal = data['label'] #nran = data['fracgood'] nran = np.ones(data['hpix'].size) mask = np.ones(data['hpix'].size, '?') sysm = data['features'] ngal_ = hp.read_map(args.hpmap_path, verbose=False, dtype=np.float64) ngal = ngal_[data['hpix']] if args.selection is not None: s_ = ft.read(args.selection) selection_fn = make_hp(nside, s_['hpix'], np.median(s_['weight'], axis=1)) #.mean(axis=1)) selection_fn = selection_fn[data['hpix']] print(np.percentile(selection_fn[mask], [0, 1, 99, 100])) else: selection_fn = None else: ngal = None nran = None mask = None sysm = None selection_fn = None ngal = comm.bcast(ngal, root=0) nran = comm.bcast(nran, root=0) mask = comm.bcast(mask, root=0) sysm = comm.bcast(sysm, root=0) selection_fn = comm.bcast(selection_fn, root=0) nnbar_list = get_meandensity(ngal, nran, mask, sysm, columns=columns, selection_fn=selection_fn, binning='simple', percentiles=[1, 99], global_nbar=True) if comm.rank == 0: output_dir = os.path.dirname(args.output_path) if not os.path.exists(output_dir): print(f'creating {output_dir}') os.makedirs(output_dir) np.save(args.output_path, nnbar_list)
def plot_ngmoll(): desi = ft.read( '/fs/ess/PHS0336/data/rongpu/imaging_sys/tables/0.57.0/nlrg_features_desi_256.fits' ) ng = make_hp( 256, desi['hpix'], desi['label'] / (desi['fracgood'] * hp.nside2pixarea(256, True)), np.inf) print(np.mean(ng[desi['hpix']])) mollview(ng, 400, 1200, r'Observed Galaxy Density [deg$^{-2}$]', cmap='YlOrRd_r', colorbar=True, galaxy=True) plt.savefig('figs/nlrg.pdf', bbox_inches='tight')
def read_mask(region): import fitsio as ft import healpy as hp from lssutils.utils import make_hp if region in ['bmzls', 'ndecals', 'sdecals', 'ngc', 'desi']: # read survey geometry data_path = '/fs/ess/PHS0336/data/' dt = ft.read( f'{data_path}/rongpu/imaging_sys/tables/0.57.0/nlrg_features_{region}_256.fits' ) mask_ = make_hp(256, dt['hpix'], 1.0) > 0.5 mask = hp.ud_grade(mask_, 1024) else: # full sky mask = np.ones(12 * 1024 * 1024, '?') return mask * 1.0, mask
data_ng = ft.read(f'{path}/density_maps/{tag_d}/resolve/density_map_sv3_{kind}_{cap}_nside_{nside}_minobs_1_maskbits_{mb}.fits') elif tag_d=='1.0.0': data_ng = ft.read(f'{path}/density_maps/{tag_d}/resolve/density_map_{kind}_{cap}_nside_{nside}_minobs_1_maskbits_{mb}.fits') data_tmp = ft.read(f'{path}/randoms_stats/{tag_r}/resolve/combined/pixmap_{cap}_nside_{nside}_minobs_1_maskbits_{mb}.fits') # split south into sdecals and ndecals if region in ['ndecals', 'sdecals']: is_region = ut.select_region(data_ng['RA'], data_ng['DEC'], region) data_ng = data_ng[is_region] is_region = ut.select_region(data_tmp['RA'], data_tmp['DEC'], region) data_tmp = data_tmp[is_region] ngal = ut.make_hp(nside, data_ng['HPXPIXEL'], data_ng['n_targets']) hpix = data_tmp['HPXPIXEL'] fracgood = data_tmp['FRACAREA'] label = ngal[hpix] features = [] for col in ut.maps_dr9: feat_ = data_tmp[col] features.append(feat_) features = np.array(features).T data_nn = ut.to_numpy(label, features, fracgood, hpix) for name in data_nn.dtype.names: assert (~np.isfinite(data_nn[name])).sum() == 0, f'{name} is bad' if region=='ndecals':
def read_wnn(path2file): w_ = ft.read(path2file) w_nn = w_['weight'] / np.median(w_['weight']) w_nn = w_nn.clip(0.5, 2.0) return ut.make_hp(1024, w_['hpix'], w_nn, True)