Skip to content

Commit

Permalink
Fixes preserving coordinates in regrid2 output
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonb5 committed Nov 20, 2024
1 parent 1cfd369 commit 2ab5cc4
Showing 1 changed file with 15 additions and 2 deletions.
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 @@ def _build_dataset(
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

0 comments on commit 2ab5cc4

Please sign in to comment.