Skip to content

Commit e067a6c

Browse files
jasonb5tomvothecoder
authored andcommitted
Fixes preserving coordinates in regrid2 output
1 parent 27396e5 commit e067a6c

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

xcdat/regridder/regrid2.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,24 @@ def _build_dataset(
238238
output_coords: dict[str, xr.DataArray] = {}
239239
output_data_vars: dict[str, xr.DataArray] = {}
240240

241-
dims = list(input_data_var.dims)
241+
for dim in input_data_var.dims:
242+
dim = str(dim)
243+
244+
try:
245+
axis_name = [x for x, y in ds.cf.axes.items() if dim in y][0]
246+
except Exception:
247+
raise ValueError(
248+
f"Could not determine axis name for dimension {dim}"
249+
) from None
250+
251+
if axis_name in ["X", "Y"]:
252+
output_coords[dim] = output_grid.cf[axis_name]
253+
else:
254+
output_coords[dim] = input_data_var.cf[axis_name]
242255

243256
output_da = xr.DataArray(
244257
output_data,
245-
dims=dims,
258+
dims=input_data_var.dims,
246259
coords=output_coords,
247260
attrs=ds[data_var].attrs.copy(),
248261
name=data_var,

0 commit comments

Comments
 (0)