Esempio n. 1
0
def create_map(width_deg = 20., px_res_arcmin = 0.5, Ngals = 10000000):
    shape,wcs = omaps.rect_geometry(width_deg = width_deg, px_res_arcmin = px_res_arcmin)
    bounds = enmap.box(shape,wcs)*180./np.pi
    Ngals = Ngals
    ras = np.random.uniform(bounds[0,1], bounds[1,1], Ngals) 
    decs = np.random.uniform(bounds[0,0], bounds[1,0], Ngals)
    cmapper = cats.CatMapper(ras, decs, shape, wcs)
    delta = cmapper.counts/cmapper.counts.mean()-1.
    modlmap = cmapper.counts.modlmap()
    
    #result = {'shape': shape, 'wcs': wcs, 'delta': delta} #PIPE
    result = OrderedDict([('shape', shape), ('wcs', wcs), ('delta', delta), ('modlmap', modlmap)])

    return result
Esempio n. 2
0
    def __init__(self, 
             lens_beam = 7.0,lens_noiseT = 33.,lens_noiseP = 56.,
             lens_tellmin = 2,lens_tellmax = 3000,lens_pellmin = 2,
             lens_pellmax = 3000,lens_kmin = 80,lens_kmax = 2000, lens_f_sky=0.65 ):

        # get lensing noise
        # Initialize cosmology and Clkk. Later parts need dimensionless spectra.
        self.l_min = lens_tellmin
        self.l_max = lens_tellmax
        self.k_min = lens_kmin
        self.k_max = lens_kmax
        self.f_sky = lens_f_sky
        cc = cosmology.Cosmology(lmax=self.l_max,pickling=True,dimensionless=True)
        theory = cc.theory
        ells = np.arange(2,self.l_max,1)
        clkk = theory.gCl('kk',ells)

        # Make a map template for calculating the noise curve on
        shape,wcs = maps.rect_geometry(width_deg = 5.,px_res_arcmin=1.5)
        # Define bin edges for noise curve
        bin_edges = np.arange(80,lens_kmax,20)
        nlgen = lensing.NlGenerator(shape,wcs,theory,bin_edges,lensedEqualsUnlensed=True)
        # Experiment parameters, here for Planck
        polCombs = ['TT','TE','EE','EB','TB']

        _,_,_,_ = nlgen.updateNoise(
            beamX=lens_beam,noiseTX=lens_noiseT,noisePX=lens_noiseP,
            tellminX=lens_tellmin,tellmaxX=lens_tellmax,
            pellminX=lens_pellmin,pellmaxX=lens_pellmax)

        ls,nls,bells,nlbb,efficiency = nlgen.getNlIterative(polCombs,lens_kmin,lens_kmax,
                                                            lens_tellmax,lens_pellmin,lens_pellmax,
                                                            verbose=True,plot=False)

        self.orphics_kk = clkk
        self.orphics_ls = ls
        self.orphics_nls = nls
        self.noise_k = np.interp(np.arange(self.l_max+1), ls, nls)

        self.noise_k[np.arange(self.l_max+1) <= lens_kmin] = 1e100
        self.noise_k[np.arange(self.l_max+1) >= lens_kmax] = 1e100
Esempio n. 3
0
def enmap_from_config_section(Config, section, pol=False):
    analysis_section = section

    projection = Config.get(analysis_section, "projection")
    try:
        pt_file = Config.get(analysis_section, "patch_template")
        imap = enmap.read_map(pt_file)
        shape_dat = imap.shape
        wcs_dat = imap.wcs
        if pol and len(shape_dat) < 3:
            shape_dat = (3, shape_dat[0], shape_dat[1])
        res = np.min(imap.extent() / imap.shape[-2:]) * 60. * 180. / np.pi

    except:
        pixel_analysis = Config.getfloat(analysis_section, "pixel_arcmin")
        try:
            width_analysis_deg = Config.getfloat(analysis_section,
                                                 "patch_degrees_width")
        except:
            width_analysis_deg = Config.getfloat(analysis_section,
                                                 "patch_arcmin_width") / 60.
        try:
            height_analysis_deg = Config.getfloat(analysis_section,
                                                  "patch_degrees_height")
        except:
            height_analysis_deg = Config.getfloat(analysis_section,
                                                  "patch_arcmin_height") / 60.
        ra_offset = Config.getfloat(analysis_section, "ra_offset")
        dec_offset = Config.getfloat(analysis_section, "dec_offset")

        shape_dat, wcs_dat = maps.rect_geometry(
            width_analysis_deg * 60.,
            pixel_analysis,
            proj=projection,
            pol=pol,
            height_arcmin=height_analysis_deg * 60.,
            xoffset_degree=ra_offset,
            yoffset_degree=dec_offset)

    return shape_dat, wcs_dat
