master_alms = {}
    fcount = 0

    for exp in experiments:
        freqs = d["freqs_%s" % exp]
        nsplits = d["nsplits_%s" % exp]

        if d["pixel_%s" % exp] == "CAR":
            template = so_map.car_template(ncomp, d["ra0_%s" % exp],
                                           d["ra1_%s" % exp],
                                           d["dec0_%s" % exp],
                                           d["dec1_%s" % exp],
                                           d["res_%s" % exp])
        else:
            template = so_map.healpix_template(ncomp,
                                               nside=d["nside_%s" % exp])

        l, nl_array_t, nl_array_pol = maps_to_params_utils.get_noise_matrix_spin0and2(
            noise_data_dir, exp, freqs, lmax_simu + 1, nsplits, lcut=lcut)

        nlms = maps_to_params_utils.generate_noise_alms(
            nl_array_t, lmax_simu, nsplits, ncomp, nl_array_pol=nl_array_pol)

        for fid, freq in enumerate(freqs):
            window = so_map.read_map("%s/window_%s_%s.fits" %
                                     (window_dir, exp, freq))
            window_tuple = (window, window)
            l, bl = np.loadtxt("sim_data/beams/beam_%s_%s.dat" % (exp, freq),
                               unpack=True)

            alms_beamed = alms.copy()
Exemplo n.º 2
0
type = "Cl"

test_dir = "result_pspyVSnamaster_spin0"
try:
    os.makedirs(test_dir)
except:
    pass

# Create a binningfile with format, lmin,lmax,lmean
pspy_utils.create_binning_file(bin_size=40,
                               n_bins=300,
                               file_name="%s/binning.dat" % test_dir)
binning_file = "%s/binning.dat" % test_dir

# the templates for the CMB splits
template = so_map.healpix_template(ncomp, nside=nside)
# the templates for the binary mask
binary = so_map.healpix_template(ncomp=1, nside=nside)
# we set pixel inside the disk at 1 and pixel outside at zero
vec = hp.pixelfunc.ang2vec(lon, lat, lonlat=True)
disc = hp.query_disc(nside, vec, radius=radius * np.pi / 180)
binary.data[disc] = 1

print("Generate noisy CMB realisation")
# First let's generate a CMB realisation
cmb = template.synfast(clfile)
split = cmb.copy()
# let's add noise to it with rms 20 uk.arcmin
noise = so_map.white_noise(split, rms_uKarcmin_T=rms_uKarcmin_T)
split.data += noise.data
Exemplo n.º 3
0
survey_mask_dir='survey_masks'

# Create three folders, one for the plot of the simulations, one for storing the combined maps and one for the survey masks
pspy_utils.create_directory(plot_dir)
pspy_utils.create_directory(combined_map_dir)
pspy_utils.create_directory(survey_mask_dir)


# We loop on all the different experiments that we want to consider
for exp in experiment:
    # Each experiment could have its associated nside and frequency list
    nside=d['nside_%s'%exp]
    freqs=d['freq_%s'%exp]
    for count,freq in enumerate(freqs):
        #We create a template for each frequency and add all composents present in 'content'
        map_all=so_map.healpix_template(ncomp=3,nside=nside)
        for cont in content:
            maps_list= d['%s_maps'%cont]
            map=maps_list[count]
            
            map=so_map.read_map(map)
            
            #some of the component are I only while other are I,Q,U
            if (len(map.data.shape)==1):
                map_all.data[0]+=map.data
            else:
                for i in range(3):
                    map_all.data[i]+=map.data[i]
    
        # we read two noise maps, since the noise maps represent the noise properties of the full SO survey
        # we multiply them by sqrt(2)
Exemplo n.º 4
0
print("  numpy :", np.__version__)
print("   pysm :", pysm.__version__)
print("   pspy :", pspy.__version__)

nside = 4096

print("Loading masks for nside =", nside)
galactic_mask = np.load("./masks/mask_galactic_1024.npz")["mask"]
survey_mask = np.load("./masks/mask_survey_1024.npz")["mask"]
mask = galactic_mask * survey_mask

mask = hp.ud_grade(mask, nside_out=nside)
assert np.all((mask == 1) | (mask == 0)), "Mask with values others than 0 or 1"

from pspy import so_map
survey = so_map.healpix_template(ncomp=1, nside=nside)
survey.data = mask

from pspy import so_window
survey = so_window.create_apodization(survey,
                                      apo_type="C1",
                                      apo_radius_degree=5)

