Exemple #1
0
def get_patch(coords, sim_idx, map_type, cmb_type, pixel_fac = 2):
    shape,wcs = enmap.fullsky_geometry(res=1.0*np.pi/180./60.)

    def _process_coords(coords):
        coords = np.array(coords)
        if coords[1,1] > 180. : coords[1,1] -= 360.
        if coords[0,1] > 180. : coords[0,1] -= 360.

        coords *= np.pi/180.
        return coords

    zpsim_idx = '%05d' %sim_idx
    coords = _process_coords(coords)

    file_name = sim_file_temp.format(zpsim_idx, map_type, cmb_type, zpsim_idx)
    emap = enmap.read_fits(file_name, box=coords, wcs_override=wcs)

    nshape = tuple(np.array([i for i in emap.shape])*2)
    data   = simTools.resample_fft_withbeam(emap, nshape, doBeam=False, beamData=None)
    oshape, owcs = enmap.scale_geometry(emap.shape, emap.wcs, pixel_fac)

    assert(oshape == nshape)
    pmap   = enmap.enmap(data, owcs)

    return emap.to_flipper()
Exemple #2
0
parser.add_argument("div")
parser.add_argument("ofile", nargs="?", default="/dev/stdout")
parser.add_argument("-d", "--downgrade", type=int, default=1)
parser.add_argument("-t", "--thin", type=int, default=1000)
parser.add_argument(
    "-A",
    "--area-model",
    type=str,
    default="exact",
    help=
    "How to model pixel area. exact: Compute shape of each pixel. average: Use a single average number for all"
)
parser.add_argument("--already-arcmin", action="store_true")
args = parser.parse_args()

div = enmap.read_fits(args.div)
if args.downgrade:
    div = enmap.downgrade(div, args.downgrade)
    div *= args.downgrade**2

div = div.reshape((-1, ) + div.shape[-2:])[0]
# Individual pixel area
if args.area_model == "average":
    pix_area = div * 0 + div.area() / div.size * (180 * 60 / np.pi)**2
else:
    pos = div.posmap()
    diffs = utils.rewind(pos[:, 1:, 1:] - pos[:, :-1, :-1], 0)
    pix_area = np.abs(diffs[0] * diffs[1]) * np.cos(pos[0, :-1, :-1])
    del diffs
    # Go to square arcmins
    pix_area /= utils.arcmin**2
Exemple #3
0
import numpy as np
import os, sys

# directory setup
postfix = 'simple_test_output'
output_dir = os.path.join('./', postfix)
output_path = lambda x: os.path.join(output_dir, x)
resource_dir = pitas.config.get_resource_dir()
resource_path = lambda x: os.path.join(resource_dir, x)

pitas.pitas_io.create_dir(output_dir)

# miscs
lmax = 3000
bin_edges = pitas.util.get_default_bin_edges(lmax)
taper = enmap.read_fits(resource_path('test_taper.fits'))

# initialize pitas (if it is a first time, it will take few minutes to compute mode coupling)
overwrite = True
transfer = None  # no transfer function here
mcm_identifier = "simple_test"  # we can tag mode coupling matrix with a string. If PITAS finds the precomputed mcm with the same tag, it automatically reloads. Set overwrite=True if you don't want this.
pitas_lib = pitas.power.PITAS(mcm_identifier, taper, taper, bin_edges, lmax,
                              transfer, overwrite)
binner = pitas_lib.binner
lbin = pitas_lib.bin_center

# load sims (unlensed 15x15 sq deg)
tmap, qmap, umap = enmap.read_fits(resource_path('test_tqu2.fits'))
tmap -= np.mean(tmap)
qmap -= np.mean(qmap)
umap -= np.mean(umap)
Exemple #4
0
mfs = {}
for pcomb in polcombs:
    if not(args.load_meanfield is None):
        mfs[pcomb] = enmap.read_hdf(args.load_meanfield+"_mf_"+pcomb+".hdf")
    else:
        mfs[pcomb] = 0.

inited = False
for i,task in enumerate(my_tasks):


    filename = lambda x,ext="fits",k=task: args.SimRoot+"_"+x+"_"+str(k).zfill(4)+args.save+"."+ext
    try:
        if args.flat and args.flat_force: raise
        if not(args.save_meanfield is None): raise
        cpatch = enmap.read_fits(filename("lensed"),box=box if not(args.flat) else None,wcs_override=fwcs if not(args.flat) else None)
        kpatch = enmap.read_fits(filename("kappa"),box=box if not(args.flat) else None,wcs_override=fwcs if not(args.flat) else None)
        if i==0: shape,wcs = cpatch.shape,cpatch.wcs
    except:
        assert args.flat or not(args.save_meanfield is None), "No sims found in directory specified. I can only make lensed sims if they are flat-sky."
        if not(inited): 
            if not(args.save_meanfield is None) and not(args.flat):
                template = enmap.read_fits(filename("lensed","fits",0),box=box if not(args.flat) else None,wcs_override=fwcs if not(args.flat) else None)
                shape,wcs = template.shape,template.wcs 
            else:
                shape,wcs = enmap.geometry(pos=box,res=args.res*np.pi/180./60., proj="car")
                if pol: shape = (3,) + shape
            mgen, kgen = init_flat(shape[-2:],wcs)
        inited = True
        unlensed = mgen.get_map(iau=args.iau)
def load(suffix, index):
    return enmap.read_fits(args.path + "_" + suffix + "_" +
                           str(index).zfill(int(np.log10(args.nsim)) + 1) +
                           ".fits")