Esempio n. 4
0
def lensNoise(Config,
              expName,
              lensName,
              beamOverride=None,
              noiseTOverride=None,
              lkneeTOverride=None,
              lkneePOverride=None,
              alphaTOverride=None,
              alphaPOverride=None,
              tellminOverride=None,
              pellminOverride=None,
              tellmaxOverride=None,
              pellmaxOverride=None,
              deg=5.,
              px=1.0,
              gradCut=10000,
              bigell=9000,
              plot=False,
              theoryOverride=None,
              lensedEqualsUnlensed=True,
              noiseFuncT=None,
              noiseFuncP=None):

    from orphics.io import list_from_config

    beam = list_from_config(Config, expName, 'beams')
    noise = list_from_config(Config, expName, 'noises')
    freq = list_from_config(Config, expName, 'freqs')
    lkneeT, lkneeP = list_from_config(Config, expName, 'lknee')
    alphaT, alphaP = list_from_config(Config, expName, 'alpha')
    if (noiseFuncT is None) and (noiseFuncP is None):
        print 'Not using noise files for generating lensing noise'
    else:
        print 'Using noise files for generating lensing noise'
    tellmin, tellmax = list_from_config(Config, expName, 'tellrange')
    if tellminOverride is not None: tellmin = tellminOverride
    if tellmaxOverride is not None: tellmax = tellmaxOverride
    pellmin, pellmax = list_from_config(Config, expName, 'pellrange')
    if pellminOverride is not None: pellmin = pellminOverride
    if pellmaxOverride is not None: pellmax = pellmaxOverride
    lmax = int(Config.getfloat(expName, 'lmax'))

    pols = Config.get(lensName, 'polList').split(',')
    freq_to_use = Config.getfloat(lensName, 'freq')
    ind = np.where(np.isclose(freq, freq_to_use))
    beamFind = np.array(beam)[ind]
    noiseFind = np.array(noise)[ind]
    assert beamFind.size == 1
    assert noiseFind.size == 1
    if beamOverride is not None:
        beamX = beamY = beamOverride
    else:
        beamX = beamY = beamFind[0]
    if noiseTOverride is not None:
        noiseTX = noiseTY = noiseTOverride
    else:
        noiseTX = noiseTY = noiseFind[0]
    if lkneeTOverride is not None: lkneeT = lkneeTOverride
    if lkneePOverride is not None: lkneeP = lkneePOverride
    if alphaTOverride is not None: alphaT = alphaTOverride
    if alphaPOverride is not None: alphaP = alphaPOverride

    from orphics.lensing import NlGenerator, getMax
    from orphics import maps
    #deg = 5.
    #px = 1.0
    dell = 10
    kellmin = 10
    shape, wcs = maps.rect_geometry(width_deg=deg, px_res_arcmin=px)

    kellmax = max(tellmax, pellmax)

    if theoryOverride is None:
        from orphics.cosmology import Cosmology
        cc = Cosmology(lmax=int(kellmax), pickling=True)
        theory = cc.theory
    else:
        theory = theoryOverride
        cc = None
    bin_edges = np.arange(kellmin, kellmax, dell)
    myNls = NlGenerator(shape,
                        wcs,
                        theory,
                        bin_edges,
                        gradCut=gradCut,
                        bigell=bigell,
                        unlensedEqualsLensed=lensedEqualsUnlensed)
    myNls.updateNoise(beamX,
                      noiseTX,
                      np.sqrt(2.) * noiseTX,
                      tellmin,
                      tellmax,
                      pellmin,
                      pellmax,
                      beamY=beamY,
                      noiseTY=noiseTY,
                      noisePY=np.sqrt(2.) * noiseTY,
                      lkneesX=(lkneeT, lkneeP),
                      lkneesY=(lkneeT, lkneeP),
                      alphasX=(alphaT, alphaP),
                      alphasY=(alphaT, alphaP),
                      noiseFuncTX=noiseFuncT,
                      noiseFuncTY=noiseFuncT,
                      noiseFuncPX=noiseFuncP,
                      noiseFuncPY=noiseFuncP)

    lsmv, Nlmv, ells, dclbb, efficiency = myNls.getNlIterative(pols,
                                                               kellmin,
                                                               kellmax,
                                                               tellmax,
                                                               pellmin,
                                                               pellmax,
                                                               dell=dell,
                                                               halo=True,
                                                               plot=plot)

    return lsmv, Nlmv, ells, dclbb, efficiency, cc
