Skip to content

Commit 2da17a6

Browse files
committed
Fix IERS_Auto logic now that IERS-A is bundled
1 parent 14ff60e commit 2da17a6

6 files changed

Lines changed: 56 additions & 84 deletions

File tree

‎astropy/coordinates/tests/test_iau_fullstack.py‎

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -197,28 +197,13 @@ def test_future_altaz():
197197
location = EarthLocation(lat=0 * u.deg, lon=0 * u.deg)
198198
t = Time("J2161")
199199

200-
# check that these message(s) appear among any other warnings. If tests are run with
201-
# --remote-data then the IERS table will be an instance of IERS_Auto which is
202-
# assured of being "fresh". In this case getting times outside the range of the
203-
# table does not raise an exception. Only if using IERS_B (which happens without
204-
# --remote-data, i.e. for all CI testing) do we expect another warning.
200+
# check that these message(s) appear among any other warnings
205201
if PYTEST_LT_8_0:
206-
ctx1 = ctx2 = nullcontext()
202+
ctx1 = nullcontext()
207203
else:
208204
ctx1 = pytest.warns(erfa.core.ErfaWarning)
209-
ctx2 = pytest.warns(AstropyWarning, match=".*times are outside of range.*")
210-
with (
211-
ctx1,
212-
ctx2,
213-
pytest.warns(
214-
AstropyWarning,
215-
match="Tried to get polar motions for times after IERS data is valid.*",
216-
) as found_warnings,
217-
):
205+
with ctx1, pytest.warns(
206+
AstropyWarning,
207+
match="Tried to get polar motions for times after IERS data is valid.*",
208+
) as found_warnings:
218209
SkyCoord(1 * u.deg, 2 * u.deg).transform_to(AltAz(location=location, obstime=t))
219-
220-
if isinstance(iers.earth_orientation_table.get(), iers.IERS_B):
221-
assert any(
222-
"(some) times are outside of range covered by IERS table." in str(w.message)
223-
for w in found_warnings
224-
)

‎astropy/utils/iers/iers.py‎

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ class Conf(_config.ConfigNamespace):
165165

