Beispiel #1
0
 def test_project_nn(self):
     shape,wcs = enmap.fullsky_geometry(res=np.deg2rad(12/60.),proj='car')
     shape2,wcs2 = enmap.fullsky_geometry(res=np.deg2rad(6/60.),proj='car')
     shape3,wcs3 = enmap.fullsky_geometry(res=np.deg2rad(24/60.),proj='car')
     imap = enmap.ones(shape,wcs)
     omap2 = enmap.project(imap,shape2,wcs2,order=0,mode='wrap')
     omap3 = enmap.project(imap,shape3,wcs3,order=0,mode='wrap')
     assert np.all(np.isclose(omap2,1))
     assert np.all(np.isclose(omap3,1))
Beispiel #2
0
def build_foreground_var(maps, bsize1=8, bsize2=4, scale=0.5):
    """Given maps[ncomp,ny,nx] that may contain point sources etc., return
	an estimate of the foreground variance. This can be used to downweight
	high-foreground regions."""
    vbox = np.array([[-32, -88], [-31, -90]]) * utils.degree
    # Can't use op=np.var here because downgrade does the operation in two steps
    v1 = enmap.downgrade(maps**2, bsize1, op=np.mean, inclusive=True)
    v1 -= enmap.downgrade(maps, bsize1, op=np.mean, inclusive=True)**2
    v2 = enmap.downgrade(v1, bsize2, op=np.median, inclusive=True)
    for v in v2:
        v[v == 0] = np.median(v[v != 0])
    res = np.exp(enmap.project(np.log(v2), maps.shape, maps.wcs, order=1))
    res *= scale
    return res
Beispiel #3
0
def smooth(m):
    '''
    Local smoothing of input map.
    
    Parameters
    ----------
    m : enmap
        Input map

    Returns
    -------
    m_smoothed : enmap
        Output map with same shape as input.
    '''

    m_smoothed = enmap.downgrade(m, 2)
    m_smoothed = enmap.project(m_smoothed, m.shape, m.wcs, order=1)
    return m_smoothed
Beispiel #4
0
pathMap2 = "./output/cmb_map/tilec_pact_cmbksz_v1.2.0/" + "tilec_map.fits"
pathMask = "./output/cmb_map/tilec_pact_cmbksz_v1.2.0/" + "mask_full_foot_gal_ps.fits"
pathDirOut = "./output/cmb_map/pactf150daynight20200228maskgal60r2_minus_tilec_pact_cmbksz/"
if not os.path.exists(pathDirOut):
    os.makedirs(pathDirOut)
pathOut = pathDirOut + "diff_map.fits"

# read the maps
map1 = enmap.read_map(pathMap1)[0]
map2 = enmap.read_map(pathMap2)
# reproject to the smaller TileC geometry
map1 = enmap.project(map1,
                     map2.shape,
                     map2.wcs,
                     order=1,
                     mode='constant',
                     cval=0.0,
                     force=False,
                     prefilter=True,
                     mask_nan=True,
                     safe=True)
# take the difference
diffMap = map1 - map2
enmap.write_map(pathOut, diffMap)
# copy the mask
copyfile(pathMask, pathDirOut + "mask_full_foot_gal_ps.fits")

###################################################################################3
# conversion from y to muK at 150 GHz
Tcmb = 2.726  # K
h = 6.63e-34  # SI
kB = 1.38e-23  # SI
Beispiel #5
0
# ACT point source mask

pathPSMask = "/global/cscratch1/sd/eschaan/project_ucsc/data/act_ps_mask/source_mask_s16_simonecat_sn5_cross_20171105.fits"
psMask = enmap.read_map(pathPSMask)

#########################################################################
# combine Deep56 and BOSS North maps, on the total ACT footprint
# reproject the D56 and BN maps to the overall ACT footprint
# then crop the map to reduce size

# combine the masks
tilecMaskD56 = enmap.project(tilecMaskD56,
                             psMask.shape,
                             psMask.wcs,
                             order=1,
                             mode='constant',
                             cval=0.0,
                             force=False,
                             prefilter=True,
                             mask_nan=True,
                             safe=True)
tilecMaskBN = enmap.project(tilecMaskBN,
                            psMask.shape,
                            psMask.wcs,
                            order=1,
                            mode='constant',
                            cval=0.0,
                            force=False,
                            prefilter=True,
                            mask_nan=True,
                            safe=True)
