def healpix2car( input_file, fields=None, mask_file=None, output_file=None, resolution=0.5, bounding_box=(-180, 180, -75, 30), lmax=6000, ): """ Convert HEALPIX map to CAR map Parameters ---------- input_file: fits file name of the input HEALPIX fits file fields: tuple HEALPIX fields to convert i.e. (0,) will keep only temperature field mask_file: fits file name of the HEALPIX mask file output_file: fits file name of the output CAR fits file resolution: string CAR final resolution in arcminutes bounding_box: tuple (ra0, ra1, dec0, dec1) in degree """ healpix_map = so_map.read_map(input_file, fields_healpix=fields) # CAR Template ra0, ra1, dec0, dec1 = bounding_box res = resolution car_template = so_map.car_template(healpix_map.ncomp, ra0, ra1, dec0, dec1, res) projected_map = so_map.healpix2car(healpix_map, car_template, lmax=lmax) if mask_file is not None: mask = so_map.read_map(mask_file) projected_mask = so_map.healpix2car(mask, car_template, lmax=lmax) if mask.ncomp == healpix_map.ncomp == 1: projected_map.data *= np.where(projected_mask.data < 0.5, 0, 1) elif mask.ncomp == 1: for i in range(healpix_map.ncomp): projected_map.data[i] *= np.where(projected_mask.data < 0.5, 0, 1) else: if healpix_map.ncomp != mask.ncomp: raise ValueError("Map and mask have different number of components") for i in range(mask.ncomp): projected_map.data[i] *= np.where(projected_mask.data[i] < 0.5, 0, 1) print("Writing '{}' file".format(output_file)) projected_map.write_map(output_file) return projected_map
type = "Cl" test_dir = "result_pspyVSnamasterCAR_spin0and2" 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.car_template(ncomp, ra0, ra1, dec0, dec1, res) # the templates for the binary mask binary = so_map.car_template(1, ra0, ra1, dec0, dec1, res) # for CAR we set pixels inside the survey at 1 and at the border to be zero binary.data[:] = 0 binary.data[1:-1, 1:-1] = 1 print("Generate 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
alms = curvedsky.rand_alm(ps_cmb, lmax=lmax_simu) if include_fg == True: fglms = curvedsky.rand_alm(ps_fg, lmax=lmax_simu) 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))
import psplay import time import pylab as plt, numpy as np from pspy import so_map, pspy_utils # Sim parameters clfile = "bode_almost_wmap5_lmax_1e4_lensedCls_startAt2.dat" n_sims = 100 template_car = so_map.car_template(3, -10, 10, -10, 10, 0.5) rms_uKarcmin_T = 8 map0_info = { "name": "split0_IQU.fits", "data_type": "IQU", "id": "split0", "cal": None } map1_info = { "name": "split1_IQU.fits", "data_type": "IQU", "id": "split1", "cal": None } maps_info_list = [map0_info, map1_info] # Patch parameter source_mask = {"name": "source_mask.fits", "apo_type": "C1", "apo_radius": 0.3} galactic_mask = "mask_galactic_equatorial_car_halfarcmin.fits" patch = {"patch_type": "Disk", "center": [0, 0], "radius": 8} apo_radius_survey = 1 # Spectra parameters
d = so_dict.so_dict() d.read_from_file(sys.argv[1]) n_sims = d["n_sims"] beamed_clfile = d["beamed_clfile"] res_arcmin = d["res_arcmin"] name_split = d["name_split"] n_splits = d["n_splits"] rms_uKarcmin_T = d["rms_uKarcmin_T"] * np.sqrt(n_splits) ra0, ra1, dec0, dec1 = d["ra0"], d["ra1"], d["dec0"], d["dec1"] run_name = d["run_name"] sim_dir = "sims_%s" % run_name pspy_utils.create_directory(sim_dir) eps = 1 template_car = so_map.car_template(3, ra0 - eps, ra1 + eps, dec0 - eps, dec1 + eps, res_arcmin) for iii in range(n_sims): print("generate sim %03d" % iii) cmb = template_car.synfast(beamed_clfile) for i in range(n_splits): name = "sim_%03d_%s%d" % (iii, name_split, i) split = cmb.copy() noise = so_map.white_noise(split, rms_uKarcmin_T=rms_uKarcmin_T) split.data += noise.data split.write_map("%s/%s.fits" % (sim_dir, name)) split.plot(file_name="%s/%s" % (sim_dir, name))
experiments = d["experiments"] lmax = d["lmax"] lmax_mcm = d["lmax_mcm"] # The first step of this code is to generate the window functions for the different frequency channels # of the different experiments. print("Geneating window functions") for exp in experiments: freqs = d["freqs_%s" % exp] 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()