def test_matrix(): """Confirm higher-dimensional arrays raise an exception""" with pytest.raises(ValueError): o = "Arecibo" loc = Observatory.get(o).earth_location_itrf() t = Time(56000 * np.ones((4, 5)), scale="tdb", format="mjd") erfautils.gcrs_posvel_from_itrf(loc, t, obsname=o)
def _get_TDB_ephem(self, t, ephem): """Read the ephem TDB-TT column. This column is provided by DE4XXt version of ephemeris. This function is only for the ground-based observatories """ geo_tdb_tt = get_tdb_tt_ephem_geocenter(t.tt, ephem) # NOTE The earth velocity is need to compute the time correcion from # Topocenter to Geocenter # Since earth velocity is not going to change a lot in 3ms. The # differences between TT and TDB can be ignored. earth_pv = objPosVel_wrt_SSB("earth", t.tdb, ephem) obs_geocenter_pv = gcrs_posvel_from_itrf( self.earth_location_itrf(), t, obsname=self.name ) # NOTE # Moyer (1981) and Murray (1983), with fundamental arguments adapted # from Simon et al. 1994. topo_time_corr = numpy.sum( earth_pv.vel / c.c * obs_geocenter_pv.pos / c.c, axis=0 ) topo_tdb_tt = geo_tdb_tt - topo_time_corr result = Time( t.tt.jd1 - JD_MJD, t.tt.jd2 - topo_tdb_tt.to(u.day).value, format="pulsar_mjd", scale="tdb", location=self.earth_location_itrf(), ) return result
def posvel(self, t, ephem, group=None): if t.isscalar: t = Time([t]) earth_pv = objPosVel_wrt_SSB("earth", t, ephem) obs_geocenter_pv = gcrs_posvel_from_itrf( self.earth_location_itrf(), t, obsname=self.name ) return obs_geocenter_pv + earth_pv
def get_gcrs(self, t, ephem=None): """Return position vector of TopoObs in GCRS Parameters ---------- t : astropy.time.Time or array of astropy.time.Time Returns ------- np.array a 3-vector of Quantities representing the position in GCRS coordinates. """ obs_geocenter_pv = gcrs_posvel_from_itrf( self.earth_location_itrf(), t, obsname=self.name ) return obs_geocenter_pv.pos
def test_compare_erfautils_astropy(): o = "Arecibo" loc = Observatory.get(o).earth_location_itrf() mjds = np.linspace(50000, 58000, 512) t = Time(mjds, scale="tdb", format="mjd") posvel = erfautils.gcrs_posvel_from_itrf(loc, t, obsname=o) astropy_posvel = erfautils.astropy_gcrs_posvel_from_itrf(loc, t, obsname=o) dopv = astropy_posvel - posvel dpos = np.sqrt((dopv.pos ** 2).sum(axis=0)) dvel = np.sqrt((dopv.vel ** 2).sum(axis=0)) assert len(dpos) == len(mjds) # This is just above the level of observed difference assert dpos.max() < 0.05 * u.m, "position difference of %s" % dpos.max().to(u.m) # This level is what is permitted as a velocity difference from tempo2 in test_times.py assert dvel.max() < 0.02 * u.mm / u.s, "velocity difference of %s" % dvel.max().to( u.mm / u.s )
def test_scalar(): o = "Arecibo" loc = Observatory.get(o).earth_location_itrf() t = Time(56000, scale="tdb", format="mjd") posvel = erfautils.gcrs_posvel_from_itrf(loc, t, obsname=o) assert posvel.pos.shape == (3, )
def test_times_against_tempo2(): log.setLevel("ERROR") # for nice output info, set the following instead # log.setLevel('INFO') ls = u.def_unit("ls", const.c * 1.0 * u.s) log.info("Reading TOAs into PINT") ts = toa.get_TOAs(datadir + "/testtimes.tim", include_bipm=False, usepickle=False) if log.level < 25: ts.print_summary() ts.table.sort("index") log.info("Calling TEMPO2") # cmd = 'tempo2 -output general2 -f tests/testtimes.par tests/testtimes.tim -s "XXX {clock0} {clock1} {clock2} {clock3} {tt} {t2tb} {telSSB} {telVel} {Ttt}\n"' # cmd = 'tempo2 -output general2 -f ' + datadir+'/testtimes.par ' + datadir + \ # '/testtimes.tim -s "XXX {clock0} {clock1} {clock2} {clock3} {tt} {t2tb} {earth_ssb1} {earth_ssb2} {earth_ssb3} {earth_ssb4} {earth_ssb5} {earth_ssb6} {telEpos} {telEVel} {Ttt}\n"' # args = shlex.split(cmd) # # tout = subprocess.check_output(args) # goodlines = [x for x in tout.split("\n") if x.startswith("XXX")] # # assert(len(goodlines)==len(ts.table)) # t2result = numpy.genfromtxt('datafile/testtimes.par' + '.tempo2_test', names=True, comments = '#') f = open(datadir + "/testtimes.par" + ".tempo2_test") lines = f.readlines() goodlines = lines[1:] # Get the output lines from the TOAs for line, TOA in zip(goodlines, ts.table): assert (len(line.split()) == 19 ), "tempo2 general2 does not support all needed outputs" ( oclk, gps_utc, tai_utc, tt_tai, ttcorr, tt2tb, ep0, ep1, ep2, ev0, ev1, ev2, tp0, tp1, tp2, tv0, tv1, tv2, Ttt, ) = (float(x) for x in line.split()) t2_epv = PosVel( numpy.asarray([ep0, ep1, ep2]) * ls, numpy.asarray([ev0, ev1, ev2]) * ls / u.s, ) t2_opv = PosVel( numpy.asarray([tp0, tp1, tp2]) * ls, numpy.asarray([tv0, tv1, tv2]) * ls / u.s, ) t2_ssb2obs = t2_epv + t2_opv # print time_to_mjd_string(TOA.mjd.tt), line.split()[-1] tempo_tt = Time(line.split()[-1], format="mjd_string", scale="tt") # Ensure that the clock corrections are accurate to better than 0.1 ns assert (math.fabs( (oclk * u.s + gps_utc * u.s - TOA["flags"]["clkcorr"]).to( u.ns).value) < 0.1) log.info("TOA in tt difference is: %.2f ns" % ((TOA["mjd"].tt - tempo_tt.tt).sec * u.s).to(u.ns).value) pint_opv = erfautils.gcrs_posvel_from_itrf(Observatory.get( TOA["obs"]).earth_location_itrf(), TOA, obsname=TOA["obs"]) pint_opv = PosVel(pint_opv.pos, pint_opv.vel) # print " obs T2:", t2_opv.pos.to(u.m).value, t2_opv.vel.to(u.m/u.s) # print " obs PINT:", pint_opv.pos.to(u.m), pint_opv.vel.to(u.m/u.s) dopv = pint_opv - t2_opv dpos = numpy.sqrt(numpy.dot(dopv.pos.to(u.m), dopv.pos.to(u.m))) dvel = numpy.sqrt( numpy.dot(dopv.vel.to(u.mm / u.s), dopv.vel.to(u.mm / u.s))) log.info(" obs diff: %.2f m, %.3f mm/s" % (dpos, dvel)) assert dpos < 2.0 and dvel < 0.02 pint_ssb2obs = PosVel( numpy.asarray(TOA["ssb_obs_pos"]) * u.km, numpy.asarray(TOA["ssb_obs_vel"]) * u.km / u.s, origin="SSB", obj="OBS", ) # print " topo T2:", t2_ssb2obs.pos.to(u.km), t2_ssb2obs.vel.to(u.km/u.s) # print " topo PINT:", pint_ssb2obs.pos.to(u.km), pint_ssb2obs.vel.to(u.km/u.s) dtopo = pint_ssb2obs - t2_ssb2obs dpos = numpy.sqrt(numpy.dot(dtopo.pos.to(u.m), dtopo.pos.to(u.m))) dvel = numpy.sqrt( numpy.dot(dtopo.vel.to(u.mm / u.s), dtopo.vel.to(u.mm / u.s))) log.info(" topo diff: %.2f m, %.3f m/s" % (dpos, dvel)) assert dpos < 2.0 and dvel < 0.02
numpy.asarray([tp0, tp1, tp2]) * ls, numpy.asarray([tv0, tv1, tv2]) * ls / u.s) t2_ssb2obs = t2_epv + t2_opv # print utils.time_toq_mjd_string(TOA.mjd.tt), line.split()[-1] tempo_tt = utils.time_from_mjd_string(line.split()[-1], scale='tt') # Ensure that the clock corrections are accurate to better than 0.1 ns assert (math.fabs( (oclk * u.s + gps_utc * u.s - TOA['flags']["clkcorr"]).to(u.ns).value) < 0.1) log.info("TOA in tt difference is: %.2f ns" % \ ((TOA['mjd'].tt - tempo_tt.tt).sec * u.s).to(u.ns).value) pint_opv = erfautils.gcrs_posvel_from_itrf(Observatory.get( TOA['obs']).earth_location_itrf(), TOA, obsname=TOA['obs']) pint_opv = utils.PosVel(pint_opv.pos.T[0], pint_opv.vel.T[0]) #print " obs T2:", t2_opv.pos.to(u.m).value, t2_opv.vel.to(u.m/u.s) #print " obs PINT:", pint_opv.pos.to(u.m), pint_opv.vel.to(u.m/u.s) dopv = pint_opv - t2_opv dpos = numpy.sqrt(numpy.dot(dopv.pos.to(u.m), dopv.pos.to(u.m))) dvel = numpy.sqrt( numpy.dot(dopv.vel.to(u.mm / u.s), dopv.vel.to(u.mm / u.s))) log.info(" obs diff: %.2f m, %.3f mm/s" % (dpos, dvel)) assert (dpos < 2.0 and dvel < 0.02) pint_ssb2obs = PosVel(numpy.asarray(TOA['ssb_obs_pos']) * u.km, numpy.asarray(TOA['ssb_obs_vel']) * u.km / u.s, origin='SSB', obj='OBS')
t2_epv = utils.PosVel(numpy.asarray([ep0, ep1, ep2]) * ls, numpy.asarray([ev0, ev1, ev2]) * ls/u.s) t2_opv = utils.PosVel(numpy.asarray([tp0, tp1, tp2]) * ls, numpy.asarray([tv0, tv1, tv2]) * ls/u.s) t2_ssb2obs = t2_epv + t2_opv # print utils.time_toq_mjd_string(TOA.mjd.tt), line.split()[-1] tempo_tt = utils.time_from_mjd_string(line.split()[-1], scale='tt') # Ensure that the clock corrections are accurate to better than 0.1 ns assert(math.fabs((oclk*u.s + gps_utc*u.s - TOA['flags']["clkcorr"]).to(u.ns).value) < 0.1) log.info("TOA in tt difference is: %.2f ns" % \ ((TOA['mjd'].tt - tempo_tt.tt).sec * u.s).to(u.ns).value) pint_opv = erfautils.gcrs_posvel_from_itrf( Observatory.get(TOA['obs']).earth_location_itrf(), TOA, obsname=TOA['obs']) pint_opv = utils.PosVel(pint_opv.pos.T[0], pint_opv.vel.T[0]) #print " obs T2:", t2_opv.pos.to(u.m).value, t2_opv.vel.to(u.m/u.s) #print " obs PINT:", pint_opv.pos.to(u.m), pint_opv.vel.to(u.m/u.s) dopv = pint_opv - t2_opv dpos = numpy.sqrt(numpy.dot(dopv.pos.to(u.m), dopv.pos.to(u.m))) dvel = numpy.sqrt(numpy.dot(dopv.vel.to(u.mm/u.s), dopv.vel.to(u.mm/u.s))) log.info(" obs diff: %.2f m, %.3f mm/s" % (dpos, dvel)) assert(dpos < 2.0 and dvel < 0.02) pint_ssb2obs = PosVel(numpy.asarray(TOA['ssb_obs_pos'])*u.km, numpy.asarray(TOA['ssb_obs_vel'])*u.km/u.s, origin='SSB', obj='OBS') #print " topo T2:", t2_ssb2obs.pos.to(u.km), t2_ssb2obs.vel.to(u.km/u.s) #print " topo PINT:", pint_ssb2obs.pos.to(u.km), pint_ssb2obs.vel.to(u.km/u.s)