def map_to_npz(self, time_str, loc_str='PAPER', verbose=False): ''' writes map of particular time to npz file Parameters ---------- time_str | str: time and date of map loc_str | str: name of obs location to incorporate into filename output verbose | Optional[bool]: whether to print values or not ''' #I could fish around in the file read to get npix and then re-loop, but why not just be lazy sometimes rng = np.arange(24) final_TEC, final_rm, final_drm, ra, dec = np.zeros((rng.shape[0], self.npix)),\ np.zeros((rng.shape[0], self.npix)),\ np.zeros((rng.shape[0], self.npix)),\ np.zeros((rng.shape[0], self.npix)),\ np.zeros((rng.shape[0], self.npix)) RM_dir = os.path.join(self.rm_dir, '{date}'.format(date=time_str)) for UT in rng: rm_file = os.path.join( RM_dir, 'IonRM{num}.txt'.format( num=utils.std_hour(UT, verbose=verbose))) radec_file = os.path.join( RM_dir, 'radec{num}.txt'.format( num=utils.std_hour(UT, verbose=verbose))) _, TEC, B, RM, dRM = np.loadtxt(rm_file, unpack=True) RA, DEC = np.loadtxt(radec_file, unpack=True) final_TEC[UT, :] = TEC final_rm[UT, :] = RM final_drm[UT, :] = dRM ra[UT, :] = RA dec[UT, :] = DEC f_name = ''.join((time_str, '_', loc_str, '.npz')) npz_dir = os.path.join(rad.root_dir, 'npz') if not os.path.exists(npz_dir): os.mkdir(npz_dir) npz_file = os.path.join(npz_dir, f_name) if verbose: print( 'Saving TEC, RM +/- dRM data and RA/Dec mapping to {filename}'. format(filename=npz_file)) np.savez(npz_file, TEC=final_TEC, RM=final_rm, dRM=final_drm, RA=ra, DEC=dec)
def altaz(self): ''' outputs RM data from altaz calculation Returns ------- tuple: array[float]: parallel B field array array[float]: RM data array[float]: RM error data ''' rm_s = [] drm_s = [] b_para_s = [] alt_src, az_src = self._hp_arr() zen_src = 90. - alt_src for date in self.times: date_str, _, _ = str(date).partition('T') RM_dir = self.make_rm_dir(date_str) year, month, day = map(int, date_str.split('-')) tec_hp, rms_hp, ion_height = self.ionex_data(year, month, day) coord_lat, coord_lon, az_punct, zen_punct = phys.ipp( self.lat_str, self.lon_str, az_src, zen_src, ion_height) #XXX B_para calculated per DAY B_para = phys.B_IGRF(year, month, day, coord_lat, coord_lon, ion_height, az_punct, zen_punct) RMs = [] dRMs = [] for ui, UT in enumerate(self.UTs): hour = utils.std_hour(UT) radec_file = os.path.join(RM_dir, 'radec{hour}.txt'.format(hour=hour)) utils.write_radec(UT, radec_file, alt_src, az_src, date_str, self.location) #UTs are integer distances apart. Would an enumeration be better? TEC_path, RMS_TEC_path = itp.get_los_tec( tec_hp[ui], rms_hp[ui], coord_lat, coord_lon, zen_punct) new_file = os.path.join(RM_dir, 'IonRM{hour}.txt'.format(hour=hour)) utils.write_RM(hour, new_file, B_para, TEC_path, RMS_TEC_path) _, _, _, RM_ut, dRM_ut = np.loadtxt(new_file, unpack=True) RMs.append(RM_ut) dRMs.append(dRM_ut) rm_s.append(RMs) drm_s.append(dRMs) b_para_s.append(B_para) self.RMs = np.array(rm_s) self.dRMs = np.array(drm_s) self.B_paras = np.array(b_para_s)
def map_to_npz(self, time_str, loc_str="PAPER", verbose=False): """ writes map of particular time to npz file Parameters ---------- time_str | str: time and date of map loc_str | str: name of obs location to incorporate into filename output verbose | Optional[bool]: whether to print values or not """ # I could fish around in the file read to get npix and then re-loop, but why not just be lazy sometimes rng = np.arange(24) final_TEC, final_rm, final_drm, ra, dec = ( np.zeros((rng.shape[0], self.npix)), np.zeros((rng.shape[0], self.npix)), np.zeros((rng.shape[0], self.npix)), np.zeros((rng.shape[0], self.npix)), np.zeros((rng.shape[0], self.npix)), ) RM_dir = os.path.join(self.rm_dir, "{date}".format(date=time_str)) for UT in rng: rm_file = os.path.join(RM_dir, "IonRM{num}.txt".format(num=utils.std_hour(UT, verbose=verbose))) radec_file = os.path.join(RM_dir, "radec{num}.txt".format(num=utils.std_hour(UT, verbose=verbose))) _, TEC, B, RM, dRM = np.loadtxt(rm_file, unpack=True) RA, DEC = np.loadtxt(radec_file, unpack=True) final_TEC[UT, :] = TEC final_rm[UT, :] = RM final_drm[UT, :] = dRM ra[UT, :] = RA dec[UT, :] = DEC f_name = "".join((time_str, "_", loc_str, ".npz")) npz_dir = os.path.join(rad.root_dir, "npz") if not os.path.exists(npz_dir): os.mkdir(npz_dir) npz_file = os.path.join(npz_dir, f_name) if verbose: print("Saving TEC, RM +/- dRM data and RA/Dec mapping to {filename}".format(filename=npz_file)) np.savez(npz_file, TEC=final_TEC, RM=final_rm, dRM=final_drm, RA=ra, DEC=dec)
def altaz(self): """ outputs RM data from altaz calculation Returns ------- tuple: array[float]: parallel B field array array[float]: RM data array[float]: RM error data """ rm_s = [] drm_s = [] b_para_s = [] alt_src, az_src = self._hp_arr() zen_src = 90.0 - alt_src for date in self.times: date_str, _, _ = str(date).partition("T") RM_dir = self.make_rm_dir(date_str) year, month, day = map(int, date_str.split("-")) tec_hp, rms_hp, ion_height = self.ionex_data(year, month, day) coord_lat, coord_lon, az_punct, zen_punct = phys.ipp( self.lat_str, self.lon_str, az_src, zen_src, ion_height ) # XXX B_para calculated per DAY B_para = phys.B_IGRF(year, month, day, coord_lat, coord_lon, ion_height, az_punct, zen_punct) RMs = [] dRMs = [] for UT in self.UTs: hour = utils.std_hour(UT) radec_file = os.path.join(RM_dir, "radec{hour}.txt".format(hour=hour)) utils.write_radec(UT, radec_file, alt_src, az_src, date_str, self.location) TEC_path, RMS_TEC_path = itp.get_los_tec(tec_hp[UT], rms_hp[UT], coord_lat, coord_lon, zen_punct) new_file = os.path.join(RM_dir, "IonRM{hour}.txt".format(hour=hour)) utils.write_RM(hour, new_file, B_para, TEC_path, RMS_TEC_path) _, _, _, RM_ut, dRM_ut = np.loadtxt(new_file, unpack=True) RMs.append(RM_ut) dRMs.append(dRM_ut) rm_s.append(RMs) drm_s.append(dRMs) b_para_s.append(B_para) self.RMs = np.array(rm_s) self.dRMs = np.array(drm_s) self.B_paras = np.array(b_para_s)
def get_radec_RM(self, ras, decs, verbose=False): # TODO: allow ra,dec to be floats, rather than arrays of floats # (to maintain single-pointing functionality) if not all((i <= 2.0 * np.pi and i >= 0.0) for i in ras): raise ValueError("All RAs must be between 0 and 2*pi radians") if not all((i <= np.pi / 2.0 and i >= -np.pi / 2.0) for i in decs): raise ValueError("All Decs must be between -pi/2 and pi/2 radians") self.coordinates_flag = "J2000_RaDec" for time in self.times: time_str, _, _ = str(time).partition("T") RM_dir = self.make_rm_dir(time_str) year, month, day = map(int, time_str.split("-")) if verbose: print(year, month, day) tec_hp, rms_hp, ion_height = self.ionex_data(year, month, day) # predict the ionospheric RM for every hour within a day for UT in self.UTs: hour = utils.std_hour(UT) c_icrs = SkyCoord( ra=ras * u.radian, dec=decs * u.radian, location=self.location, obstime=time + UT * u.hr, frame="icrs", ) c_altaz = c_icrs.transform_to("altaz") alt_src = np.array(c_altaz.alt.degree) az_src = np.array(c_altaz.az.degree) zen_src = np.array(Angle(c_altaz.zen).degree) # AltAz.zen doesn't have method to return angle data coord_lat, coord_lon, az_punct, zen_punct = phys.ipp( self.lat_str, self.lon_str, az_src, zen_src, ion_height ) # XXX B_para calculated per UT B_para = phys.B_IGRF(year, month, day, coord_lat, coord_lon, ion_height, az_punct, zen_punct) TEC_path, RMS_TEC_path = itp.get_los_tec(tec_hp[UT], rms_hp[UT], coord_lat, coord_lon, zen_punct) new_file = os.path.join(RM_dir, "IonRM{hour}.txt".format(hour=hour)) utils.write_RM(hour, new_file, B_para, TEC_path, RMS_TEC_path, write_to_file=True) b_para_s = [] rm_s = [] drm_s = [] for time in self.times: time_str, _, _ = str(time).partition("T") RM_add = [] dRM_add = [] RM_dir = os.path.join(self.rm_dir, "{date}".format(date=time_str)) for UT in self.UTs: data_file = os.path.join(RM_dir, "IonRM{hour}.txt".format(hour=utils.std_hour(UT))) _, _, B_para, RM_ut, dRM_ut = np.loadtxt(data_file, unpack=True) b_para_s.append(B_para) RM_add.append(RM_ut) dRM_add.append(dRM_ut) rm_s.append(RM_add) drm_s.append(dRM_add) self.B_para = np.array(b_para_s) self.RMs = np.array(rm_s) self.dRMs = np.array(drm_s)
def calc_radec_rm(self, ras, decs, verbose=False): #TODO: allow ra,dec to be floats, rather than arrays of floats # (to maintain single-pointing functionality) if not all((i <= 2. * np.pi and i >= 0.) for i in ras): raise ValueError('All RAs must be between 0 and 2*pi radians') if not all((i <= np.pi / 2. and i >= -np.pi / 2.) for i in decs): raise ValueError('All Decs must be between -pi/2 and pi/2 radians') self.coordinates_flag = 'J2000_RaDec' #final storage arrays b_para_s = [] rm_s = [] drm_s = [] lsts_s = [] alt_src_s = [] for time in self.times: #for every day #parsing, creating directory structure time_str, _, _ = str(time).partition('T') RM_dir = self.make_rm_dir(time_str) year, month, day = map(int, time_str.split('-')) if verbose: print(year, month, day) #data aquisition tec_hp, rms_hp, ion_height = self.ionex_data(year, month, day) #temp storage arrays alt_src_all = np.zeros([24, 3072]) lsts = np.zeros(24) RM_add = [] dRM_add = [] # predict the ionospheric RM for every hour within a day for ui, UT in enumerate(self.UTs): hour = utils.std_hour(UT) c_icrs = SkyCoord(ra=ras * u.radian, dec=decs * u.radian, location=self.location, obstime=time + UT * u.hr, frame='icrs') # Added to calculate LST for the given time c_local = AltAz(az=0. * u.deg, alt=90. * u.deg, obstime=time + UT * u.hr, location=self.location) c_local_Zeq = c_local.transform_to(ICRS) lsts[ui] = c_local_Zeq.ra.degree # Transform given RA/Dec into alt/az c_altaz = c_icrs.transform_to('altaz') alt_src = np.array(c_altaz.alt.degree) az_src = np.array(c_altaz.az.degree) alt_src_all[ui, :] = alt_src # AltAz.zen doesn't have method to return angle data zen_src = np.array(Angle(c_altaz.zen).degree) # Calculating the ion piercing point (IPP) depends on alt/az coords coord_lat, coord_lon, az_punct, zen_punct = phys.ipp( self.lat_str, self.lon_str, az_src, zen_src, ion_height) #XXX B_para calculated per UT #these are the data we care about B_para = phys.B_IGRF(year, month, day, coord_lat, coord_lon, ion_height, az_punct, zen_punct) TEC_path, RMS_TEC_path = itp.get_los_tec( tec_hp[ui], rms_hp[ui], coord_lat, coord_lon, zen_punct) IRM = 2.6e-17 * B_para * TEC_path rms_IRM = 2.6e-17 * B_para * RMS_TEC_path #TODO: replace append commands with numpy array indicies b_para_s.append(B_para) RM_add.append(IRM) dRM_add.append(rms_IRM) alt_src_s.append(alt_src_all) lsts_s.append(lsts) rm_s.append(RM_add) drm_s.append(dRM_add) self.B_para = np.array(b_para_s) self.RMs = np.array(rm_s) self.dRMs = np.array(drm_s) self.alt_src = np.array(alt_src_s) self.lst = np.array(lsts_s)
from radiono import rm from radiono import utils as ut import healpy as hp, numpy as np, os from matplotlib import pyplot as plt from astropy.time import Time # Moore et al.: 7 Dec 2011 to 27 Feb 2012 #dates = (('2011-12', range(6, 32)),('2012-01', range(1, 32)),('2012-02', range(1, 29))) dates = [] for d in range(6, 32): dates.append('-'.join(['2011-12', ut.std_hour(d)])) for d in range(1, 32): dates.append('-'.join(['2012-01', ut.std_hour(d)])) for d in range(1, 29): dates.append('-'.join(['2012-02', ut.std_hour(d)])) # PAPER INFO lat_str = '30d43m17.5ss' lon_str = '21d25m41.9se' IM = rm.IonoMap(lat_str, lon_str, dates) ras = [ np.radians(15. * 2.), np.radians(15. * 4.), np.radians(15. * 6.), np.radians(15. * 8.) ] #2,4,6,8 hrs dec = np.radians(-30. - (43. / 60.) - (17.5 / 3600.)) #decs = [dec,dec,dec] #zenith decs = [dec, dec, dec, dec]
from radiono import rm from radiono import utils as ut import healpy as hp, numpy as np, os from matplotlib import pyplot as plt from astropy.time import Time # Moore et al.: 7 Dec 2011 to 27 Feb 2012 #dates = (('2011-12', range(6, 32)),('2012-01', range(1, 32)),('2012-02', range(1, 29))) dates = [] for d in range(6,32): dates.append('-'.join(['2011-12',ut.std_hour(d)])) for d in range(1,32): dates.append('-'.join(['2012-01',ut.std_hour(d)])) for d in range(1,29): dates.append('-'.join(['2012-02',ut.std_hour(d)])) # PAPER INFO lat_str = '30d43m17.5ss' lon_str = '21d25m41.9se' IM = rm.IonoMap(lat_str,lon_str,dates) ras = [np.radians(15.*2.),np.radians(15.*4.),np.radians(15.*6.),np.radians(15.*8.)] #2,4,6,8 hrs dec = np.radians(-30.-(43./60.)-(17.5/3600.)) #decs = [dec,dec,dec] #zenith decs = [dec,dec,dec,dec] #if not os.path.exists('./1h4h8h.npz'): if not os.path.exists('./2h4h6h8h.npz'): print 'getting RMs' IM.get_radec_RM(ras,decs,verbose=True) np.savez('./2h4h6h8h.npz',RM=IM.RMs,dRM=IM.dRMs,dates=dates) else: d = np.load('./2h4h6h8h.npz') dvec = np.zeros( (len(d['dates']),4,2) )
def test_stdHour(self): hr1 = ut.std_hour(1) self.assertEqual(hr1, '01') #should be "01" hr10 = ut.std_hour(10, verbose=True)