Exemple #1
0
def layered_contour(imap,
                    imap_contour,
                    contour_levels,
                    contour_color,
                    contour_width=1,
                    mask=None,
                    filename=None,
                    ticks=1,
                    downgrade=1,
                    font_size=20,
                    **kwargs):
    from pixell import enplot
    p1 = enplot.plot(imap,
                     layers=True,
                     mask=mask,
                     ticks=ticks,
                     downgrade=downgrade,
                     font_size=font_size,
                     **kwargs)
    p2 = enplot.plot(imap_contour,
                     layers=True,
                     contours=contour_levels,
                     contour_width=contour_width,
                     mask=mask,
                     contour_color=contour_color,
                     ticks=ticks,
                     downgrade=downgrade,
                     font_size=font_size)
    p1 += [a for a in p2 if "cont" in a.name]
    img = enplot.merge_images([a.img for a in p1])
    if filename is not None: enplot.write(filename, img)
    return img
Exemple #2
0
def hplot(img, savename=None, verbose=True, grid=False, **kwargs):
    from pixell import enplot
    plots = enplot.get_plots(img, grid=grid, **kwargs)
    if savename is None:
        enplot.show(plots)
        return
    enplot.write(savename, plots)
    if verbose: cprint("Saved plot to " + savename, color="g")
Exemple #3
0
def plot(fname,imap,dg=4,grid=False,**kwargs):
    from orphics import io

    img = enplot.plot(enmap.downgrade(imap,dg),grid=grid,**kwargs)
    if fname is None: 
        enplot.show(img)
    else: 
        enplot.write(fname,img)
        print(io.bcolors.OKGREEN+"Saved high-res plot to", fname+io.bcolors.ENDC)
def save_maps(hmap, root_name, telescope):
    for res in resolutions[telescope]:
        shape, wcs = get_geometry(res, bounds_deg=bounds[telescope])
        imap = ivar_hp_to_cyl(hmap, shape, wcs)
        if comm.rank == 0:
            oname = cr_remote_data.get_local_output(
                f"{root_name}_CAR_{res:.2f}_arcmin.fits")
            enmap.write_map(oname, imap)
            os.system(f"gzip -f {oname}")
            plots = enplot.get_plots(enmap.downgrade(imap, 8))
            savename = cr_remote_data.get_local_output(
                f"rmap_{root_name}_{res:.2f}")
            enplot.write(savename, plots)
            print(f"Plot saved to {savename}")
Exemple #5
0
# also reproject the PS mask
psMask = enmap.project(psMask,
                       tilecMask.shape,
                       tilecMask.wcs,
                       order=1,
                       mode='constant',
                       cval=0.0,
                       force=False,
                       prefilter=True,
                       mask_nan=True,
                       safe=True)

# Plot the combined maps to check
plot = enplot.plot(tilecMask, grid=True)
enplot.write(pathFig + "foot_mask", plot)

plot = enplot.plot(tilecMap, grid=True)
enplot.write(pathFig + "map", plot)

# Save the map now, to clear memory
print "saving map to " + pathOut + "tilec_maps.fits"
enmap.write_map(pathOut + "tilec_map.fits", tilecMap)

#########################################################################
# Mask the Milky Way with a Planck mask

# Read the Planck Galactic mask
pathPlanckMask = "/global/cscratch1/sd/eschaan/project_ucsc/data/planck_galactic_mask/HFI_Mask_GalPlane-apo0_2048_R2.00.fits"
# field, fsky:
#0, 0.20
Exemple #6
0
        geometry=m1.geometry)

print(m1.wcs)
print(m2.wcs)

off = [0, 1000]
m1s = enmap.shift(enmap.downgrade(m1, 10), off)
m2s = enmap.shift(enmap.downgrade(m2, 10), off)

p1 = enplot.plot(m1s,
                 min=500,
                 max=1e4,
                 color="cooltowarm",
                 ticks="10",
                 layers=True,
                 font_size=50,
                 contour_color='ffffff')
p2 = enplot.plot(m2s,
                 min=0,
                 max=1,
                 ticks="10",
                 layers=True,
                 contours="0.5,",
                 contour_width=6,
                 annotate="paper/annot.txt",
                 font_size=50,
                 contour_color='ffffff')