Esempio n. 5
0
from orphics import maps, cosmology, io
from enlib import enmap, lensing
import numpy as np

theory_file_root = "../alhazen/data/Aug6_highAcc_CDM"
theory = cosmology.loadTheorySpectraFromCAMB(theory_file_root,
                                             unlensedEqualsLensed=False,
                                             useTotal=False,
                                             TCMB=2.7255e6,
                                             lpad=9000,
                                             get_dimensionless=False)

shape, wcs = maps.rect_geometry(width_deg=10., px_res_arcmin=0.5)

lmax = 4000
ells = np.arange(0, lmax, 1)

cltt = theory.uCl('TT', ells)
pstt = cltt.reshape((1, 1, ells.size))
cgen = maps.MapGen(shape, wcs, pstt)

imap = cgen.get_map()
clpp = np.nan_to_num(theory.gCl('kk', ells) * 4. / ells**4.)

psphi = clpp.reshape((1, 1, ells.size))
phigen = maps.MapGen(shape, wcs, psphi)
phi = phigen.get_map()
grad_phi = enmap.grad(phi)
omap = lensing.lens_map(imap,
                        grad_phi,
                        order=3,
Esempio n. 6
0
from __future__ import print_function
from orphics import maps,io,cosmology,stats
from pixell import enmap
import numpy as np
import os,sys
import symlens


nsims = 40
deg = 25.
px = 2.0

shape,wcs = maps.rect_geometry(width_deg=deg,px_res_arcmin=px,proj='plain')


modlmap = enmap.modlmap(shape,wcs)
ymap,xmap = enmap.posmap(shape,wcs)

omap = np.sin(ymap/np.pi*100) + np.cos(xmap/np.pi*100)
mfact = 10
afact = 20
rms = (omap - omap.min())*mfact + afact
# io.hplot(rms,colorbar=True)

pmap = enmap.pixsizemap(shape,wcs)

ivar = maps.ivar(shape,wcs,rms,ipsizemap=pmap)
# io.hplot(ivar,colorbar=True)

my_tasks = range(nsims)
Esempio n. 7
0
                                                 bin_annulus=20,
                                                 lknee_guess=3000,
                                                 alpha_guess=-4,
                                                 method="fft",
                                                 radial_fit=True)

#io.plot_img(np.fft.fftshift(np.log10(ndown)),"ndown.png",aspect='auto',lim=[-6,3])
#io.hplot(np.fft.fftshift(np.log10(ndown)),"hndown")
io.hplot(np.fft.fftshift((ndown)), "hndown")
io.plot_img(np.fft.fftshift(ndown / nfitted), "nunred.png", aspect='auto')

nmod = ndown / nfitted
enmap.write_map("anisotropy_template.fits", enmap.samewcs(nmod, npower))

shape, wcs = maps.rect_geometry(width_deg=50.,
                                height_deg=30,
                                px_res_arcmin=0.5)
rms = 10.0
lknee = 3000
alpha = -3
n2d = covtools.get_anisotropic_noise(shape, wcs, rms, lknee, alpha)
modlmap = enmap.modlmap(shape, wcs)
bin_edges = np.arange(100, 8000, 100)
binner = stats.bin2D(modlmap, bin_edges)
cents, n1d = binner.bin(n2d)

pl = io.Plotter(yscale='log', xlabel='l', ylabel='C')
pl.add(cents, n1d)
pl.add(cents, covtools.rednoise(cents, rms, lknee=lknee, alpha=alpha), ls="--")
pl.done()
Esempio n. 8
0
from __future__ import print_function
from orphics import maps,cosmology
from pixell import enmap
import numpy as np
import os,sys
from symlens import qe
from enlib import bench

# Say we want analytic RDN0 for the TTTE estimator
XY='TE'
UV='TE'

# example geometry, you can use your own map's geometry
shape,wcs = maps.rect_geometry(width_deg=25.,px_res_arcmin=2.0)
modlmap = enmap.modlmap(shape,wcs)

