Repository navigation
Expand file tree
/
Copy pathiers.py
More file actions
144 lines (120 loc) · 6.05 KB
/
Copy pathiers.py
File metadata and controls
144 lines (120 loc) · 6.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Licensed under a 3-clause BSD style license - see LICENSE.rst
# -*- coding: utf-8 -*-
"""
=============
desiutil.iers
=============
Utilities for overriding astropy IERS functionality (:mod:`astropy.utils.iers`),
especially for preventing unnecessary downloads of IERS data files in a
high performance computing environment.
The frozen files come from `astropy-iers-data 0.2023.6.15.21.10.12`_, which is
the very first version, and thus closest in time to the start of the DESI survey.
If even older files are desired, in principle, they could be derived from files
available in the `IERS archive`_. However, this could also require a considerable
investment of time.
.. _`astropy-iers-data 0.2023.6.15.21.10.12`: https://pypi.org/project/astropy-iers-data/0.2023.6.15.21.10.12/
.. _`IERS archive`: https://www.iers.org/IERS/EN/DataProducts/EarthOrientationData/eop
"""
import warnings
from importlib.resources import files
import astropy.utils.iers
from .log import get_logger
#
# Global flag for frozen state.
#
_iers_is_frozen = False
def freeze_iers(name='iers_frozen.ecsv', ignore_warnings=True):
"""Use a frozen IERS table saved with this package.
This should be called at the beginning of a script that calls
astropy time and coordinates functions which refer to the UT1-UTC
and polar motions tabulated by IERS. The purpose is to ensure
identical results across systems and astropy releases, to avoid a
potential network download, and to eliminate some astropy warnings.
After this call, all :mod:`astropy.utils.iers` functions will read
from frozen tables and updates will not be downloaded.
See https://docs.astropy.org/en/stable/utils/iers.html for details.
This function returns immediately after the first time it is called,
so it it safe to insert anywhere that consistent IERS models are
required, and subsequent calls with different arguments will have no
effect.
The :func:`desiutil.plots.plot_iers` function is useful for inspecting
IERS tables and how they are extrapolated to DESI survey dates.
Parameters
----------
name : :class:`str`, optional
This argument is ignored, but retained for backward-compatibility.
ignore_warnings : :class:`bool`, optional
Ignore ERFA and IERS warnings about future dates generated by
astropy time and coordinates functions. Specifically, ERFA warnings
containing the string "dubious year" are filtered out, as well
as AstropyWarnings related to IERS table extrapolation. Set this
to ``False`` to see the warnings.
Notes
-----
In detail this function performs these operations::
astropy.utils.iers.conf.auto_download = False
astropy.utils.iers.conf.auto_max_age = None
astropy.utils.iers.conf.iers_auto_url = 'frozen'
astropy.utils.iers.conf.iers_auto_url_mirror = 'frozen'
if ignore_warnings:
astropy.utils.iers.conf.iers_degraded_accuracy = 'ignore'
# Filter various warnings.
else:
astropy.utils.iers.conf.iers_degraded_accuracy = 'warn'
# DATA is internal to this package.
astropy.utils.iers.IERS_A_FILE = str(DATA / "finals2000A.all")
astropy.utils.iers.IERS_A_URL = "frozen"
astropy.utils.iers.IERS_A_URL_MIRROR = "frozen"
astropy.utils.iers.IERS_A_README = str(DATA / "ReadMe.finals2000A")
# Similar steps for IERS_B and Leap Second file.
"""
global _iers_is_frozen
log = get_logger()
if _iers_is_frozen:
log.debug('IERS table already frozen.')
return
log.info('Freezing IERS table used by astropy time, coordinates.')
# Prevent any attempts to automatically download updated IERS-A tables.
astropy.utils.iers.conf.auto_download = False
astropy.utils.iers.conf.auto_max_age = None
astropy.utils.iers.conf.iers_auto_url = 'frozen'
astropy.utils.iers.conf.iers_auto_url_mirror = 'frozen'
if ignore_warnings:
astropy.utils.iers.conf.iers_degraded_accuracy = 'ignore'
try:
warnings.filterwarnings('ignore',
category=astropy._erfa.core.ErfaWarning,
message=r'ERFA function \"[a-z0-9_]+\" yielded [0-9]+ of \"dubious year')
except AttributeError:
# Astropy >= 4.2
from erfa import ErfaWarning
warnings.filterwarnings('ignore',
category=ErfaWarning,
message=r'ERFA function \"[a-z0-9_]+\" yielded [0-9]+ of \"dubious year')
warnings.filterwarnings('ignore',
category=astropy.utils.exceptions.AstropyWarning,
message=r'Tried to get polar motions for times after IERS data')
warnings.filterwarnings('ignore',
category=astropy.utils.exceptions.AstropyWarning,
message=r'\(some\) times are outside of range covered by IERS')
else:
astropy.utils.iers.conf.iers_degraded_accuracy = 'warn'
#
# Redirect the table files to frozen copies internal to desiutil.
#
DATA = files('desiutil').joinpath('data')
# IERS-A default file name, URL, and ReadMe with content description
astropy.utils.iers.IERS_A_FILE = str(DATA / "finals2000A.all")
astropy.utils.iers.IERS_A_URL = "frozen"
astropy.utils.iers.IERS_A_URL_MIRROR = "frozen"
astropy.utils.iers.IERS_A_README = str(DATA / "ReadMe.finals2000A")
# IERS-B default file name, URL, and ReadMe with content description
astropy.utils.iers.IERS_B_FILE = str(DATA / "eopc04.1962-now")
astropy.utils.iers.IERS_B_URL = "frozen"
astropy.utils.iers.IERS_B_README = str(DATA / "ReadMe.eopc04")
# LEAP SECONDS default file name, URL, and alternative format/URL
astropy.utils.iers.IERS_LEAP_SECOND_FILE = str(DATA / "Leap_Second.dat")
astropy.utils.iers.IERS_LEAP_SECOND_URL = "frozen"
astropy.utils.iers.IERS_LEAP_SECOND_URL_MIRROR = "frozen"
# Shortcircuit any subsequent calls to this function.
_iers_is_frozen = True