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,93 +0,0 @@
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
-
11
- import inspect
12
- import logging
13
- import os
14
- from typing import Any
15
- from typing import Callable
16
-
17
- from ..filter import Filter
18
- from . import filter_registry
19
-
20
- LOG = logging.getLogger(__name__)
21
-
22
-
23
- class LegacyFilter(Filter):
24
- """A legacy filter class.
25
-
26
- Parameters
27
- ----------
28
- context : Any
29
- The context in which the filter is created.
30
- *args : tuple
31
- Positional arguments.
32
- **kwargs : dict
33
- Keyword arguments.
34
- """
35
-
36
- def __init__(self, context: Any, *args: Any, **kwargs: Any) -> None:
37
- super().__init__(context, *args, **kwargs)
38
- self.args = args
39
- self.kwargs = kwargs
40
-
41
-
42
- class legacy_filter:
43
- """A decorator class for legacy filters.
44
-
45
- Parameters
46
- ----------
47
- name : str
48
- The name of the legacy filter.
49
- """
50
-
51
- def __init__(self, name: str) -> None:
52
- name, _ = os.path.splitext(os.path.basename(name))
53
- self.name = name
54
-
55
- def __call__(self, execute: Callable) -> Callable:
56
- """Call method to wrap the execute function.
57
-
58
- Parameters
59
- ----------
60
- execute : Callable
61
- The execute function to be wrapped.
62
-
63
- Returns
64
- -------
65
- Callable
66
- The wrapped execute function.
67
- """
68
- this = self
69
- name = f"Legacy{self.name.title()}Filter"
70
- source = ".".join([execute.__module__, execute.__name__])
71
-
72
- def execute_wrapper(self, input) -> Any:
73
- """Wrapper method to call the execute function."""
74
- try:
75
- return execute(self.context, input, *self.args, **self.kwargs)
76
- except TypeError:
77
- LOG.error(f"Error executing filter {this.name} from {source}")
78
- LOG.error(f"Function signature is: {inspect.signature(execute)}")
79
- LOG.error(f"Arguments are: {self.args=}, {self.kwargs=}")
80
- raise
81
-
82
- klass = type(
83
- name,
84
- (LegacyFilter,),
85
- {
86
- "execute": execute_wrapper,
87
- "_source": source,
88
- },
89
- )
90
-
91
- filter_registry.register(self.name)(klass)
92
-
93
- return execute
@@ -1,37 +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 typing import Any
11
-
12
- import earthkit.data as ekd
13
-
14
- from .legacy import legacy_filter
15
-
16
-
17
- @legacy_filter(__file__)
18
- def execute(context: Any, input: ekd.FieldList, *args: Any, **kwargs: Any) -> ekd.FieldList:
19
- """No operation filter that returns the input as is.
20
-
21
- Parameters
22
- ----------
23
- context : Any
24
- The context in which the function is executed.
25
- input : ekd.FieldList
26
- List of input fields.
27
- *args : Any
28
- Additional arguments.
29
- **kwargs : Any
30
- Additional keyword arguments.
31
-
32
- Returns
33
- -------
34
- List[Any]
35
- The input list of fields.
36
- """
37
- return input
@@ -1,58 +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
-
14
- import earthkit.data as ekd
15
- from anemoi.transform.fields import new_field_from_numpy
16
- from anemoi.transform.fields import new_fieldlist_from_list
17
-
18
- from .legacy import legacy_filter
19
-
20
-
21
- @legacy_filter(__file__)
22
- def execute(context: Any, input: ekd.FieldList, orog: str, z: str = "z") -> ekd.FieldList:
23
- """Convert orography [m] to z (geopotential height).
24
-
25
- Parameters
26
- ----------
27
- context : Any
28
- The context in which the function is executed.
29
- input : FieldList
30
- List of input fields.
31
- orog : str
32
- Orography parameter.
33
- z : str, optional
34
- Geopotential height parameter. Defaults to "z".
35
-
36
- Returns
37
- -------
38
- FieldList
39
- List of fields with geopotential height.
40
- """
41
- result = []
42
- processed_fields: Dict[tuple, Dict[str, Any]] = defaultdict(dict)
43
-
44
- for f in input:
45
- key = f.metadata(namespace="mars")
46
- param = key.pop("param")
47
- if param == orog:
48
- key = tuple(key.items())
49
-
50
- if param in processed_fields[key]:
51
- raise ValueError(f"Duplicate field {param} for {key}")
52
-
53
- output = f.to_numpy(flatten=True) * 9.80665
54
- result.append(new_field_from_numpy(f, output, param=z))
55
- else:
56
- result.append(f)
57
-
58
- return new_fieldlist_from_list(result)
@@ -1,83 +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.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, rh: str, q: str = "q") -> ekd.FieldList:
25
- """Convert relative humidity on pressure levels to specific 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
- rh : str
36
- Relative humidity parameter.
37
- q : str, optional
38
- Specific humidity parameter. Defaults to "q".
39
-
40
- Returns
41
- -------
42
- ekd.FieldList
43
- Array of fields with specific humidity.
44
- """
45
- result = []
46
- params: Tuple[str, str] = (t, rh)
47
- pairs: Dict[Tuple[Any, ...], 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_pl = values[t].to_numpy(flatten=True)
73
- rh_pl = values[rh].to_numpy(flatten=True)
74
- pressure = next(
75
- float(v) * 100 for k, v in keys if k in ["level", "levelist"]
76
- ) # Looks first for "level" then "levelist" value
77
- # print(f"Handling fields for pressure level {pressure}...")
78
-
79
- # actual conversion from rh --> q_v
80
- q_pl = thermo.specific_humidity_from_relative_humidity(t_pl, rh_pl, pressure)
81
- result.append(new_field_from_numpy(values[rh], q_pl, param=q))
82
-
83
- 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
-
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.data.indexing.fieldlist import FieldArray
19
- from earthkit.meteo import thermo
20
-
21
- from .legacy import legacy_filter
22
-
23
-
24
- @legacy_filter(__file__)
25
- def execute(context: Any, input: ekd.FieldList, t: str, q: str, rh: str = "r") -> FieldArray:
26
- """Convert specific humidity on pressure levels to relative humidity.
27
-
28
- Parameters
29
- ----------
30
- context : Any
31
- The context in which the function is executed.
32
- input : List[Any]
33
- List of input fields.
34
- t : str
35
- Temperature parameter.
36
- q : str
37
- Specific humidity parameter.
38
- rh : str, optional
39
- Relative humidity parameter. Defaults to "r".
40
-
41
- Returns
42
- -------
43
- ekd.FieldList
44
- Array of fields with relative humidity.
45
- """
46
- result = []
47
- params: tuple[str, str] = (t, q)
48
- pairs: Dict[tuple, Dict[str, Any]] = defaultdict(dict)
49
-
50
- # Gather all necessary fields
51
- for f in input:
52
- key = f.metadata(namespace="mars")
53
- param = key.pop("param")
54
- if param in params:
55
- key = tuple(key.items())
56
-
57
- if param in pairs[key]:
58
- raise ValueError(f"Duplicate field {param} for {key}")
59
-
60
- pairs[key][param] = f
61
- if param == t:
62
- result.append(f)
63
- # all other parameters
64
- else:
65
- result.append(f)
66
-
67
- for keys, values in pairs.items():
68
- # some checks
69
-
70
- if len(values) != 2:
71
- raise ValueError("Missing fields")
72
-
73
- t_pl = values[t].to_numpy(flatten=True)
74
- q_pl = values[q].to_numpy(flatten=True)
75
- pressure = next(
76
- float(v) * 100 for k, v in keys if k in ["level", "levelist"]
77
- ) # Looks first for "level" then "levelist" value
78
- # print(f"Handling fields for pressure level {pressure}...")
79
-
80
- # actual conversion from rh --> q_v
81
- rh_pl = thermo.relative_humidity_from_specific_humidity(t_pl, q_pl, pressure)
82
- result.append(new_field_from_numpy(values[q], rh_pl, param=rh))
83
-
84
- return new_fieldlist_from_list(result)
@@ -1,205 +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
- import re
11
- from typing import Any
12
- from typing import Dict
13
- from typing import Optional
14
-
15
- import earthkit.data as ekd
16
- from earthkit.data.indexing.fieldlist import FieldArray
17
-
18
- from .legacy import legacy_filter
19
-
20
-
21
- class RenamedFieldMapping:
22
- """Rename a field based on the value of another field.
23
-
24
- Parameters
25
- ----------
26
- field : Any
27
- The field to be renamed.
28
- what : str
29
- The name of the field that will be used to rename the field.
30
- renaming : dict of dict of str
31
- A dictionary mapping the values of 'what' to the new names.
32
- """
33
-
34
- def __init__(self, field: Any, what: str, renaming: Dict[str, Dict[str, str]]) -> None:
35
- """Initialize a RenamedFieldMapping instance.
36
-
37
- Parameters
38
- ----------
39
- field : Any
40
- The field to be renamed.
41
- what : str
42
- The name of the field that will be used to rename the field.
43
- renaming : dict of dict of str
44
- A dictionary mapping the values of 'what' to the new names.
45
- """
46
- self.field = field
47
- self.what = what
48
- self.renaming = {}
49
- for k, v in renaming.items():
50
- self.renaming[k] = {str(a): str(b) for a, b in v.items()}
51
-
52
- def metadata(self, key: Optional[str] = None, **kwargs: Any) -> Any:
53
- """Get metadata from the original field, with the option to rename the parameter.
54
-
55
- Parameters
56
- ----------
57
- key : str, optional
58
- The metadata key.
59
- **kwargs : Any
60
- Additional keyword arguments.
61
-
62
- Returns
63
- -------
64
- Any
65
- The metadata value.
66
- """
67
- if key is None:
68
- return self.field.metadata(**kwargs)
69
-
70
- value = self.field.metadata(key, **kwargs)
71
- if key == self.what:
72
- return self.renaming.get(self.what, {}).get(value, value)
73
-
74
- return value
75
-
76
- def __getattr__(self, name: str) -> Any:
77
- """Get an attribute from the original field.
78
-
79
- Parameters
80
- ----------
81
- name : str
82
- The name of the attribute.
83
-
84
- Returns
85
- -------
86
- Any
87
- The attribute value.
88
- """
89
- return getattr(self.field, name)
90
-
91
- def __repr__(self) -> str:
92
- """Get the string representation of the original field.
93
-
94
- Returns
95
- -------
96
- str
97
- The string representation of the original field.
98
- """
99
- return repr(self.field)
100
-
101
-
102
- class RenamedFieldFormat:
103
- """Rename a field based on a format string.
104
-
105
- Parameters
106
- ----------
107
- field : Any
108
- The field to be renamed.
109
- what : str
110
- The name of the field that will be used to rename the field.
111
- format : str
112
- The format string for renaming.
113
- """
114
-
115
- def __init__(self, field: Any, what: str, format: str) -> None:
116
- """Initialize a RenamedFieldFormat instance.
117
-
118
- Parameters
119
- ----------
120
- field : Any
121
- The field to be renamed.
122
- what : str
123
- The name of the field that will be used to rename the field.
124
- format : str
125
- The format string for renaming.
126
- """
127
- self.field = field
128
- self.what = what
129
- self.format = format
130
- self.bits = re.findall(r"{(\w+)}", format)
131
-
132
- def metadata(self, *args: Any, **kwargs: Any) -> Any:
133
- """Get metadata from the original field, with the option to rename the parameter using a format string.
134
-
135
- Parameters
136
- ----------
137
- *args : Any
138
- Positional arguments.
139
- **kwargs : Any
140
- Additional keyword arguments.
141
-
142
- Returns
143
- -------
144
- Any
145
- The metadata value.
146
- """
147
- value = self.field.metadata(*args, **kwargs)
148
- if args:
149
- assert len(args) == 1
150
- if args[0] == self.what:
151
- bits = {b: self.field.metadata(b, **kwargs) for b in self.bits}
152
- return self.format.format(**bits)
153
- return value
154
-
155
- def __getattr__(self, name: str) -> Any:
156
- """Get an attribute from the original field.
157
-
158
- Parameters
159
- ----------
160
- name : str
161
- The name of the attribute.
162
-
163
- Returns
164
- -------
165
- Any
166
- The attribute value.
167
- """
168
- return getattr(self.field, name)
169
-
170
- def __repr__(self) -> str:
171
- """Get the string representation of the original field.
172
-
173
- Returns
174
- -------
175
- str
176
- The string representation of the original field.
177
- """
178
- return repr(self.field)
179
-
180
-
181
- @legacy_filter(__file__)
182
- def execute(context: Any, input: ekd.FieldList, what: str = "param", **kwargs: Any) -> ekd.FieldList:
183
- """Rename fields based on the value of another field or a format string.
184
-
185
- Parameters
186
- ----------
187
- context : Any
188
- The context in which the function is executed.
189
- input : List[Any]
190
- List of input fields.
191
- what : str, optional
192
- The field to be used for renaming. Defaults to "param".
193
- **kwargs : Any
194
- Additional keyword arguments for renaming.
195
-
196
- Returns
197
- -------
198
- ekd.FieldList
199
- Array of renamed fields.
200
- """
201
-
202
- if what in kwargs and isinstance(kwargs[what], str):
203
- return FieldArray([RenamedFieldFormat(fs, what, kwargs[what]) for fs in input])
204
-
205
- return FieldArray([RenamedFieldMapping(fs, what, kwargs) for fs in input])
@@ -1,105 +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
- from typing import Optional
15
-
16
- import earthkit.data as ekd
17
- import tqdm
18
- from anemoi.transform.fields import new_field_from_numpy
19
- from anemoi.transform.fields import new_fieldlist_from_list
20
- from anemoi.utils.humanize import plural
21
- from earthkit.geo.rotate import rotate_vector
22
-
23
- from .legacy import legacy_filter
24
-
25
-
26
- @legacy_filter(__file__)
27
- def execute(
28
- context: Any,
29
- input: ekd.FieldList,
30
- x_wind: str,
31
- y_wind: str,
32
- source_projection: Optional[str] = None,
33
- target_projection: str = "+proj=longlat",
34
- ) -> ekd.FieldList:
35
- """Rotate wind components from one projection to another.
36
-
37
- Parameters
38
- ----------
39
- context : Any
40
- The context in which the function is executed.
41
- input : ekd.FieldList
42
- List of input fields.
43
- x_wind : str
44
- X wind component parameter.
45
- y_wind : str
46
- Y wind component parameter.
47
- source_projection : Optional[str], optional
48
- Source projection, by default None.
49
- target_projection : str, optional
50
- Target projection, by default "+proj=longlat".
51
-
52
- Returns
53
- -------
54
- ekd.FieldList
55
- Array of fields with rotated wind components.
56
- """
57
- from pyproj import CRS
58
-
59
- context.trace("🔄", "Rotating winds (extracting winds from ", plural(len(input), "field"))
60
-
61
- result = []
62
-
63
- wind_params: tuple[str, str] = (x_wind, y_wind)
64
- wind_pairs: Dict[tuple, Dict[str, Any]] = defaultdict(dict)
65
-
66
- for f in input:
67
- key = f.metadata(namespace="mars")
68
- param = key.pop("param")
69
-
70
- if param not in wind_params:
71
- result.append(f)
72
- continue
73
-
74
- key = tuple(key.items())
75
-
76
- if param in wind_pairs[key]:
77
- raise ValueError(f"Duplicate wind component {param} for {key}")
78
-
79
- wind_pairs[key][param] = f
80
-
81
- context.trace("🔄", "Rotating", plural(len(wind_pairs), "wind"), "(speed will likely include data download)")
82
-
83
- for _, pairs in tqdm.tqdm(list(wind_pairs.items())):
84
- if len(pairs) != 2:
85
- raise ValueError("Missing wind component")
86
-
87
- x = pairs[x_wind]
88
- y = pairs[y_wind]
89
-
90
- assert x.grid_mapping == y.grid_mapping
91
-
92
- lats, lons = x.grid_points()
93
- x_new, y_new = rotate_vector(
94
- lats,
95
- lons,
96
- x.to_numpy(flatten=True),
97
- y.to_numpy(flatten=True),
98
- (source_projection if source_projection is not None else CRS.from_cf(x.grid_mapping)),
99
- target_projection,
100
- )
101
-
102
- result.append(new_field_from_numpy(x, x_new))
103
- result.append(new_field_from_numpy(y, y_new))
104
-
105
- return new_fieldlist_from_list(result)