-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy path__init__.py
More file actions
376 lines (299 loc) · 9.81 KB
/
Copy path__init__.py
File metadata and controls
376 lines (299 loc) · 9.81 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
"""The Python `cf` package is an Earth Science data analysis library
that is built on a complete implementation of the CF data model.
The `cf` package implements the CF data model for its internal data
structures and so is able to process any CF-compliant dataset. It is
not strict about CF-compliance, however, so that partially conformant
datasets may be ingested from existing datasets and written to new
datasets. This is so that datasets which are partially conformant may
nonetheless be modified in memory.
The `cf` package uses `dask` for all of its array manipulation and
can:
* read field constructs from netCDF, CDL, PP and UM datasets,
* read field constructs and domain constructs from netCDF, CDL, PP and
UM datasets with a choice of netCDF backends,
* read files from OPeNDAP servers and S3 object stores,
* create new field constructs in memory,
* write and append field constructs to netCDF datasets on disk,
* read, write, and manipulate UGRID mesh topologies,
* read, write, and create coordinates defined by geometry cells,
* read netCDF and CDL datasets containing hierarchical groups,
* inspect field constructs,
* test whether two field constructs are the same,
* modify field construct metadata and data,
* create subspaces of field constructs,
* write field constructs to netCDF datasets on disk,
* incorporate, and create, metadata stored in external files,
* read, write, and create data that have been compressed by convention
(i.e. ragged or gathered arrays, or coordinate arrays compressed by
subsampling), whilst presenting a view of the data in its
uncompressed form,
* combine field constructs arithmetically,
* manipulate field construct data by arithmetical and trigonometrical
operations,
* perform statistical collapses on field constructs,
* perform histogram, percentile and binning operations on field
constructs,
* regrid field constructs with (multi-)linear, nearest neighbour,
first- and second-order conservative and higher order patch recovery
methods,
* apply convolution filters to field constructs,
* create running means from field constructs,
* apply differential operators to field constructs,
* create derived quantities (such as relative vorticity).
**Visualisation**
Powerful, flexible, and very simple to produce visualisations of field
constructs uses the `cfplot` package
(http://ajheaps.github.io/cf-plot), that is automatically installed
along with with `cf`.
See the :ref:`cf-python home page <cf-python-home>` for documentation,
installation and source code.
"""
__Conventions__ = "CF-1.11"
__date__ = "2024-??-??"
__version__ = "3.17.0"
_requires = (
"numpy",
"netCDF4",
"cftime",
"cfunits",
"cfdm",
"psutil",
"dask",
"packaging",
"scipy",
)
x = ", ".join(_requires)
_error0 = f"cf v{__version__} requires the modules {x}. "
try:
import cfdm
except ImportError as error1:
raise ImportError(_error0 + str(error1))
__cf_version__ = cfdm.core.__cf_version__
__cfa_version__ = "0.6.2"
from packaging.version import Version
import importlib.util
import platform
# ESMF renamed its Python module to `esmpy` at ESMF version 8.4.0. Allow
# either for now for backwards compatibility.
_found_esmpy = bool(
importlib.util.find_spec("esmpy") or importlib.util.find_spec("ESMF")
)
try:
import netCDF4
except ImportError as error1:
raise ImportError(_error0 + str(error1))
try:
import numpy
except ImportError as error1:
raise ImportError(_error0 + str(error1))
try:
import cftime
except ImportError as error1:
raise ImportError(_error0 + str(error1))
try:
import cfunits
except ImportError as error1:
raise ImportError(_error0 + str(error1))
try:
import psutil
except ImportError as error1:
raise ImportError(_error0 + str(error1))
try:
import dask
except ImportError as error1:
raise ImportError(_error0 + str(error1))
try:
import packaging
except ImportError as error1:
raise ImportError(_error0 + str(error1))
try:
import scipy
except ImportError as error1:
raise ImportError(_error0 + str(error1))
# Check the version of packaging
_minimum_vn = "20.0"
if Version(packaging.__version__) < Version(_minimum_vn):
raise RuntimeError(
f"Bad packaging version: cf requires packaging>={_minimum_vn}. "
f"Got {packaging.__version__} at {packaging.__file__}"
)
# Check the version of psutil
_minimum_vn = "0.6.0"
if Version(psutil.__version__) < Version(_minimum_vn):
raise RuntimeError(
f"Bad psutil version: cf requires psutil>={_minimum_vn}. "
f"Got {psutil.__version__} at {psutil.__file__}"
)
# Check the version of netCDF4
_minimum_vn = "1.6.5"
if Version(netCDF4.__version__) < Version(_minimum_vn):
raise RuntimeError(
f"Bad netCDF4 version: cf requires netCDF4>={_minimum_vn}. "
f"Got {netCDF4.__version__} at {netCDF4.__file__}"
)
# Check the version of cftime
_minimum_vn = "1.6.2"
if Version(cftime.__version__) < Version(_minimum_vn):
raise RuntimeError(
f"Bad cftime version: cf requires cftime>={_minimum_vn}. "
f"Got {cftime.__version__} at {cftime.__file__}"
)
# Check the version of numpy
_minimum_vn = "1.22"
if Version(numpy.__version__) < Version(_minimum_vn):
raise RuntimeError(
f"Bad numpy version: cf requires numpy>={_minimum_vn}. "
f"Got {numpy.__version__} at {numpy.__file__}"
)
# Check the version of cfunits
_minimum_vn = "3.3.7"
if Version(cfunits.__version__) < Version(_minimum_vn):
raise RuntimeError(
f"Bad cfunits version: cf requires cfunits>={_minimum_vn}. "
f"Got {cfunits.__version__} at {cfunits.__file__}"
)
# Check the version of cfdm
_minimum_vn = "1.11.2.0"
_maximum_vn = "1.11.3.0"
_cfdm_version = Version(cfdm.__version__)
if not Version(_minimum_vn) <= _cfdm_version < Version(_maximum_vn):
raise RuntimeError(
f"Bad cfdm version: cf requires {_minimum_vn}<=cfdm<{_maximum_vn}. "
f"Got {_cfdm_version} at {cfdm.__file__}"
)
# Check the version of dask
# Check the version of Python
_minimum_vn = "3.8.0"
if Version(platform.python_version()) < Version(_minimum_vn):
raise ValueError(
f"Bad python version: cf requires python version {_minimum_vn} "
f"or later. Got {platform.python_version()}"
)
# Check the version of scipy
_minimum_vn = "1.10.0"
if Version(scipy.__version__) < Version(_minimum_vn):
raise RuntimeError(
f"Bad scipy version: cf requires scipy>={_minimum_vn}. "
f"Got {scipy.__version__} at {scipy.__file__}"
)
from .constructs import Constructs
from .mixin import Coordinate
from .count import Count
from .index import Index
from .interpolationparameter import InterpolationParameter
from .list import List
from .nodecountproperties import NodeCountProperties
from .partnodecountproperties import PartNodeCountProperties
from .interiorring import InteriorRing
from .tiepointindex import TiePointIndex
from .bounds import Bounds
from .domain import Domain
from .datum import Datum
from .coordinateconversion import CoordinateConversion
from .cfdatetime import dt, dt_vector
from .flags import Flags
from .timeduration import TimeDuration, Y, M, D, h, m, s
from .units import Units
from .constructlist import ConstructList
from .fieldlist import FieldList
from .domainlist import DomainList
from .dimensioncoordinate import DimensionCoordinate
from .auxiliarycoordinate import AuxiliaryCoordinate
from .coordinatereference import CoordinateReference
from .cellconnectivity import CellConnectivity
from .cellmethod import CellMethod
from .cellmeasure import CellMeasure
from .domainancillary import DomainAncillary
from .domainaxis import DomainAxis
from .domaintopology import DomainTopology
from .fieldancillary import FieldAncillary
from .field import Field
from .data import Data
from .data.array import (
BoundsFromNodesArray,
CellConnectivityArray,
CFAH5netcdfArray,
CFANetCDF4Array,
FullArray,
GatheredArray,
H5netcdfArray,
NetCDFArray,
NetCDF4Array,
PointTopologyArray,
RaggedContiguousArray,
RaggedIndexedArray,
RaggedIndexedContiguousArray,
SubsampledArray,
UMArray,
)
from .data.fragment import (
FullFragmentArray,
NetCDFFragmentArray,
UMFragmentArray,
)
from .aggregate import aggregate, climatology_cells
from .query import (
Query,
lt,
le,
gt,
ge,
eq,
ne,
isclose,
contain,
contains,
wi,
wo,
set,
year,
month,
day,
hour,
minute,
second,
dtlt,
dtle,
dtgt,
dtge,
dteq,
dtne,
cellsize,
cellge,
cellgt,
cellle,
celllt,
cell_overlaps,
cellwi,
cellwo,
djf,
mam,
jja,
son,
seasons,
)
from .constants import * # noqa: F403
from .functions import * # noqa: F403
from .maths import curl_xy, div_xy, relative_vorticity, histogram
from .examplefield import example_field, example_fields, example_domain
from .cfimplementation import CFImplementation, implementation
from .read_write import read, write
from .regrid import RegridOperator
# Set up basic logging for the full project with a root logger
import logging
import sys
# Configure the root logger which all module loggers inherit from:
logging.basicConfig(
stream=sys.stdout,
style="{", # default is old style ('%') string formatting
format="{message}", # no module names or datetimes etc. for basic case
level=logging.WARNING, # default but change level via log_level()
)
# And create custom level inbetween 'INFO' & 'DEBUG', to understand value see:
# https://docs.python.org/3.8/howto/logging.html#logging-levels
logging.DETAIL = 15 # set value as an attribute as done for built-in levels
logging.addLevelName(logging.DETAIL, "DETAIL")
def detail(self, message, *args, **kwargs):
if self.isEnabledFor(logging.DETAIL):
self._log(logging.DETAIL, message, args, **kwargs)
logging.Logger.detail = detail