tilecMask = tilecMaskD56 + tilecMaskBN
def generate_map(qids, overwrite=False, verbose=True, dg=2, **kwargs):
    # Here we compute the real coadd map and simulated maps from the noise covariance and pre-computed fullsky signal
    # This function uses actsims "simgen" code

    for qid in qids:

        if qid in ['boss_d04', 's16_d03', 'boss_04']:
            # Here, the simulation is performed for each array, not frequency, to take into account their correlation
            # For pa3, there are two frequency bands
            if verbose:
                print('skip ' + qid +
                      ': the map is generated by running f090 case.')
            continue

        if '_d0' in qid:
            version = 'v6.3.0_calibrated_mask_version_masks_20200723'
        else:
            version = 'v6.3.0_calibrated_mask_version_padded_v1'

        # define qid_array to take into account multi-frequency case
        if qid == 'boss_d03':
            qid_array = ['boss_d03', 'boss_d04']
        elif qid == 's16_d02':
            qid_array = ['s16_d02', 's16_d03']
        elif qid == 'boss_03':
            qid_array = ['boss_03', 'boss_04']
        else:
            # single frequency case
            qid_array = [qid]

        # define filename
        aobj = {
            q: local.init_analysis_params(qid=q, **kwargs)
            for q in qid_array
        }

        # load survey mask
        mask = load_survey_mask(qid, dg=1)

        # Define an object for sim generation
        model, season, array, patch, freq = local.qid_info(qid)
        if model == 'dr5':
            simobj = simgen.SimGen(version=version, qid=qid_array, model=model)
        if model == 'act_mr3':
            simobj = simgen.SimGen(version=version, model=model)

        # save 1/var map
        if not misctools.check_path(aobj[qid_array[0]].fivar,
                                    overwrite=overwrite,
                                    verbose=verbose):
            ivars = get_ivar(qid_array, mask)
            civars = np.average(ivars, axis=1)  # coadd ivar
            for qi, q in enumerate(qid_array):
                enmap.write_map(aobj[q].fivar, civars[qi, :, :, :])

        # loop over realizations
        for i in tqdm.tqdm(aobj[qid].rlz):

            if misctools.check_path(aobj[qid].fmap['s'][i],
                                    overwrite=overwrite,
                                    verbose=verbose):
                continue

            # maps will have signal ('s') and noise ('n') and each has [Nfreq, NTPol, Coord1, Coord2]
            maps = {}

            # real data
            if i == 0:

                # take coadd data
                maps['s'] = coadd_real_data(qid_array, mask)

                # SZ map subtraction
                shape, wcs = maps['s'][0, 0, :, :].shape, maps['s'].wcs
                if q in [
                        'boss_d03', 's16_d02', 'boss_03'
                ]:  # need both freqs for combined data array of two freqs
                    sz_map_090 = enmap.project(
                        enmap.read_map(
                            'data_local/input/S18d_202006_confirmed_model_f090.fits'
                        ), shape, wcs) / local.Tcmb
                    sz_map_150 = enmap.project(
                        enmap.read_map(
                            'data_local/input/S18d_202006_confirmed_model_f150.fits'
                        ), shape, wcs) / local.Tcmb
                    maps['s'][0, 0, :, :] -= sz_map_090
                    maps['s'][1, 0, :, :] -= sz_map_150
                else:
                    sz_map = enmap.project(
                        enmap.read_map(
                            'data_local/input/S18d_202006_confirmed_model_f150.fits'
                        ), shape, wcs) / local.Tcmb
                    maps['s'][0, 0, :, :] -= sz_map

            # simulation
            else:
                maps['s'], maps['n'], ivars = simobj.get_sim(season,
                                                             patch,
                                                             array,
                                                             sim_num=i,
                                                             set_idx=0)

                # coadd with civars weight implicitly multiplied
                civars = np.average(ivars, axis=1)
                civars[civars == 0] = np.inf
                maps['s'] = mask[None, None, :, :] * np.average(
                    maps['s'] * ivars, axis=1) / civars / local.Tcmb
                maps['n'] = mask[None, None, :, :] * np.average(
                    maps['n'] * ivars, axis=1) / civars / local.Tcmb

                # downgrade
                maps['s'] = enmap.downgrade(maps['s'], dg)
                maps['n'] = enmap.downgrade(maps['n'], dg)

            # save signal and noise to files
            for s in ['s', 'n']:
                if s == 'n' and i == 0:
                    continue  # real data is saved to a signal file
                for qi, q in enumerate(qid_array):
                    enmap.write_map(aobj[q].fmap[s][i], maps[s][qi, :, :, :])
        ratio[hitmap == 0] = np.nan

        plot = enplot.plot(hitmap, **plot_opts)
        enplot.write(opj(mapdir, 'hits'), plot)

        plot = enplot.plot(cutmap, **plot_opts)
        enplot.write(opj(mapdir, 'cuts'), plot)

        plot = enplot.plot(ratio, min=0, max=args.range, **plot_opts)
        enplot.write(opj(mapdir, 'ratio'), plot)

        if args.signal_map is not None:

            ratio[hitmap == 0] = 0.
            ratio_sm = enmap.downgrade(ratio, 32 / float(args.downgrade))
            ratio_sm = enmap.project(ratio_sm, ratio.shape, ratio.wcs, order=1)

            contours = '0.003, 0.01'
            contour_layer = enplot.plot(ratio_sm,
                                        contours=contours,
                                        no_image=True,
                                        contour_width=2,
                                        contour_color='hotcold',
                                        min=0,
                                        max=args.range,
                                        **plot_opts)
            enplot.write(opj(mapdir, 'ratio_contour'), contour_layer)

            signal_layer = enplot.plot(signal,
                                       layers=True,
                                       min=-300,
Beispiel #8
0
"""
Loads a catalog
Maps it
Smooths it
Thresholds it
Projects it onto ACT
This gives a mask of 1s and 0s from which a random catalog can be made
"""


paths = cutils.paths
#cat_type = "wise_panstarrs"
#cat_type = "madcows_photz"
cat_type = args.sys[1]
meanfield = False

# cat_type = "sdss_redmapper"
# meanfield = True

shape,wcs = enmap.fullsky_geometry(res=1 * utils.degree)
ras,decs,_ = cutils.catalog_interface(cat_type,is_meanfield=meanfield)
cmapper = catalogs.CatMapper(ras,decs,shape=shape,wcs=wcs)
cmap = maps.binary_mask(enmap.smooth_gauss(cmapper.counts,2 * utils.degree),1e-3)
io.hplot(cmap,'counts')


shape,wcs = enmap.read_map_geometry(paths.coadd_data + f"act_planck_s08_s18_cmb_f150_daynight_srcfree_map.fits")
omap = enmap.project(cmap,shape,wcs,order=0)
io.plot_img(omap,'pcounts')
enmap.write_map(f'{paths.scratch}{cat_type}_mask.fits',omap)
Beispiel #9
0
def project_mask(mask, shape, wcs, fname=None):
    sim_mask = enmap.project(mask, shape, wcs, order=1)
    if fname != None:
        enmap.write_fits(fname, sim_mask, extra={})
Beispiel #10
0
pathPSMask = "/global/cscratch1/sd/eschaan/project_ksz_act_planck/data/act_ps_mask/source_mask_s16_simonecat_sn5_cross_20171105.fits"
psMask = enmap.read_map(pathPSMask)

# In[16]:

psMask = (psMask > 0.95).astype(np.float)

# In[17]:

# project to TileC footprint
psMask = enmap.project(psMask,
                       footMask.shape,
                       footMask.wcs,
                       order=1,
                       mode='constant',
                       cval=0.0,
                       force=False,
                       prefilter=True,
                       mask_nan=True,
                       safe=True)

# In[18]:

# plot=enplot.plot(psMask, downgrade=1, min=0., max=1.)
# enplot.show(plot)

# # Full mask: footprint + Galactic + point sources

# In[23]:

fullMask = footMask * planckMask * psMask
Beispiel #11
0
from orphics import maps,io,cosmology,catalogs
from pixell import enmap,reproject
import numpy as np
import os,sys,shutil
from soapack import interfaces as sints
import healpy as hp

box = np.deg2rad([ [11,-173.5],
                   [13.5,-171] ])



rosat = enmap.read_map("/scratch/r/rbond/msyriac/data/for_sigurd/rosat_r7_boss.fits").submap(box)

print(rosat.shape,maps.resolution(rosat.shape,rosat.wcs) * 180.*60./np.pi)

version = "map_v1.0.0_rc_joint"
cversion = "v1.0.0_rc"
region = 'boss'
yname = "/scratch/r/rbond/msyriac/data/depot/tilec/v1.0.0_rc_20190919/%s_%s/tilec_single_tile_%s_comptony_%s.fits" % (version,region,region,version)

ymap = enmap.read_map(yname).submap(box)
print(ymap.center()*180./np.pi)
rosat = enmap.project(rosat,ymap.shape,ymap.wcs)


io.hplot(np.log10(rosat),'fig_virgo_rosat')
#io.hplot(enmap.smooth_gauss(ymap,np.deg2rad(3./60.)),'fig_virgo_act',color='gray') #,min=-1.25e-5,max=3.0e-5
io.hplot(ymap,'fig_virgo_act',color='gray') #,min=-1.25e-5,max=3.0e-5

Beispiel #12
0
map1_srfree = map_path + 's17_cmb_pa4_f150_nohwp_night_1pass_2way_set1_map_srcfree.fits'
ivar1 = map_path + 's17_cmb_pa4_f150_nohwp_night_1pass_2way_set1_ivar.fits'
map1 = map_path + 's17_cmb_pa4_f150_nohwp_night_1pass_2way_set1_map.fits'
map1sz = map_path + 's17_cmb_pa4_f150_nohwp_night_1pass_2way_set1_map_src_sz.fits'

imap0 = enmap.read_map(map0_srfree, )
imap1 = enmap.read_map(map1_srfree, )

ivar0 = enmap.read_map(ivar0, )
ivar1 = enmap.read_map(ivar1, )

#################################################################################################################################
#create pixel map
shape = imap0.shape
wcs = imap0.wcs
mask = enmap.project(mask, shape, wcs, order=1)
pmap = enmap.pixsizemap(shape, wcs)

map_list = [imap0, imap1]
ivar_list = [ivar0, ivar1]

pol_a = 0
pol_b = 0
#calculate the flattened power spectrum used to produce simulations
cls = simgen.get_power(map_list, ivar_list, pol_a, pol_b, mask, N=5)
np.savetxt(f'/global/homes/j/jia_qu/sim_gen/flattened{pol_a}{pol_b}.txt', cls)
plot_cl = False
if plot_cl:
    ls = np.arange(cls.size)
    print(cls)
    plt.plot(ls, cls, label='cls')