def test_erfa_wrapper(): """ Runs a set of tests that mostly make sure vectorization is working as expected """ jd = np.linspace(2456855.5, 2456855.5+1.0/24.0/60.0, 60*2+1) ra = np.linspace(0.0, np.pi*2.0, 5) dec = np.linspace(-np.pi/2.0, np.pi/2.0, 4) aob, zob, hob, dob, rob, eo = erfa.atco13(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, jd, 0.0, 0.0, 0.0, np.pi/4.0, 0.0, 0.0, 0.0, 1014.0, 0.0, 0.0, 0.5) assert aob.shape == (121,) aob, zob, hob, dob, rob, eo = erfa.atco13(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, jd[0], 0.0, 0.0, 0.0, np.pi/4.0, 0.0, 0.0, 0.0, 1014.0, 0.0, 0.0, 0.5) assert aob.shape == () aob, zob, hob, dob, rob, eo = erfa.atco13(ra[:, None, None], dec[None, :, None], 0.0, 0.0, 0.0, 0.0, jd[None, None, :], 0.0, 0.0, 0.0, np.pi/4.0, 0.0, 0.0, 0.0, 1014.0, 0.0, 0.0, 0.5) (aob.shape) == (5, 4, 121) iy, im, id, ihmsf = erfa.d2dtf("UTC", 3, jd, 0.0) assert iy.shape == (121,) assert ihmsf.shape == (121,) assert ihmsf.dtype == erfa.dt_hmsf iy, im, id, ihmsf = erfa.d2dtf("UTC", 3, jd[0], 0.0) assert iy.shape == () assert ihmsf.shape == () assert ihmsf.dtype == erfa.dt_hmsf
def jds_to_mjds_pulsar(jd1, jd2): # Do the reverse of the above calculation # Note this will return an incorrect value during # leap seconds, so raise an exception in that # case. y, mo, d, hmsf = erfa.d2dtf("UTC", _digits, jd1, jd2) # For ASTROPY_LT_3_1, convert to the new structured array dtype that # is returned by the new erfa gufuncs. if not hmsf.dtype.names: hmsf = hmsf.view(_new_ihmsfs_dtype)[..., 0] if np.any((hmsf["s"] == 60) & (hmsf["f"] != 0)): # if f is exactly zero, this is probably fine to treat as the end of the day. raise ValueError( "UTC times during a leap second cannot be represented in pulsar_mjd format" ) j1, j2 = erfa.cal2jd(y, mo, d) return day_frac( j1 - erfa.DJM0 + j2, hmsf["h"] / 24.0 + hmsf["m"] / 1440.0 + hmsf["s"] / 86400.0 + hmsf["f"] / 86400.0 / 10**_digits, )
DY06 = -0.2259 * AS2R / 1000. # TT (MJD) DJMJD0, DATE = erfa.cal2jd(IY, IM, ID) TIME = (60 * (60 * IH + MIN) + SEC) / 86400. UTC = DATE + TIME DAT = erfa.dat(IY, IM, ID, TIME) TAI = UTC + DAT / 86400. TT = TAI + 32.184 / 86400. # UT1 TUT = TIME + DUT1 / 86400. UT1 = DATE + TUT print("UTC :%4d/%2.2d/%2.2d%3d:%2.2d:%2.2d.%3.3d" % erfa.d2dtf(3, *erfa.dtf2d(IY, IM, ID, IH, MIN, SEC))) print("TT = 2400000.5 + %.17f " % TT) print("UT1 = 2400000.5 + %.17f " % UT1) print(''' ====================================== IAU 1976/1980/1982/1994, equinox based ====================================== ''') # IAU 1976 precession matrix, J2000.0 to date. RP = erfa.pmat76(DJMJD0, TT) # IAU 1980 nutation DP80, DE80 = erfa.nut80(DJMJD0, TT)
and report it rounded to 1ms precision''') # encode UTC date and time into internal format u1, u2 = erfa.dtf2d('utc', np.array([2010]), np.array([7]), np.array([24]), np.array([11]), np.array([18]), np.array([7.318])) # transform UTC to TAI, then TAI to TT a1, a2 = erfa.utctai(u1, u2) t1, t2 = erfa.taitt(a1, a2) # decode and report the TT y, m, d, h = erfa.d2dtf('TT', 3, t1, t2) print("UTC: 2010 July 24, 11:18:07.318") for i in range(len(y)): print("TT : %4d/%2.2d/%2.2d, "%(y[i],m[i],d[i]), end =' ') print("%3d:%2.2d:%2.2d.%3.3d"%tuple(h[i])) print('=====') print(''' TAI to UTC take a time expressed as TAI, encode it into the internal format and transform it into UTC''') # encode TAI date and time into internal format a1, a2 = erfa.dtf2d("TAI", np.array([2009]),
DX06 = 0.1750 * AS2R/1000. DY06 = -0.2259 * AS2R/1000. # TT (MJD) DJMJD0, DATE = erfa.cal2jd(IY, IM, ID) TIME = ( 60*(60*IH + MIN) + SEC ) / 86400. UTC = DATE + TIME DAT = erfa.dat(IY, IM, ID, TIME) TAI = UTC + DAT/86400. TT = TAI + 32.184/86400. # UT1 TUT = TIME + DUT1/86400. UT1 = DATE + TUT print("UTC :%4d/%2.2d/%2.2d%3d:%2.2d:%2.2d.%3.3d"%erfa.d2dtf(3, *erfa.dtf2d(IY, IM, ID, IH, MIN, SEC))) print("TT = 2400000.5 + %.17f "%TT) print("UT1 = 2400000.5 + %.17f "%UT1) print(''' ====================================== IAU 1976/1980/1982/1994, equinox based ====================================== ''') # IAU 1976 precession matrix, J2000.0 to date. RP = erfa.pmat76(DJMJD0, TT) # IAU 1980 nutation DP80, DE80 = erfa.nut80(DJMJD0, TT)
from __future__ import print_function import math import erfa print('''UTC to TT transform 2010 July 24, 11:18:07.318 (UTC) into Terrestrial Time (TT) and report it rounded to 1ms precision''') # encode UTC date and time into internal format u1, u2 = erfa.dtf2d(2010, 7, 24, 11, 18, 7.318) # transform UTC to TAI, then TAI to TT a1, a2 = erfa.utctai(u1, u2) t1, t2 = erfa.taitt(a1, a2) # decode and report the TT y, m, d, h, mn, sc, f = erfa.d2dtf(3, t1, t2) print("UTC: 2010 July 24, 11:18:07.318") print("TT: %4d/%2.2d/%2.2d%3d:%2.2d:%2.2d.%3.3d" % (y, m, d, h, mn, sc, f)) print('=====') print(''' TAI to UTC take a time expressed as TAI, encode it into the internal format and transform it into UTC''') # encode TAI date and time into internal format a1, a2 = erfa.dtf2d(2009, 1, 1, 0, 0, 33.7, "TAI") # decode and report TAI print("TAI :%4d/%2.2d/%2.2d%3d:%2.2d:%2.2d.%3.3d" % erfa.d2dtf(3, a1, a2))
DY06 = -0.2259 * AS2R/1000. # TT (MJD) DJMJD0, DATE = erfa.cal2jd(IY, IM, ID) TIME = ( 60*(60*IH + MIN) + SEC ) / 86400. UTC = DATE + TIME DAT = erfa.dat(IY, IM, ID, TIME) TAI = UTC + DAT/86400. TT = TAI + 32.184/86400. # UT1 TUT = TIME + DUT1/86400. UT1 = DATE + TUT _utc = erfa.dtf2d('utc', IY, IM, ID, IH, MIN, SEC) y,m,d,h = erfa.d2dtf('utc', 3, *_utc) for i in range(len(y)): print("UTC :%4d/%2.2d/%2.2d "%(y[i],m[i],d[i]), end='T') print("%3d:%2.2d:%2.2d.%3.3d"%tuple(h[i])) for t in TT: print("TT = 2400000.5 + %.17f "%t) for t in UT1: print("UT1 = 2400000.5 + %.17f "%t) print(''' ====================================== IAU 1976/1980/1982/1994, equinox based ====================================== ''') # IAU 1976 precession matrix, J2000.0 to date.
from __future__ import print_function import math import erfa print('''UTC to TT transform 2010 July 24, 11:18:07.318 (UTC) into Terrestrial Time (TT) and report it rounded to 1ms precision''') # encode UTC date and time into internal format u1, u2 = erfa.dtf2d(2010,7,24,11,18,7.318) # transform UTC to TAI, then TAI to TT a1, a2 = erfa.utctai(u1, u2) t1, t2 = erfa.taitt(a1, a2) # decode and report the TT y, m, d, h, mn, sc, f = erfa.d2dtf(3, t1, t2) print("UTC: 2010 July 24, 11:18:07.318") print("TT: %4d/%2.2d/%2.2d%3d:%2.2d:%2.2d.%3.3d"%(y, m, d, h, mn, sc, f)) print('=====') print(''' TAI to UTC take a time expressed as TAI, encode it into the internal format and transform it into UTC''') # encode TAI date and time into internal format a1, a2 = erfa.dtf2d(2009,1,1,0,0,33.7, "TAI") # decode and report TAI print("TAI :%4d/%2.2d/%2.2d%3d:%2.2d:%2.2d.%3.3d"%erfa.d2dtf(3, a1, a2))