Skip to content

Commit 5f2973f

Browse files
authored
fix: xarray-zarr filters (#457)
## Description The PR solves an issue where filters didn't work with xarray-zarr sources ## What problem does this change solve? This is a bugfix for two issues: - In `XArrayField.to_numpy()` with `flatten=True`, the output is `values.values.flatten()` but for `flatten=False` the output is only `values` where it should be `values.values` to actually get the numpy array. - XArrayMetadata contains both 'variable' and 'param' so grouping by the metadata doesn't work because GroupByParam._get_groups only takes param into account by popping it and looking at the remaining metadata. If the remaining metadata matches then the params are grouped together. This doesn't work when variable is also there, because now the remaining metadata doesn't match ## What issue or task does this change relate to? #456 ## Additional notes ## ***As a contributor to the Anemoi framework, please ensure that your changes include unit tests, updates to any affected dependencies and documentation, and have been tested in a parallel setting (i.e., with multiple GPUs). As a reviewer, you are also responsible for verifying these aspects and requesting changes if they are not adequately addressed. For guidelines about those please refer to https://anemoi.readthedocs.io/en/latest/*** By opening this pull request, I affirm that all authors agree to the [Contributor License Agreement.](https://github.com/ecmwf/codex/blob/main/Legal/contributor_license_agreement.md)
1 parent 2d810e3 commit 5f2973f

File tree

1 file changed

+4
-4
lines changed
  • src/anemoi/datasets/create/sources/xarray_support

1 file changed

+4
-4
lines changed

src/anemoi/datasets/create/sources/xarray_support/field.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,16 @@ def to_numpy(self, flatten: bool = False, dtype: type | None = None, index: int
121121
Index to select a specific element, by default None.
122122
"""
123123
if index is not None:
124-
values = self.selection[index]
124+
values = self.selection[index].values
125125
else:
126-
values = self.selection
126+
values = self.selection.values
127127

128128
assert dtype is None
129129

130130
if flatten:
131-
return values.values.flatten()
131+
return values.flatten()
132132

133-
return values # .reshape(self.shape)
133+
return values
134134

135135
@cached_property
136136
def _metadata(self) -> XArrayMetadata:

0 commit comments

Comments
 (0)