Exemplo n.º 1
0
def load_snr(fcode=None, box=None, pol=False, downgrade=1, use='coadd'):
    # load map and ivar
    imap = load_map(filedb[fcode][use], fcode=fcode, box=box)
    ivar = load_ivar(filedb[fcode][f"{use}_ivar"], fcode=fcode, box=box)
    if not pol:  # total intensity
        snr = imap[0] * ivar[0]**0.5
    else:  # polarization intensity
        P = np.sum(imap[1:]**2, axis=0)**0.5
        P_err = lib.P_error(imap, ivar)
        snr = P / P_err
    return snr
    # optionally downgrade
    if downgrade > 1:
        snr = snr.downgrade(downgrade) * downgrade
    if box is not None: return snr.submap(box)
    else: return snr
Exemplo n.º 2
0
    '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
    # color[~mask,-1] = 1
    val = np.min([Psnr, np.ones_like(Psnr) * 3], axis=0)
    val /= 3
    color[..., -1] = val
    color = color.reshape(color.shape[0] * color.shape[1], 4)
else:
    color = 'k'
ax.quiver(X,
Exemplo n.º 3
0
 else:
     Y_, X_ = imap.posmap()/np.pi*180
     im = ax.contourf(back, colors=color, levels=level)
     xmin, xmax = box2extent(box)[:2]/np.pi*180
     ax.set_xlim([xmin, xmax])  # revert x axis
 theta = lib.Bangle(imap_ds[1], imap_ds[2], toIAU=True)
 theta += (np.pi/2.)
 # x- and y-components of magnetic field
 Bx = np.cos(theta)
 By = np.sin(theta)
 # optionally mask regions above certain angular uncertainty level
 # and high the segments through alpha
 if args.mask == 'Psnr':
     # mask by Polarization intensity SNR
     P     = np.sum(imap_ds[1:]**2, axis=0)**0.5        
     P_err = lib.P_error(imap_ds, ivar_ds*s**2)
     mask  = (P/P_err) <= 3
 elif args.mask == 'Pangle':
     Pa_err= lib.Pangle_error(imap_ds, ivar_ds*s**2, deg=True)
     mask  = Pa_err >= 20
 else:
     print("No mask applied")
     mask  = np.zeros_like(imap_ds) 
 cmap_ = plt.get_cmap('binary')  # actual cmap doesn't matter
 color = cmap_(np.ones_like(X))
 color[mask,-1] = 0.3
 color[~mask,-1] = args.alpha
 color=color.reshape(color.shape[0]*color.shape[1],4)
 ax.quiver(X,Y,Bx,By,pivot='middle', headlength=0,
           headaxislength=0, color=color, scale=args.scale,
           transform=ax.get_transform('world'))
Exemplo n.º 4
0
    imap = enmap.smooth_gauss(imap, args.smooth * u.fwhm * u.arcmin)
    ivar = enmap.smooth_gauss(ivar, args.smooth * u.fwhm * u.arcmin)
    s = sfactor(args.freq, args.smooth)
else:
    s = 1
# optionally apply downgrade
if args.downgrade > 1:
    imap = imap.downgrade(args.downgrade)
    ivar = ivar.downgrade(args.downgrade)
# decide whether to look at I or P
if not args.pol:
    noise = ivar[0]**-0.5 / s
    label = "Noise (I)"
    if title: label = f'{title}: ' + label
else:
    noise = lib.P_error(imap, ivar * s**2)
    label = "Noise (P)"
    if title: label = f'{title}: ' + label

# start plotting
opts = {'cmap': 'gray', 'vmin': args.min, 'vmax': args.max}
fig = plt.figure()
ax = plt.subplot(111, projection=imap.wcs)
plotstyle.setup_axis(ax, nticks=[5, 5], fmt=None)
im = ax.imshow(noise, **opts)
plt.xlabel('$l$')
plt.ylabel('$b$')

cax = plotstyle.add_colorbar_hpad(ax)
fig.colorbar(im, cax=cax, orientation='horizontal').set_label(
    texify(f"{label} {fcode} [MJy/sr]"), fontsize=12)
Exemplo n.º 5
0
    # imap = load_map(filedb[fcode]['coadd'], fcode=fcode, mJy=False)
    # ivar = load_ivar(filedb[fcode]['coadd_ivar'], fcode=fcode, mJy=False)

    # optionally apply smoothing
    if args.smooth > 0:
        imap = enmap.smooth_gauss(imap, args.smooth*u.fwhm*u.arcmin)
        ivar = enmap.smooth_gauss(ivar, args.smooth*u.fwhm*u.arcmin)
    # optionally apply downgrade
    if args.downgrade > 1:
        imap = imap.downgrade(args.downgrade)
        ivar = ivar.downgrade(args.downgrade)*args.downgrade**2
    # decide whether to look at I or P
    if not args.pol:
        snr = imap[0] * ivar[0]**0.5
    else:
        perr = lib.P_error(imap, ivar, method=args.method)
        snr = np.sum(imap[1:]**2,axis=0)**0.5/perr
    # start plotting
    opts = {
        'origin': 'lower',
        'cmap': 'jet',
        'extent': box2extent(box)/np.pi*180,
        'vmin': args.min,
        'vmax': args.max
    }
    if args.log: plt.imshow(np.log10(snr), **opts)
    else: plt.imshow(snr, **opts)
    plt.xlabel('l [deg]')
    plt.ylabel('b [deg]')
    if not args.pol:
        plt.colorbar(shrink=0.55).set_label('Total intensity S/N')