[AstroPy] How to disable astropy warnings (in particular IERS precision warnings)?

Evert Rol evert.rol at gmail.com
Wed Mar 16 01:09:32 EDT 2016


How do I disable (the logging of) astropy warnings?
From the astropy logging documentation, I thought that `log.disable_warnings_logging()` would do it, but it looks like it doesn't. Setting the log level to 'ERROR' doesn't do it either. See below. (I also find it a tad odd that I get warned twice about the same issue, though granted that they are not the same error message.)

I have managed to silence this, with the following construct:

import warnings
from astropy.utils.exceptions import AstropyWarning
with warnings.catch_warnings():
    warnings.simplefilter('ignore', category=AstropyWarning)
    <code that issues AstropyWarnings>

but that seems rather complex compared to a simple `log.disable_warnings_logging()` call.

What am I missing?

Thanks,

  Evert



Example that I thought should shut up the IERS warnings:

>>> from astropy import log
>>> from astropy.time import Time
>>> from astropy.coordinates import get_sun, EarthLocation, AltAz
>>> log.disable_warnings_logging()
>>> log.setLevel('ERROR')
>>> t = Time.now()
>>> frame = AltAz(obstime=t, location=EarthLocation(lon=0, lat=0, height=0))
>>> get_sun(t).transform_to(frame)
/usr/local/lib/python3.5/site-packages/astropy/coordinates/builtin_frames/utils.py:93: AstropyWarning: Tried to get polar motions for times after IERS data is valid. Defaulting to polar motion from the 50-yr mean for those.
If you need enough precision such that this matters (~<10 arcsec), you can
use the latest IERS predictions by running:

    >>> from astropy.utils import iers
    >>> iers.IERS.iers_table = iers.IERS_A.open(iers.IERS_A_URL)


  warnings.warn(wmsg, AstropyWarning)
/usr/local/lib/python3.5/site-packages/astropy/coordinates/builtin_frames/utils.py:107: AstropyWarning: (some) times are outside of range covered by IERS table. Assuming UT1-UTC=0 for coordinate transformations.
If you need enough precision such that this matters (~<10 arcsec), you can
use the latest IERS predictions by running:

    >>> from astropy.utils import iers
    >>> iers.IERS.iers_table = iers.IERS_A.open(iers.IERS_A_URL)


  warnings.warn(msg.format(ierserr.args[0], _IERS_HINT), AstropyWarning)
<SkyCoord (AltAz: obstime=2016-03-16 04:49:49.619741, location=(6378137.0, 0.0, 0.0) m, pressure=0.0 hPa, temperature=0.0 deg_C, relative_humidity=0, obswl=1.0 micron): (az, alt, distance) in (deg, deg, m)
    (91.26098425, -20.60224434, 148825375564.27697754)>
>>>


More information about the AstroPy mailing list