anemoi-datasets 0.5.24__py3-none-any.whl → 0.5.26__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.
Files changed (58) hide show
  1. anemoi/datasets/_version.py +2 -2
  2. anemoi/datasets/commands/finalise-additions.py +2 -1
  3. anemoi/datasets/commands/finalise.py +2 -1
  4. anemoi/datasets/commands/grib-index.py +1 -1
  5. anemoi/datasets/commands/init-additions.py +2 -1
  6. anemoi/datasets/commands/load-additions.py +2 -1
  7. anemoi/datasets/commands/load.py +2 -1
  8. anemoi/datasets/create/__init__.py +24 -33
  9. anemoi/datasets/create/filter.py +22 -24
  10. anemoi/datasets/create/input/__init__.py +0 -20
  11. anemoi/datasets/create/input/step.py +2 -16
  12. anemoi/datasets/create/sources/accumulations.py +7 -6
  13. anemoi/datasets/create/sources/planetary_computer.py +44 -0
  14. anemoi/datasets/create/sources/xarray_support/__init__.py +6 -22
  15. anemoi/datasets/create/sources/xarray_support/coordinates.py +8 -0
  16. anemoi/datasets/create/sources/xarray_support/field.py +1 -4
  17. anemoi/datasets/create/sources/xarray_support/flavour.py +44 -6
  18. anemoi/datasets/create/sources/xarray_support/patch.py +44 -1
  19. anemoi/datasets/create/sources/xarray_support/variable.py +6 -2
  20. anemoi/datasets/data/complement.py +44 -10
  21. anemoi/datasets/data/dataset.py +29 -0
  22. anemoi/datasets/data/forwards.py +8 -2
  23. anemoi/datasets/data/misc.py +74 -16
  24. anemoi/datasets/data/observations/__init__.py +316 -0
  25. anemoi/datasets/data/observations/legacy_obs_dataset.py +200 -0
  26. anemoi/datasets/data/observations/multi.py +64 -0
  27. anemoi/datasets/data/padded.py +227 -0
  28. anemoi/datasets/data/records/__init__.py +442 -0
  29. anemoi/datasets/data/records/backends/__init__.py +157 -0
  30. anemoi/datasets/data/stores.py +7 -56
  31. anemoi/datasets/data/subset.py +5 -0
  32. anemoi/datasets/grids.py +6 -3
  33. {anemoi_datasets-0.5.24.dist-info → anemoi_datasets-0.5.26.dist-info}/METADATA +3 -2
  34. {anemoi_datasets-0.5.24.dist-info → anemoi_datasets-0.5.26.dist-info}/RECORD +38 -51
  35. {anemoi_datasets-0.5.24.dist-info → anemoi_datasets-0.5.26.dist-info}/WHEEL +1 -1
  36. anemoi/datasets/create/filters/__init__.py +0 -33
  37. anemoi/datasets/create/filters/empty.py +0 -37
  38. anemoi/datasets/create/filters/legacy.py +0 -93
  39. anemoi/datasets/create/filters/noop.py +0 -37
  40. anemoi/datasets/create/filters/orog_to_z.py +0 -58
  41. anemoi/datasets/create/filters/pressure_level_relative_humidity_to_specific_humidity.py +0 -83
  42. anemoi/datasets/create/filters/pressure_level_specific_humidity_to_relative_humidity.py +0 -84
  43. anemoi/datasets/create/filters/rename.py +0 -205
  44. anemoi/datasets/create/filters/rotate_winds.py +0 -105
  45. anemoi/datasets/create/filters/single_level_dewpoint_to_relative_humidity.py +0 -78
  46. anemoi/datasets/create/filters/single_level_relative_humidity_to_dewpoint.py +0 -84
  47. anemoi/datasets/create/filters/single_level_relative_humidity_to_specific_humidity.py +0 -163
  48. anemoi/datasets/create/filters/single_level_specific_humidity_to_relative_humidity.py +0 -451
  49. anemoi/datasets/create/filters/speeddir_to_uv.py +0 -95
  50. anemoi/datasets/create/filters/sum.py +0 -68
  51. anemoi/datasets/create/filters/transform.py +0 -51
  52. anemoi/datasets/create/filters/unrotate_winds.py +0 -105
  53. anemoi/datasets/create/filters/uv_to_speeddir.py +0 -94
  54. anemoi/datasets/create/filters/wz_to_w.py +0 -98
  55. anemoi/datasets/create/testing.py +0 -76
  56. {anemoi_datasets-0.5.24.dist-info → anemoi_datasets-0.5.26.dist-info}/entry_points.txt +0 -0
  57. {anemoi_datasets-0.5.24.dist-info → anemoi_datasets-0.5.26.dist-info}/licenses/LICENSE +0 -0
  58. {anemoi_datasets-0.5.24.dist-info → anemoi_datasets-0.5.26.dist-info}/top_level.txt +0 -0