# symlens QEs always need you to specify 2d Fourier space masks
# for the CMB, and also for the final lensing k-mask
# For the CMB I use our typical ranges
ellmin = 500 ; ellmax = 3000
# and create a 2d mask (you can pass lxcut, lycut etc. if you want
# or use the 2d masks you already have for your analysis)
cmb_kmask = maps.mask_kspace(shape,wcs,lmin=ellmin,lmax=ellmax)
# Similarly, I create a final lensing k-mask which can go to lower L
Lmin = 100 ; Lmax = 3000
lens_kmask = maps.mask_kspace(shape,wcs,lmin=Lmin,lmax=Lmax)

# You always need a feed_dict to specify various 2d power spectra
feed_dict = {}
# We need some theory spectra. You'll have your own way to get them,
# but I'll load them with orphics
Esempio n. 9
0
import mlflow
from orphics import maps

data_dir = config.default_data_dir
sehgal_dir = os.path.join(data_dir, 'sehgal')
cuda = True
compts = ["kappa", "ksz", "tsz", "ir_pts", "rad_pts"]
compt_idxes = [0, 1, 2, 3, 4]
shape = (len(compt_idxes), 128, 128)
sample_interval = 200
save_interval = 5
batch_size = 32
nepochs = 100
norm_info_file = "/home/dwhan89/workspace/cosmikyu/data/sehgal/281020_logzshrink_normalization_info_validation.npz"

_, wcs = maps.rect_geometry(width_arcmin=64., px_res_arcmin=0.5)

# Configure data loader
os.makedirs(data_dir, exist_ok=True)
os.makedirs(sehgal_dir, exist_ok=True)
SDN = transforms.SehgalDataNormalizerScaledLogZShrink(norm_info_file)
SC = transforms.SehgalSubcomponets(compt_idxes)
RF = transforms.RandomFlips(p_v=0.5, p_h=0.5)
SDS_train = datasets.SehgalDataSet(sehgal_dir,
                                   data_type="train141020",
                                   transforms=[SDN, RF, SC],
                                   dummy_label=True)

