def test_observed_mollview(): """ Generate animated maps of observing coverage over 24 hours """ (latitude, longitude, elevation) = ('37.2', '-118.2', 1222) ov = GSMObserver() ov.lon = longitude ov.lat = latitude ov.elev = elevation obs = [] for ii in range(0, 24, 1): ov.date = datetime(2000, 1, 1, ii, 0) ov.generate(50) sky = ov.view_observed_gsm(logged=True, show=False, min=9, max=20) plt.savefig('generated_sky/galactic-%02d.png' % ii) plt.close() hp.mollview(sky, coord=['G', 'E'], min=9, max=20) plt.savefig('generated_sky/ecliptic-%02d.png' % ii) plt.close() hp.mollview(sky, coord=['G', 'C'], min=9, max=20) plt.savefig('generated_sky/equatorial-%02d.png' % ii) plt.close() ov.view(logged=True, show=False, min=9, max=20) plt.savefig('generated_sky/ortho-%02d.png' % ii) plt.close() print ii os.system('convert -delay 20 generated_sky/ortho-*.png ortho.gif') os.system('convert -delay 20 generated_sky/galactic-*.png galactic.gif') os.system('convert -delay 20 generated_sky/ecliptic-*.png ecliptic.gif') os.system('convert -delay 20 generated_sky/equatorial-*.png equatorial.gif')
def observer_test(): # Setup observatory location - in this case, Parkes Australia (latitude, longitude, elevation) = ('-32.998370', '148.263659', 100) ov = GSMObserver2016() ov.lon = longitude ov.lat = latitude ov.elev = elevation ov.date = datetime(2000, 1, 1, 23, 0) ov.generate(1400) d = ov.view(logged=True) ov = GSMObserver() ov.lon = longitude ov.lat = latitude ov.elev = elevation ov.date = datetime(2000, 1, 1, 23, 0) ov.generate(1400) d = ov.view(logged=True) plt.show()
thetalim = 5 * np.pi / 8 # 'Aperture Width' of Beam func = 1 - (((thetas - np.pi) / (thetalim - np.pi))**2) # Beam Function for j in phis: pixels = hp.ang2pix(nside, thetas, j) n[pixels] = func[pixels] n[n < 0] = 0 filter_array = n # This is the filter to apply to GSM (latitude, longitude, elevation) = ('-32.998370', '148.263659', 100 ) # Near EDGES site delta_t = 60 # EDGES antenna takes a number of measurements in 24 hours; this is the time between measurements in minutes sky_array = [] timer = datetime(2018, 1, 1, 0, 0) while timer.hour < 23: gsm = GSMObserver() gsm.lon = longitude gsm.lat = latitude gsm.elev = elevation gsm.date = timer g = hp.ud_grade( gsm.generate(78), nside) # 78MHz is the frequency of the 21cm signal absorption feature g_filt = g * n #g_filt = g_filt*(np.amax(g)/np.amax(g_filt)) # normalisation hp.orthview(g_filt, half_sky=True) plt.savefig(timer.strftime("%H:%M:%S") + "_filtered.png") g_int = np.trapz(g_filt) sky_array.append(g_int) timer = timer + timedelta(minutes=delta_t)
# Read in paper beam data paper_beam = {} paper_im = np.zeros_like(hera_im) for fi, f in enumerate(temp_f): beam_file = '/data4/beards/instr_data/paper_beam_{0}.fits'.format(np.int(f)) paper_im[:, fi] = hp.ud_grade(hp.read_map(beam_file), nside) # Interpolate to the desired frequencies func = interpolate.interp1d(temp_f, paper_im, kind='cubic', axis=1) for pol in pols: paper_beam[pol] = np.abs(func(freqs))**2.0 # Set up the observer (latitude, longitude, elevation) = ('-30.7224', '21.4278', 1100) ov = GSMObserver() ov.lon = longitude ov.lat = latitude ov.elev = elevation fig = plt.figure("Tsky calc") for poli, pol in enumerate(pols): for fi, freq in enumerate(freqs): print 'Forming HERA Tsky for frequency ' + str(freq) + ' MHz.' # Rotate and project hera beam (Need to figure out how to do this w/o making figure) pol_ang = 90 * (1 - poli) # Extra rotation for X hbeam = hp.orthview(hera_beam[pol][:, fi], rot=[pol_ang, 90], fig=fig.number, xsize=400, return_projected_map=True, half_sky=True) hbeam[np.isinf(hbeam)] = np.nan if calc_paper: pbeam = hp.orthview(paper_beam[pol][:, fi], rot=[pol_ang, 90], fig=fig.number,
def test_gsm_observer(): """ Test GSMObserver() is working """ (latitude, longitude, elevation) = ('37.2', '-118.2', 1222) ov = GSMObserver() ov.lon = longitude ov.lat = latitude ov.elev = elevation ov.date = datetime(2000, 1, 1, 23, 0) ov.generate(50) ov.view(logged=True) ov.view_observed_gsm(logged=True)
def test_observed_mollview(): """ Generate animated maps of observing coverage over 24 hours """ (latitude, longitude, elevation) = ('37.2', '-118.2', 1222) ov = GSMObserver() ov.lon = longitude ov.lat = latitude ov.elev = elevation obs = [] for ii in range(0, 24, 1): ov.date = datetime(2000, 1, 1, ii, 0) ov.generate(50) sky = ov.view_observed_gsm(logged=True, show=False, min=9, max=20) plt.savefig('generated_sky/galactic-%02d.png' % ii) plt.close() hp.mollview(sky, coord=['G', 'E'], min=9, max=20) plt.savefig('generated_sky/ecliptic-%02d.png' % ii) plt.close() hp.mollview(sky, coord=['G', 'C'], min=9, max=20) plt.savefig('generated_sky/equatorial-%02d.png' % ii) plt.close() ov.view(logged=True, show=False, min=9, max=20) plt.savefig('generated_sky/ortho-%02d.png' % ii) plt.close() print ii os.system('convert -delay 20 generated_sky/ortho-*.png ortho.gif') os.system('convert -delay 20 generated_sky/galactic-*.png galactic.gif') os.system('convert -delay 20 generated_sky/ecliptic-*.png ecliptic.gif') os.system( 'convert -delay 20 generated_sky/equatorial-*.png equatorial.gif')
from scipy import interpolate from datetime import datetime from astropy.time import Time import matplotlib.pyplot as plt import healpy as hp df = 1.5625 # 100 MHz / 64 averaged channels freqs = np.arange(100.0 + df / 2.0, 200.0, df) hours = np.arange(0.0, 24.0, .5) lsts = np.zeros_like(hours) pols = ['X', 'Y'] # Only have X beam, but try rotating 90 degrees for Y HERA_Tsky = np.zeros((len(pols), freqs.shape[0], lsts.shape[0])) # Set up the observer (latitude, longitude, elevation) = ('-30.7224', '21.4278', 1100) ov = GSMObserver() ov.lon = longitude ov.lat = latitude ov.elev = elevation proj_sky = hp.projector.OrthographicProj(rot=[0, 0, 0], half_sky=True, xsize=400) observed_sky = ov.generate(100) nside_sky = hp.pixelfunc.npix2nside(hp.pixelfunc.get_map_size(observed_sky)) f_sky = lambda x, y, z: hp.pixelfunc.vec2pix(nside_sky, x, y, z, nest=False) sky = proj_sky.projmap(observed_sky, f_sky) generated_sky = np.zeros(
from pygsm import GlobalSkyModel, GSMObserver from datetime import datetime import numpy as np import healpy as hp import matplotlib.pyplot as plt (latitude, longitude, elevation) = ('-26.69719', '116.63903', 373) freq = np.linspace(50, 99, 3) amp = [] for i in freq: gsm = GSMObserver() gsm.lon = longitude gsm.lat = latitude gsm.elev = elevation gsm.date = datetime(2018, 1, 1, 3, 0) g = gsm.generate(i) gsm.view(logged=False, filename='freq_%i' % i)
def calc_Tsky(self): """ Calculate the Tsky sim based on beam file and the GSM """ if self.beam_file is None: raise(ValueError('Beam file is not defined, cannot compute Tsky simulation.')) # Otherwise go ahead and calculate self.Tsky = np.zeros((len(self.pols), len(self.freqs), len(self.lsts))) # First set up beam uvb = UVBeam() uvb.read_beamfits(self.beam_file) beam = {} rot_pol = {} #temp_f = fits.getdata(self.beam_file, extname='FREQS') temp_f = uvb.freq_array[0]*1e-6 for i, pol in enumerate(self.pols): '''try: im = fits.getdata(self.beam_file, extname='BEAM_{0}'.format(pol)) rot_pol[pol] = False except KeyError: # My example file only has one pol, need to rotate it (later) im = fits.getdata(self.beam_file, extname='BEAM_{0}'.format(self.pols[1 - i])) rot_pol[pol] = True func = interpolate.interp1d(temp_f, im, kind='cubic', axis=1) beam[pol] = func(self.freqs)''' rot_pol[pol] = False im = uvb.data_array[0,0,i].transpose() func = interpolate.interp1d(temp_f, im, kind='cubic', axis=1) beam[pol] = func(self.freqs) # Get the effective area self.Ae = np.zeros((len(self.pols), len(self.freqs))) for poli, pol in enumerate(self.pols): self.Ae[poli] = ((const.c.to('m*MHz').value / self.freqs)**2. / (4 * np.pi / im.shape[0] * np.sum(beam[pol], axis=0) / np.max(beam[pol], axis=0))) # Set up observer if self.gsm==2008: ov = GSMObserver() elif self.gsm==2016: ov = GSMObserver2016() ov.lon = str(self.lon) ov.lat = str(self.lat) ov.elev = self.elev fig = plt.figure('Tsky_calc') # Never found a way to not open a figure... for poli, pol in enumerate(self.pols): for fi, freq in enumerate(self.freqs): if rot_pol[pol]: pol_ang = 0.0 else: pol_ang = 90.0 temp_beam = hp.orthview(beam[pol][:, fi], rot=[pol_ang, 90], fig=fig.number, xsize=400, return_projected_map=True, half_sky=True) temp_beam[np.isinf(temp_beam)] = np.nan for ti, t in enumerate(self.hours): plt.clf() dt = datetime(2013, 1, 1, np.int(t), np.int(60.0 * (t - np.floor(t))), np.int(60.0 * (60.0 * t - np.floor(t * 60.0)))) self.lsts[ti] = Time(dt).sidereal_time('apparent', self.lon).hour ov.date = dt ov.generate(freq) d = ov.view(fig=fig.number) sky = hp.orthview(d, fig=fig.number, xsize=400, return_projected_map=True, half_sky=True) sky[np.isinf(sky)] = np.nan self.Tsky[poli, fi, ti] = np.nanmean(temp_beam * sky) / np.nanmean(temp_beam) inds = np.argsort(self.lsts) self.lsts = self.lsts[inds] self.Tsky = self.Tsky[:, :, inds]
HERA_Tsky = np.zeros((len(pols), freqs.shape[0], lsts.shape[0])) # Read in HERA beam data, just use full sky for paper hera_beam = {} # Only have X right now, will rotate later hera_im = fits.getdata(hera_beam_file, extname='BEAM_{0}'.format('X')) nside = hp.npix2nside(hera_im.shape[0]) temp_f = fits.getdata(hera_beam_file, extname='FREQS_{0}'.format('X')) # Interpolate to the desired frequencies func = interpolate.interp1d(temp_f, hera_im, kind='cubic', axis=1) for pol in pols: hera_beam[pol] = func(freqs) # Set up the observer (latitude, longitude, elevation) = ('-30.7224', '21.4278', 1100) ov = GSMObserver() ov.lon = longitude ov.lat = latitude ov.elev = elevation f = lambda x, y, z: hp.pixelfunc.vec2pix(nside, x, y, z, nest=False) i = 0 j = 0 sky_array = np.load(sky_files[i])['sky'] print sky_files for poli, pol in enumerate(pols): pol_ang = 90 * (1 - poli) # Extra rotation for X proj_beam = hp.projector.OrthographicProj(rot=[pol_ang, 90], half_sky=True,