Skip to content

Commit bf75cc7

Browse files
committed
Add coordinate attrs back in for the interp based methods
1 parent 6cba003 commit bf75cc7

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/xarray_regrid/methods/conservative.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ def conservative_regrid_dataset(
7777
latitude_coord: str,
7878
) -> xr.Dataset:
7979
"""Dataset implementation of the conservative regridding method."""
80-
data_vars: list[str] = list(data.data_vars)
81-
data_coords: list[str] = list(data.coords)
80+
data_vars = list(data.data_vars)
81+
data_coords = list(data.coords)
8282
dataarrays = [data[var] for var in data_vars]
8383

8484
attrs = data.attrs
@@ -122,7 +122,7 @@ def conservative_regrid_dataarray(
122122
latitude_coord: str,
123123
) -> xr.DataArray:
124124
"""DataArray implementation of the conservative regridding method."""
125-
data_coords: list[str] = list(data.coords)
125+
data_coords = list(data.coords)
126126

127127
attrs = data.attrs
128128
coord_attrs = [data[coord].attrs for coord in data_coords]

src/xarray_regrid/methods/interp.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,15 @@ def interp_regrid(
3939
"""
4040
coord_names = set(target_ds.coords).intersection(set(data.coords))
4141
coords = {name: target_ds[name] for name in coord_names}
42+
coord_attrs = {coord: data[coord].attrs for coord in coord_names}
4243

43-
return data.interp(
44+
interped = data.interp(
4445
coords=coords,
4546
method=method,
4647
)
48+
49+
# xarray's interp drops some of the coordinate's attributes (e.g. long_name)
50+
for coord in coord_names:
51+
interped[coord].attrs = coord_attrs[coord]
52+
53+
return interped

0 commit comments

Comments
 (0)