166166
auto_download = _config.ConfigItem(
167167
True,
168-
"Enable auto-downloading of the latest IERS data. If set to False "
169-
"then the local IERS-B file will be used by default (even if the "
170-
"full IERS file with predictions was already downloaded and cached). "
168+
"Enable auto-downloading of the latest IERS-A data. If set to False "
169+
"then the bundled IERS-A file will be used by default (even if a "
170+
"newer version of the IERS-A file was already downloaded and cached). "
171171
"This parameter also controls whether internet resources will be "
172172
"queried to update the leap second table if the installed version is "
173173
"out of date. Default is True.",
@@ -545,9 +545,9 @@ class IERS_A(IERS):
545545
546546
Notes
547547
-----
548-
The IERS A file is not part of astropy. It can be downloaded from
549-
``iers.IERS_A_URL`` or ``iers.IERS_A_URL_MIRROR``. See ``iers.__doc__``
550-
for instructions on use in ``Time``, etc.
548+
If the package IERS A file (```iers.IERS_A_FILE``) is out of date, a new
549+
version can be downloaded from ``iers.IERS_A_URL`` or ``iers.IERS_A_URL_MIRROR``.
550+
See ``iers.__doc__`` for instructions on use in ``Time``, etc.
551551
"""
552552

553553
iers_table = None
@@ -758,6 +758,10 @@ class IERS_Auto(IERS_A):
758758
"""
759759
Provide most-recent IERS data and automatically handle downloading
760760
of updated values as necessary.
761+
762+
The returned table combines the IERS-A and IERS-B files, with the data
763+
in the IERS-B file considered to be official values and thus superseding
764+
values from th IERS-A file at the same times.
761765
"""
762766

763767
iers_table = None
@@ -772,8 +776,8 @@ def open(cls):
772776
(or non-existent) then it will be downloaded over the network and cached.
773777
774778
If the configuration setting ``astropy.utils.iers.conf.auto_download``
775-
is set to False then ``astropy.utils.iers.IERS()`` is returned. This
776-
is normally the IERS-B table that is supplied with astropy.
779+
is set to False then the bundled IERS-A table will be used rather than
780+
any downloaded version of the IERS-A table.
777781
778782
On the first call in a session, the table will be memoized (in the
779783
``iers_table`` class attribute), and further calls to ``open`` will
@@ -786,7 +790,7 @@ def open(cls):
786790
787791
"""
788792
if not conf.auto_download:
789-
cls.iers_table = IERS_B.open()
793+
cls.iers_table = cls.read()
790794
return cls.iers_table
791795

792796
all_urls = (conf.iers_auto_url, conf.iers_auto_url_mirror)
@@ -817,8 +821,8 @@ def open(cls):
817821
# Issue a warning here, perhaps user is offline. An exception
818822
# will be raised downstream if actually trying to interpolate
819823
# predictive values.
820-
warn("unable to download valid IERS file, using local IERS-B", IERSWarning)
821-
cls.iers_table = IERS_B.open()
824+
warn("unable to download valid IERS file, using local IERS-A", IERSWarning)
825+
cls.iers_table = cls.read()
822826

823827
return cls.iers_table
824828

@@ -932,7 +936,7 @@ def _substitute_iers_b(cls, table):
932936
IERS-A has IERS-B values included, but for reasons unknown these
933937
do not match the latest IERS-B values (see comments in #4436).
934938
Here, we use the bundled astropy IERS-B table to overwrite the values
935-
in the downloaded IERS-A table.
939+
in the IERS-A table.
936940
"""
937941
iers_b = IERS_B.open()
938942
# Substitute IERS-B values for existing B values in IERS-A table

‎astropy/utils/iers/tests/test_iers.py‎

Lines changed: 29 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,9 @@
2525

2626
FILE_NOT_FOUND_ERROR = getattr(__builtins__, "FileNotFoundError", OSError)
2727

28-
try:
29-
iers.IERS_A.open("finals2000A.all") # check if IERS_A is available
30-
except OSError:
31-
HAS_IERS_A = False
32-
else:
33-
HAS_IERS_A = True
34-
3528
IERS_A_EXCERPT = get_pkg_data_filename(os.path.join("data", "iers_a_excerpt"))
3629

3730

38-
def setup_module():
39-
# Need auto_download so that IERS_B won't be loaded and cause tests to
40-
# fail. Files to be downloaded are handled appropriately in the tests.
41-
iers.conf.auto_download = True
42-
43-
44-
def teardown_module():
45-
# This setting is to be consistent with astropy/conftest.py
46-
iers.conf.auto_download = False
47-
48-
4931
class TestBasic:
5032
"""Basic tests that IERS_B returns correct values"""
5133

@@ -216,7 +198,6 @@ def test_simple(self):
216198
assert len(iers_tab[:2]) == 2
217199

218200

219-
@pytest.mark.skipif(not HAS_IERS_A, reason="requires IERS_A")
220201
class TestIERS_A:
221202
@classmethod
222203
def teardown_class(self):
@@ -261,6 +242,14 @@ def setup_class(self):
261242
self.iers_a_url_2 = Path(self.iers_a_file_2).as_uri()
262243
self.t = Time.now() + TimeDelta(10, format="jd") * np.arange(self.N)
263244

245+
# This group of tests requires auto downloading to be on
246+
iers.conf.auto_download = True
247+
248+
# auto_download = False is tested in test_IERS_B_parameters_loading_into_IERS_Auto()
249+
250+
def teardown_class(self):
251+
iers.conf.auto_download = False
252+
264253
def teardown_method(self, method):
265254
"""Run this after every test."""
266255
iers.IERS_Auto.close()
@@ -310,12 +299,6 @@ def test_auto_max_age_minimum(self):
310299
iers_table = iers.IERS_Auto.open()
311300
_ = iers_table.ut1_utc(self.t.jd1, self.t.jd2)
312301

313-
def test_no_auto_download(self):
314-
with iers.conf.set_temp("auto_download", False):
315-
t = iers.IERS_Auto.open()
316-
assert type(t) is iers.IERS_B
317-
318-
@pytest.mark.remote_data
319302
def test_simple(self):
320303
with iers.conf.set_temp("iers_auto_url", self.iers_a_url_1):
321304
dat = iers.IERS_Auto.open()
@@ -383,8 +366,10 @@ def test_simple(self):
383366
assert dat["MJD"][-1] == (57539.0 + 60) * u.d
384367

385368

386-
@pytest.mark.remote_data
387369
def test_IERS_B_parameters_loading_into_IERS_Auto():
370+
# Double-check that auto downloading is off
371+
assert not iers.conf.auto_download
372+
388373
A = iers.IERS_Auto.open()
389374
B = iers.IERS_B.open()
390375

@@ -448,35 +433,31 @@ def test_iers_b_dl():
448433
iers.IERS_B.close()
449434

450435

451-
@pytest.mark.remote_data
452-
def test_iers_out_of_range_handling(tmp_path):
453-
# Make sure we don't have IERS-A data available anywhere
454-
with set_temp_cache(tmp_path):
455-
iers.IERS_A.close()
456-
iers.IERS_Auto.close()
457-
iers.IERS.close()
436+
def test_iers_b_out_of_range_handling():
437+
# The following error/warning applies only to IERS_B, not to the default IERS_Auto
438+
with iers.earth_orientation_table.set(iers.IERS_B.open()):
458439
now = Time.now()
459-
with iers.conf.set_temp("auto_download", False):
460-
# Should be fine with built-in IERS_B
461-
(now - 300 * u.day).ut1
462440

463-
# Default is to raise an error
464-
match = r"\(some\) times are outside of range covered by IERS table"
465-
with pytest.raises(iers.IERSRangeError, match=match):
466-
(now + 100 * u.day).ut1
441+
# Should be fine with bundled IERS-B
442+
(now - 300 * u.day).ut1
467443

468-
with iers.conf.set_temp("iers_degraded_accuracy", "warn"):
469-
with pytest.warns(iers.IERSDegradedAccuracyWarning, match=match):
470-
(now + 100 * u.day).ut1
444+
# Default is to raise an error
445+
match = r"\(some\) times are outside of range covered by IERS table"
446+
with pytest.raises(iers.IERSRangeError, match=match):
447+
(now + 100 * u.day).ut1
471448

472-
with iers.conf.set_temp("iers_degraded_accuracy", "ignore"):
449+
with iers.conf.set_temp("iers_degraded_accuracy", "warn"):
450+
with pytest.warns(iers.IERSDegradedAccuracyWarning, match=match):
473451
(now + 100 * u.day).ut1
474452

453+
with iers.conf.set_temp("iers_degraded_accuracy", "ignore"):
454+
(now + 100 * u.day).ut1
455+
475456

476457
@pytest.mark.remote_data
477458
def test_iers_download_error_handling(tmp_path):
478-
# Make sure we don't have IERS-A data available anywhere
479-
with set_temp_cache(tmp_path):
459+
# Make sure an IERS-A table isn't already loaded
460+
with set_temp_cache(tmp_path), iers.conf.set_temp("auto_download", True):
480461
iers.IERS_A.close()
481462
iers.IERS_Auto.close()
482463
iers.IERS.close()
@@ -488,7 +469,7 @@ def test_iers_download_error_handling(tmp_path):
488469
with iers.conf.set_temp("iers_auto_url_mirror", "https://google.com"):
489470
with pytest.warns(iers.IERSWarning) as record:
490471
with iers.conf.set_temp("iers_degraded_accuracy", "ignore"):
491-
(now + 100 * u.day).ut1
472+
(now + 400 * u.day).ut1
492473

493474
assert len(record) == 3
494475
assert str(record[0].message).startswith(
@@ -498,7 +479,7 @@ def test_iers_download_error_handling(tmp_path):
498479
"malformed IERS table from https://google.com"
499480
)
500481
assert str(record[2].message).startswith(
501-
"unable to download valid IERS file, using local IERS-B"
482+
"unable to download valid IERS file, using local IERS-A"
502483
)
503484

504485

‎docs/changes/utils/16187.api.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The return type of ``IERS_Auto.open()`` is no longer ``IERS_B`` when automatic updating of the IERS-A file is disabled or the downloading of the new file fails.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed the unintended behavior where the IERS-A file bundled in ``astropy-iers-data`` would be ignored if automatic updating of the IERS-A file were disabled or if downloading the new file failed.

‎docs/utils/iers.rst‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ that relate to automatic IERS downloading. Four of the most
9494
important to consider are the following:
9595

9696
auto_download:
97-
Enable auto-downloading of the latest IERS data. If set to ``False`` then
98-
the local IERS-A and IERS-B files will be used by default (even if the full
99-
IERS file with predictions was already downloaded and cached). This
97+
Enable auto-downloading of the latest IERS-A data. If set to ``False`` then
98+
the bundled IERS-A file will be used by default (even if a newer
99+
versions of the IERS-A file was already downloaded and cached). This
100100
parameter also controls whether internet resources will be queried to update
101101
the leap second table if the installed version is out of date.
102102

0 commit comments

Comments
 (0)