@@ -1,78 +0,0 @@
1
- # (C) Copyright 2024 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
-
11
- from collections import defaultdict
12
- from typing import Any
13
- from typing import Dict
14
-
15
- import earthkit.data as ekd
16
- from anemoi.transform.fields import new_field_from_numpy
17
- from anemoi.transform.fields import new_fieldlist_from_list
18
- from earthkit.meteo import thermo
19
-
20
- from .legacy import legacy_filter
21
-
22
-
23
- @legacy_filter(__file__)
24
- def execute(context: Any, input: ekd.FieldList, t: str, td: str, rh: str = "d") -> ekd.FieldList:
25
- """Convert dewpoint on single levels to relative humidity.
26
-
27
- Parameters
28
- ----------
29
- context : Any
30
- The context in which the function is executed.
31
- input : List[Any]
32
- List of input fields.
33
- t : str
34
- Temperature parameter.
35
- td : str
36
- Dewpoint parameter.
37
- rh : str, optional
38
- Relative humidity parameter. Defaults to "d".
39
-
40
- Returns
41
- -------
42
- ekd.FieldList
43
- Array of fields with relative humidity.
44
- """
45
- result = []
46
- params: tuple[str, str] = (t, td)
47
- pairs: Dict[tuple, Dict[str, Any]] = defaultdict(dict)
48
-
49
- # Gather all necessary fields
50
- for f in input:
51
- key = f.metadata(namespace="mars")
52
- param = key.pop("param")
53
- if param in params:
54
- key = tuple(key.items())
55
-
56
- if param in pairs[key]:
57
- raise ValueError(f"Duplicate field {param} for {key}")
58
-
59
- pairs[key][param] = f
60
- if param == t:
61
- result.append(f)
62
- # all other parameters
63
- else:
64
- result.append(f)
65
-
66
- for keys, values in pairs.items():
67
- # some checks
68
-
69
- if len(values) != 2:
70
- raise ValueError("Missing fields")
71
-
72
- t_values = values[t].to_numpy(flatten=True)
73
- td_values = values[td].to_numpy(flatten=True)
74
- # actual conversion from td --> rh
75
- rh_values = thermo.relative_humidity_from_dewpoint(t=t_values, td=td_values)
76
- result.append(new_field_from_numpy(values[td], rh_values, param=rh))
77
-
78
- return new_fieldlist_from_list(result)
@@ -1,84 +0,0 @@
1
- # (C) Copyright 2024 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
- from collections import defaultdict
11
- from typing import Any
12
- from typing import Dict
13
- from typing import Tuple
14
-
15
- import earthkit.data as ekd
16
- from anemoi.transform.fields import new_field_from_numpy
17
- from anemoi.transform.fields import new_fieldlist_from_list
18
- from earthkit.data.indexing.fieldlist import FieldArray
19
- from earthkit.meteo import thermo
20
-
21
- from .legacy import legacy_filter
22
-
23
- EPS = 1.0e-4
24
-
25
-
26
- @legacy_filter(__file__)
27
- def execute(context: Any, input: ekd.FieldList, t: str, rh: str, td: str = "d") -> FieldArray:
28
- """Convert relative humidity on single levels to dewpoint.
29
-
30
- Parameters
31
- ----------
32
- context : Any
33
- The context in which the function is executed.
34
- input : List[Any]
35
- List of input fields.
36
- t : str
37
- Temperature parameter.
38
- rh : str
39
- Relative humidity parameter.
40
- td : str, optional
41
- Dewpoint parameter. Defaults to "d".
42
-
43
- Returns
44
- -------
45
- FieldArray
46
- Array of fields with dewpoint.
47
- """
48
- result = []
49
- params: Tuple[str, str] = (t, rh)
50
- pairs: Dict[Tuple[Any, ...], Dict[str, Any]] = defaultdict(dict)
51
-
52
- # Gather all necessary fields
53
- for f in input:
54
- key = f.metadata(namespace="mars")
55
- param = key.pop("param")
56
- if param in params:
57
- key = tuple(key.items())
58
-
59
- if param in pairs[key]:
60
- raise ValueError(f"Duplicate field {param} for {key}")
61
-
62
- pairs[key][param] = f
63
- if param == t:
64
- result.append(f)
65
- # all other parameters
66
- else:
67
- result.append(f)
68
-
69
- for keys, values in pairs.items():
70
- # some checks
71
-
72
- if len(values) != 2:
73
- raise ValueError("Missing fields")
74
-
75
- t_values = values[t].to_numpy(flatten=True)
76
- rh_values = values[rh].to_numpy(flatten=True)
77
- # Prevent 0 % Relative humidity which cannot be converted to dewpoint
78
- # Seems to happen over Egypt in the CERRA dataset
79
- rh_values[rh_values == 0] = EPS
80
- # actual conversion from rh --> td
81
- td_values = thermo.dewpoint_from_relative_humidity(t=t_values, r=rh_values)
82
- result.append(new_field_from_numpy(values[rh], td_values, param=td))
83
-
84
- return new_fieldlist_from_list(result)
@@ -1,163 +0,0 @@
1
- # (C) Copyright 2024 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
-
11
- from typing import Any
12
- from typing import Dict
13
- from typing import List
14
-
15
- import earthkit.data as ekd
16
- import numpy as np
17
- from anemoi.transform.fields import new_field_from_numpy
18
- from anemoi.transform.fields import new_fieldlist_from_list
19
- from earthkit.meteo import thermo
20
-
21
- from .legacy import legacy_filter
22
- from .single_level_specific_humidity_to_relative_humidity import AutoDict
23
- from .single_level_specific_humidity_to_relative_humidity import pressure_at_height_level
24
-
25
-
26
- @legacy_filter(__file__)
27
- def execute(
28
- context: Any,
29
- input: List[Any],
30
- height: float,
31
- t: str,
32
- rh: str,
33
- sp: str,
34
- new_name: str = "2q",
35
- **kwargs: Dict[str, Any],
36
- ) -> ekd.FieldList:
37
- """Convert the single (height) level relative humidity to specific humidity.
38
-
39
- Parameters
40
- ----------
41
- context : Any
42
- The context in which the function is executed.
43
- input : List[Any]
44
- List of input fields.
45
- height : float
46
- The height level.
47
- t : str
48
- Temperature parameter name.
49
- rh : str
50
- Relative humidity parameter name.
51
- sp : str
52
- Surface pressure parameter name.
53
- new_name : str, optional
54
- The new name for the specific humidity field, by default "2q".
55
- **kwargs : Dict[str, Any]
56
- Additional keyword arguments.
57
-
58
- Returns
59
- -------
60
- ekd.FieldList
61
- The resulting field list with specific humidity fields.
62
-
63
- Raises
64
- ------
65
- KeyError
66
- If mandatory keys are missing.
67
- ValueError
68
- If there are duplicate fields or missing fields.
69
- """
70
- result = []
71
-
72
- MANDATORY_KEYS = ["A", "B"]
73
- OPTIONAL_KEYS = ["t_ml", "q_ml"]
74
- MISSING_KEYS = []
75
- DEFAULTS = dict(t_ml="t", q_ml="q")
76
-
77
- for key in OPTIONAL_KEYS:
78
- if key not in kwargs:
79
- print(f"key {key} not found in yaml-file, using default key: {DEFAULTS[key]}")
80
- kwargs[key] = DEFAULTS[key]
81
-
82
- for key in MANDATORY_KEYS:
83
- if key not in kwargs:
84
- MISSING_KEYS.append(key)
85
-
86
- if MISSING_KEYS:
87
- raise KeyError(f"Following keys are missing: {', '.join(MISSING_KEYS)}")
88
-
89
- single_level_params = (t, rh, sp)
90
- model_level_params = (kwargs["t_ml"], kwargs["q_ml"])
91
-
92
- needed_fields = AutoDict()
93
-
94
- # Gather all necessary fields
95
- for f in input:
96
- key = f.metadata(namespace="mars")
97
- param = key.pop("param")
98
- # check single level parameters
99
- if param in single_level_params:
100
- levtype = key.pop("levtype")
101
- key = tuple(key.items())
102
-
103
- if param in needed_fields[key][levtype]:
104
- raise ValueError(f"Duplicate single level field {param} for {key}")
105
-
106
- needed_fields[key][levtype][param] = f
107
- if param == rh:
108
- if kwargs.get("keep_rh", False):
109
- result.append(f)
110
- else:
111
- result.append(f)
112
-
113
- # check model level parameters
114
- elif param in model_level_params:
115
- levtype = key.pop("levtype")
116
- levelist = key.pop("levelist")
117
- key = tuple(key.items())
118
-
119
- if param in needed_fields[key][levtype][levelist]:
120
- raise ValueError(f"Duplicate model level field {param} for {key} at level {levelist}")
121
-
122
- needed_fields[key][levtype][levelist][param] = f
123
-
124
- # all other parameters
125
- else:
126
- result.append(f)
127
-
128
- for _, values in needed_fields.items():
129
- # some checks
130
- if len(values["sfc"]) != 3:
131
- raise ValueError("Missing surface fields")
132
-
133
- rh_sl = values["sfc"][rh].to_numpy(flatten=True)
134
- t_sl = values["sfc"][t].to_numpy(flatten=True)
135
- sp_sl = values["sfc"][sp].to_numpy(flatten=True)
136
-
137
- nlevels = len(kwargs["A"]) - 1
138
- if len(values["ml"]) != nlevels:
139
- raise ValueError("Missing model levels")
140
-
141
- for key in values["ml"].keys():
142
- if len(values["ml"][key]) != 2:
143
- raise ValueError(f"Missing field on level {key}")
144
-
145
- # create 3D arrays for upper air fields
146
- levels = list(values["ml"].keys())
147
- levels.sort()
148
- t_ml = []
149
- q_ml = []
150
- for level in levels:
151
- t_ml.append(values["ml"][level][kwargs["t_ml"]].to_numpy(flatten=True))
152
- q_ml.append(values["ml"][level][kwargs["q_ml"]].to_numpy(flatten=True))
153
-
154
- t_ml = np.stack(t_ml)
155
- q_ml = np.stack(q_ml)
156
-
157
- # actual conversion from rh --> q_v
158
- p_sl = pressure_at_height_level(height, q_ml, t_ml, sp_sl, np.array(kwargs["A"]), np.array(kwargs["B"]))
159
- q_sl = thermo.specific_humidity_from_relative_humidity(t_sl, rh_sl, p_sl)
160
-
161
- result.append(new_field_from_numpy(values["sfc"][rh], q_sl, param=new_name))
162
-
163
- return new_fieldlist_from_list(result)