anemoi-datasets 0.5.18__py3-none-any.whl → 0.5.20__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- anemoi/datasets/_version.py +2 -2
- anemoi/datasets/commands/compare-lam.py +401 -0
- anemoi/datasets/commands/grib-index.py +114 -0
- anemoi/datasets/create/__init__.py +8 -1
- anemoi/datasets/create/config.py +5 -0
- anemoi/datasets/create/filters/pressure_level_relative_humidity_to_specific_humidity.py +3 -1
- anemoi/datasets/create/filters/pressure_level_specific_humidity_to_relative_humidity.py +3 -1
- anemoi/datasets/create/filters/transform.py +1 -3
- anemoi/datasets/create/filters/wz_to_w.py +3 -2
- anemoi/datasets/create/input/action.py +4 -1
- anemoi/datasets/create/input/function.py +5 -5
- anemoi/datasets/create/input/result.py +1 -1
- anemoi/datasets/create/sources/accumulations.py +13 -0
- anemoi/datasets/create/sources/accumulations2.py +652 -0
- anemoi/datasets/create/sources/anemoi_dataset.py +73 -0
- anemoi/datasets/create/sources/grib.py +7 -0
- anemoi/datasets/create/sources/grib_index.py +614 -0
- anemoi/datasets/create/sources/legacy.py +7 -2
- anemoi/datasets/create/sources/xarray_support/__init__.py +1 -1
- anemoi/datasets/create/sources/xarray_support/fieldlist.py +2 -2
- anemoi/datasets/create/sources/xarray_support/flavour.py +6 -0
- anemoi/datasets/create/sources/xarray_support/grid.py +15 -4
- anemoi/datasets/data/__init__.py +16 -0
- anemoi/datasets/data/complement.py +4 -1
- anemoi/datasets/data/dataset.py +14 -0
- anemoi/datasets/data/interpolate.py +76 -0
- anemoi/datasets/data/masked.py +77 -0
- anemoi/datasets/data/misc.py +159 -0
- anemoi/datasets/grids.py +8 -2
- {anemoi_datasets-0.5.18.dist-info → anemoi_datasets-0.5.20.dist-info}/METADATA +10 -4
- {anemoi_datasets-0.5.18.dist-info → anemoi_datasets-0.5.20.dist-info}/RECORD +35 -30
- {anemoi_datasets-0.5.18.dist-info → anemoi_datasets-0.5.20.dist-info}/WHEEL +1 -1
- {anemoi_datasets-0.5.18.dist-info → anemoi_datasets-0.5.20.dist-info}/entry_points.txt +0 -0
- {anemoi_datasets-0.5.18.dist-info → anemoi_datasets-0.5.20.dist-info}/licenses/LICENSE +0 -0
- {anemoi_datasets-0.5.18.dist-info → anemoi_datasets-0.5.20.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# (C) Copyright 2025 Anemoi contributors.
|
|
2
|
+
#
|
|
3
|
+
# This software is licensed under the terms of the Apache Licence Version 2.0
|
|
4
|
+
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
|
|
5
|
+
#
|
|
6
|
+
# In applying this licence, ECMWF does not waive the privileges and immunities
|
|
7
|
+
# granted to it by virtue of its status as an intergovernmental organisation
|
|
8
|
+
# nor does it submit to any jurisdiction.
|
|
9
|
+
|
|
10
|
+
import numpy as np
|
|
11
|
+
|
|
12
|
+
from .legacy import legacy_source
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@legacy_source(__file__)
|
|
16
|
+
def execute(context, dates, params=None, **kwargs):
|
|
17
|
+
import earthkit.data as ekd
|
|
18
|
+
|
|
19
|
+
from anemoi.datasets import open_dataset
|
|
20
|
+
|
|
21
|
+
ds = open_dataset(**kwargs)
|
|
22
|
+
# dates_to_index = {date: i for i, date in enumerate(ds.dates)}
|
|
23
|
+
|
|
24
|
+
indices = []
|
|
25
|
+
for date in dates:
|
|
26
|
+
idx = np.where(ds.dates == date)[0]
|
|
27
|
+
if len(idx) == 0:
|
|
28
|
+
continue
|
|
29
|
+
indices.append((int(idx[0]), date))
|
|
30
|
+
|
|
31
|
+
vars = ds.variables
|
|
32
|
+
if params is None:
|
|
33
|
+
params = vars
|
|
34
|
+
|
|
35
|
+
if not isinstance(params, (list, tuple, set)):
|
|
36
|
+
params = [params]
|
|
37
|
+
|
|
38
|
+
params = set(params)
|
|
39
|
+
results = []
|
|
40
|
+
|
|
41
|
+
ensemble = ds.shape[2] > 1
|
|
42
|
+
latitudes = ds.latitudes
|
|
43
|
+
longitudes = ds.longitudes
|
|
44
|
+
|
|
45
|
+
for idx, date in indices:
|
|
46
|
+
|
|
47
|
+
metadata = dict(valid_datetime=date, latitudes=latitudes, longitudes=longitudes)
|
|
48
|
+
|
|
49
|
+
for j, y in enumerate(ds[idx]):
|
|
50
|
+
|
|
51
|
+
param = vars[j]
|
|
52
|
+
if param not in params:
|
|
53
|
+
continue
|
|
54
|
+
|
|
55
|
+
# metadata['name'] = param
|
|
56
|
+
# metadata['param_level'] = param
|
|
57
|
+
metadata["param"] = param
|
|
58
|
+
|
|
59
|
+
for k, e in enumerate(y):
|
|
60
|
+
if ensemble:
|
|
61
|
+
metadata["number"] = k + 1
|
|
62
|
+
|
|
63
|
+
metadata["values"] = e
|
|
64
|
+
|
|
65
|
+
results.append(metadata.copy())
|
|
66
|
+
|
|
67
|
+
print(results[0].keys())
|
|
68
|
+
|
|
69
|
+
# "list-of-dicts" does support resolution
|
|
70
|
+
results = ekd.from_source("list-of-dicts", results)
|
|
71
|
+
|
|
72
|
+
# return new_fieldlist_from_list([new_field_from_latitudes_longitudes(x, latitudes, longitudes) for x in results])
|
|
73
|
+
return results
|
|
@@ -17,6 +17,7 @@ from typing import Optional
|
|
|
17
17
|
from typing import Union
|
|
18
18
|
|
|
19
19
|
import earthkit.data as ekd
|
|
20
|
+
from anemoi.transform.flavour import RuleBasedFlavour
|
|
20
21
|
from earthkit.data import from_source
|
|
21
22
|
from earthkit.data.indexing.fieldlist import FieldArray
|
|
22
23
|
from earthkit.data.utils.patterns import Pattern
|
|
@@ -244,6 +245,7 @@ def execute(
|
|
|
244
245
|
path: Union[str, List[str]],
|
|
245
246
|
latitudes: Optional[Dict[str, Any]] = None,
|
|
246
247
|
longitudes: Optional[Dict[str, Any]] = None,
|
|
248
|
+
flavour: Optional[Union[str, Dict[str, Any]]] = None,
|
|
247
249
|
*args: Any,
|
|
248
250
|
**kwargs: Any,
|
|
249
251
|
) -> ekd.FieldList:
|
|
@@ -255,6 +257,7 @@ def execute(
|
|
|
255
257
|
path (Union[str, List[str]]): Path or list of paths to the GRIB files.
|
|
256
258
|
latitudes (Optional[Dict[str, Any]], optional): Latitude information. Defaults to None.
|
|
257
259
|
longitudes (Optional[Dict[str, Any]], optional): Longitude information. Defaults to None.
|
|
260
|
+
flavour (Optional[Union[str, Dict[str, Any]]], optional): Flavour information. Defaults to None.
|
|
258
261
|
*args (Any): Additional arguments.
|
|
259
262
|
**kwargs (Any): Additional keyword arguments.
|
|
260
263
|
|
|
@@ -264,6 +267,8 @@ def execute(
|
|
|
264
267
|
The loaded dataset.
|
|
265
268
|
"""
|
|
266
269
|
given_paths = path if isinstance(path, list) else [path]
|
|
270
|
+
if flavour is not None:
|
|
271
|
+
flavour = RuleBasedFlavour(flavour)
|
|
267
272
|
|
|
268
273
|
geography = None
|
|
269
274
|
if latitudes is not None and longitudes is not None:
|
|
@@ -282,6 +287,8 @@ def execute(
|
|
|
282
287
|
for path in _expand(paths):
|
|
283
288
|
context.trace("📁", "PATH", path)
|
|
284
289
|
s = from_source("file", path)
|
|
290
|
+
if flavour is not None:
|
|
291
|
+
s = flavour.map(s)
|
|
285
292
|
s = s.sel(valid_datetime=dates, **kwargs)
|
|
286
293
|
ds = ds + s
|
|
287
294
|
|