|
| 1 | +""" |
| 2 | +This script compute the one dimensional power spectra of spt simulations |
| 3 | +""" |
| 4 | + |
| 5 | +from pspy import pspy_utils, so_dict, so_map, sph_tools, so_mcm, so_spectra, so_mpi |
| 6 | +from pspipe_utils import pspipe_list, log |
| 7 | +import numpy as np |
| 8 | +import healpy as hp |
| 9 | +import sys |
| 10 | +import time |
| 11 | + |
| 12 | +d = so_dict.so_dict() |
| 13 | +d.read_from_file(sys.argv[1]) |
| 14 | +log = log.get_logger(**d) |
| 15 | + |
| 16 | +survey = "spt" |
| 17 | +lmax = d["lmax"] |
| 18 | +niter = d["niter"] |
| 19 | +type = d["type"] |
| 20 | +binning_file = d["binning_file"] |
| 21 | +binned_mcm = d["binned_mcm"] |
| 22 | +release_dir = d["release_dir"] |
| 23 | +alm_conv = d[f"alm_conv_{survey}"] |
| 24 | + |
| 25 | + |
| 26 | +mcm_dir = "mcms" |
| 27 | +tf_dir = "sim_spectra_for_tf" |
| 28 | + |
| 29 | +pspy_utils.create_directory(tf_dir) |
| 30 | + |
| 31 | +spectra = ["TT", "TE", "TB", "ET", "BT", "EE", "EB", "BE", "BB"] |
| 32 | +spin_pairs = ["spin0xspin0", "spin0xspin2", "spin2xspin0", "spin2xspin2"] |
| 33 | +arrays_spt = d["arrays_spt"] |
| 34 | + |
| 35 | + |
| 36 | +so_mpi.init(True) |
| 37 | +subtasks = so_mpi.taskrange(imin=d["iStart"], imax=d["iStop"]) |
| 38 | + |
| 39 | +for iii in subtasks: |
| 40 | + log.info(f"Simulation n° {iii:05d}/{d['iStop']:05d}") |
| 41 | + log.info(f"-------------------------") |
| 42 | + |
| 43 | + t0 = time.time() |
| 44 | + |
| 45 | + master_alms = {} |
| 46 | + |
| 47 | + for ar in arrays_spt: |
| 48 | + |
| 49 | + sim_in = so_map.read_map(f"{release_dir}/simulated_maps/input_maps/input_maps_realization{iii:03d}_{ar}ghz.fits") |
| 50 | + sim_out = so_map.read_map(f"{release_dir}/simulated_maps/output_maps/masking_yes/output_maps_masking_yes_realization{iii:03d}_{ar}ghz.fits") |
| 51 | + |
| 52 | + win_T = so_map.read_map(d[f"window_T_{survey}_{ar}"]) |
| 53 | + win_pol = so_map.read_map(d[f"window_pol_{survey}_{ar}"]) |
| 54 | + |
| 55 | + window_tuple = (win_T, win_pol) |
| 56 | + |
| 57 | + master_alms[survey, ar, "nofilter"] = sph_tools.get_alms(sim_in, window_tuple, niter, lmax, alm_conv=alm_conv) |
| 58 | + master_alms[survey, ar, "filter"] = sph_tools.get_alms(sim_out, window_tuple, niter, lmax, alm_conv=alm_conv) |
| 59 | + |
| 60 | + alm_mask = hp.read_alm(d[f"alm_mask_{survey}_{ar}"], hdu=1) |
| 61 | + alm_mask = hp.sphtfunc.resize_alm(alm_mask, d["lmax_mask"], d["lmax_mask"], lmax, lmax) |
| 62 | + |
| 63 | + master_alms[survey, ar, "nofilter_mask"] = master_alms[survey, ar, "nofilter"] * alm_mask |
| 64 | + master_alms[survey, ar, "filter_mask"] = master_alms[survey, ar, "filter"] * alm_mask |
| 65 | + |
| 66 | + |
| 67 | + _, _, lb, _ = pspy_utils.read_binning_file(binning_file, lmax) |
| 68 | + |
| 69 | + n_spec, sv1_list, ar1_list, sv2_list, ar2_list = pspipe_list.get_spectra_list(d) |
| 70 | + |
| 71 | + for i_spec in range(n_spec): |
| 72 | + sv1, ar1, sv2, ar2 = sv1_list[i_spec], ar1_list[i_spec], sv2_list[i_spec], ar2_list[i_spec] |
| 73 | + spec_name = f"{type}_{sv1}_{ar1}x{sv2}_{ar2}" |
| 74 | + |
| 75 | + mbb_inv, Bbl = so_mcm.read_coupling(prefix=f"{mcm_dir}/{sv1}_{ar1}x{sv2}_{ar2}", spin_pairs=spin_pairs) |
| 76 | + |
| 77 | + for filt in ["filter", "filter_mask", "nofilter", "nofilter_mask"]: |
| 78 | + |
| 79 | + l, ps_master = so_spectra.get_spectra_pixell(master_alms[sv1, ar1, filt], master_alms[sv2, ar2, filt], spectra=spectra) |
| 80 | + |
| 81 | + lb, ps = so_spectra.bin_spectra(l, |
| 82 | + ps_master, |
| 83 | + binning_file, |
| 84 | + lmax, |
| 85 | + type=type, |
| 86 | + mbb_inv=mbb_inv, |
| 87 | + spectra=spectra, |
| 88 | + binned_mcm=binned_mcm) |
| 89 | + |
| 90 | + so_spectra.write_ps(tf_dir + f"/{spec_name}_{filt}_{iii:05d}.dat", lb, ps, type, spectra=spectra) |
| 91 | + |
| 92 | + log.info(f"[{iii}] Simulation n° {iii:05d} done in {time.time()-t0:.02f} s") |
0 commit comments