dataloader = torch.utils.data.DataLoader(
    SDS_train,
    batch_size=batch_size,
Esempio n. 10
0
args = parser.parse_args()

# Theory
theory_file_root = "../alhazen/data/Aug6_highAcc_CDM"
cc = counts.ClusterCosmology(skipCls=True)
theory = cosmology.loadTheorySpectraFromCAMB(theory_file_root,
                                             unlensedEqualsLensed=False,
                                             useTotal=False,
                                             TCMB=2.7255e6,
                                             lpad=9000,
                                             get_dimensionless=False)

# Geometry

shape, wcs = maps.rect_geometry(width_arcmin=args.arc,
                                px_res_arcmin=args.pix,
                                pol=False)
modlmap = enmap.modlmap(shape, wcs)
modrmap = enmap.modrmap(shape, wcs)
bshape, bwcs = maps.rect_geometry(width_arcmin=args.arc * args.buffer_factor,
                                  px_res_arcmin=args.pix,
                                  pol=False)
bmodlmap = enmap.modlmap(bshape, bwcs)
bmodrmap = enmap.modrmap(bshape, bwcs)

#gshape, gwcs = maps.rect_geometry(width_arcmin=args.arc,px_res_arcmin=0.1953125,pol=False)
gshape, gwcs = maps.rect_geometry(width_arcmin=100.,
                                  px_res_arcmin=args.pix,
                                  pol=False)
gshape, gwcs = bshape, bwcs
gmodlmap = enmap.modlmap(gshape, gwcs)
Esempio n. 11
0
File: sims.py Progetto: mntw/szar
 def get_ksz_special(self,mass_index,snap,tcmb=2.7255e6):
     shape,wcs = fmaps.rect_geometry(width_arcmin=20.,px_res_arcmin=old_div(20.,128.))
     return self.get_map('kszN',mass_index,snap,shape=shape,wcs=wcs)*tcmb
Esempio n. 12
0
parser.add_argument("--sim-location",
                    type=str,
                    default=None,
                    help="Path to sims.")
parser.add_argument("--norm-file",
                    type=str,
                    default="norm.txt",
                    help="Norm file.")
parser.add_argument("--dtype", type=int, default=64, help="dtype bits")
args = parser.parse_args()
dtype = np.complex128 if args.dtype == 64 else np.complex64

# Resolution
res = args.res
shape, wcs = maps.rect_geometry(width_deg=args.width,
                                px_res_arcmin=res,
                                proj="car")
mlmax = max(args.lmaxt, args.lmaxp) + 500

# Sim location
try:
    if args.sim_location is not None: raise
    from soapack import interfaces as sints
    sim_location = sints.dconfig['actsims']['signal_path']
except:
    sim_location = args.sim_location
    assert sim_location is not None

# Beam and noise
ells = np.arange(mlmax)
Esempio n. 13
0
def make_circular_geometry(shape,
                           wcs,
                           context_arcmin,
                           hole_arcmin,
                           power2d,
                           buffer_factor=2,
                           verbose=False):
    '''Makes the circular geometry matrices that need to be pre-calculated for later inpainting.

    Arguments
    ---------

    input2DPower - ndarray containing 2D power spectrum of a map. It need not already have been
                   downsampled to the shape of the stamp cutout
    inputLy
    inputLx      - the fourier wavenumbers corresponding to the y and x axes of the stamp cutout
    stampArc     - the width in arcminutes of the stamp cut out
    stampPxX      - the pixel width in arcminutes of the stamp cut out in the x direction
    stampPxY      - the pixel width in arcminutes of the stamp cut out in the y direction
    holeArc      - the radius of the circular hole in arcminutes
    bufferFactor - the pixel covariance matrix will be calculated on a periodic stamp larger by this
                   factor
    verbose      - True if you want more commentary

    Returns
    -------

    meanMul      - a matrix that has shape (nh,nc) where nh is the number of pixels in the hole and
                   nc is the number of pixels outside (in the "context"). It should be multiplied
                   by a vector (nc) containing pixels outside to get a vector (nh) for the mean
                   value of the pixels inside
    covRoot      - a (nh,nh) sqrt(covariance matrix) that can be used to generate a random realization
                   in the hole. This can be generated by multiplying the sqrt of cov by a vector (nh)
                   of standard normal variables. The generated vector should be added to the mean value
                   obtained using meanMul
    pcov         - the pixel-pixel covariance matrix used in intermediate steps, if you want to re-use it
    targetTemplate - a liteMap template of the stamp cutout
    m1           - a boolean array that can be used to select the hole region
    m2           - a boolean array that can be used to select the context region


    '''

    arc = context_arcmin
    res = maps.resolution(shape, wcs) * 60. * 180. / np.pi

    bshape, bwcs = maps.rect_geometry(width_arcmin=arc * buffer_factor,
                                      px_res_arcmin=res)
    tshape, twcs = maps.rect_geometry(width_arcmin=arc, px_res_arcmin=res)
    sny, snx = tshape
    bmodlmap = enmap.modlmap(bshape, bwcs)
    modlmap = enmap.modlmap(shape, wcs)

    if verbose: print("Downsampling...")
    Niy, Nix = shape[-2:]
    Noy, Nox = bshape[-2:]

    # print(bshape,tshape,power2d.shape)
    # io.plot_img(np.fft.fftshift(np.log10(power2d)))
    #out_power = resample.resample_fft(power2d,bshape[-2:],axes=[-2,-1])
    #out_power = np.fft.ifftshift(resample.resample_fft(np.fft.fftshift(power2d),bshape[-2:],axes=[-2,-1]))
    out_power = resample.resample_bin(
        power2d, factors=[float(Noy) / Niy, float(Nox) / Nix], axes=[-2, -1])
    # io.plot_img(np.fft.fftshift(np.log10(out_power)))
    # print(out_power.shape)

    if verbose: print("Starting slow part...")
    d = maps.diagonal_cov(out_power)
    with bench.show("pixcov"):
        pcov = maps.pixcov(bshape, bwcs, d)[0, 0, :sny, :snx, :sny, :snx]
    modrmap = enmap.modrmap(tshape, twcs)
    m1 = np.where(modrmap.reshape(-1) < hole_arcmin * np.pi / 180. / 60.)[0]
    m2 = np.where(modrmap.reshape(-1) >= hole_arcmin * np.pi / 180. / 60.)[0]

    with bench.show("geom"):
        meanMul, cov = get_geometry(pcov.reshape(sny * snx, sny * snx), m1, m2)

    covRoot = stats.eig_pow(cov, 0.5)

    return meanMul, covRoot, pcov, tshape, twcs, m1, m2
Esempio n. 14
0
def enmaps_from_config(Config, sim_section, analysis_section, pol=False):
    """
    Algorithm for deciding sim and analysis shapes and wcs:

    Check if user has specified a *data* template
        * If yes, use its shape and wcs for the data
        - Determine ratio simpixel/anpixel
        - Upsample by that ratio to make sim template
        * If no, 

    """

    pixel_sim = Config.getfloat(sim_section, "pixel_arcmin")
    buffer_sim = Config.getfloat(sim_section, "buffer")
    projection = Config.get(analysis_section, "projection")
    try:
        pt_file = Config.get(analysis_section, "patch_template")
        imap = enmap.read_map(pt_file)
        shape_dat = imap.shape
        wcs_dat = imap.wcs

        res = np.min(imap.extent() / imap.shape[-2:]) * 60. * 180. / np.pi
        if np.isclose(pixel_sim, res, 1.e-2):
            shape_sim = shape_dat
            wcs_sim = wcs_dat
        else:
            bbox = enmap.box(shape_dat, wcs_dat)
            shape_sim, wcs_sim = enmap.geometry(bbox,
                                                res=pixel_sim * np.pi / 180. /
                                                60.,
                                                proj=projection)

    except:
        pixel_analysis = Config.getfloat(analysis_section, "pixel_arcmin")
        try:
            width_analysis_deg = Config.getfloat(analysis_section,
                                                 "patch_degrees_width")
        except:
            width_analysis_deg = Config.getfloat(analysis_section,
                                                 "patch_arcmin_width") / 60.
        try:
            height_analysis_deg = Config.getfloat(analysis_section,
                                                  "patch_degrees_height")
        except:
            height_analysis_deg = Config.getfloat(analysis_section,
                                                  "patch_arcmin_height") / 60.
        ra_offset = Config.getfloat(analysis_section, "ra_offset")
        dec_offset = Config.getfloat(analysis_section, "dec_offset")

        shape_dat, wcs_dat = maps.rect_geometry(
            width_analysis_deg * 60.,
            pixel_analysis,
            proj=projection,
            pol=pol,
            height_arcmin=height_analysis_deg * 60.,
            xoffset_degree=ra_offset,
            yoffset_degree=dec_offset)

        if np.abs(buffer_sim - 1.) < 1.e-3:
            shape_sim, wcs_sim = maps.rect_geometry(
                width_analysis_deg * 60.,
                pixel_sim,
                proj=projection,
                pol=pol,
                height_arcmin=height_analysis_deg * 60.,
                xoffset_degree=ra_offset,
                yoffset_degree=dec_offset)
        else:
            raise NotImplementedError("Buffer !=1 not implemented")

    return shape_sim, wcs_sim, shape_dat, wcs_dat
Esempio n. 15
0
# Paths

PathConfig = io.load_path_config()
pout_dir = PathConfig.get("paths","plots")+"qest_hdv_"+str(args.noise)+"_"
io.mkdir(pout_dir,comm)


# Theory
theory_file_root = "../alhazen/data/Aug6_highAcc_CDM"
cc = counts.ClusterCosmology(skipCls=True)
theory = cosmology.loadTheorySpectraFromCAMB(theory_file_root,unlensedEqualsLensed=False,
                                                    useTotal=False,TCMB = 2.7255e6,lpad=9000,get_dimensionless=False)

# Geometry
shape, wcs = maps.rect_geometry(width_arcmin=args.arc,px_res_arcmin=args.pix,pol=False)
modlmap = enmap.modlmap(shape,wcs)
modrmap = enmap.modrmap(shape,wcs)

# Binning
bin_edges = np.arange(0.,20.0,args.pix*2)
binner = stats.bin2D(modrmap*60.*180./np.pi,bin_edges)

# Noise model
noise_uK_rad = args.noise*np.pi/180./60.
normfact = np.sqrt(np.prod(enmap.pixsize(shape,wcs)))
kbeam = maps.gauss_beam(args.beam,modlmap)


# Simulate
lmax = int(modlmap.max()+1)
Esempio n. 16
0
theory_file_root = "../alhazen/data/Aug6_highAcc_CDM"
theory = cosmology.loadTheorySpectraFromCAMB(theory_file_root,
                                             unlensedEqualsLensed=False,
                                             useTotal=False,
                                             TCMB=2.7255e6,
                                             lpad=9000,
                                             get_dimensionless=False)

ls, nls = np.loadtxt("nlkk.dat", usecols=[0, 1], unpack=True)
clkk = theory.gCl('kk', ls)
ellrange = np.arange(0, 6000, 1)
totcls = interp1d(ls, clkk + nls, bounds_error=False,
                  fill_value="extrapolate")(ellrange)
ps = totcls.reshape((1, 1, ellrange.size))
bshape, bwcs = maps.rect_geometry(width_deg=80.,
                                  px_res_arcmin=2.0,
                                  height_deg=15.)
tap_per = 1. / 40. * 100.
pad_per = 1. / 40. * 100.

mg = maps.MapGen(bshape, bwcs, ps)
fc = maps.FourierCalc(bshape, bwcs)

taper, w2 = maps.get_taper(bshape,
                           taper_percent=tap_per,
                           pad_percent=pad_per,
                           weight=None)

bmap = mg.get_map()

#io.plot_img(bmap*taper,"map.png",high_res=True)
Esempio n. 17
0
from enlib import enmap
import orphics.analysis.flatMaps as fmaps
import orphics.maps as maps
import orphics.analysis.pure as pure
import orphics.tools.io as io
import orphics.tools.stats as stats
from orphics.theory.cosmology import Cosmology
import numpy as np
import os, sys

out_dir = os.environ['WWW']+"plots/pureTest_"
cc = Cosmology(lmax=6000,pickling=True,dimensionless=False)
theory = cc.theory
deg = 20.
px = 1.0
shape, wcs = maps.rect_geometry(width_deg=deg,px_res_arcmin=px,pol=True)
pa = fmaps.PatchArray(shape,wcs,cc=cc,orphics_is_dimensionless=False)
ulensed = pa.get_unlensed_cmb()
kappa = pa.get_grf_kappa()
cmb = pa.get_lensed(ulensed,order=5)

# io.highResPlot2d(cmb[0],out_dir+"t.png")
# io.highResPlot2d(cmb[1],out_dir+"q.png")
# io.highResPlot2d(cmb[2],out_dir+"u.png")

modlmap = enmap.modlmap(shape,wcs)
fc = maps.FourierCalc(shape,wcs)
lbin_edges = np.arange(200,6000,40)
lbinner = stats.bin2D(modlmap,lbin_edges)

def plot_powers(cmb,suffix,power=None,w2=1.):
Esempio n. 18
0
                                             TCMB=2.7255e6,
                                             lpad=9000,
                                             get_dimensionless=False)

