def test_basic(): lmax = 10 nside = 8 rank = MPI.COMM_WORLD.Get_rank() ms = np.arange(rank, lmax + 1, MPI.COMM_WORLD.Get_size(), dtype=np.int32) order = libsharp.packed_real_order(lmax, ms=ms) grid = libsharp.healpix_grid(nside) alm = np.zeros(order.local_size()) if rank == 0: alm[0] = 1 elif rank == 1: alm[0] = 1 map = libsharp.synthesis(grid, order, np.repeat(alm[None, None, :], 3, 0), comm=MPI.COMM_WORLD) assert np.all(map[2, :] == map[1, :]) and np.all(map[1, :] == map[0, :]) map = map[0, 0, :] if rank == 0: healpy.mollzoom(map) from matplotlib.pyplot import show show()
def clean_map(file_name, threshold, show_plot=1): this_map = hp.read_map(setup.out_files_path + file_name + ".fits") mask = hp.read_map(setup.out_files_path + "mask.fits") cleaned_map = np.ma.array(this_map, mask=(mask == 0), fill_value=0.) cleaned_map = (cleaned_map - threshold) * (cleaned_map > threshold ) #*(cleaned_map < 1e19) if show_plot: hp.mollzoom(cleaned_map, title="Cleaned Map : " + file_name) #, min = 0, max = 1e-4) plt.show() return cleaned_map
def compare_power(input_file1, input_file2, nside=2048, lmax=2000, read_inputs=True, object1=None, object2=None, display_plots=True): ''' simple power spectrum comparison ''' map_dens1 = create_healpix_map(input_file1, nside, read_inputs=read_inputs, object1=object1) map_dens2 = create_healpix_map(input_file2, nside, read_inputs=read_inputs, object1=object2) # scaling to remove monopole - this helps with power spectrum computation. mask_octant = compute_mask(nside=nside, octant="upper") map_dens1 = scale_map(map_dens1, mask_octant, nside=nside) map_dens2 = scale_map(map_dens2, mask_octant, nside=nside) print('comparing density maps') hp.mollview(map_dens1) hp.mollview(map_dens2) hp.mollzoom(map_dens1 - map_dens2) if display_plots: plt.show() alm_1 = hp.map2alm(map_dens1, lmax=lmax) alm_2 = hp.map2alm(map_dens2, lmax=lmax) cl_1 = hp.alm2cl(alm_1) cl_2 = hp.alm2cl(alm_2) print('computed power spectra') l = np.arange(lmax + 1) fsky = 1. / 8 plt.figure() plt.plot(l, cl_1 * l * (l + 1) / (2. * np.pi) / fsky) plt.plot(l, cl_2 * l * (l + 1) / (2. * np.pi) / fsky) plt.savefig('cls_' + input_file1 + '_' + input_file2 + '.png', dpi=500) if display_plots: plt.show() plt.figure() plt.plot(l, np.abs(cl_1 - cl_2) / cl_1) plt.savefig('cls_fractional_' + input_file1 + '_' + input_file2 + '.png', dpi=500) if display_plots: plt.show() return map_dens1, map_dens2, cl_1, cl_2
def main(): nb_comp = 2 NSIDE = 2048 F_matrix = [] for i in range(nb_comp): F_matrix.append(Total_matrix[i]) print 'F_matrix : %s' % F_matrix truncated_maps = library.get_truncated_maps(NSIDE) mask = hp.read_map(setup.out_files_path + 'mask.fits') for i in range(nb_comp): #if i == 0: if True: print 'Computing component %s' % i e_vector = list() for j in range(nb_comp): e_vector.append(0) e_vector[i] = 1. S = library.compute_S_matrix(truncated_maps, F_matrix, e_vector) # hp.mollview(S[i], title="Component %s" % i, norm='hist') if i == 0: hp.gnomview(S, rot=[0, 90]) hp.mollzoom(S, norm='hist') hp.write_map( setup.out_files_path + "ILC_SZ_comp_" + str(NSIDE) + ".fits", S) S = np.ma.array(S, mask=(mask == 0), fill_value=hp.UNSEEN) hp.mollview(S, title="Component_%s" % i, norm='hist') library.save_figure('Component_%s' % i, sub_folder='figures/ILC') del S plt.show() return 0
mp.clf() display(convolved_sky, 'Original map', iplot=1) display(solution_fusion['x'], 'Reconstructed map', iplot=4) res_fusion = display(solution_fusion['x'] - convolved_sky, 'Difference map', iplot=7) mp.figure(3) for res, color in zip((res_qubic, res_fusion), ('blue', 'green')): for i, kind in enumerate('IQU'): axis = mp.subplot(3, 1, i+1) x, y = profile(res[i]**2) x *= 5 / 60 y = np.sqrt(y) y *= np.degrees(np.sqrt(4 * np.pi / acq_qubic.scene.npixel)) mp.plot(x, y, color=color) mp.title(kind) mp.ylabel('Sensitivity [$\mu$K deg]') mp.xlabel('Angular distance [degrees]') # BICEP-2 / Planck # sigmas = 1.2 * np.array([1 / np.sqrt(2), 1, 1]) sigmas = np.std(acq_planck.sigma, 0) for i, sigma in enumerate(sigmas): axis = mp.subplot(3, 1, i+1) mp.axhline(sigma, color='red') hp.mollzoom(solution_fusion['x'][:, 0] - convolved_sky[:, 0]) mp.show()
vmin = -cc vmax = cc ax.pcolormesh(x_grid, y_grid, arr.T, rasterized=True, vmin=vmin, vmax=vmax) #, cmap=cmap) ax.axis('off') #ax.set_title(title, y=0.975) # Plot equiangular map '''fig, ax = plt.subplots(1) #,1) myplot_moll(f_mw.real, L, ax, title=r'Input CMB map') #map converted to MW') fig.subplots_adjust(left=0.01, right=0.99, bottom=0.01, top=0.95) plt.savefig('/Users/keir/Documents/s2let_ilc_latex/s2let_ilc_papers/s2let_ilc_temp/cmb_orig_mollweide.pdf',dpi=1200)''' #plt.show() '''LIM = 150 hp.mollzoom(f_ini[0]*1e6,unit=r'$\mu\mathrm{K}$',title=r'Input CMB Stokes $Q$ map',min=-1.*LIM,max=LIM) plt.savefig('/Users/keir/Documents/s2let_ilc_latex/s2let_ilc_papers/s2let_ilc_pol/fg_353_q.pdf') hp.mollzoom(f_ini[1]*1e6,unit=r'$\mu\mathrm{K}$',title=r'Input CMB Stokes $U$ map',min=-1.*LIM,max=LIM) plt.savefig('/Users/keir/Documents/s2let_ilc_latex/s2let_ilc_papers/s2let_ilc_pol/fg_353_u.pdf')''' # Create giant array figure plt.rc('font', family='serif', size=14.0) fig, axs = plt.subplots(nrows, 3, sharex=True, sharey=True, figsize=(8., 6.4 * (nrows / 4.))) axs = axs.ravel() # Loop through scales j and directions n for j in xrange(0, 3):
mp.figure(2) mp.clf() display(conv_sky, 'Original map', iplot=1) display(x_rec_fusion, 'Reconstructed map', iplot=4) res_fusion = display(x_rec_fusion - conv_sky, 'Difference map', iplot=7) mp.figure(3) for res, color in zip((res_qubic, res_fusion), ('blue', 'green')): for i, kind in enumerate('IQU'): axis = mp.subplot(3, 1, i + 1) x, y = profile(res[i]**2) x *= 5 / 60 y = np.sqrt(y) y *= np.degrees(np.sqrt(4 * np.pi / acq.scene.npixel)) mp.plot(x, y, color=color) mp.title(kind) mp.ylim(0, 1.8) mp.ylabel('Sensitivity [$\mu$K deg]') mp.xlabel('Angular distance [degrees]') # BICEP-2 / Planck # sigmas = 1.2 * np.array([1 / np.sqrt(2), 1, 1]) sigmas = np.std(acq_planck.sigma, 0) for i, sigma in enumerate(sigmas): axis = mp.subplot(3, 1, i + 1) mp.axhline(sigma, color='red') hp.mollzoom(x_rec_fusion[:, 0] - conv_sky[:, 0]) mp.show()
display(convolved_sky, 'Original map', iplot=1) display(solution_fusion['x'], 'Reconstructed map', iplot=4) res_fusion = display(solution_fusion['x'] - convolved_sky, 'Difference map', iplot=7) mp.figure(3) for res, color in zip((res_qubic, res_fusion), ('blue', 'green')): for i, kind in enumerate('IQU'): axis = mp.subplot(3, 1, i + 1) x, y = profile(res[i]**2) x *= 5 / 60 y = np.sqrt(y) y *= np.degrees(np.sqrt(4 * np.pi / acq_qubic.scene.npixel)) mp.plot(x, y, color=color) mp.title(kind) mp.ylabel('Sensitivity [$\mu$K deg]') mp.xlabel('Angular distance [degrees]') # BICEP-2 / Planck # sigmas = 1.2 * np.array([1 / np.sqrt(2), 1, 1]) sigmas = np.std(acq_planck.sigma, 0) for i, sigma in enumerate(sigmas): axis = mp.subplot(3, 1, i + 1) mp.axhline(sigma, color='red') hp.mollzoom(solution_fusion['x'][:, 0] - convolved_sky[:, 0]) mp.show()
# create_healpix_map.py Create a healpix map showing the Galactic DM contribution. """ import healpy as hp import numpy as np import pyymw16 import pylab as plt import os filename = 'ymw16_allsky.fits' if os.path.exists(filename): print("File %s exists, skipping write" % filename) d_2016 = hp.read_map(filename) else: print("Generating healpix map... (this may take a while)") NSIDE = 128 pix_id = np.arange(hp.nside2npix(NSIDE)) gl, gb = hp.pix2ang(NSIDE, pix_id, lonlat=True) d_2016 = np.zeros_like(pix_id, dtype='float32') for ii in pix_id: dm, tau = pyymw16.dist_to_dm(gl[ii], gb[ii], 30000) d_2016[ii] = dm.value print("Writing to %s" % filename) hp.write_map(filename, d_2016, coord='G') hp.mollzoom(np.log(d_2016), title='YMW16', cmap='magma') plt.show()
mp.figure(2) mp.clf() display(conv_sky, 'Original map', iplot=1) display(x_rec_fusion, 'Reconstructed map', iplot=4) res_fusion = display(x_rec_fusion - conv_sky, 'Difference map', iplot=7) mp.figure(3) for res, color in zip((res_qubic, res_fusion), ('blue', 'green')): for i, kind in enumerate('IQU'): axis = mp.subplot(3, 1, i+1) x, y = profile(res[i]**2) x *= 5 / 60 y = np.sqrt(y) y *= np.degrees(np.sqrt(4 * np.pi / acq.scene.npixel)) mp.plot(x, y, color=color) mp.title(kind) mp.ylim(0, 1.8) mp.ylabel('Sensitivity [$\mu$K deg]') mp.xlabel('Angular distance [degrees]') # BICEP-2 / Planck # sigmas = 1.2 * np.array([1 / np.sqrt(2), 1, 1]) sigmas = np.std(acq_planck.sigma, 0) for i, sigma in enumerate(sigmas): axis = mp.subplot(3, 1, i+1) mp.axhline(sigma, color='red') hp.mollzoom(x_rec_fusion[:, 0] - conv_sky[:, 0]) mp.show()
def plot_map(hpxmap, unit='unit'): mpl.rcParams['image.cmap'] = 'jet' hp.mollzoom(hpxmap, unit=unit, title='title') hp.graticule()
# diffAbsMax = diffMax # if os.path.exists(phiMapFilename): # print "read phi map" # phiMap = hp.read_map(phiMapFilename) # else: # print "read phi alm" # phiAlm = hp.read_alm(phiAlmFilename) # phiMap = hp.alm2map(phiAlm, 2048) # hp.write_map(phiMapFilename, phiMap) # diffScheme = colors.SymLogNorm(linthresh=9.e-5, linscale=0.03, vmin=-diffMax, vmax=diffMax) # normScheme = colors.SymLogNorm(linthresh=1.5e-8, linscale=1., vmin=minTemp, vmax=maxTemp) print 'plot unlensed' hp.mollzoom(unlensedMap, xsize=2048, cmap=cibCmap, title="Unlensed @ %.2f<zmax<%.2f smoothed fwhm=0.0035" % (zMinCib,zMaxCib), min=unlensedMin, max=unlensedMax, rot=rotAngle)#, norm=normScheme) # hp.set_g_clim(minTemp, maxTemp) #sets min/max of zoomed portion hp.set_g_clim(unlensedMin, unlensedMax) # plt.savefig('/scratch2/r/rbond/phamloui/pics/jul17_unlensed_fwhm_0.0035/unlensed_zmin%.1f_zmax%.1f.png' % (zMinCib, zMaxCib), dpi=220) print 'plot lensed' hp.mollzoom(lensedUnseen, xsize=2048, cmap=cibCmap, title="Unlensed @ %.2f<zmax<%.2f" % (zMinCib,zMaxCib), min=lensedMin, max=lensedMax, rot=rotAngle)#, norm=normScheme) # hp.set_g_clim(minTemp, maxTemp) hp.set_g_clim(lensedMin, lensedMax) # plt.savefig('/scratch2/r/rbond/phamloui/pics/jul17_lensed_fwhm_0.0035/lensed_zmin%.1f_zmax%.1f.png' % (zMinCib, zMaxCib), dpi=220) # print 'plot diff' # hp.mollzoom(diffUnseen, xsize=2048, cmap=diffCmap, title="Diff @ %.2f<zmax<%.2f" % (zMinCib,zMaxCib), min=-diffMax, max=diffMax)#, norm=diffScheme) # hp.set_g_clim(-diffMax, diffMax) # plt.savefig('/scratch2/r/rbond/phamloui/pics/jul17_diff_fwhm_0.0035/diff_zmin%.1f_zmax%.1f.png' % (zMinCib, zMaxCib), dpi=220) # print 'plot kappa' # hp.mollzoom(kappaMap, xsize=2048, cmap=lensingCmap, title="Kappa @ 0.20<zmax<%.2f" % zMax) # print 'plot phi'
assert (lmax_in > lmax_out), "New lmax must be less than lmax of input alms" alm_out = np.zeros(hp.Alm.getsize(lmax_out), dtype=np.complex) for il in xrange(0, lmax_out + 1): alm_out[hp.Alm.getidx(lmax_out, il, np.arange(0, il + 1))] = alm_in[hp.Alm.getidx( lmax_in, il, np.arange(0, il + 1))] return alm_out # Usage: new_lmax = 8000 alm = lower_lmax(alm, new_lmax) # Make map from alms tmap = hp.alm2map(alm, nside) # Look at map interactively hp.mollzoom(tmap) # SPT-only products: # Read filter transfer functions tlm = hp.read_alm('tlm_150GHz_lmax10000.fits') # Read beam file bl = np.fromfile('bl_gauss_fwhm1p75am_lmax10000.bin') # Create new beam: fwhm_arcmin_new = 1.85 # FWHM of new beam bl_new = hp.gauss_beam(fwhm_arcmin_new / 60. * np.pi / 180., lmax=10000)
fig = plt.figure(1) hp.mollview(gravPotential, fig=1, xsize=2048, hold=True) plt.quiver(x[nanIndices], y[nanIndices], gradphiI[nanIndices], gradphiR[nanIndices], units='x', width=0.0006, scale=0.045, pivot='mid') #lower scale -> larger arrows plt.figure(2) hp.mollzoom(unlensed, fig=2, xsize=2048, title="Unlensed", min=cibMin, max=cibMax) hp.set_g_clim(cibMin, cibMax) plt.figure(3) hp.mollzoom(lensedUnseen, fig=3, xsize=2048, title="Lensed", min=cibMin, max=cibMax) hp.set_g_clim(cibMin, cibMax) # plt.figure(4) # diffMap = lensed - unlensed # diffRange = np.absolute(diffMap).max()
zMinCib, zMaxCib) primary_smoothed_file = appendToFilename(primary_file, "fwhm_%s" % _fwhm) # if not os.path.exists(primary_smoothed_file): # primary_map = hp.read_map(primary_file) # hp.mollzoom(primary_map, xsize=2048, title="Unlensed %.1f<z<%.1f" % (zMinCib, zMaxCib)) # print "smoothing primary..." # primary_map_smoothed = hp.smoothing(primary_map, fwhm=_fwhm) # hp.mollzoom(primary_map_smoothed, xsize=2048, title="Unlensed smoothed %.1f<z<%.1f" % (zMinCib, zMaxCib)) # plt.show() # print "writing smoothed primary to file..." # hp.write_map(primary_smoothed_file, primary_map_smoothed) # else: # print "smoothed primary already exists - skipping" if not os.path.exists(kappa_smoothed_file): kappa_map = hp.read_map(kappa_file) hp.mollzoom(kappa_map, xsize=2048, title="Kappa 0.2<z<%.1f" % zMax) print "smoothing kappa..." kappa_map_smoothed = hp.smoothing(kappa_map, fwhm=_fwhm) hp.mollzoom(kappa_map_smoothed, xsize=2048, title="kappa smoothed 0.2<z<%.1f" % zMax) plt.show() print "writing smoothed kappa to file..." hp.write_map(kappa_smoothed_file, kappa_map_smoothed) else: print "smoothed kappa already exists - skipping" i += 1