def __init__(self, elgmap, ranmap, select_fun, sysm, mask, njack=20): self.nside = hp.get_nside(elgmap) #delta = np.zeros(elgmap.size) #randc = ranmap * select_fun #sf = (elgmap[mask].sum() / randc[mask].sum()) #delta[mask] = elgmap[mask] / randc[mask] / sf - 1 delta = makedelta(elgmap, ranmap, mask, select_fun=select_fun, is_sys=False) # # #delta2 = np.zeros(elgmap.size) #sf2 = (sysm[mask]*ranmap[mask]).sum() / ranmap[mask].sum() #delta2[mask] = sysm[mask] / (sf2 * ranmap[mask]) - 1.0 #delta2[mask] = sysm[mask] / (sf2) - 1.0 delta2 = makedelta(sysm, ranmap, mask, is_sys=True) # # w = ranmap[mask] theta, phi = hp.pix2ang(self.nside, np.argwhere(mask).flatten()) thetal, phil, wl, deltal, delta2l = split_jackknife(theta, phi, w, delta[mask], delta2[mask], njack=njack) self.theta = thetal self.phi = phil self.weight = wl self.delta = deltal self.delta2 = delta2l self.mean1 = np.average(delta[mask], weights=w) self.mean2 = np.average(delta2[mask], weights=w)
def __init__(self, elgmap, ranmap, sysmap, select_fun, mask): self.nside = hp.get_nside(elgmap) # set up the delta #delta = np.zeros(elgmap.size) #randc = ranmap * select_fun #sf = (elgmap[mask].sum() / randc[mask].sum()) #delta[mask] = elgmap[mask] / randc[mask] / sf - 1 delta = makedelta(elgmap, ranmap, mask, select_fun=select_fun, is_sys=False) # # set up the delta # delta2 = np.zeros(elgmap.size) # sf2 = (sysmap[mask]*ranmap[mask]).sum() / ranmap[mask].sum() # delta2[mask] = sysmap[mask] / (sf2) - 1.0 delta2 = makedelta(sysmap, ranmap, mask, is_sys=True) # # weight w = ranmap[mask] theta, phi = hp.pix2ang(self.nside, np.argwhere(mask).flatten()) self.theta = theta self.phi = phi self.weight = w self.delta = delta[mask] self.delta2 = delta2[mask] self.mean1 = np.average(delta[mask], weights=w) self.mean2 = np.average(delta2[mask], weights=w)
def __init__(self, elgmap, ranmap, select_fun, mask, njack=20): # set up the delta self.nside = hp.get_nside(elgmap) #delta = np.zeros(elgmap.size) #randc = ranmap * select_fun #sf = (elgmap[mask].sum() / randc[mask].sum()) #delta[mask] = elgmap[mask] / randc[mask] / sf - 1 delta = makedelta(elgmap, ranmap, mask, select_fun=select_fun, is_sys=False) # # weight w = ranmap[mask] theta, phi = hp.pix2ang(self.nside, np.argwhere(mask).flatten()) thetal, phil, wl, deltal, _ = split_jackknife(theta, phi, w, delta[mask], delta[mask], njack=njack) print('input njack %d, output njack %d' % (njack, len(wl))) self.theta = thetal self.phi = phil self.weight = wl self.delta = deltal self.mean1 = np.average(delta[mask], weights=w)
def hd5_2_fits(metaname, fitname, hpmask, hpfrac, cols, mask_in=None, res=512): metadata = pd.read_hdf(metaname) ngal = metadata['ngal'].values nran = metadata['nran'].values if mask_in is None: maskou = metadata['mask'].values else: maskou = metadata['mask'].values & mask_in features = metadata[cols][maskou].values hpind = np.argwhere(maskou).flatten() fracgood = nran / nran[maskou].mean() label = ut.makedelta(ngal, fracgood, maskou, select_fun=None, is_sys=False) + 1 label = label[maskou] fracgood = fracgood[maskou] # for n in metadata.columns: # print('%20s : %d'%(n, np.isnan(metadata[metadata['mask']][n]).sum())) outdata = np.zeros(features.shape[0], dtype=[('label', 'f8'), ('hpind', 'i8'), ('features', ('f8', features.shape[1])), ('fracgood', 'f8')]) outdata['label'] = label outdata['hpind'] = hpind outdata['features'] = features outdata['fracgood'] = fracgood # # ft.write(fitname, outdata, clobber=True) print('wrote %s' % fitname) # # mask = np.zeros(12 * res * res, '?') mask[hpind] = True hp.write_map(hpmask, mask, overwrite=True, fits_IDL=False) print('wrote %s' % hpmask) # # frac = np.zeros(12 * res * res) frac[hpind] = fracgood hp.write_map(hpfrac, frac, overwrite=True, fits_IDL=False) print('wrote %s' % hpfrac)
if not os.path.isfile(ns.wmap): wmap = None log += '{:35s} : {}\n'.format('Computing Cl w/o wmap', ns.wmap) else: wmap = hp.read_map(ns.wmap, verbose=False) log += '{:35s} : {}\n'.format('Computing Cl with wmap', ns.wmap) if ns.smooth: log += '{:35s}\n'.format('Smoothing the wmap') wmap[~mask] = np.mean( wmap[mask] ) # fill in empty pixels ?? required for smoothing sdeg = np.deg2rad(0.25) # smooth with sigma of 1/4 of a deg wmap = hp.sphtfunc.smoothing(wmap.copy(), sigma=sdeg) # # construct delta delta_ngal = makedelta(galmap, ranmap, mask, select_fun=wmap) # # compute C_l map_i = hp.ma(mask.astype('f8')) map_i.mask = np.logical_not(mask) clmask = hp.anafast(map_i.filled(), lmax=ns.lmax) sf = ((2 * np.arange(clmask.size) + 1) * clmask).sum() / (4. * np.pi) map_ngal = hp.ma(delta_ngal * ranmap) map_ngal.mask = np.logical_not(mask) cl_auto = hp.anafast(map_ngal.filled(), lmax=ns.lmax) / sf # if ns.njack == 0: cl_err = 0.0 else: cl_err = clerr_jack(delta_ngal,