|
| 1 | +""" |
| 2 | +This script projects SPT and ACT maps and masks into a CAR template defined around SPT survey |
| 3 | +""" |
| 4 | + |
| 5 | +from pixell import enplot, enmap, reproject, utils |
| 6 | +import numpy as np |
| 7 | +from pspy import so_map |
| 8 | +from os.path import join as opj |
| 9 | +import os |
| 10 | + |
| 11 | +save_dir = "" |
| 12 | +spt_maps_dir = opj(save_dir, "maps/spt") |
| 13 | +spt_mask_dir = opj(save_dir, "masks") |
| 14 | + |
| 15 | +os.makedirs(spt_maps_dir, exist_ok=True) |
| 16 | +os.makedirs(spt_mask_dir, exist_ok=True) |
| 17 | + |
| 18 | +### Define project geometry (arbitrary box around SPT patch + few degrees) |
| 19 | + |
| 20 | +print("create SPT CAR geometry") |
| 21 | +box = [[-77, -62],[-35,60]] * utils.adeg |
| 22 | +shape,wcs = enmap.geometry2(pos=box,res=0.5 * utils.arcmin,proj='car', variant='fejer1') |
| 23 | +print(f"Project on geometry: {shape=}, {wcs=}") |
| 24 | +template = enmap.ones(shape, wcs) |
| 25 | +enmap.write_map(opj(save_dir, "SPT_CAR_template.fits"), template) |
| 26 | + |
| 27 | + |
| 28 | +### Project SPT full maps |
| 29 | + |
| 30 | +spt_maps_read_dir = "/global/cfs/cdirs/sobs/users/tlouis/spt_data/real_data_maps" |
| 31 | +spt_full_maps_fn_list = [opj(spt_maps_read_dir, f"full/full_{freq}ghz.fits") for freq in ["095"]] |
| 32 | + |
| 33 | +for spt_maps_fn in spt_full_maps_fn_list: |
| 34 | + # Project maps |
| 35 | + maps_so = so_map.read_map(spt_maps_fn, fields_healpix=(0, 1, 2)) |
| 36 | + maps = maps_so.data |
| 37 | + |
| 38 | + maps_proj = reproject.healpix2map(maps, shape, wcs, method='harm') # For maps we use harm |
| 39 | + |
| 40 | + enmap.write_map(opj(spt_maps_dir, os.path.basename(spt_maps_fn)[:-5] + "_CAR.fits"), maps_proj) |
| 41 | + |
| 42 | + plot = enplot.get_plots( |
| 43 | + maps_proj, ticks=10, mask=0, downgrade=2, colorbar=True, range=(100, 30, 30) |
| 44 | + ) |
| 45 | + enplot.write(opj(spt_maps_dir, os.path.basename(spt_maps_fn)[:-5] + "_CAR"), plot) |
| 46 | + |
| 47 | + # We also need ivar, we use a fudge factor to get close to the real ivar: here I use 1e-2 which corresponds to 5uk.arcmin depth |
| 48 | + fudge_ivar = 1e-2 |
| 49 | + maps_so = so_map.read_map(spt_maps_fn, fields_healpix=(3)) |
| 50 | + maps = maps_so.data * fudge_ivar |
| 51 | + |
| 52 | + maps_proj = reproject.healpix2map(maps, shape, wcs, method='harm') # For maps we use harm |
| 53 | + |
| 54 | + enmap.write_map(opj(spt_maps_dir, os.path.basename(spt_maps_fn)[:-5].replace("full", "ivar") + "_CAR.fits"), maps_proj) |
| 55 | + |
| 56 | + plot = enplot.get_plots( |
| 57 | + maps_proj, ticks=10, mask=0, downgrade=2, colorbar=True, range=(1) |
| 58 | + ) |
| 59 | + enplot.write(opj(spt_maps_dir, os.path.basename(spt_maps_fn)[:-5].replace("full", "ivar") + "_CAR"), plot) |
| 60 | + |
| 61 | + |
| 62 | +spt_masks_read_dir = "/global/cfs/cdirs/sobs/users/tlouis/spt_data/ancillary_products/generally_applicable" |
| 63 | +spt_masks_fn_list = [ |
| 64 | + opj(spt_masks_read_dir, "pixel_mask_apodized_borders_objects.fits"), |
| 65 | + opj(spt_masks_read_dir, "pixel_mask_apodized_borders_only.fits"), |
| 66 | + opj(spt_masks_read_dir, "pixel_mask_binary_borders_objects.fits"), |
| 67 | + opj(spt_masks_read_dir, "pixel_mask_binary_borders_only.fits"), |
| 68 | +] |
| 69 | + |
| 70 | +for spt_mask_fn in spt_masks_fn_list: |
| 71 | + # Project masks |
| 72 | + maps_so = so_map.read_map(spt_mask_fn) |
| 73 | + maps = maps_so.data |
| 74 | + |
| 75 | + maps_proj = reproject.healpix2map(maps, shape, wcs, method='spline') # For masks we use spline |
| 76 | + |
| 77 | + enmap.write_map(opj(spt_mask_dir, os.path.basename(spt_mask_fn)[:-5] + "_CAR.fits"), maps_proj) |
| 78 | + |
| 79 | + plot = enplot.get_plots( |
| 80 | + maps_proj, ticks=10, mask=0, downgrade=2, colorbar=True, range=1 |
| 81 | + ) |
| 82 | + enplot.write(opj(spt_mask_dir, os.path.basename(spt_mask_fn)[:-5] + "_CAR"), plot) |
| 83 | + |
| 84 | + # We also need reverted masks for dory |
| 85 | + enmap.write_map(opj(spt_mask_dir, os.path.basename(spt_mask_fn)[:-5] + "_CAR_rev.fits"), 1 - maps_proj) |
| 86 | + |
| 87 | + plot = enplot.get_plots( |
| 88 | + 1 - maps_proj, ticks=10, mask=0, downgrade=2, colorbar=True, range=1 |
| 89 | + ) |
| 90 | + enplot.write(opj(spt_mask_dir, os.path.basename(spt_mask_fn)[:-5] + "_CAR_rev"), plot) |
| 91 | + |
| 92 | + |
| 93 | + |
0 commit comments