Skip to content

Commit

Permalink
Respect auto_download even if IERS_Auto predictive values are stale
Browse files Browse the repository at this point in the history
  • Loading branch information
ayshih committed Nov 13, 2024
1 parent 8a09077 commit 028a71b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
10 changes: 10 additions & 0 deletions astropy/utils/iers/iers.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,16 @@ def _refresh_table_as_needed(self, mjd):
if max_input_mjd > predictive_mjd and (now_mjd - predictive_mjd) > auto_max_age:
all_urls = (conf.iers_auto_url, conf.iers_auto_url_mirror)

# Bail out with a warning if downloading is disabled
if not conf.auto_download:
warn(
IERSStaleWarning(
"IERS_Auto predictive values are older than"
f" {conf.auto_max_age} days but downloading is disabled"
)
)
return

# Get the latest version
try:
filename = download_file(all_urls[0], sources=all_urls, cache="update")
Expand Down
14 changes: 10 additions & 4 deletions astropy/utils/iers/tests/test_iers.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,18 @@ def test_simple(self):
dat.ut1_utc(Time(60000, format="mjd").jd)
assert len(warns) == 1

# Warning only if we are getting return status
# Warning only (i.e., no exception) if we are getting return status
with pytest.warns(
iers.IERSStaleWarning, match="IERS_Auto predictive values are older"
) as warns:
iers.IERSStaleWarning, match="IERS_Auto predictive values are older.*did not find newer values"
):
dat.ut1_utc(Time(60000, format="mjd").jd, return_status=True)
assert len(warns) == 1

# Confirm that the warning message is different if downloading is disabled
with pytest.warns(
iers.IERSStaleWarning, match=r"IERS_Auto predictive values are older.*downloading is disabled"
):
with iers.conf.set_temp("auto_download", False):
dat.ut1_utc(Time(60000, format="mjd").jd, return_status=True)

# Now set auto_max_age = None which says that we don't care how old the
# available IERS-A file is. There should be no warnings or exceptions.
Expand Down

0 comments on commit 028a71b

Please sign in to comment.