Skip to content
Snippets Groups Projects
Verified Commit 5e04660b authored by Philipp S. Sommer's avatar Philipp S. Sommer
Browse files

minor fix for selecting the level

parent a4dc57bd
No related branches found
No related tags found
No related merge requests found
Pipeline #344748 passed
......@@ -532,10 +532,14 @@ def select_level(level, ds, coord, dim):
selection = xr.apply_ufunc(np.fabs, coord - level).argmin(dim)
for da in arrays:
if selection.ndim:
selected = da[selection]
else:
selected = da.sel(**{dim: selection.values})
if da.name in ds.coords:
new_ds.coords[da.name] = da.isel(**{dim: selection.values})
new_ds.coords[da.name] = selected
else:
new_ds[da.name] = da.isel(**{dim: selection.values})
new_ds[da.name] = selected
remove_coordinates(da.attrs, [coord.name])
remove_coordinates(da.encoding, [coord.name])
new_ds.coords[coord.name] = ((), level, coord.attrs)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment