Skip to content

Commit 7048693

Browse files
taldcrofteteq
authored andcommitted
Merge pull request #4436 from taldcroft/iers-cache
Implement auto-downloading of IERS data
1 parent 3c47c10 commit 7048693

17 files changed

Lines changed: 1126 additions & 173 deletions

File tree

‎CHANGES.rst‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ New Features
3434
point/object specified in another frame). [#4909]
3535

3636
- Added ``SkyCoord.spherical_offsets_to`` method. [#4338]
37+
- Recent Earth rotation (IERS) data are now auto-downloaded so that AltAz
38+
transformations for future dates now use the most accurate available
39+
rotation values. [#4436]
3740

3841
- ``astropy.cosmology``
3942

@@ -143,6 +146,9 @@ New Features
143146
- Added caching of scale and format transformations for improved performance.
144147
[#4422]
145148

149+
- Recent Earth rotation (IERS) data are now auto-downloaded so that UT1
150+
transformations for future times now work out of the box. [#4436]
151+
146152
- ``astropy.units``
147153

148154
- The option to use tuples to indicate fractional powers of units,
@@ -171,6 +177,9 @@ New Features
171177
- Added a new context manager ``set_locale`` to temporarily set the
172178
current locale. [#4363]
173179

180+
- Added new IERS_Auto class to auto-download recent IERS (Earth rotation)
181+
data when required by coordinate or time transformations. [#4436]
182+
174183
- ``astropy.visualization``
175184

176185
- Add zscale interval based on Numdisplay's implementation. [#4776]
@@ -393,6 +402,10 @@ API changes
393402

394403
- The astropy.utils.metadata.MetaData descriptor has now two optional
395404
parameters: doc and copy. [#4921]
405+
- The default IERS (Earth rotation) data now is now auto-downloaded via a
406+
new class IERS_Auto. When extrapolating UT1-UTC or polar motion values
407+
outside the available time range, the values are now clipped at the last
408+
available value instead of being linearly extrapolated. [#4436]
396409

397410
- ``astropy.visualization``
398411

‎astropy/coordinates/builtin_frames/utils.py‎

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,6 @@
3232
# comes from the mean of the 1962-2014 IERS B data
3333
_DEFAULT_PM = (0.035, 0.29)*u.arcsec
3434

35-
_IERS_HINT = """
36-
If you need enough precision such that this matters (~<10 arcsec), you can
37-
use the latest IERS predictions by running:
38-
39-
>>> from astropy.utils import iers
40-
>>> iers.IERS.iers_table = iers.IERS_A.open(iers.IERS_A_URL)
41-
42-
"""
43-
4435

4536
def cartrepr_from_matmul(pmat, coo, transpose=False):
4637
"""
@@ -71,21 +62,23 @@ def get_polar_motion(time):
7162
"""
7263
gets the two polar motion components in radians for use with apio13
7364
"""
74-
# get the polar motion from the IERS table
75-
xp, yp, status = iers.IERS.open().pm_xy(time, return_status=True)
65+
# Get the polar motion from the IERS table
66+
xp, yp, status = iers.IERS_Auto.open().pm_xy(time, return_status=True)
7667

7768
wmsg = None
7869
if np.any(status == iers.TIME_BEFORE_IERS_RANGE):
7970
wmsg = ('Tried to get polar motions for times before IERS data is '
80-
'valid. Defaulting to polar motion from the 50-yr mean for those.')
71+
'valid. Defaulting to polar motion from the 50-yr mean for those. '
72+
'This may affect precision at the 10s of arcsec level')
8173
xp.ravel()[status.ravel() == iers.TIME_BEFORE_IERS_RANGE] = _DEFAULT_PM[0]
8274
yp.ravel()[status.ravel() == iers.TIME_BEFORE_IERS_RANGE] = _DEFAULT_PM[1]
8375

8476
warnings.warn(wmsg, AstropyWarning)
8577

8678
if np.any(status == iers.TIME_BEYOND_IERS_RANGE):
8779
wmsg = ('Tried to get polar motions for times after IERS data is '
88-
'valid. Defaulting to polar motion from the 50-yr mean for those.' + _IERS_HINT)
80+
'valid. Defaulting to polar motion from the 50-yr mean for those. '
81+
'This may affect precision at the 10s of arcsec level')
8982

9083
xp.ravel()[status.ravel() == iers.TIME_BEYOND_IERS_RANGE] = _DEFAULT_PM[0]
9184
yp.ravel()[status.ravel() == iers.TIME_BEYOND_IERS_RANGE] = _DEFAULT_PM[1]
@@ -103,8 +96,8 @@ def _warn_iers(ierserr):
10396
----------
10497
ierserr : An `~astropy.utils.iers.IERSRangeError`
10598
"""
106-
msg = '{0} Assuming UT1-UTC=0 for coordinate transformations.{1}'
107-
warnings.warn(msg.format(ierserr.args[0], _IERS_HINT), AstropyWarning)
99+
msg = '{0} Assuming UT1-UTC=0 for coordinate transformations.'
100+
warnings.warn(msg.format(ierserr.args[0]), AstropyWarning)
108101

109102

110103
def get_dut1utc(time):

‎astropy/coordinates/tests/accuracy/test_altaz_icrs.py‎

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,47 @@
2121
def test_against_hor2eq():
2222
"""Check that Astropy gives consistent results with an IDL hor2eq example.
2323
24-
See EXAMPLE input and output here:
25-
http://idlastro.gsfc.nasa.gov/ftp/pro/astro/hor2eq.pro
24+
See : http://idlastro.gsfc.nasa.gov/ftp/pro/astro/hor2eq.pro
25+
26+
Test is against these run outputs, run at 2000-01-01T12:00:00:
27+
28+
# NORMAL ATMOSPHERE CASE
29+
IDL> hor2eq, ten(37,54,41), ten(264,55,06), 2451545.0d, ra, dec, /verb, obs='kpno', pres=781.0, temp=273.0
30+
Latitude = +31 57 48.0 Longitude = *** 36 00.0
31+
Julian Date = 2451545.000000
32+
Az, El = 17 39 40.4 +37 54 41 (Observer Coords)
33+
Az, El = 17 39 40.4 +37 53 40 (Apparent Coords)
34+
LMST = +11 15 26.5
35+
LAST = +11 15 25.7
36+
Hour Angle = +03 38 30.1 (hh:mm:ss)
37+
Ra, Dec: 07 36 55.6 +15 25 02 (Apparent Coords)
38+
Ra, Dec: 07 36 55.2 +15 25 08 (J2000.0000)
39+
Ra, Dec: 07 36 55.2 +15 25 08 (J2000)
40+
IDL> print, ra, dec
41+
114.23004 15.418818
42+
43+
# NO PRESSURE CASE
44+
IDL> hor2eq, ten(37,54,41), ten(264,55,06), 2451545.0d, ra, dec, /verb, obs='kpno', pres=0.0, temp=273.0
45+
Latitude = +31 57 48.0 Longitude = *** 36 00.0
46+
Julian Date = 2451545.000000
47+
Az, El = 17 39 40.4 +37 54 41 (Observer Coords)
48+
Az, El = 17 39 40.4 +37 54 41 (Apparent Coords)
49+
LMST = +11 15 26.5
50+
LAST = +11 15 25.7
51+
Hour Angle = +03 38 26.4 (hh:mm:ss)
52+
Ra, Dec: 07 36 59.3 +15 25 31 (Apparent Coords)
53+
Ra, Dec: 07 36 58.9 +15 25 37 (J2000.0000)
54+
Ra, Dec: 07 36 58.9 +15 25 37 (J2000)
55+
IDL> print, ra, dec
56+
114.24554 15.427022
2657
"""
2758
# Observatory position for `kpno` from here:
2859
# http://idlastro.gsfc.nasa.gov/ftp/pro/astro/observatory.pro
2960
location = EarthLocation(lon=Angle('-111d36.0m'),
3061
lat=Angle('31d57.8m'),
3162
height=2120. * u.m)
3263

33-
# obstime = Time('2041-12-26 05:00:00')
34-
obstime = Time(2466879.7083333, format='jd')
35-
# obstime += TimeDelta(-2, format='sec')
64+
obstime = Time(2451545.0, format='jd', scale='ut1')
3665

3766
altaz_frame = AltAz(obstime=obstime, location=location,
3867
temperature=0 * u.deg_C, pressure=0.781 * u.bar)
@@ -43,22 +72,19 @@ def test_against_hor2eq():
4372

4473
radec_frame = 'icrs'
4574

46-
# The following transformation throws a warning about precision problems
47-
# because the observation date is in the future
48-
with catch_warnings() as _:
49-
radec_actual = altaz.transform_to(radec_frame)
50-
radec_actual_noatm = altaz_noatm.transform_to(radec_frame)
75+
radec_actual = altaz.transform_to(radec_frame)
76+
radec_actual_noatm = altaz_noatm.transform_to(radec_frame)
5177

52-
radec_expected = SkyCoord('00h13m14.1s +15d11m0.3s', frame=radec_frame)
78+
radec_expected = SkyCoord('07h36m55.2s +15d25m08s', frame=radec_frame)
5379
distance = radec_actual.separation(radec_expected).to('arcsec')
5480

5581
# this comes from running the example hor2eq but with the pressure set to 0
56-
radec_expected_noatm = SkyCoord('00h13m17.8s +15d11m30s', frame=radec_frame)
82+
radec_expected_noatm = SkyCoord('07h36m58.9s +15d25m37s', frame=radec_frame)
5783
distance_noatm = radec_actual_noatm.separation(radec_expected_noatm).to('arcsec')
5884

59-
# the baseline difference is ~2.6285 arcsec as of when this was lest updated.
60-
# the difference is mainly due to the somewhat different atmospheric model
61-
# that hor2eq assumes. This is confirmed by the second test which has the
85+
# The baseline difference is ~2.3 arcsec with one atm of pressure. The
86+
# difference is mainly due to the somewhat different atmospheric model that
87+
# hor2eq assumes. This is confirmed by the second test which has the
6288
# atmosphere "off" - the residual difference is small enough to be embedded
6389
# in the assumptions about "J2000" or rounding errors.
6490
assert distance < 5 * u.arcsec

‎astropy/coordinates/tests/test_iau_fullstack.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def test_iau_fullstack(fullstack_icrs, fullstack_fiducial_altaz,
108108
assert np.all(addecs < tol), 'largest Dec change is {0} mas, > {1}'.format(np.max(addecs.arcsec*1000), tol)
109109

110110
# check that we're consistent with the ERFA alt/az result
111-
xp, yp = u.Quantity(iers.IERS.open().pm_xy(fullstack_times)).to(u.radian).value
111+
xp, yp = u.Quantity(iers.IERS_Auto.open().pm_xy(fullstack_times)).to(u.radian).value
112112
lon = fullstack_locations.geodetic[0].to(u.radian).value
113113
lat = fullstack_locations.geodetic[1].to(u.radian).value
114114
height = fullstack_locations.geodetic[2].to(u.m).value
@@ -157,9 +157,15 @@ def test_future_altaz(recwarn):
157157

158158
SkyCoord(1*u.deg, 2*u.deg).transform_to(AltAz(location=location, obstime=t))
159159

160-
# check that these messages appear among any other warnings
161-
messages_to_find = ["Tried to get polar motions for times after IERS data is valid.",
162-
"(some) times are outside of range covered by IERS table."]
160+
# check that these message(s) appear among any other warnings. If tests are run with
161+
# --remote-data then the IERS table will be an instance of IERS_Auto which is
162+
# assured of being "fresh". In this case getting times outside the range of the
163+
# table does not raise an exception. Only if using IERS_B (which happens without
164+
# --remote-data, i.e. for all CI testing) do we expect another warning.
165+
messages_to_find = ["Tried to get polar motions for times after IERS data is valid."]
166+
if isinstance(iers.IERS_Auto.iers_table, iers.IERS_B):
167+
messages_to_find.append("(some) times are outside of range covered by IERS table.")
168+
163169
messages_found = [False for _ in messages_to_find]
164170
for w in recwarn.list:
165171
if issubclass(w.category, AstropyWarning):

‎astropy/coordinates/tests/test_regression.py‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from ... import units as u
1515
from .. import AltAz, EarthLocation, SkyCoord, get_sun, ICRS, CIRS, ITRS
1616
from ...time import Time
17+
from ...utils import iers
1718

1819
from ...tests.helper import pytest, assert_quantity_allclose
1920
from .test_matching import HAS_SCIPY, OLDER_SCIPY
@@ -174,10 +175,11 @@ def test_regression_futuretimes_4302(recwarn):
174175
c = CIRS(1*u.deg, 2*u.deg, obstime=future_time)
175176
c.transform_to(ITRS(obstime=future_time))
176177

177-
saw_iers_warnings = False
178-
for w in recwarn.list:
179-
if issubclass(w.category, AstropyWarning):
180-
if '(some) times are outside of range covered by IERS table' in str(w.message):
181-
saw_iers_warnings = True
182-
break
183-
assert saw_iers_warnings, 'Never saw IERS warning'
178+
if not isinstance(iers.IERS_Auto.iers_table, iers.IERS_Auto):
179+
saw_iers_warnings = False
180+
for w in recwarn.list:
181+
if issubclass(w.category, AstropyWarning):
182+
if '(some) times are outside of range covered by IERS table' in str(w.message):
183+
saw_iers_warnings = True
184+
break
185+
assert saw_iers_warnings, 'Never saw IERS warning'

‎astropy/time/core.py‎

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,22 +1228,6 @@ def get_delta_ut1_utc(self, iers_table=None, return_status=False):
12281228
>>> delta, status = t.get_delta_ut1_utc(return_status=True)
12291229
>>> status == TIME_BEFORE_IERS_RANGE
12301230
array([ True, False], dtype=bool)
1231-
1232-
To use an updated IERS A bulletin to calculate UT1-UTC
1233-
(see also ``astropy.utils.iers``)::
1234-
1235-
>>> from astropy.utils.iers import IERS_A, IERS_A_URL
1236-
>>> from astropy.utils.data import download_file
1237-
>>> t = Time(['1974-01-01', '2000-01-01'], scale='utc')
1238-
>>> iers_a_file = download_file(IERS_A_URL,
1239-
... cache=True) # doctest: +REMOTE_DATA
1240-
Downloading ... [Done]
1241-
>>> iers_a = IERS_A.open(iers_a_file) # doctest: +REMOTE_DATA
1242-
>>> t.delta_ut1_utc = t.get_delta_ut1_utc(iers_a) # doctest: +REMOTE_DATA
1243-
1244-
The delta_ut1_utc property will be used to calculate t.ut1;
1245-
raises IndexError if any of the times is out of range.
1246-
12471231
"""
12481232
if iers_table is None:
12491233
from ..utils.iers import IERS
@@ -1262,8 +1246,8 @@ def _get_delta_ut1_utc(self, jd1=None, jd2=None):
12621246
# Sec. 4.3.1: the arg DUT is the quantity delta_UT1 = UT1 - UTC in
12631247
# seconds. It is obtained from tables published by the IERS.
12641248
if not hasattr(self, '_delta_ut1_utc'):
1265-
from ..utils.iers import IERS
1266-
iers_table = IERS.open()
1249+
from ..utils.iers import IERS_Auto
1250+
iers_table = IERS_Auto.open()
12671251
# jd1, jd2 are normally set (see above), except if delta_ut1_utc
12681252
# is access directly; ensure we behave as expected for that case
12691253
if jd1 is None:

‎astropy/time/tests/test_basic.py‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import numpy as np
1212

1313
from ...tests.helper import pytest, catch_warnings
14+
from ...tests.disable_internet import INTERNET_OFF
1415
from ...extern import six
1516
from ...utils import isiterable
1617
from .. import Time, ScaleValueError, TIME_SCALES, TimeString, TimezoneInfo
@@ -895,8 +896,16 @@ def test_TimeFormat_scale():
895896
assert t.unix == t.utc.unix
896897

897898
def test_scale_conversion():
898-
with pytest.raises(ScaleValueError):
899-
t = Time(Time.now().cxcsec, format='cxcsec', scale='ut1')
899+
if INTERNET_OFF:
900+
# With internet off (which is the default for testing) then this will
901+
# fall back to the bundled IERS-B table and raise an exception. But when
902+
# testing with --remote-data the IERS_Auto class will get the latest IERS-A
903+
# and this works.
904+
with pytest.raises(ScaleValueError):
905+
Time(Time.now().cxcsec, format='cxcsec', scale='ut1')
906+
else:
907+
Time(Time.now().cxcsec, format='cxcsec', scale='ut1')
908+
900909

901910

902911
def test_byteorder():

‎astropy/time/tests/test_ut1.py‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import numpy as np
55

66
from ...tests.helper import pytest
7+
from ...tests.disable_internet import INTERNET_OFF
78
from .. import Time
89
from ...utils.iers import iers # used in testing
910

@@ -38,7 +39,15 @@ def test_utc_to_ut1(self):
3839
assert allclose_jd(t.jd, t_back.jd)
3940

4041
tnow = Time.now()
41-
with pytest.raises(IndexError):
42+
43+
# With internet off (which is the default for testing) then this will
44+
# fall back to the bundled IERS-B table and raise an exception. But when
45+
# testing with --remote-data the IERS_Auto class will get the latest IERS-A
46+
# and this works.
47+
if INTERNET_OFF:
48+
with pytest.raises(IndexError):
49+
tnow.ut1
50+
else:
4251
tnow.ut1
4352

4453
def test_ut1_to_utc(self):
@@ -77,3 +86,14 @@ def test_ut1_iers_A(self):
7786
assert status == iers.FROM_IERS_A_PREDICTION
7887
tnow_ut1_jd = tnow.ut1.jd
7988
assert tnow_ut1_jd != tnow.jd
89+
90+
91+
@pytest.mark.skipif('INTERNET_OFF')
92+
class TestTimeUT1_IERS_Auto():
93+
def test_ut1_iers_auto(self):
94+
tnow = Time.now()
95+
iers_a = iers.IERS_Auto.open()
96+
tnow.delta_ut1_utc, status = iers_a.ut1_utc(tnow, return_status=True)
97+
assert status == iers.FROM_IERS_A_PREDICTION
98+
tnow_ut1_jd = tnow.ut1.jd
99+
assert tnow_ut1_jd != tnow.jd

0 commit comments

Comments
 (0)