Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes preserving coordinates in regrid2 #716

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions xcdat/regridder/regrid2.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,24 @@
output_coords: dict[str, xr.DataArray] = {}
output_data_vars: dict[str, xr.DataArray] = {}

dims = list(input_data_var.dims)
for dim in input_data_var.dims:
dim = str(dim)

try:
axis_name = [x for x, y in ds.cf.axes.items() if dim in y][0]
except Exception:
raise ValueError(

Check warning on line 247 in xcdat/regridder/regrid2.py

View check run for this annotation

Codecov / codecov/patch

xcdat/regridder/regrid2.py#L246-L247

Added lines #L246 - L247 were not covered by tests
f"Could not determine axis name for dimension {dim}"
) from None

if axis_name in ["X", "Y"]:
output_coords[dim] = output_grid.cf[axis_name]
else:
output_coords[dim] = input_data_var.cf[axis_name]

output_da = xr.DataArray(
output_data,
dims=dims,
dims=input_data_var.dims,
coords=output_coords,
attrs=ds[data_var].attrs.copy(),
name=data_var,
Expand Down
Loading