ptot = enplot.merge_plots(p1 + p2[1:3])
enplot.write("fig_footprint.png", ptot)
            freq = [x for x in mapdir.split('_') if x.startswith('f')][0]
            signal_map = args.signal_map
            if len(signal_map) == 1:
                signal_map = signal_map[0]
            signal = read_signal_map(signal_map, freq, ratio.shape, ratio.wcs)
            signal = enmap.downgrade(signal, args.downgrade)

        hitmap = enmap.downgrade(hitmap, args.downgrade)
        cutmap = enmap.downgrade(cutmap, args.downgrade)
        ratio = enmap.downgrade(ratio, args.downgrade)

        ratio[hitmap == 0] = np.nan

        plot = enplot.plot(hitmap, **plot_opts)
        enplot.write(opj(mapdir, 'hits'), plot)

        plot = enplot.plot(cutmap, **plot_opts)
        enplot.write(opj(mapdir, 'cuts'), plot)

        plot = enplot.plot(ratio, min=0, max=args.range, **plot_opts)
        enplot.write(opj(mapdir, 'ratio'), plot)

        if args.signal_map is not None:

            ratio[hitmap == 0] = 0.
            ratio_sm = enmap.downgrade(ratio, 32 / float(args.downgrade))
            ratio_sm = enmap.project(ratio_sm, ratio.shape, ratio.wcs, order=1)

            contours = '0.003, 0.01'
            contour_layer = enplot.plot(ratio_sm,
Exemple #8
0
def eshow(x, fname):
    ''' Define a function to help us plot the maps neatly '''
    plots = enplot.get_plots(x, downgrade=1)
    enplot.write(f"/scratch/r/rbond/jiaqu/plots/{fname}.png", plots)
Exemple #9
0
map_name = "cmb.fits"
odir = "leaflet"
if os.path.exists(odir):
    os.system("rm -rf %s" % odir)

comm = mpi.COMM_WORLD
tile_utils_sigurd.leaftile(map_name,
                           odir,
                           verbose=True,
                           comm=comm,
                           monolithic=True)
args = enplot.parse_args()

for plot in enplot.plot_iterator(*args.ifiles, comm=mpi.COMM_WORLD, **args):
    enplot.write(plot.name, plot)

filename = "test_plot.html"
g = open(filename, mode='w')
g.write('<html>\n')
g.write('<head>\n')
g.write('<link rel=stylesheet href=html_utils/leaflet.css>\n')
g.write('<link rel=stylesheet href=html_utils/L.Control.MousePosition.css>\n')
g.write('<script src=html_utils/leaflet-src.js></script>\n')
g.write('<script src=html_utils/L.Control.MousePosition.js></script>\n')
g.write('<script src=html_utils/Leaflet.Graticule.js></script>\n')
g.write('<script src=html_utils/leaflet-ellipse.js></script>\n')
g.write('<script src=html_utils/L.ColorizableLayer.js></script>\n')
g.write('<script src=html_utils/multitile2.js></script>\n')
g.write('<style>\n')
g.write('body {margin: 0px;} #map {height: 100%; cursor: default;}\n')
Exemple #10
0
def car2tiles(
    input_file,
    mask_file=None,
    enplot_args=None,
    output_dir=None,
    delete_fits=True,
    use_webplot=True,
    pre_operation=None,
):
    """Convert CAR map to PNG tiles
    Parameters
    ----------
    input_file: fits file
      name of the input CAR fits file
    mask_file: fits file
      name of the CAR mask file
    enplot_args:
      list of enplot/webplot options (see corresponding programs)
    output_dir: string
      name of the output directory holding PNG files
    delete_fits: boolean
      delete the FITS files corresponding to the tiles
    use_webplot: boolean
      use webplot in place of enplot program
    """
    enplot_args = enplot_args or []

    comm = mpi.COMM_WORLD
    if comm.rank == 0:
        if output_dir is None:
            output_dir = os.path.join("tiles", os.path.basename(input_file))
        # Check if path to fits file are already stored
        fits_files = os.path.join(output_dir, "*/*.fits")
        if fits_files not in enplot_args:
            enplot_args.append(fits_files)

        if os.path.exists(output_dir):
            os.system("rm -rf %s" % output_dir)

        if mask_file is not None:
            car = so_map.read_map(input_file)
            mask = so_map.read_map(mask_file)

            # from pixell import wcsutils
            # if not wcsutils.is_compatible(mask.geometry[0], car.geometry[0]):
            #     raise ValueError("Map and mask must have compatible geometries")

            if mask.ncomp == car.ncomp == 1:
                car.data *= np.where(mask.data < 0.5, 0, 1)
            elif mask.ncomp == 1:
                for i in range(car.ncomp):
                    car.data[i] *= np.where(mask.data < 0.5, 0, 1)
            else:
                if mask.ncomp != car.ncomp:
                    raise ValueError("Map and mask have different number of components")
                for i in range(mask.ncomp):
                    car.data[i] *= np.where(mask.data[i] < 0.5, 0, 1)
            input_file += ".tmp"
            car.write_map(input_file)

        if pre_operation is not None:
            car = so_map.read_map(input_file)
            car.data = eval(pre_operation, {"m": car.data}, np.__dict__)
            input_file += ".tmp"
            car.write_map(input_file)

    if not mpi.disabled:
        comm.barrier()

    tile_utils_sigurd.leaftile(
        input_file,
        output_dir,
        verbose="-v" in enplot_args,
        comm=comm if not mpi.disabled else None,
        monolithic=True,
    )

    if use_webplot:
        args = webplot.parse_args(enplot_args)
        webplot.plot(args)
    else:
        args = enplot.parse_args(enplot_args)
        for plot in enplot.plot_iterator(*args.ifiles, comm=comm, **args):
            enplot.write(plot.name, plot)

    if comm.rank == 0:
        if mask_file is not None or pre_operation is not None:
            os.remove(input_file)

        if delete_fits:
            for fits in args.ifiles:
                os.remove(fits)
    stack = 0
    for i in range(len(ras)):
        stamp = reproject.postage_stamp(map, ras[i], decs[i], 20., 0.5)
        if stamp is None: continue
        stack += stamp[0]
    stack /= len(ras)
    return stack


print("Starting ACT Maps")

imap = enmap.read_map('/maps/ACTPol_148_D56_PA1_S2_1way_I.fits')

plots = enplot.plot(imap, range=300, mask=0)

enplot.write("ACT_map", plots)

width = np.deg2rad(30. / 60.)

t = QTable.read('madcows/AdvACT_S18Clusters_v1.0-beta.fits')
ra_temp = t['RADeg']
dec_temp = t['decDeg']
ra, dec = np.array(ra_temp), np.array(dec_temp)
s18stack = stack(ra, dec, imap)
plots = enplot.plot(enmap.upgrade(s18stack, 5),
                    grid=False,
                    colorbar=True,
                    color='gray')
enplot.write("s18stack_act", plots)

for i in range(len(ra)):