lens_func = lambda x: lensing.nfw_kappa(mass,
                                        x,
                                        cc,
                                        zL=0.7,
                                        concentration=3.2,
                                        overdensity=200.,
                                        critical=True,
                                        atClusterZ=True)
#sigma = 1.0 * np.pi/180./60.
#lens_func = lambda x: 0.2 * np.exp(-x**2./sigma**2./2.)

rshape, rwcs = maps.rect_geometry(width_arcmin=5., px_res_arcmin=0.001)
fshape, fwcs = maps.rect_geometry(width_arcmin=20., px_res_arcmin=0.1)
cshape, cwcs = maps.rect_geometry(width_arcmin=20., px_res_arcmin=0.5)
rmodrmap = enmap.modrmap(rshape, rwcs)
fmodrmap = enmap.modrmap(fshape, fwcs)
cmodrmap = enmap.modrmap(cshape, cwcs)
rmodlmap = enmap.modlmap(rshape, rwcs)
fmodlmap = enmap.modlmap(fshape, fwcs)
cmodlmap = enmap.modlmap(cshape, cwcs)
print(fshape, cshape)

mass = 2.e14
fkappa = lens_func(fmodrmap)
phi, _ = lensing.kappa_to_phi(fkappa, fmodlmap, return_fphi=True)
grad_phi = enmap.grad(phi)
pos = enmap.posmap(fshape, fwcs) + grad_phi
Esempio n. 19
0
from __future__ import print_function
from orphics import maps,io,cosmology,stats
from enlib import enmap
import numpy as np
import os,sys
from scipy import signal

