Exemple #1
0
def _test_erfa_conversion(leap, i_f):
    i_i, f_i = i_f
    assume(0 <= f_i < 1)
    if leap:
        assume(i_i in leap_sec_days)
    else:
        assume(i_i not in leap_sec_days)
    jd1_in, jd2_in = day_frac(erfa.DJM0 + i_i, f_i)
    y, mo, d, f = erfa.jd2cal(jd1_in, jd2_in)
    assert 0 < y < 3000
    assert 0 < mo <= 12
    assert 0 <= d < 32
    assert 0 <= f < 1

    jd1_temp, jd2_temp = erfa.cal2jd(y, mo, d)
    jd1_temp, jd2_temp = day_frac(jd1_temp, jd2_temp)  # improve numerics
    jd1_temp, jd2_temp = day_frac(jd1_temp, jd2_temp + f)
    jd_change = abs((jd1_temp - jd1_in) + (jd2_temp - jd2_in)) * u.day
    assert jd_change.to(u.ns) < 1 * u.ns

    ft = 24 * f
    h = safe_kind_conversion(np.floor(ft), dtype=int)
    ft -= h
    ft *= 60
    m = safe_kind_conversion(np.floor(ft), dtype=int)
    ft -= m
    ft *= 60
    s = ft
    assert 0 <= h < 24
    assert 0 <= m < 60
    assert 0 <= s < 60

    jd1, jd2 = erfa.dtf2d("UTC", y, mo, d, h, m, s)
    y2, mo2, d2, f2 = erfa.jd2cal(jd1, jd2)
    # assert (y, mo, d) == (y2, mo2, d2)
    # assert (abs(f2-f)*u.day).to(u.s) < 1*u.ns

    assert jd1 == np.floor(jd1) + 0.5
    assert 0 <= jd2 < 1
    jd1, jd2 = day_frac(jd1, jd2)
    jd_change = abs((jd1 - jd1_in) + (jd2 - jd2_in)) * u.day
    if leap:
        assert jd_change.to(u.s) < 1 * u.s
    else:
        assert jd_change.to(u.ns) < 2 * u.ns
        # assert jd_change.to(u.ns) < 1 * u.ns
    return

    i_o, f_o = day_frac(jd1 - erfa.DJM0, jd2)

    mjd_change = abs((i_o - i_i) + (f_o - f_i)) * u.day
    if leap:
        assert mjd_change.to(u.s) < 1 * u.s
    else:
        assert mjd_change.to(u.ns) < 1 * u.ns
Exemple #2
0
def mjds_to_jds_pulsar(mjd1, mjd2):
    # To get around leap second issues, first convert to YMD,
    # then back to astropy/ERFA-convention jd1,jd2 using the
    # ERFA dtf2d() routine which handles leap seconds.
    v1, v2 = day_frac(mjd1, mjd2)
    (y, mo, d, f) = erfa.jd2cal(erfa.DJM0 + v1, v2)
    # Fractional day to HMS.  Uses 86400-second day always.
    # Seems like there should be a ERFA routine for this..
    # There is: erfa.d2tf. Unfortunately it takes a "number of
    # digits" argument and returns some kind of bogus
    # fractional-part-as-an-integer thing.
    # Worse, it fails to provide nanosecond accuracy.
    # Good idea, though, because using np.remainder is
    # numerically unstable and gives bogus values now
    # and then. This is more stable.
    f *= 24
    h = safe_kind_conversion(np.floor(f), dtype=int)
    f -= h
    f *= 60
    m = safe_kind_conversion(np.floor(f), dtype=int)
    f -= m
    f *= 60
    s = f
    return erfa.dtf2d("UTC", y, mo, d, h, m, s)
