ax.spines[side].set_color('white') ############### # right panel # ############### ax = plt.subplot(122, projection=irmap.wcs) opts = { 'cmap': 'planck_half', 'norm': colors.LogNorm(vmin=1e-5, vmax=1e-2), } plotstyle.setup_axis(ax, nticks=[5, 5], yticks=False, fmt=None) irmap[irmap < 0] = 1e-6 im = ax.imshow(irmap, **opts) # polarization angle plot # reload imap to get the original resolution theta = lib.Bangle(imap[1], imap[2], toIAU=True) theta += (np.pi / 2) # this gets the B-field angle corrected # x- and y-components of magnetic field Bx = np.cos(theta) By = np.sin(theta) # mask by polarization intensity if args.mask: P = np.sum(imap[1:]**2, axis=0)**0.5 P_err = lib.P_error(imap, ivar * s**2) Psnr = P / P_err mask = Psnr < 3 # Pangle_err = lib.Pangle_error(imap, ivar*s**2, deg=True) # mask = Pangle_err > 10 cmap_ = plt.get_cmap('binary') # actual cmap doesn't matter color = cmap_(np.ones_like(X)) # color[ mask,-1] = 0.2
import argparse, os, os.path as op from common import * import lib from matplotlib import pyplot as plt from pixell import enmap import plotstyle # parser defined in common parser.add_argument("--freq", default='f090') parser.add_argument("--smooth", type=float, default=None) args = parser.parse_args() if not op.exists(args.odir): os.makedirs(args.odir) box = boxes[args.area] imap = load_map(filedb[args.freq]['coadd'], box=box, fcode=args.freq) / 1e9 if args.smooth: imap = enmap.smooth_gauss(imap, args.smooth * u.fwhm * u.arcmin) # u defined in common # calculate polarization angle Pangle = 90 - lib.Bangle(imap[1], imap[2], toIAU=True) / np.pi * 180 print(f"Pangle = {np.median(Pangle)} +- {np.std(Pangle, ddof=1)}") plt.hist(np.ravel(Pangle), bins=100) plt.xlabel('Tilt w.r.t Galactic plane [deg]') ofile = op.join(args.odir, args.oname) print("Writing:", ofile) plt.savefig(ofile, bbox_inches='tight')
# fig.colorbar(im, cax=cax).set_label(texify("Total intensity [MJy/sr]")) cax = plotstyle.add_colorbar_hpad(ax, pad="1%", hpad="50%") locator = ticker.MaxNLocator(nbins=4) fig.colorbar(im, cax=cax, orientation='horizontal', ticks=locator).set_label(texify("I [MJy/sr]"), fontsize=10) cax.xaxis.set_label_position('top') cax.xaxis.set_ticks_position('top') ax.text(0.12, 1.03, texify("f090"), transform=ax.transAxes, fontsize=12) # ax.text(0.1, 1.06, texify("f090"), transform=ax.transAxes, fontsize=12) # ax.text(0.06, 1.02, texify("B")+"-"+texify("fields")+": "+texify("f090"), # transform=ax.transAxes, fontsize=8) ax.set_xlabel(r"$l$") ax.set_ylabel(r"$b$") # foreground: magnetic field orientation theta = lib.Bangle(imap_sm[1], imap_sm[2], toIAU=True) theta += np.pi / 2 # this gets the B-field angle corrected # x- and y-components of magnetic field Bx = np.cos(theta) By = np.sin(theta) # calculate polarization error as masking P = np.sum(imap[1:]**2, axis=0)**0.5 P_err = lib.P_error(imap, ivar * s**2) P_snr = P / P_err mask = P_snr < 3 cmap_ = plt.get_cmap('binary') # actual cmap doesn't matter color = cmap_(np.ones_like(P)) # color[ mask,-1] = 0.3 # color[~mask,-1] = 1 val = np.min([P_snr, np.ones_like(P_snr) * 3], axis=0) val /= 3
parser.add_argument("-Q", "--quantity", help='quantity of interests', default='bangle') parser.add_argument("--figsize", default=None) parser.add_argument("--bins", type=int, default=50) parser.add_argument("--ofile") args = parser.parse_args() if not op.exists(args.odir): os.makedirs(args.odir) if args.figsize: figsize = eval(args.figsize) else: figsize = None # load data box = boxes[args.area] imap = load_map(filedb[args.freq][args.use], box=box, fcode=args.freq) if args.quantity == 'bangle': # histogram of polarization angle quantity = np.ravel(lib.Bangle(imap[1], imap[2], toIAU=True)) / np.pi * 180 xlabel = r"$\psi_B$ [deg]" else: raise ValueError("Specify a quantity") # make a figure fig = plt.figure(figsize=None) ax = fig.add_subplot(111) ax.hist(quantity, bins=args.bins) ax.set_xlabel(xlabel) ax.set_ylabel('Count') ofile = op.join(args.odir, args.ofile) print("Writing:", ofile) plt.savefig(ofile, bbox_inches='tight')