def G_plus_C_four(freq): """plots fourier of GSM and CMB added together User defines GSM frequency in MHz WARNING:takes some times to run Note: GSM default shape is 512 CMB default shape is 2048 GSM and CMB shape must match to add arrays GSM has been cast to a higher nside of 2048 """ gsm = GlobalSkyModel() #creates a model of the GSM gsmdata = gsm.generate(freq) #upgrades the GSM to 2048 gsmdata = hp.ud_grade(gsmdata, 2048) cmbdata = hp.read_map( '/home/amber/data/cmb/COM_CMB_IQU-commander-field-Int_2048_R2.01_full.fits' ) LMAX = 1024 bothmap = hp.anafast(gsmdata + cmbdata, lmax=LMAX) ell = np.arange(len(bothmap)) plt.figure() freq_str = str(freq) plt.plot(ell, ell * (ell + 1) * bothmap, color='b', label='GSM at ' + freq_str + ' MHz +CMB') plt.xlabel('ell') plt.ylabel('ell(ell+1)') plt.grid() #delete this line? #hp.write_bothmap('bothmap.fits',bothmap) plt.legend(loc='upper right') plt.show()
def G_plus_C_four(freq): """plots fourier of GSM and CMB added together User defines GSM frequency in MHz WARNING:takes some times to run Note: GSM default shape is 512 CMB default shape is 2048 GSM and CMB shape must match to add arrays GSM has been cast to a higher nside of 2048 """ gsm=GlobalSkyModel() #creates a model of the GSM gsmdata=gsm.generate(freq) #upgrades the GSM to 2048 gsmdata=hp.ud_grade(gsmdata,2048) cmbdata=hp.read_map('/home/amber/data/cmb/COM_CMB_IQU-commander-field-Int_2048_R2.01_full.fits') LMAX=1024 bothmap=hp.anafast(gsmdata+cmbdata,lmax=LMAX) ell=np.arange(len(bothmap)) plt.figure() freq_str=str(freq) plt.plot(ell,ell*(ell+1)*bothmap,color='b',label='GSM at '+freq_str+' MHz +CMB') plt.xlabel('ell');plt.ylabel('ell(ell+1)');plt.grid() #delete this line? #hp.write_bothmap('bothmap.fits',bothmap) plt.legend(loc='upper right') plt.show()
def compare_to_gsm(): """ Compare output of python version to fortran version. Compares against output of original GSM. Note that the interpolation functions used in this and in the original differ. So, the outputs differ too, by as much as 5%. This just goes to show that there's only so much accuracy that one can get via interpolation. If the frequency matches a map used to generate the GSM, then the fortran and python should match up pretty much exactly as no interpolation is required. In between maps is where the differences will become more apparent. Note: The gsm.f that is supplied only ever uses the haslam map. It also has no option to change the interpolation method. Note: Because each output """ gsm = GlobalSkyModel(basemap='haslam', interpolation='cubic') gsm_fortran = h5py.File('gsm_fortran_test_data.h5') for freq in (10, 100, 408, 1000, 1420, 2326, 10000, 23000, 40000, 90000, 94000): print("\nComparing at %i MHz..." % freq) a = gsm_fortran['map_%imhz.out' % freq][:] b = gsm.generate(freq) print "FORTRAN: ", a print "PYTHON: ", b print "FRAC AVG: %2.6f" % np.average(np.abs(1 - a/b))
def GSM_four(freq, scale): """plots fourier of the GSM model used defines freq in MHz such as 5000 user defines power of 10 scale down such as -4 """ gsm = GlobalSkyModel() #generates the GSM model gsmdata = gsm.generate(freq) LMAX = 1024 gsmmap = hp.anafast(gsmdata * (10**scale), lmax=LMAX) ell = np.arange(len(gsmmap)) plt.figure() #convert variables to text for labels scale_str = str(scale) freq_str = str(freq) plt.plot(ell, ell * (ell + 1) * gsmmap, color='b', label='GSM*10^ ' + scale_str + ' at ' + freq_str + ' MHz') plt.xlabel('ell') plt.ylabel('ell(ell+1)') plt.grid() #delete this line? #hp.write_gsmmap('gsmmap.fits',gsmmap) plt.legend(loc='upper right') plt.show()
def G_plus_C_cross_C_four(freq,scale): """plot of fourier of GSM(scale)+CMB crossed with CMB compared to CMB only User defines GSM freq in MHz User defines scale of GSM such as 0.1 or 0.01 WARNING: takes some time to run """ gsm=GlobalSkyModel() #create the GSM model gsmdata=gsm.generate(freq) #rather than upgrading GSM, downgrade the CMB to 512 cmbdata=hp.read_map('/home/amber/data/cmb/COM_CMB_IQU-commander-field-Int_2048_R2.01_full.fits') cmbmap=hp.ud_grade(cmbdata,512) LMAX=1024 both=(gsmdata*scale)+cmbmap #cross cmb+gsm with the cmb c_plus_g_cross_c=hp.sphtfunc.anafast(both,map2=cmbmap,lmax=LMAX) ell=np.arange(len(c_plus_g_cross_c)) plt.figure() #format variables as text for labels freq_str=str(freq) scale_str=str(scale) plt.plot(ell,ell*(ell+1)*c_plus_g_cross_c,color='b',label='GSM('+scale_str+') at '+freq_str+' MHZ+CMB cross CMB') cmbmaponly=hp.anafast(cmbdata,lmax=LMAX) ell=np.arange(len(cmbmaponly)) plt.plot(ell,ell*(ell+1)*cmbmaponly,color='r',label='CMB') #delete this line? #hp.write_cmbmaponly('cmbmaponly.fits',cmbmaponly) plt.xlabel('ell');plt.ylabel('ell(ell+1)');plt.grid() #delete this line? #hp.write_cp_plus_g_cross_c('c_plus_g_cross_c.fits',c_plus_g_cross_c) plt.legend(loc='upper right') plt.show()
def compare_gsm_to_old(): g = GlobalSkyModel2016(freq_unit='GHz', resolution='hi', unit='TCMB') d = g.generate(0.408) g.view() g_old = GlobalSkyModel(freq_unit='GHz', basemap='haslam') d_old = g_old.generate(0.408) g_old.view()
def test_speed(): gsm = GlobalSkyModel(basemap='haslam') t1 = time.time() for ff in np.linspace(10, 10000, 100): gsm.generate(ff) t2 = time.time() print("Time taken: %2.2fs" % (t2 - t1))
def Beam_G_plus_C_cross_C_four(freq,scale,itheta,iphi,nside,sig=np.pi/10): """plot of fourier for GSM(scale)+CMB crossed with CMB beam applied then accounted for all compared to CMB alone User defines frequency of GSM and scale to decrease it User selects point of interest: theta and phi User may designate sigma for beam User selects nside Default sigma is pi/10 """ gsm=GlobalSkyModel() #generates GSM model gsmdata=gsm.generate(freq) #rather than upgrading GSM, downgrade the CMB to 512 cmbdata=hp.read_map('/home/amber/data/cmb/COM_CMB_IQU-commander-field-Int_2048_R2.01_full.fits') cmbmap=hp.ud_grade(cmbdata,512) LMAX=1024 both=(gsmdata*scale)+cmbmap #run the beam function with the given input showbeam=beam(itheta,iphi,nside,sig) npix=12*nside**2 #correct the data to account for the beam correction=npix/(np.sum(showbeam)) both=both*showbeam*correction #cross GSM+CMB with CMB and transform c_plus_g_cross_c=hp.sphtfunc.anafast(both,map2=cmbmap,lmax=LMAX) ell=np.arange(len(c_plus_g_cross_c)) plt.figure() #convert variables into text for labels freq_str=str(freq) scale_str=str(scale) plt.plot(ell,ell*(ell+1)*c_plus_g_cross_c,color='b',label='GSM('+scale_str+') at '+freq_str+' MHZ+CMB cross CMB') #transform CMB cmbmaponly=hp.anafast(cmbmap,lmax=LMAX) ell=np.arange(len(cmbmaponly)) plt.plot(ell,ell*(ell+1)*cmbmaponly,color='r',label='CMB') #delete this line? #hp.write_cmbmaponly('cmbmaponly.fits',cmbmaponly) plt.xlabel('ell');plt.ylabel('ell(ell+1)');plt.grid() #delete this line? #hp.write_c_plus_g_cross_c('c_plus_g_cross_c.fits',c_plus_g_cross_c) #convert variable into text for labels theta_str=str(itheta) phi_str=str(iphi) plt.legend(loc='upper right') plt.title('Point of Interest:('+theta_str+','+phi_str+')') #set the limits for the y axis plt.ylim(-0.00000001,0.00000006) plt.show()
def __init__(self, freq=350 * u.MHz, model='2008'): assert str(model) in ['2008', '2016'] if not isinstance(freq, astropy.units.quantity.Quantity): # assume MHz freq = freq * u.MHz if str(model) == '2008': self.gsm = GlobalSkyModel() elif str(model) == '2016': self.gsm = GlobalSkyModel2016() self.map = self.gsm.generate(freq.to(u.MHz).value) self.freq = freq self.model = model
def healpix_brightness(self, sbar): if self.params['use_2008']: gsm = GlobalSkyModel(unit="MJysr", theta_rot = self.params['theta0'], phi_rot = self.params['phi0'], resolution="lo" if self.params['low_res'] else "hi") else: gsm = GlobalSkyModel2016(unit="MJysr", theta_rot = self.params['theta0'], phi_rot = self.params['phi0'], resolution="lo" if self.params['low_res'] else "hi") #This only works for the steven-murray/PyGSM fork. gsm.generate(self.params['nu0'] * self.f0) data = np.atleast_2d(gsm.generated_map_data) * 1e6 # rot_map = np.zeros_like(data) # # for i in range(len(self.f0)): # rot_map[i] = 1e6 * rotate_map(data[i], self.params['theta0'], self.params['phi0']) #1e6 because units are MJy return data
def _generate_gsm_map(self) -> da.Array: """ """ # Generate the GSM map at the given frequency gsm = GlobalSkyModel(freq_unit="MHz") gsm_map = gsm.generate(self.frequency) # Resize the GSM HEALPix map to the required dimensions gsm_map_nside = hp.pixelfunc.npix2nside(gsm_map.shape[-1]) if gsm_map_nside != self.nside: gsm_map = hp.pixelfunc.ud_grade( map_in=gsm_map, nside_out=self.nside ) # gsm_map = gal_to_eq.rotate_map_alms( # gsm_map # ) # Add frequency if size=1 if self.frequency.size == 1: gsm_map = np.expand_dims(gsm_map, axis=0) # Convert the map, currently in Galactic coordinates to equatorial gal_to_eq = hp.rotator.Rotator( deg=True, rot=[0, 0], coord=['G', 'C'] ) for i in range(self.frequency.size): with HiddenPrints(): gsm_map[i, :] = gal_to_eq.rotate_map_pixel( gsm_map[i, :] ) # Transform into dask array gsm_map = da.from_array(gsm_map) # Add time/polarization dimensions gsm_map = np.tile(gsm_map, (self.time.size, 1, 1, 1)) gsm_map = np.moveaxis(gsm_map, source=2, destination=1) return gsm_map
def G_plus_C_cross_C_beam_chi(freq, scale, itheta, iphi, nside, sig, cmbmap, cmbmaponly): """returns the ratio of chi/signal for beam applied to GSM(scale)+CMB crossed with CMB versus CMB alone uses same input as Beam_G_plus_C_cross_C_four() but returns value of ratio only, no plot CANNOT BE RUN ALONE, REFERENCES ANOTHER FUNCTION """ gsm = GlobalSkyModel() #generates GSM model gsmdata = gsm.generate(freq) #rather than upgrading GSM, downgrade the CMB to 512 #following lines moved into find chi function #cmbdata=hp.read_map('/home/amber/data/cmb/COM_CMB_IQU-commander-field-Int_2048_R2.01_full.fits') #cmbmap=hp.ud_grade(cmbdata,512) LMAX = 1024 both = (gsmdata * scale) + cmbmap #run the beam function with the given input showbeam = beam(itheta, iphi, nside, sig) npix = 12 * nside**2 #correct the data to account for the beam correction = npix / (np.sum(showbeam)) both = both * showbeam * correction #cross GSM+CMB with CMB and transform c_plus_g_cross_c = hp.sphtfunc.anafast(both, map2=cmbmap, lmax=LMAX) #moved to find function #cmbmaponly=hp.anafast(cmbmap,lmax=LMAX) ell = np.arange(len(cmbmaponly)) #find chi squared, the deviation from the desired data difference = c_plus_g_cross_c - cmbmaponly chi_squared = (np.sum( (ell * (ell + 1) * difference)**2)) / (len(c_plus_g_cross_c)) signal_squared = (np.sum( (ell * (ell + 1) * cmbmaponly)**2)) / (len(c_plus_g_cross_c)) chi = np.sqrt(chi_squared) signal = np.sqrt(signal_squared) ratio = chi / signal return ratio
def G_plus_C_cross_C_four(freq, scale): """plot of fourier of GSM(scale)+CMB crossed with CMB compared to CMB only User defines GSM freq in MHz User defines scale of GSM such as 0.1 or 0.01 WARNING: takes some time to run """ gsm = GlobalSkyModel() #create the GSM model gsmdata = gsm.generate(freq) #rather than upgrading GSM, downgrade the CMB to 512 cmbdata = hp.read_map( '/home/amber/data/cmb/COM_CMB_IQU-commander-field-Int_2048_R2.01_full.fits' ) cmbmap = hp.ud_grade(cmbdata, 512) LMAX = 1024 both = (gsmdata * scale) + cmbmap #cross cmb+gsm with the cmb c_plus_g_cross_c = hp.sphtfunc.anafast(both, map2=cmbmap, lmax=LMAX) ell = np.arange(len(c_plus_g_cross_c)) plt.figure() #format variables as text for labels freq_str = str(freq) scale_str = str(scale) plt.plot(ell, ell * (ell + 1) * c_plus_g_cross_c, color='b', label='GSM(' + scale_str + ') at ' + freq_str + ' MHZ+CMB cross CMB') cmbmaponly = hp.anafast(cmbdata, lmax=LMAX) ell = np.arange(len(cmbmaponly)) plt.plot(ell, ell * (ell + 1) * cmbmaponly, color='r', label='CMB') #delete this line? #hp.write_cmbmaponly('cmbmaponly.fits',cmbmaponly) plt.xlabel('ell') plt.ylabel('ell(ell+1)') plt.grid() #delete this line? #hp.write_cp_plus_g_cross_c('c_plus_g_cross_c.fits',c_plus_g_cross_c) plt.legend(loc='upper right') plt.show()
def G_plus_C_cross_C_beam_chi(freq,scale,itheta,iphi,nside,sig,cmbmap,cmbmaponly): """returns the ratio of chi/signal for beam applied to GSM(scale)+CMB crossed with CMB versus CMB alone uses same input as Beam_G_plus_C_cross_C_four() but returns value of ratio only, no plot CANNOT BE RUN ALONE, REFERENCES ANOTHER FUNCTION """ gsm=GlobalSkyModel() #generates GSM model gsmdata=gsm.generate(freq) #rather than upgrading GSM, downgrade the CMB to 512 #following lines moved into find chi function #cmbdata=hp.read_map('/home/amber/data/cmb/COM_CMB_IQU-commander-field-Int_2048_R2.01_full.fits') #cmbmap=hp.ud_grade(cmbdata,512) LMAX=1024 both=(gsmdata*scale)+cmbmap #run the beam function with the given input showbeam=beam(itheta,iphi,nside,sig) npix=12*nside**2 #correct the data to account for the beam correction=npix/(np.sum(showbeam)) both=both*showbeam*correction #cross GSM+CMB with CMB and transform c_plus_g_cross_c=hp.sphtfunc.anafast(both,map2=cmbmap,lmax=LMAX) #moved to find function #cmbmaponly=hp.anafast(cmbmap,lmax=LMAX) ell=np.arange(len(cmbmaponly)) #find chi squared, the deviation from the desired data difference=c_plus_g_cross_c-cmbmaponly chi_squared=(np.sum((ell*(ell+1)*difference)**2))/(len(c_plus_g_cross_c)) signal_squared=(np.sum((ell*(ell+1)*cmbmaponly)**2))/(len(c_plus_g_cross_c)) chi=np.sqrt(chi_squared) signal=np.sqrt(signal_squared) ratio=chi/signal return ratio
def GSM_four(freq,scale): """plots fourier of the GSM model used defines freq in MHz such as 5000 user defines power of 10 scale down such as -4 """ gsm=GlobalSkyModel() #generates the GSM model gsmdata=gsm.generate(freq) LMAX=1024 gsmmap=hp.anafast(gsmdata*(10**scale),lmax=LMAX) ell=np.arange(len(gsmmap)) plt.figure() #convert variables to text for labels scale_str=str(scale) freq_str=str(freq) plt.plot(ell,ell*(ell+1)*gsmmap,color='b',label='GSM*10^ '+scale_str+' at '+freq_str+' MHz') plt.xlabel('ell');plt.ylabel('ell(ell+1)');plt.grid() #delete this line? #hp.write_gsmmap('gsmmap.fits',gsmmap) plt.legend(loc='upper right') plt.show()
def test_gsm_generate(): """ Test maps generate successfully, and that output shapes are correct. """ freq = 40 gsm = GlobalSkyModel() map = gsm.generate(freq) assert map.shape == (3145728,) freqs = [40, 80, 120, 160] gsm = GlobalSkyModel(interpolation='cubic') map = gsm.generate(freqs) assert map.shape == (4, 3145728) freqs = np.linspace(1, 90, 10) freq_unit = 'GHz' for map_id in ['5deg', 'haslam', 'wmap']: gsm = GlobalSkyModel(basemap=map_id, interpolation='pchip', freq_unit=freq_unit) map = gsm.generate(freqs) assert map.shape == (10, 3145728)
def mk_map_GSM(f=150.,frange=None,nbins=None,write2fits=True): """ Make a Stokes I map/cube using pyGSM Can also provide frange=[lo,hi] and nbins to get an image cube (ignores f) Both f arguments need to be in MHz """ from pygsm import GlobalSkyModel gsm = GlobalSkyModel() if frange==None: gsm = gsm.generate(f) if write2fits: gsm.write_fits("gsm_%sMHz.fits"%str(int(f))) M = gsm else: flo,fhi=frange[0],frange[1] try: freqs = np.linspace(flo,fhi,nbins) except: print 'Did you provide "nbins"?' return None map_cube = gsm.generate(freqs) #if write2fits: map_cube.write_fits("gsm_cube_%s-%sMHz"%(str(int(flo)), str(int(fhi)))) M = np.swapaxes(map_cube,0,1) #conform to other map making routines return M
class GSModel: """ class interface to GSM model so that structures/data stay in memory gsm=GSModel(freq=freq, model=model) to use on astropy SkyCoord: gsm.SkyCoord_Tsky(source) to use on pulsar parfile: gsm.pulsar_Tsky(parfile) """ def __init__(self, freq=350 * u.MHz, model='2008'): assert str(model) in ['2008', '2016'] if not isinstance(freq, astropy.units.quantity.Quantity): # assume MHz freq = freq * u.MHz if str(model) == '2008': self.gsm = GlobalSkyModel() elif str(model) == '2016': self.gsm = GlobalSkyModel2016() self.map = self.gsm.generate(freq.to(u.MHz).value) self.freq = freq self.model = model def SkyCoord_Tsky(self, source): T = healpy.pixelfunc.get_interp_val(self.map, source.galactic.l.value, source.galactic.b.value, lonlat=True) return T * u.K def pulsar_Tsky(self, parfile): m = models.get_model(parfile) try: psr = SkyCoord(m.RAJ.value, m.DECJ.value, unit='deg') except: try: psr = SkyCoord(m.ELONG.value * u.deg, m.ELAT.value * u.deg, frame='pulsarecliptic') except: raise KeyError, 'Cannot find RAJ,DECJ or ELONG,ELAT in:\n%s' % m.as_parfile( ) return self.SkyCoord_Tsky(psr)
def test_write_fits(): gsm = GlobalSkyModel() gsm.generate(1000) gsm.write_fits("test_write_fits.fits") d_fits = hp.read_map("test_write_fits.fits") d_gsm = gsm.generated_map_data assert d_fits.shape == d_gsm.shape assert np.allclose(d_fits, d_gsm) os.remove("test_write_fits.fits")
def mk_map_GSM(f=150., frange=None, nbins=None, write2fits=True): """ Make a Stokes I map/cube using pyGSM Can also provide frange=[lo,hi] and nbins to get an image cube (ignores f) Both f arguments need to be in MHz """ from pygsm import GlobalSkyModel gsm = GlobalSkyModel() if frange == None: gsm = gsm.generate(f) if write2fits: gsm.write_fits("gsm_%sMHz.fits" % str(int(f))) M = gsm else: flo, fhi = frange[0], frange[1] try: freqs = np.linspace(flo, fhi, nbins) except: print 'Did you provide "nbins"?' return None map_cube = gsm.generate(freqs) #if write2fits: map_cube.write_fits("gsm_cube_%s-%sMHz"%(str(int(flo)), str(int(fhi)))) M = np.swapaxes(map_cube, 0, 1) #conform to other map making routines return M
import matplotlib.pyplot as plt import numpy as np import healpy as hp from pygsm import GlobalSkyModel gsm = GlobalSkyModel() class CMB_GSM_analysis: """description""" #init with things that will not change through out. #user will have to specify these the first time #allow for pass in of cmb file location, but default for ease def __init__( self, threshold, sig, freq, nside, LMAX, CMB_file_name='/home/amber/data/cmb/COM_CMB_IQU-commander-field-Int_2048_R2.01_full.fits' ): self.threshold = threshold self.sig = sig self.freq = freq #check that nside value is valid if not np.all(hp.isnsideok(nside)): raise ValueError( "%s is not a valid nside parameter (must be a power of 2, less than 2**30)" % str(nside)) self.nside = nside
# Select time steps if max_n_timestamps is None: max_n_timestamps = len(timestamps) else: max_n_timestamps = min(max_n_timestamps, len(timestamps)) timestamps = timestamps[min_timestamp:min_timestamp + max_n_timestamps] # *** Set up sky model lst = 299.28404 * NP.pi / 180 if use_GSM: print 'Getting the GSM' nside = 128 # Load in GSM gsm = GlobalSkyModel() sky = gsm.generate(f0 * 10**(-6)) sky = HP.ud_grade(sky, nside) # provided with nside=512, convert to lower res inds = NP.arange(HP.nside2npix(nside)) theta, phi = HP.pixelfunc.pix2ang(nside, inds) gc = Galactic(l=phi, b=NP.pi / 2 - theta, unit=(units.radian, units.radian)) radec = gc.fk5 eq = aipy.coord.radec2eq((-lst + radec.ra.radian, radec.dec.radian)) xyz = NP.dot(aipy.coord.eq2top_m(0, lat * NP.pi / 180), eq) # Keep just pixels above horizon include = NP.where(xyz[2, :] > 0) sky = sky[include]
def _load_gsm(freq): """ """ gsm = GlobalSkyModel(freq_unit='MHz') gsmap = gsm.generate(freq) return gsmap
# Select time steps if max_n_timestamps is None: max_n_timestamps = len(timestamps) else: max_n_timestamps = min(max_n_timestamps, len(timestamps)) timestamps = timestamps[min_timestamp:min_timestamp+max_n_timestamps] #### Set up sky model lst = 299.28404*NP.pi/180 if use_GSM: print 'Getting the GSM' nside = 128 # Load in GSM gsm = GlobalSkyModel() sky = gsm.generate(f0*10**(-6)) sky = HP.ud_grade(sky,nside) # provided with nside=512, convert to lower res inds = NP.arange(HP.nside2npix(nside)) theta,phi = HP.pixelfunc.pix2ang(nside,inds) gc = Galactic(l=phi, b=NP.pi/2-theta, unit=(units.radian,units.radian)) radec = gc.fk5 eq = aipy.coord.radec2eq((-lst+radec.ra.radian,radec.dec.radian)) xyz = NP.dot(aipy.coord.eq2top_m(0,lat*NP.pi/180),eq) # Keep just pixels above horizon include = NP.where(xyz[2,:]>0) sky = sky[include] xyz = xyz[:,include].squeeze() n_src = sky.shape[0]
plt.imshow(mycov, extent=[freqs.min(), freqs.max(), freqs.max(), freqs.min()]) plt.colorbar() plt.title('Full Unweighted Correlation, ' + tag) plt.xlabel('Freq (MHz)') plt.ylabel('Freq (MHz)') plt.savefig('corr_mat_nowt_' + tag + '.png') cc = mycov[freqs < 90, :] cc = cc[:, freqs < 90] #get the GSM, in this case evaluated at a single frequency (since this script was designed #to investigate beam effects on the most boring possibly foregrounds) gsm = GlobalSkyModel() gsm_map_org = gsm.generate(80) gsm_map_org = healpy.ud_grade(gsm_map_org, nside) #if desired, cap the max flux in the map to be some number times the mean if False: thresh = 10 mn = np.mean(gsm_map_org) gsm_map_org[gsm_map_org > thresh * mn] = thresh * mn gsm_tag = '_capped' else: gsm_tag = '' #rotate GSM into equatorial coordinates. myrot = healpy.rotator.Rotator(coord=['G', 'E']) gsm_map = myrot.rotate_map_pixel(gsm_map_org)
def Beam_G_plus_C_cross_C_four(freq, scale, itheta, iphi, nside, sig=np.pi / 10): """plot of fourier for GSM(scale)+CMB crossed with CMB beam applied then accounted for all compared to CMB alone User defines frequency of GSM and scale to decrease it User selects point of interest: theta and phi User may designate sigma for beam User selects nside Default sigma is pi/10 """ gsm = GlobalSkyModel() #generates GSM model gsmdata = gsm.generate(freq) #rather than upgrading GSM, downgrade the CMB to 512 cmbdata = hp.read_map( '/home/amber/data/cmb/COM_CMB_IQU-commander-field-Int_2048_R2.01_full.fits' ) cmbmap = hp.ud_grade(cmbdata, 512) LMAX = 1024 both = (gsmdata * scale) + cmbmap #run the beam function with the given input showbeam = beam(itheta, iphi, nside, sig) npix = 12 * nside**2 #correct the data to account for the beam correction = npix / (np.sum(showbeam)) both = both * showbeam * correction #cross GSM+CMB with CMB and transform c_plus_g_cross_c = hp.sphtfunc.anafast(both, map2=cmbmap, lmax=LMAX) ell = np.arange(len(c_plus_g_cross_c)) plt.figure() #convert variables into text for labels freq_str = str(freq) scale_str = str(scale) plt.plot(ell, ell * (ell + 1) * c_plus_g_cross_c, color='b', label='GSM(' + scale_str + ') at ' + freq_str + ' MHZ+CMB cross CMB') #transform CMB cmbmaponly = hp.anafast(cmbmap, lmax=LMAX) ell = np.arange(len(cmbmaponly)) plt.plot(ell, ell * (ell + 1) * cmbmaponly, color='r', label='CMB') #delete this line? #hp.write_cmbmaponly('cmbmaponly.fits',cmbmaponly) plt.xlabel('ell') plt.ylabel('ell(ell+1)') plt.grid() #delete this line? #hp.write_c_plus_g_cross_c('c_plus_g_cross_c.fits',c_plus_g_cross_c) #convert variable into text for labels theta_str = str(itheta) phi_str = str(iphi) plt.legend(loc='upper right') plt.title('Point of Interest:(' + theta_str + ',' + phi_str + ')') #set the limits for the y axis plt.ylim(-0.00000001, 0.00000006) plt.show()
# A script to plot the GSM to match LWA observation # IMPORTANT: Run this AFTER running the calibrate_LWA_data script - it relies on having certain things already calculated. import lwa_ant from datetime import datetime import scipy.ndimage as ndimage from pygsm import GlobalSkyModel #resolution = (FCNST.speed_of_light / f0) / 100.0 # rough resolution of LWA (in radians) print 'Getting the GSM' nside = 512 # Load in GSM gsm = GlobalSkyModel( ) # Note that I'm not using the 2016 GSM because it excludes certain sources (importantly CygA) sky = gsm.generate(f0 * 10**(-6)) # convert sky to Jy/(LWA beam) Aeff = 100.0**2 * NP.pi / 4.0 # basically a filled aperture sky *= 2 * FCNST.Boltzmann / Aeff * 10**26 # Jy per LWA beam #sky *= 2*FCNST.Boltzmann / (FCNST.speed_of_light / f0)**2 * 10**26 # Jy/str #sky = HP.smoothing(sky, fwhm=resolution) # Don't need this anymore because now I'm convolving with PSF sky = HP.ud_grade(sky, nside) # provided with nside=512, convert to lower res inds = NP.arange(HP.nside2npix(nside)) theta, phi = HP.pixelfunc.pix2ang(nside, inds) gc = Galactic(l=phi, b=NP.pi / 2 - theta, unit=(units.radian, units.radian)) radec = gc.fk5 eq = aipy.coord.radec2eq((-lst + radec.ra.radian, radec.dec.radian)) xyz = NP.dot(aipy.coord.eq2top_m(0, lat * NP.pi / 180), eq)
def test_set_methods(): gsm = GlobalSkyModel() gsm.generate(40) #gsm.view() gsm.set_basemap('haslam') gsm.view() gsm.set_basemap('5deg') gsm.view() gsm.set_basemap('wmap') gsm.view() gsm.set_freq_unit('GHz') gsm.view()