print("Generating binning file")
import os
output_dir = "/tmp/pysm"
os.makedirs(output_dir, exist_ok=True)
binning_file = os.path.join(output_dir, "binning.dat")
from pspy import pspy_utils
pspy_utils.create_binning_file(bin_size=40,
                               n_bins=1000,
Exemplo n.º 5
0
fn = d["planck_galactic_masks"]
hdul = fits.open(fn)

# Try to get nside and apodization from filename
m = re.search("apo(.)", fn)
apod = int(m.group(1)) if m else d.get("galactic_mask_apodization", 0)
m = re.search("apo.*_(.*)_", fn)
nside = int(m.group(1)) if m else d.get("galactic_mask_nside", 2048)

# Loop over maps
data = hdul[1].data
for mask_name in data.names:
    print(f"Processing {mask_name} mask...")
    healpix_map = so_map.healpix_template(1,
                                          nside,
                                          coordinate=d.get(
                                              "galatic_mask_coordinate",
                                              "gal"))
    healpix_map.data = (hp.reorder(data.field(mask_name), n2r=True) if d.get(
        "galactic_mask_nest_ordering", True) else data.field(mask_name))

    print("Projecting in CAR pixellisation...")
    car_project = so_map.healpix2car(healpix_map, survey)
    car_project.data[car_project.data > 0.5] = 1
    car_project.data[car_project.data <= 0.5] = 0
    car_project.data = car_project.data.astype(np.int16)

    mask_dir = os.path.dirname(d["output_file"])
    car_file = os.path.join(
        mask_dir,
        f"mask_galactic_equatorial_car_{mask_name.lower()}_apo{apod}.fits")
Exemplo n.º 6
0
from pspy import so_map

# Healpix Template
nside = 4096
ncomp = 1
lmax = 6000

# CAR Template
ra0 = -180
ra1 = 180
dec0 = -75
dec1 = 30
res = 0.5

healpix_template = so_map.healpix_template(ncomp=ncomp, nside=nside)
clfile = "bode_almost_wmap5_lmax_1e4_lensedCls_startAt2.dat"
cmb_healpix = healpix_template.synfast(clfile)

car_template = so_map.car_template(ncomp, ra0, ra1, dec0, dec1, res)
cmb_projected = so_map.healpix2car(cmb_healpix, car_template, lmax=lmax)

map_name = "cmb.fits"
cmb_projected.write_map(map_name)

Exemplo n.º 7
0
import numpy as np
from pspy import so_window, so_map, so_dict
import sys

d = so_dict.so_dict()
d.read_from_file(sys.argv[1])

# You have to spefify the data directory in which the products will be downloaded
data_dir = d["data_dir"]
freqs = d["freqs"]

maps_dir = data_dir + "/maps"
EB_mask_dir = data_dir + "/EB_masks"

nside = 2048
window = so_map.healpix_template(ncomp=1, nside=nside)

with fits.open("%s/HFI_Mask_PointSrc_2048_R2.00.fits" % EB_mask_dir) as hdul:
    data = hdul["SRC-POL"].data
ps_mask = {
    f: hp.reorder(data[f], n2r=True)
    for f in ["F100", "F143", "F217", "F353"]
}

for freq in freqs:

    CO_mask = np.ones(12 * nside**2)

    if freq is not "143":
        log10_CO_noise_ratio = so_map.read_map(
            "%s/HFI_BiasMap_%s-CO-noiseRatio_2048_R3.00_full.fits" %
Exemplo n.º 8
0
        maps = d['maps_%s_%s' % (exp, f)]
        nSplits[exp] = len(maps)
        window_T = so_map.read_map('%s/window_T_%s_%s.fits' %
                                   (window_dir, exp, f))
        window_P = so_map.read_map('%s/window_P_%s_%s.fits' %
                                   (window_dir, exp, f))

        window_tuple = (window_T, window_P)

        count = 0
        for map in maps:
            split = so_map.read_map(map)
            if split.ncomp == 1:
                Tsplit = split.copy()
                split = so_map.healpix_template(ncomp=3, nside=split.nside)
                split.data[0] = Tsplit.data
                split.data[1] = Tsplit.data * 0
                split.data[2] = Tsplit.data * 0

            split = remove_mean(split, window_tuple, ncomp)
            master_alms[exp, f,
                        count] = sph_tools.get_alms(split, window_tuple, niter,
                                                    lmax)
            count += 1

# We then compute the cls from the alms and deconvolve the mcm that take into account the effect of the window function
Db_dict = {}
for id_exp1, exp1 in enumerate(experiment):
    freqs1 = d['freq_%s' % exp1]
    nSplits1 = nSplits[exp1]
    if d["pixel_%s" % exp] == "CAR":
        binary = so_map.car_template(ncomp=1,
                                     ra0=d["ra0_%s" % exp],
                                     ra1=d["ra1_%s" % exp],
                                     dec0=d["dec0_%s" % exp],
                                     dec1=d["dec1_%s" % exp],
                                     res=d["res_%s" % exp])

        binary.data[:] = 1
        if d["binary_is_survey_mask"] == True:
            binary.data[:] = 0
            binary.data[1:-1, 1:-1] = 1

    elif d["pixel_%s" % exp] == "HEALPIX":
        binary = so_map.healpix_template(ncomp=1, nside=d["nside_%s" % exp])
        binary.data[:] = 1

    for freq in freqs:
        window = binary.copy()

        if d["galactic_mask_%s" % exp] == True:
            gal_mask = so_map.read_map(d["galactic_mask_%s_file_%s" %
                                         (exp, freq)])
            gal_mask.plot(file_name="%s/gal_mask_%s_%s" %
                          (plot_dir, exp, freq))
            window.data[:] *= gal_mask.data[:]

        if d["survey_mask_%s" % exp] == True:
            survey_mask = so_map.read_map(d["survey_mask_%s_file_%s" %
                                            (exp, freq)])
Exemplo n.º 10
0
pspy_utils.create_binning_file(bin_size=bin_size,
                               n_bins=300,
                               file_name=binning_file)

map_dir = d["map_dir"]
mcm_dir = "mcms"
spectra_dir = "spectra"
plot_dir = "plot/map"
window_dir = "windows"

pspy_utils.create_directory(window_dir)
pspy_utils.create_directory(mcm_dir)
pspy_utils.create_directory(spectra_dir)
pspy_utils.create_directory(plot_dir)

template = so_map.healpix_template(ncomp=3, nside=1024)
cmb = template.synfast(clfile)

Db_dict = {}
for scan in scan_list:

    print("processing %s" % scan)
    binary = so_map.healpix_template(ncomp=1, nside=1024)
    binary.data[:] = 1

    sim = {}
    for split in split_list:
        noise_map = so_map.read_map("%s/%s_telescope_all_time_all_map.fits" %
                                    (map_dir[split], scan))
        binary.data[noise_map.data[0] == hp.pixelfunc.UNSEEN] = 0
        # the sqrt(2) is because each split has noise corresponding to the whole survey