cc = cosmology.Cosmology(lmax=6000,pickling=True)

deg = 15.
shape,wcs = maps.rect_geometry(width_deg=deg,px_res_arcmin=1.0)
modlmap = enmap.modlmap(shape,wcs)
modrmap = enmap.modrmap(shape,wcs)
lmax = modlmap.max()
ells = np.arange(0,lmax,1)
ps = cc.theory.lCl('TT',ells).reshape((1,1,ells.size))

mgen = maps.MapGen(shape,wcs,ps)




fwhm = 5.
kbeam = maps.gauss_beam(modlmap,fwhm)
imap = mgen.get_map()

bmap2 = maps.convolve_gaussian(imap.copy(),fwhm=fwhm,nsigma=5.0)
print(bmap2.shape)

bmap = maps.filter_map(imap.copy(),kbeam)
Esempio n. 20
0
rank = comm.Get_rank()
numcores = comm.Get_size()


# Paths
PathConfig = io.load_path_config()
GridName = PathConfig.get("paths","output_data")+args.GridName
with open(GridName+"/attribs.json",'r') as f:
    attribs = json.loads(f.read())
barc = attribs['arc'] ; bpix = attribs['pix']  ; bbeam = attribs['beam']  
pout_dir = PathConfig.get("paths","plots")+args.GridName+"/joint_bayesian_hdv_plots_"+io.join_nums((barc,bpix,bbeam,args.noise))+"_"
io.mkdir(pout_dir,comm)


