Skip to content

Commit

Permalink
Omit x, y coordinates, x & y bounds from conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Huite committed Feb 24, 2025
1 parent a7a9bd2 commit 6d30cde
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tests/test_ugrid_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ def test_from_bounds(self):
}
},
)
assert set(uds.data_vars) == {"a", "b", "c", "grid_x", "grid_y"}
assert set(uds.data_vars) == {"a", "b", "c"}
assert uds["a"].dims == ("layer", "mesh2d_nFaces")
assert uds["b"].dims == ("x",)
assert uds["c"].dims == ()
Expand Down
7 changes: 5 additions & 2 deletions xugrid/core/wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ def from_structured2d(

grids = []
dss = []
xy_vars = set() # store x, y, x_bounds, y_bounds to drop.
for name, args in topology.items():
x_bounds = None
y_bounds = None
Expand All @@ -594,6 +595,7 @@ def from_structured2d(
raise ValueError("x and y must be provided for bounds")
x_bounds = dataset[args["x_bounds"]]
y_bounds = dataset[args["y_bounds"]]
xy_vars.update((args["x_bounds"], args["y_bounds"]))
elif isinstance(args, tuple):
x, y = args
else:
Expand All @@ -619,10 +621,11 @@ def from_structured2d(
# Use subset to check that ALL dims of stackdims are present in the
# variable.
checkdims = set(stackdims)
xy_vars.update(checkdims)
ugrid_vars = [
name
for name, var in dataset.data_vars.items()
if checkdims.issubset(var.dims)
if checkdims.issubset(var.dims) and name not in xy_vars
]
dss.append(
dataset[ugrid_vars] # noqa: PD013
Expand All @@ -633,7 +636,7 @@ def from_structured2d(
grids.append(grid)

# Add the original dataset to include all non-UGRID variables.
dss.append(dataset)
dss.append(dataset.drop_vars(xy_vars, errors="ignore"))
# Then merge with compat="override". This'll pick the first available
# variable: i.e. it will prioritize the UGRID form.
merged = xr.merge(dss, compat="override")
Expand Down

0 comments on commit 6d30cde

Please sign in to comment.