#        if PS15mJy_rep[i][:][:].all()==True:
#                PS15mJy_cut[i]=1
#        if PS100mJy_rep[i][:][:].all()==True:
#                PS100mJy_cut[i]=1
#
#
#print 'len PS15', len(PS15mJy)
#print 'Pass:'******'Fail:', len([x for x in PS15mJy_cut if x==0])
#print 'len PS100', len(PS100mJy)
#print 'Pass:'******'Fail:', len([x for x in PS100mJy_cut if x==0])

######## Mask Component Separated Map Areas (D56 and BN)
#
d56mask = enmap.read_fits(pathd56mask, hdu=None, sel=None, sel_threshold=10e6)
bnmask = enmap.read_fits(pathbnmask, hdu=None, sel=None, sel_threshold=10e6)

subs = 18  #in number of pixels

pixarrayd56 = enmap.sky2pix(d56mask.shape,
                            d56mask.wcs,
                            np.vstack((dec, ra)) * np.pi / 180.,
                            safe=True)
radpixelsd56 = pixarrayd56[1, :]
decdpixelsd56 = pixarrayd56[0, :]

pixarraybn = enmap.sky2pix(bnmask.shape,
                           bnmask.wcs,
                           np.vstack((dec, ra)) * np.pi / 180.,
                           safe=True)
Exemple #7
0
            theo_idx  = 'clee'
            frac_diff =  (clbin - theo_bin[theo_idx])/theo_bin[theo_idx]
            st.add_to_stats('frac%s_deconv'%'ee', frac_diff)

            theo_idx  = 'clbb'
            frac_diff =  (clbin - theo_bin[theo_idx])/theo_bin[theo_idx]
            st.add_to_stats('frac%s_deconv'%'bb', frac_diff)

st = stats.Stats(cmblens.mpi.comm)
for sim_idx in subtasks:
    log.info("processing %d" %sim_idx)
    sim_idx_str = str(sim_idx)
    sim_idx_str = sim_idx_str.zfill(5)

    tmap = enmap.read_fits("/global/cscratch1/sd/engelen/simsS1516_v0.2/data/cmb_set00_%s/fullskyUnlensedMap_T_%s.fits" %(sim_idx_str, sim_idx_str))
    tmap -= np.mean(tmap)
    #tmap, qmap, umap  = get_sim(sim_idx, mode='actsim') 
    #tmap *= taper
    #qmap *= taper
    #umap *= taper

    #emap, bmap = cusps.util.qu2eb(qmap, umap)
    #emap, bmap = qu2eb(qmap, umap)

    #if sim_idx == 0:
    #    io.high_res_plot_img(tmap, output_path('tmap_unlen_%d.png'%sim_idx), down=3)
    #    io.high_res_plot_img(qmap, output_path('qmap_unlen_%d.png'%sim_idx), down=3)
    #    io.high_res_plot_img(umap, output_path('umap_unlen_%d.png'%sim_idx), down=3)
    #    io.high_res_plot_img(emap, output_path('emap_unlen_%d.png'%sim_idx), down=3)
    #    io.high_res_plot_img(bmap, output_path('bmap_unlen_%d.png'%sim_idx), down=3)
Exemple #8
0
st = cmblens.stats.STATS(stat_identifier=mcm_identifier)
lbin = None
for sim_idx in subtasks:
    log.info("processing: %d" % sim_idx)

    if st.has_data('clbb_lensed_frac', sim_idx): continue

    zpsim_idx = '%05d' % sim_idx
    for map_type, cmb_type in product(map_types, cmb_types):
        log.info("processing %s" % (((map_type, cmb_type), )))

        file_name = sim_file_temp.format(zpsim_idx, map_type, cmb_type,
                                         zpsim_idx)
        log.info("loading %s" % file_name)

        emap = enmap.read_fits(file_name)

        theo_key = 'cl' + (cmb_type.lower() * 2)
        stat_key = theo_key + '_' + map_type.lower()
        frac_key = stat_key + '_frac'

        lbin, clbin = add_raw_spec(st, stat_key, sim_idx, emap)
        add_frac_diff(st, frac_key, sim_idx, clbin,
                      theo_bin[map_type.lower()][theo_key])

        del emap
        # load unlensed

    cmblens.mpi.barrier()
    ret = st.get_stats()
Exemple #9
0
import numpy as np, argparse
from enlib import enmap, utils, bench
parser = argparse.ArgumentParser()
parser.add_argument("div")
parser.add_argument("ofile", nargs="?", default="/dev/stdout")
parser.add_argument("-d", "--downgrade", type=int, default=1)
parser.add_argument("-t", "--thin", type=int, default=1000)
parser.add_argument("-A", "--area-model", type=str, default="exact", help="How to model pixel area. exact: Compute shape of each pixel. average: Use a single average number for all")
args = parser.parse_args()

div = enmap.read_fits(args.div)
if args.downgrade:
	div  = enmap.downgrade(div, args.downgrade)
	div *= args.downgrade**2

div = div.reshape((-1,)+div.shape[-2:])[0]
# Individual pixel area
if args.area_model == "average":
	pix_area = div*0 + div.area()/div.size*(180*60/np.pi)**2
else:
	pos   = div.posmap()
	diffs = utils.rewind(pos[:,1:,1:]-pos[:,:-1,:-1],0)
	pix_area = np.abs(diffs[0]*diffs[1])*np.cos(pos[0,:-1,:-1])
	del diffs
	# Go to square arcmins
	pix_area /= utils.arcmin**2
	# Pad to recover edge pixels
	pix_area = np.concatenate([pix_area,pix_area[-1:]],0)
	pix_area = np.concatenate([pix_area,pix_area[:,-1:]],1)

# Flatten everything