Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9f4de8d

Browse files
authored
Apply iers_degraded_accuracy to stale IERS_Auto predictive values (#20256)
* Apply iers_degraded_accuracy to stale IERS_Auto predictive values IERS_Auto always raised a ValueError when the co-installed IERS-A data was older than auto_max_age and a conversion needed predictive values, regardless of iers_degraded_accuracy. This regressed from IERS-B-only behavior where 'warn'/'ignore' were honored. Now IERS_Auto._check_interpolate_indices behaves like IERS does for out-of-range times: the default 'error' still raises ValueError, 'warn' emits IERSDegradedAccuracyWarning, and 'ignore' is silent. This matches the maintainer-invited fix requested in issue #19823. Tests: 2 new TestIERS_Auto cases for 'warn' and 'ignore'; all 29 IERS suite tests and 5 time/ut1 tests pass. --------- Co-authored-by: Shurong Cao <[email protected]>
1 parent 4bd86a6 commit 9f4de8d

4 files changed

Lines changed: 46 additions & 3 deletions

File tree

astropy/utils/iers/iers.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class Conf(_config.ConfigNamespace):
193193
["error", "warn", "ignore"],
194194
"IERS behavior if the range of available IERS data does not "
195195
"cover the times when converting time scales, potentially leading "
196-
"to degraded accuracy. Applies only when using IERS-B data on its own.",
196+
"to degraded accuracy.",
197197
)
198198
system_leap_second_file = _config.ConfigItem("", "System file with leap seconds.")
199199
iers_leap_second_auto_url = _config.ConfigItem(
@@ -824,7 +824,18 @@ def _check_interpolate_indices(self, indices_orig, indices_clipped, max_input_mj
824824
max_input_mjd > predictive_mjd
825825
and Time.now().mjd - predictive_mjd > auto_max_age
826826
):
827-
raise ValueError(INTERPOLATE_ERROR.format(auto_max_age))
827+
# If predictive values are stale, behave like IERS_B does for
828+
# out-of-range times: honor the iers_degraded_accuracy setting
829+
# instead of always raising. Only the default "error" setting
830+
# raises; "warn" warns and "ignore" is silent.
831+
if conf.iers_degraded_accuracy == "error":
832+
raise ValueError(INTERPOLATE_ERROR.format(auto_max_age))
833+
elif conf.iers_degraded_accuracy == "warn":
834+
msg = (
835+
f"interpolating from IERS_Auto using predictive values that "
836+
f"are more than {auto_max_age} days old; accuracy is degraded."
837+
)
838+
warn(msg, IERSDegradedAccuracyWarning)
828839

829840
def _refresh_table_as_needed(self, mjd):
830841
"""Potentially update the IERS table in place depending on the requested

astropy/utils/iers/tests/test_iers.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,34 @@ def test_interpolate_error_formatting(self, monkeypatch):
283283
warnings.simplefilter("ignore", iers.IERSStaleWarning)
284284
iers_table.ut1_utc(self.t.jd1, self.t.jd2)
285285

286+
def test_iers_degraded_accuracy_warn(self, monkeypatch):
287+
"""The iers_degraded_accuracy setting applies to stale IERS_Auto values."""
288+
monkeypatch.setattr(iers, "IERS_A_FILE", self.iers_a_file_1)
289+
with iers.conf.set_temp("iers_auto_url", self.iers_a_url_1):
290+
with iers.conf.set_temp("iers_auto_url_mirror", self.iers_a_url_1):
291+
with iers.conf.set_temp("auto_max_age", self.ame):
292+
iers_table = iers.IERS_Auto.open()
293+
with warnings.catch_warnings():
294+
# Ignore stale-warning noise from the refresh; the
295+
# degradation warning below is what we are asserting on.
296+
warnings.simplefilter("ignore", iers.IERSStaleWarning)
297+
with iers.conf.set_temp("iers_degraded_accuracy", "warn"):
298+
with pytest.warns(iers.IERSDegradedAccuracyWarning):
299+
iers_table.ut1_utc(self.t.jd1, self.t.jd2)
300+
301+
def test_iers_degraded_accuracy_ignore(self, monkeypatch):
302+
"""With iers_degraded_accuracy='ignore' stale IERS_Auto values are silent."""
303+
monkeypatch.setattr(iers, "IERS_A_FILE", self.iers_a_file_1)
304+
with iers.conf.set_temp("iers_auto_url", self.iers_a_url_1):
305+
with iers.conf.set_temp("iers_auto_url_mirror", self.iers_a_url_1):
306+
with iers.conf.set_temp("auto_max_age", self.ame):
307+
iers_table = iers.IERS_Auto.open()
308+
with warnings.catch_warnings():
309+
warnings.simplefilter("ignore", iers.IERSStaleWarning)
310+
with iers.conf.set_temp("iers_degraded_accuracy", "ignore"):
311+
delta = iers_table.ut1_utc(self.t.jd1, self.t.jd2)
312+
assert delta.shape == (self.N,)
313+
286314
def test_auto_max_age_none(self, monkeypatch):
287315
"""Make sure that iers.INTERPOLATE_ERROR's advice about setting
288316
auto_max_age = None actually works.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fixed an issue where ``iers_degraded_accuracy`` did not apply to stale
2+
predictive values in the co-installed IERS-A data used by
3+
``IERS_Auto``, so setting it to ``"warn"`` or ``"ignore"`` raised a
4+
``ValueError`` instead of warning or being silent.

docs/utils/iers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ ANSWERS!*
187187

188188
Set ``astropy.utils.iers.conf.iers_degraded_accuracy`` to either ``'warn'``
189189
or ``'ignore'``. These prevent the normal exception that occurs if a
190-
time conversion falls outside the bounds of available local IERS-B data.
190+
time conversion falls outside the bounds of available IERS data.
191191

192192

193193
Direct table access

0 commit comments

Comments
 (0)