示例#1
0
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)
示例#2
0
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)
示例#3
0
 def run_cl(self):
     
     if self.comm.rank==0:
         self.logger.info('C_ell vs systematics')
         self.logger.info(f'{self.df.shape}')
         
     cl_obs = get_cl(self.galmap, self.ranmap, self.mask, 
                     systematics=self.df, njack=self.args['njack'])
     
     if self.comm.rank==0:
         ouname = ''.join([self.args['oudir'], self.args['clfile']])
         np.save(ouname, cl_obs)
         self.logger.info(f'write cl in {ouname}')
示例#4
0
def angular_power(args, columns=maps_eboss_v7p2):
    zmin, zmax = args.zlim
    nside = args.nside
    use_systot = args.use_systot


    data_path = args.data_path
    randoms_path = args.randoms_path
    templates_path = args.templates_path
    output_path = args.output_path

    # read data, randoms, and templates
    data = EbossCat(data_path, kind='data', zmin=zmin, zmax=zmax)
    randoms = EbossCat(randoms_path, kind='randoms', zmin=zmin, zmax=zmax)

    templates = pd.read_hdf(templates_path, key='templates')
    sysm = templates[columns].values
    if nside is None:
        nside = npix2nside(sysm.shape[0])        

    # project to HEALPix
    if use_systot:
        ngal = data.to_hp(nside, zmin, zmax, raw=2)
        nran = randoms.to_hp(nside, zmin, zmax, raw=2)
    else:
        ngal = data.to_hp(nside, zmin, zmax, raw=1)
        nran = randoms.to_hp(nside, zmin, zmax, raw=1)

    # construct the mask    
    mask_nran = nran > 0
    mask_ngal = np.isfinite(ngal)
    mask_sysm = (~np.isfinite(sysm)).sum(axis=1) < 1
    
    if npix2nside(sysm.shape[0]) != nside:
        mask_sysm = ud_grade(mask_sysm, nside_out=nside)

    mask = mask_sysm & mask_nran & mask_ngal  

    nran_bar = nside2pixarea(nside, degrees=True)*5000.
    cls_list = get_cl(ngal, nran, mask, systematics=None, njack=0, nran_bar=nran_bar) # no systematics
    
    output_dir = os.path.dirname(output_path)
    if not os.path.exists(output_dir):
        print(f'creating {output_dir}')
        os.makedirs(output_dir)

    np.save(output_path, cls_list)
示例#5
0

# In[7]:


assert np.array_equal(np.sort(wnn_old['hpind']), np.sort(wnn['hpix']))


# In[8]:


# compute C_ells

kw = dict(njack=0, nran_bar=nran_mean)

cl_old = get_cl(nobs_w, nran_w, mask, selection_fn=wnn_old_hp, **kw) # old NN
cl_def = get_cl(nobs_def, nran_def, mask, **kw)                      # default systot

cl_avg = {}
cl_avg[-1] = get_cl(nobs_w, nran_w, mask, selection_fn=None, **kw)   # wo correction

# average wNN over chains -> get C_ell
for idx in range(1, wnn['weight'].shape[1]+1):

    wsys = wnn['weight'][:, :idx].mean(axis=1)
    wsys_hp = make_hp(hpix, wsys)

    wsys_normed = normalize(wsys_hp, nobs_w, mask)

    cl_avg[idx] = get_cl(nobs_w, nran_w, mask, selection_fn=wsys_normed, **kw)
    print('.', end='')
示例#6
0
def angular_power_wcross(args, columns=maps_eboss_v7p2, comm=None):
    
    if comm.rank == 0:        
        # --- only rank 0
        zmin, zmax = args.zlim
        nside = args.nside
        use_systot = args.use_systot

        
        data_path = args.data_path
        randoms_path = args.randoms_path
        templates_path = args.templates_path
        output_path = args.output_path

        # read data, randoms, and templates
        data = EbossCat(data_path, kind='data', zmin=zmin, zmax=zmax)
        randoms = EbossCat(randoms_path, kind='randoms', zmin=zmin, zmax=zmax)

        templates = pd.read_hdf(templates_path, key='templates')
        sysm = templates[columns].values
        if nside is not None:
            assert sysm.shape[0] == 12*nside*nside, 'templates do not match with nside'
        else:
            nside = npix2nside(sysm.shape[0])
        
        # project to HEALPix
        if use_systot:
            ngal = data.to_hp(nside, zmin, zmax, raw=2)
            nran = randoms.to_hp(nside, zmin, zmax, raw=2)
        else:
            ngal = data.to_hp(nside, zmin, zmax, raw=1)
            nran = randoms.to_hp(nside, zmin, zmax, raw=1)

        # construct the mask    
        mask_nran = nran > 0
        mask_ngal = np.isfinite(ngal)
        mask_sysm = (~np.isfinite(sysm)).sum(axis=1) < 1

        mask = mask_sysm & mask_nran & mask_ngal  

        nran_bar = nside2pixarea(nside, degrees=True)*5000.

    else:
        ngal = None
        nran = None
        mask = None
        sysm = None
        nran_bar = 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)
    nran_bar = comm.bcast(nran_bar, root=0)
    
    cls_list = get_cl(ngal, nran, mask, systematics=sysm, njack=0, nran_bar=nran_bar, cross_only=args.cross_only)
    
    if comm.rank == 0:
        output_dir = os.path.dirname(output_path)
        if not os.path.exists(output_dir):
            print(f'creating {output_dir}')
            os.makedirs(output_dir)
       
        np.save(output_path, cls_list)