tavg * nt_standard / nt)].reshape( (len(subublindex) * nt / tavg, 12 * nside_standard**2)))) average_size = nside_standard / nside Bfile = '/home/omniscope/data/GSM_data/Bmatrix_nside%i_to_nside%i.bin' % ( nside_standard, nside) if os.path.isfile(Bfile): B = np.fromfile(Bfile, dtype='float32').reshape( (12 * nside**2, 12 * nside_standard**2)) else: B = np.zeros((12 * nside**2, 12 * nside_standard**2), dtype='float32') for ringpix in range(12 * nside_standard**2): B[hpf.nest2ring( nside, hpf.ring2nest(nside_standard, ringpix) / average_size**2), ringpix] = average_size**-2 B.tofile( '/home/omniscope/data/GSM_data/Bmatrix_nside%i_to_nside%i.bin' % (nside_standard, nside)) if nside <= 4 and nside != nside_standard: equatorial_GSM = B.dot(equatorial_GSM_standard) ##plt.imshow(B.transpose().dot(B)) ##plt.colorbar() ##plt.show() ##print "Computing BtBi...", ##sys.stdout.flush() ##rcondB = 1e-3 ##BtBi = la.pinv(B.transpose().dot(B) , rcond=rcondB)#+ 10.**sigmap*np.identity(len(B[0])), rcond=rcondB)
A[p][:, i] = np.array([vs.calculate_pointsource_visibility(ra, dec, d, freq, beam_heal_equ = beam_heal_equ, tlist = tlist) for d in ubls]).flatten() print "%f minutes used"%(float(time.time()-timer)/60.) sys.stdout.flush() A[p].tofile(A_filename) A[p] = A[p].reshape((len(ubls), len(tlist), 12*nside_beamweight**2))[:,tmask].reshape((len(ubls)*len(tlist[tmask]), 12*nside_beamweight**2)) #################################################### ###beam weights using an equal pixel A matrix###### ################################################# print "Computing beam weight...", sys.stdout.flush() beam_weight = (np.sum([la.norm(A[p], axis = 0)**2 for p in pols], axis = 0)**.5)[hpf.nest2ring(nside_beamweight, range(12*nside_beamweight**2))] beam_weight = beam_weight/np.mean(beam_weight) beam_weight = np.array([beam_weight for i in range(nside_standard**2/nside_beamweight**2)]).transpose().flatten() print "done." sys.stdout.flush() #hpv.mollview(beam_weight, nest=True) #plt.show() #quit() ################################################ #####################GSM########################### ############################################# #rotate sky map and converts to nest equatorial_GSM_standard_2000 = np.fromfile(datadir + 'skymap_mwacs_nside256_float32.dat', dtype='float32') print "Rotating GSM_standard and converts to nest...", sys.stdout.flush()
print "%f minutes used" % (float(time.time() - timer) / 60.) sys.stdout.flush() A[p].tofile(A_filename) A[p] = A[p].reshape( (len(ubls), len(tlist), 12 * nside_beamweight**2))[:, tmask].reshape( (len(ubls) * len(tlist[tmask]), 12 * nside_beamweight**2)) #################################################### ###beam weights using an equal pixel A matrix###### ################################################# print "Computing beam weight...", sys.stdout.flush() beam_weight = (np.sum([la.norm(A[p], axis=0)**2 for p in pols], axis=0)**.5)[hpf.nest2ring( nside_beamweight, range(12 * nside_beamweight**2))] beam_weight = beam_weight / np.mean(beam_weight) beam_weight = np.array([ beam_weight for i in range(nside_standard**2 / nside_beamweight**2) ]).transpose().flatten() print "done." sys.stdout.flush() #hpv.mollview(beam_weight, nest=True) #plt.show() #quit() ################################################ #####################GSM########################### ############################################# #rotate sky map and converts to nest equatorial_GSM_standard_2000 = np.fromfile(datadir +
###################################plot actual errors and such, see if the gridding is too coarse #A = np.fromfile('/home/omniscope/simulate_visibilities/data/Amatrix_%iubl_nside%i_%iby%i_redundantinfo_X5_q3x.bin'%(nUBL, nside, nt*nUBL, 12*nside**2),dtype='complex64').reshape((nUBL, nt, 12*nside**2))[subublindex,::tavg].reshape((len(subublindex) * nt/tavg, 12*nside**2))/nside**2 #ublindex = [u for u in range(len(ubls_standard)) if la.norm(ubls_standard[u]) < (nside * 299.792458 / freq)] A_standard = np.fromfile('/home/omniscope/data/GSM_data/Amatrix_%iubl_nside%i_%iby%i_redundantinfo_X5_q3x.bin'%(nUBL, nside_standard, nt_standard*nUBL, 12*nside_standard**2),dtype='complex64').reshape((nUBL, nt_standard, 12*nside_standard**2))[subublindex, ::(tavg*nt_standard/nt)].reshape((len(subublindex)*nt/tavg, 12*nside_standard**2)) A_standard = np.concatenate((A_standard, np.fromfile('/home/omniscope/data/GSM_data/Amatrix_%iubl_nside%i_%iby%i_redundantinfo_X5_q3y.bin'%(nUBL, nside_standard, nt_standard*nUBL, 12*nside_standard**2),dtype='complex64').reshape((nUBL, nt_standard, 12*nside_standard**2))[subublindex, ::(tavg*nt_standard/nt)].reshape((len(subublindex)*nt/tavg, 12*nside_standard**2)))) average_size = nside_standard/nside Bfile = '/home/omniscope/data/GSM_data/Bmatrix_nside%i_to_nside%i.bin'%(nside_standard,nside) if os.path.isfile(Bfile): B = np.fromfile(Bfile, dtype='float32').reshape((12*nside**2,12*nside_standard**2)) else: B = np.zeros((12*nside**2,12*nside_standard**2), dtype='float32') for ringpix in range(12*nside_standard**2): B[hpf.nest2ring(nside, hpf.ring2nest(nside_standard, ringpix)/average_size**2), ringpix] = average_size**-2 B.tofile('/home/omniscope/data/GSM_data/Bmatrix_nside%i_to_nside%i.bin'%(nside_standard,nside)) if nside <= 4 and nside != nside_standard: equatorial_GSM = B.dot(equatorial_GSM_standard) ##plt.imshow(B.transpose().dot(B)) ##plt.colorbar() ##plt.show() ##print "Computing BtBi...", ##sys.stdout.flush() ##rcondB = 1e-3 ##BtBi = la.pinv(B.transpose().dot(B) , rcond=rcondB)#+ 10.**sigmap*np.identity(len(B[0])), rcond=rcondB) ##print "Done." ##sys.stdout.flush() ##BtBi.astype('float32').tofile('/home/omniscope/data/GSM_data/BtBi_nside%i_to_nside%i.bin'%(nside_standard,nside)) #plt.imshow(np.abs(B.transpose().dot(B)))
stockert11cm = {2.72: stockert11cm} resolutions[2.72] = 21 * ARCMIN#data website uses 21, paper says 4.3 if plot_individual: plot_dataset(stockert11cm) ######################### ###mother file######################### ######################### # motherfile = {} # motherfile_data = np.fromfile("/home/omniscope/data/polarized foregrounds/motherfile_3145728_16_float64.bin", dtype='float64').reshape((3145728, 16))[hpf.nest2ring(512, range(3145728))] # for i in range(motherfile_data.shape[1]): # motherfile[i] = motherfile_data[:, i] # plot_dataset(motherfile) motherfile = {} motherfile_data = np.fromfile("/home/omniscope/data/polarized foregrounds/motherfile_3145728_16_float64.bin", dtype='float64').reshape((3145728, 16))[hpf.nest2ring(512, range(3145728))] motherfile[.045] = motherfile_data[:, -9] motherfile[2.33] = motherfile_data[:, -1] # motherfile[.0345] = motherfile_data[:, -11] # motherfile[.408] = motherfile_data[:, -3] # motherfile[.022] = motherfile_data[:, -13] # motherfile[.82] = motherfile_data[:, -2] # motherfile[.010] = motherfile_data[:, -16] # resolutions[.010] = (2.6 * 1.9)**.5 * DEGREE # resolutions[.022] = (1.1 * 1.7)**.5 * DEGREE resolutions[.045] = 3.6 * DEGREE # resolutions[.82] = 1.2 * DEGREE resolutions[2.33] = 20 * ARCMIN if plot_individual: plot_dataset(motherfile)
def smoothing(m, fwhm, nest=True): if fwhm <= 0: return m nside = hpf.npix2nside(len(m)) if nest: return hps.smoothing(m[hpf.ring2nest(nside, np.arange(hpf.nside2npix(nside)))], fwhm=fwhm)[hpf.nest2ring(nside, np.arange(hpf.nside2npix(nside)))] else: return hps.smoothing(m, fwhm=fwhm)
[vs.calculate_pointsource_visibility(ra, dec, d, freq, beam_heal_equ=beam_heal_equ, tlist=tlist) for d in ubls]).flatten() print "%f minutes used" % (float(time.time() - timer) / 60.) sys.stdout.flush() A[p].tofile(A_path) A[p] = A[p].reshape((len(ubls), len(tlist), 12 * nside_beamweight ** 2))[:, tmask].reshape( (len(ubls) * len(tlist[tmask]), 12 * nside_beamweight ** 2)) #################################################### ###beam weights using an equal pixel A matrix###### ################################################# print "Computing beam weight...", sys.stdout.flush() beam_weight = ((la.norm(A['x'], axis=0) ** 2 + la.norm(A['y'], axis=0) ** 2) ** .5)[ hpf.nest2ring(nside_beamweight, range(12 * nside_beamweight ** 2))] beam_weight = beam_weight / np.mean(beam_weight) beam_weight = np.array([beam_weight for i in range(nside_standard ** 2 / nside_beamweight ** 2)]).transpose().flatten() print "done." sys.stdout.flush() ################################################ #####################GSM########################### ############################################# pca1 = hp.fitsfunc.read_map(script_dir + '/../data/gsm1.fits' + str(nside_standard)) pca2 = hp.fitsfunc.read_map(script_dir + '/../data/gsm2.fits' + str(nside_standard)) pca3 = hp.fitsfunc.read_map(script_dir + '/../data/gsm3.fits' + str(nside_standard)) components = np.loadtxt(script_dir + '/../data/components.dat') scale_loglog = si.interp1d(np.log(components[:, 0]), np.log(components[:, 1])) w1 = si.interp1d(components[:, 0], components[:, 2]) w2 = si.interp1d(components[:, 0], components[:, 3])
dataset = {} ###1.4GHz### stockert = fit.read("/home/omniscope/data/polarized foregrounds/stocker_villa_elisa.bin")[0] stockert[:, :-1] = np.roll(stockert[:, :-1], 720, axis=1)[:, ::-1] stockert[:, -1] = stockert[:, 0] stockert = equirectangular2heapix(stockert, extract_nside) reich_q = equirectangular2heapix(fit.read("/home/omniscope/data/polarized foregrounds/allsky.q.lb.fits")[0], extract_nside, data_x=(np.pi+np.arange(np.pi * 2 + 1e-9, 0, -np.pi/720))%(np.pi*2+1e-9)) reich_u = -equirectangular2heapix(fit.read("/home/omniscope/data/polarized foregrounds/allsky.u.lb.fits")[0], extract_nside, data_x=(np.pi+np.arange(np.pi * 2 + 1e-9, 0, -np.pi/720))%(np.pi*2+1e-9))#reich is in IAU convention whose U is minus sign the CMB healpix convention dataset[1.42] = np.array([ stockert, #merge_map([chipass, stockert], verbose=True, renormalize=True), reich_q, #merge_map([drao[1], elisa[1]]), reich_u, #merge_map([drao[2], elisa[2]]), ]) / 1.e3 ########################### ###S-PASS 9' 2.3GHz 224MHz BW ######################### dataset[2.3] = np.array([fit.read('/home/omniscope/data/polarized foregrounds/spass_hmap_m_1111_%s.fits'%IQU)['UNKNOWN1'].flatten()[hpf.nest2ring(1024, range(hpf.nside2npix(1024)))] for IQU in ['I', 'Q', 'U']]) dataset[2.3][2] = -dataset[2.3][2] # IAU convention to CMB convention ########################### ###CMB###### ############### #####wmap dataset[22.8] = np.array([fit.read("/home/omniscope/data/polarized foregrounds/wmap_band_iqumap_r9_9yr_K_v5.fits")[key] for key in ['TEMPERATURE', 'Q_POLARISATION', 'U_POLARISATION']]) / 1.e3 plot_dataset(dataset)
dec = np.pi / 2 - dec print "\r%.1f%% completed" % (100. * float(i) / (12. * nside_beamweight ** 2)), sys.stdout.flush() if abs(dec - lat_degree * np.pi / 180) <= np.pi / 2: A[p][:, i] = vs.calculate_pointsource_visibility(ra, dec, ubls, freq, beam_heal_equ=beam_heal_equ, tlist=tlist).flatten() print "%f minutes used" % (float(time.time() - timer) / 60.) sys.stdout.flush() A[p].tofile(A_path) #################################################### ###beam weights using an equal pixel A matrix###### ################################################# print "Computing beam weight...", sys.stdout.flush() beam_weight = ((la.norm(A['x'], axis=0) ** 2 + la.norm(A['y'], axis=0) ** 2) ** .5)[hpf.nest2ring(nside_beamweight, range(12 * nside_beamweight ** 2))] beam_weight = beam_weight / np.mean(beam_weight) thetas_standard, phis_standard = hpf.pix2ang(nside_standard, range(hpf.nside2npix(nside_standard)), nest=True) beam_weight = hpf.get_interp_val(beam_weight, thetas_standard, phis_standard, nest=True) #np.array([beam_weight for i in range(nside_standard ** 2 / nside_beamweight ** 2)]).transpose().flatten() print "done." sys.stdout.flush() ################################################ #####################GSM########################### ############################################# pca1 = hp.fitsfunc.read_map(script_dir + '/../data/gsm1.fits' + str(nside_standard)) pca2 = hp.fitsfunc.read_map(script_dir + '/../data/gsm2.fits' + str(nside_standard)) pca3 = hp.fitsfunc.read_map(script_dir + '/../data/gsm3.fits' + str(nside_standard)) components = np.loadtxt(script_dir + '/../data/components.dat') scale_loglog = si.interp1d(np.log(components[:, 0]), np.log(components[:, 1])) w1 = si.interp1d(components[:, 0], components[:, 2])
print "\r%.1f%% completed, %f minutes left"%(100.*float(i)/(12.*nside_beamweight**2), (12.*nside_beamweight**2-i)/(i+1)*(float(time.time()-timer)/60.)), sys.stdout.flush() A[p][:, i] = np.array([vs.calculate_pointsource_visibility(ra, dec, d, freq, beam_heal_equ = beam_heal_equ, tlist = tlist) for d in ubls]).flatten() print "%f minutes used"%(float(time.time()-timer)/60.) sys.stdout.flush() A[p].tofile(A_filename) A[p] = A[p].reshape((len(ubls), len(tlist), 12*nside_beamweight**2))[:,tmask].reshape((len(ubls)*len(tlist[tmask]), 12*nside_beamweight**2)) #################################################### ###beam weights using an equal pixel A matrix###### ################################################# print "Computing beam weight...", sys.stdout.flush() beam_weight = ((la.norm(A['x'], axis = 0)**2 + la.norm(A['y'], axis = 0)**2)**.5)[hpf.nest2ring(nside_beamweight, range(12*nside_beamweight**2))] beam_weight = beam_weight/np.mean(beam_weight) beam_weight = np.array([beam_weight for i in range(nside_standard**2/nside_beamweight**2)]).transpose().flatten() print "done." sys.stdout.flush() ################################################ #####################GSM########################### ############################################# pca1 = hp.fitsfunc.read_map(script_dir + '/../data/gsm1.fits' + str(nside_standard)) pca2 = hp.fitsfunc.read_map(script_dir + '/../data/gsm2.fits' + str(nside_standard)) pca3 = hp.fitsfunc.read_map(script_dir + '/../data/gsm3.fits' + str(nside_standard)) components = np.loadtxt(script_dir + '/../data/components.dat') scale_loglog = si.interp1d(np.log(components[:,0]), np.log(components[:,1])) w1 = si.interp1d(components[:,0], components[:,2]) w2 = si.interp1d(components[:,0], components[:,3])