# Tiny Geometry
bshape, bwcs = maps.rect_geometry(width_arcmin=barc,px_res_arcmin=bpix,pol=False)
bmodlmap = enmap.modlmap(bshape,bwcs)
bmodrmap = enmap.modrmap(bshape,bwcs)





# Noise model
noise_uK_rad = args.noise*np.pi/180./60.
normfact = np.sqrt(np.prod(enmap.pixsize(bshape,bwcs)))
noise_uK_pixel = noise_uK_rad/normfact
Ncov = np.diag([(noise_uK_pixel)**2.]*np.prod(bshape))

kbeam = maps.gauss_beam(bbeam,bmodlmap)
Esempio n. 21
0
from __future__ import print_function
from orphics import maps, io, cosmology, stats
from pixell import enmap
import numpy as np
import os, sys
from symlens import qe
from symlens.factorize import e

shape, wcs = maps.rect_geometry(width_deg=20., px_res_arcmin=1.5, proj='plain')
theory = cosmology.default_theory()
modlmap = enmap.modlmap(shape, wcs)

hardening = 'src'

# Lmax = 2000
# cluster = False

Lmax = 6000
cluster = True

if cluster:
    xmask = maps.mask_kspace(shape, wcs, lmin=100, lmax=2000)
    ymask = maps.mask_kspace(shape, wcs, lmin=100, lmax=6000)
    lxmask = maps.mask_kspace(shape, wcs, lmin=100, lmax=2000)
    lymask = maps.mask_kspace(shape, wcs, lmin=100, lmax=6000)
    estimator = 'hdv'
else:
    xmask = maps.mask_kspace(shape, wcs, lmin=100, lmax=3500)
    ymask = maps.mask_kspace(shape, wcs, lmin=100, lmax=3500)
    lxmask = maps.mask_kspace(shape, wcs, lmin=100, lmax=3500)
    lymask = maps.mask_kspace(shape, wcs, lmin=100, lmax=3500)
    # imap = enmap.enmap(fc.ifft(kmap).real,wcs)
    # io.hplot(imap,tag)
    pcross2d = f2power(ik1.reshape((Ny, Nx)), ik2.reshape((Ny, Nx)))
    cents, p1d = binner.bin(pcross2d)
    s.add_to_stats(tag, p1d.copy())


def ncompute(ik, nk, tag):
    pauto2d = f2power(ik.reshape((Ny, Nx)), ik.reshape(
        (Ny, Nx))) - f2power(nk.reshape((Ny, Nx)), nk.reshape((Ny, Nx)))
    cents, p1d = binner.bin(pauto2d)
    s.add_to_stats(tag, p1d.copy())


shape, wcs = maps.rect_geometry(width_deg=width,
                                height_deg=height,
                                px_res_arcmin=px)
minell = maps.minimum_ell(shape, wcs)
lmax1 = lmax - minell

ells = np.arange(0, lmax, 1)
theory = cosmology.default_theory()

nu0 = 150.
if dust: cibkcorr = fg.kappa_cib_corrcoeff(ells)
ycorr = fg.y_kappa_corrcoeff(ells)

cltt = theory.lCl('tt', ells)
clkk = theory.gCl('kk', ells)
clss = fg.power_tsz(ells, nu0)
# pl = io.Plotter(xscale='log',yscale='log',scalefn=lambda x:x**2.)