Skip to content

When iers_degraded_accuracy = error, Astropy reports a warning and not an error (in coordinates) #16128

Closed

Description

@IlDordollano

Description

iers_degraded_accuracy can be set to "error", "warn" or "silent".

iers_degraded_accuracy = error has the same behavior as iers_degraded_accuracy = warn

Expected behavior

Expected behavior is log error instead of warning and an uncatched IERSRangeError . As documented here https://docs.astropy.org/en/stable/utils/iers.html

iers_degraded_accuracy:
Some time conversions like UTC -> UT1 require IERS-A Earth rotation data for full accuracy. In cases where full accuracy is not required and downloading the IERS-A is not possible or desired (for instance running on a cluster) then this option can be set to either 'warn' or 'ignore'. The default is 'error' which will raise an exception if full accuracy is not possible for a time conversion, 'warn' will issue a warning, and 'ignore' will ignore the problem and use available IERS-B data.

How to Reproduce

astropy.utils.iers.conf.iers_degraded_accuracy = "error"
t = Time("2016:001")
t.ut1

Versions

Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
astropy 6.0.0
Numpy 1.26.2
pyerfa 2.0.1.1
Scipy 1.11.4
Matplotlib 3.8.2

Activity

  1. github-actions commented on Feb 28, 2024

    @github-actions
    Contributor

    Welcome to Astropy 👋 and thank you for your first issue!

    A project member will respond to you as soon as possible; in the meantime, please double-check the guidelines for submitting issues and make sure you've provided the requested details.

    GitHub issues in the Astropy repository are used to track bug reports and feature requests; If your issue poses a question about how to use Astropy, please instead raise your question in the Astropy Discourse user forum and close this issue.

    If you feel that this issue has not been responded to in a timely manner, please send a message directly to the development mailing list. If the issue is urgent or sensitive in nature (e.g., a security vulnerability) please send an e-mail directly to the private e-mail [email protected].

  2. pllim commented on Feb 28, 2024

    @pllim
    Member

    Are you sure that is going to raise anything? I tried your code with latest dev version and there is not even a warning.

    We do test for the config behavior here and it seems to work both in CI and locally:

    # Default is to raise an error
    match = r"\(some\) times are outside of range covered by IERS table"
    with pytest.raises(iers.IERSRangeError, match=match):
    (now + 100 * u.day).ut1

  3. IlDordollano commented on Feb 29, 2024

    @IlDordollano
    Author

    Sorry, indeed my example was wrong. I need to post a more elaborate example, that gives only warning and does not stop. This is the case where internet is not enabled and times are outside of range covered by IERS table.

    import astropy.units as u
    import astropy
    
    astropy.utils.data.clear_download_cache()
    astropy.utils.data.conf.allow_internet = False
    astropy.utils.iers.conf.iers_degraded_accuracy = "error"
    
    time = Time("2024-02-29T17:53:03.605", format="isot", scale="utc")
    x = np.array([1, 0, 0])
    y = np.array([0, 1, 0])
    z = np.array([0, 0, 1])
    itrs = ITRS(CartesianRepresentation(x * u.m, y * u.m, z * u.m), obstime=time)
    gcrs = itrs.transform_to(GCRS(obstime=time))

    Running this example, I receive some warnings, but the execution doesn't stop and doesn't send any error for iers_degraded_accuracy:

    WARNING: IERSWarning: failed to download https://datacenter.iers.org/data/9/finals2000A.all: <urlopen error URL https://datacenter.iers.org/data/9/finals2000A.all was supposed to be downloaded but allow_internet is False; if this is unexpected check the astropy.cfg file for the option allow_internet> [astropy.utils.iers.iers]
    WARNING: IERSWarning: failed to download https://maia.usno.navy.mil/ser7/finals2000A.all: <urlopen error URL https://maia.usno.navy.mil/ser7/finals2000A.all was supposed to be downloaded but allow_internet is False; if this is unexpected check the astropy.cfg file for the option allow_internet> [astropy.utils.iers.iers]
    WARNING: IERSWarning: unable to download valid IERS file, using local IERS-B [astropy.utils.iers.iers]
    WARNING: Tried to get polar motions for times after IERS data is valid. Defaulting to polar motion from the 50-yr mean for those. This may affect precision at the arcsec level. Please check your astropy.utils.iers.conf.iers_auto_url and point it to a newer version if necessary. [astropy.coordinates.builtin_frames.utils]
    WARNING: (some) times are outside of range covered by IERS table. Cannot convert with full accuracy. To allow conversion with degraded accuracy set astropy.utils.iers.conf.iers_degraded_accuracy to "warn" or "silent". For more information about setting this configuration parameter or controlling its value globally, see the Astropy configuration system documentation https://docs.astropy.org/en/stable/config/index.html. Assuming UT1-UTC=0 for coordinate transformations. [astropy.coordinates.builtin_frames.utils]

  4. pllim commented on Feb 29, 2024

    @pllim
    Member

    Thank you very much for the complete example. Turns out the bug is in coordinates, not utils.iers. The warnings you see are coming from https://github.com/astropy/astropy/blob/main/astropy/coordinates/builtin_frames/utils.py that has custom code to bypass your configs. I am not sure if this is intentional or oversight.

    For example, in get_jd12 (but not the only place it happens):

    try:
    newtime = getattr(time, scale)
    except iers.IERSRangeError as e:
    _warn_iers(e)

    And this is where the "polar motion" one happens and it does not check for config at all:

    "Tried to get polar motions for times {} IERS data is "

    A quick git blame points to @maxnoe and @taldcroft for some of the designs, so hopefully they can clarify or ping those who can.

  5. changed the title [-]When iers_degraded_accuracy = error, Astropy reports a warning and not an error.[/-] [+]When iers_degraded_accuracy = error, Astropy reports a warning and not an error (in coordinates)[/+] on Feb 29, 2024
  6. maxnoe commented on Feb 29, 2024

    @maxnoe
    Member

    I am pretty sure that I didn't touch any code directly related to the warning / error handling there.

    Checking the blame, I just slightly changed the wording of the message there

  7. pllim commented on Feb 29, 2024

    @pllim
    Member

    I think @eteq is also in the blame somewhere. 😸

    Sorry for the noise, @maxnoe !

  8. maxnoe commented on Feb 29, 2024

    @maxnoe
    Member

    @pllim no problem at all, our software also runs in cluster environments so this issue is definitely relevant to us

  9. pllim commented on Feb 29, 2024

    @pllim
    Member

    In the meantime, for the affected use case, you would have to catch those warnings yourselves and promote them to error using https://docs.python.org/3/library/warnings.html

  10. IlDordollano commented on Feb 29, 2024

    @IlDordollano
    Author

    @pllim nice workaround thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions