Skip to content

Commit

Permalink
del bounds attr from coord in drop_attributes() (#733)
Browse files Browse the repository at this point in the history
* del bounds attr from coord in drop_attributes()

* add TODO statement
  • Loading branch information
jtmims authored Jan 17, 2025
1 parent a45d2bd commit 3895cc9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,9 +849,14 @@ def drop_attributes(self, xr_ds: xr.Dataset) -> xr.Dataset:
'average_T1',
'height',
'date']
# TODO: find a suitable answer to conflicts in xarray merging (i.e. nctoolkit)
for att in drop_atts:
if xr_ds.get(att, None) is not None:
xr_ds = xr_ds.drop_vars(att)
for coord in xr_ds.coords:
if 'bounds' in xr_ds[coord].attrs:
if xr_ds[coord].attrs['bounds'] == att:
del xr_ds[coord].attrs['bounds']
return xr_ds

def check_multichunk(self, group_df: pd.DataFrame, case_dr, log) -> pd.DataFrame:
Expand Down
2 changes: 1 addition & 1 deletion src/xr_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ def reconcile_coord_bounds(self, our_coord, ds, ds_coord_name):
expectations based on the model's convention (*our_var*), for the bounds
on the dimension coordinate *our_coord*.
"""
if len(ds.cf.bounds) > 0:
if len(ds.cf.bounds.get(ds_coord_name, [])) > 0:
bounds = ds.cf.get_bounds(ds_coord_name)
elif hasattr(ds[ds_coord_name], 'attrs'):
if ds[ds_coord_name].attrs.get('bounds', None):
Expand Down

0 comments on commit 3895cc9

Please sign in to comment.