Exemple #3
0
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)
Exemple #4
0
# -*- coding: utf-8 -*-
'''example from sofa_ts_c.pdf
'''
from __future__ import print_function
import math
import numpy as np
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('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]))
Exemple #5
0
# Ambient pressure (HPa), temperature (C) and rel. humidity (frac).
phpa = np.array([731.0])
tc = np.array([12.8])
rh = np.array([0.59])

# Effective color (microns).
wl = np.array([0.55])

# UTC date
y = np.array([2013], dtype="int32")
m = np.array([4], dtype="int32")
d = np.array([2], dtype="int32")
h = np.array([23], dtype="int32")
mn = np.array([15], dtype="int32")
sec = np.array([43.55])
utc1, utc2 = erfa.dtf2d("UTC", y, m, d, h, mn, sec)

# TT date
tai1, tai2 = erfa.utctai(utc1, utc2)
tt1, tt2 = erfa.taitt(tai1, tai2)

# EOPs: polar motion in radians, UT1-UTC in seconds.
xp = np.array([50.995e-3 * erfa.DAS2R])
yp = np.array([376.723e-3 * erfa.DAS2R])
dut1 = np.array([155.0675e-3])
##print('xp, yp', xp, yp)
# Corrections to IAU 2000A CIP (radians).
dx = 0.269e-3 * erfa.DAS2R
dy = -0.274e-3 * erfa.DAS2R

# Star ICRS RA,Dec (radians).
Exemple #6
0
def strputc(string):
    '''parse a utc string and return utc1, utc2'''
    Y,m,d,H,M,S,w,y,dst=time.strptime(string, '%Y/%m/%dT%H:%M:%S')
    return erfa.dtf2d(Y,m,d,H,M,S)
Exemple #7
0
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)
Exemple #8
0
# -*- coding: utf-8 -*-
'''SOFA example, from sofa_ts_c.pdf
'''
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")
Exemple #9
0
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

_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
======================================
''')
Exemple #10
0
    
# site longitude, latitude (radians) and height above the geoid (m).
phi = erfa.af2a(-15,57,42.8)
elong = erfa.af2a(-5,41,54.2)
hm = 625.0

# Ambient pressure (HPa), temperature (C) and rel. humidity (frac).
phpa = 952.0
tc = 18.5
rh = 0.83

# Effective color (microns).
wl = 0.55

# UTC date
utc1, utc2 = erfa.dtf2d(2013, 4, 2, 23, 15, 43.55, "UTC")

# TT date
tai1, tai2 = erfa.utctai(utc1, utc2)
tt1, tt2 = erfa.taitt(tai1, tai2)

# EOPs: polar motion in radians, UT1-UTC in seconds. 
xp = 50.995e-3 * erfa.DAS2R
yp = 376.723e-3 * erfa.DAS2R
dut1 = 155.0675e-3
##print('xp, yp', xp, yp)
# Corrections to IAU 2000A CIP (radians). 
dx = 0.269e-3 * erfa.DAS2R
dy = -0.274e-3 * erfa.DAS2R

# Star ICRS RA,Dec (radians).
Exemple #11
0
# -*- coding: utf-8 -*-
'''SOFA example, from sofa_ts_c.pdf
'''
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")
Exemple #12
0
# site longitude, latitude (radians) and height above the geoid (m).
phi = erfa.af2a(-15, 57, 42.8)
elong = erfa.af2a(-5, 41, 54.2)
hm = 625.0

# Ambient pressure (HPa), temperature (C) and rel. humidity (frac).
phpa = 952.0
tc = 18.5
rh = 0.83

# Effective color (microns).
wl = 0.55

# UTC date
utc1, utc2 = erfa.dtf2d(2013, 4, 2, 23, 15, 43.55, "UTC")

# TT date
tai1, tai2 = erfa.utctai(utc1, utc2)
tt1, tt2 = erfa.taitt(tai1, tai2)

# EOPs: polar motion in radians, UT1-UTC in seconds.
xp = 50.995e-3 * erfa.DAS2R
yp = 376.723e-3 * erfa.DAS2R
dut1 = 155.0675e-3
##print('xp, yp', xp, yp)
# Corrections to IAU 2000A CIP (radians).
dx = 0.269e-3 * erfa.DAS2R
dy = -0.274e-3 * erfa.DAS2R

# Star ICRS RA,Dec (radians).