File tree Expand file tree Collapse file tree 2 files changed +11
-4
lines changed
src/xarray_regrid/methods Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Original file line number Diff line number Diff 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 ]
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments