Skip to content

Commit

Permalink
WIP use isel instead of drop (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
micahkim23 authored and Spencer Hill committed Nov 27, 2017
1 parent da18455 commit 7ef73e3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
4 changes: 0 additions & 4 deletions aospy/data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ def grid_attrs_to_aospy_names(data):
data_coord_name = set(names_ext).intersection(dims_and_vars)
if data_coord_name:
data = data.rename({data_coord_name.pop(): name_int})
# Unless a dim is scalar, force it to have a coord.
# Prevents headaches when subsequently sub-setting.
if name_int in data.dims and not data[name_int].coords:
data = data.assign_coords(**{name_int: data[name_int]})
return set_grid_attrs_as_coords(data, set_time_vars=False)


Expand Down
2 changes: 1 addition & 1 deletion aospy/test/test_data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_rename_grid_attrs_dim_no_coord(self):
ds = arr.rename({'dim_0': bounds_dim}).to_dataset()
assert not ds[bounds_dim].coords
result = grid_attrs_to_aospy_names(ds)
assert result[BOUNDS_STR].coords
assert not result[BOUNDS_STR].coords

def test_rename_grid_attrs_skip_scalar_dim(self):
phalf_dim = 'phalf'
Expand Down
10 changes: 6 additions & 4 deletions aospy/utils/times.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,12 @@ def ensure_time_avg_has_cf_metadata(ds):
time_weights = time_weights.rename(TIME_WEIGHTS_STR).squeeze()
ds[TIME_WEIGHTS_STR] = time_weights.drop(BOUNDS_STR)

avg_start_date = ds[TIME_BOUNDS_STR].isel(**{TIME_STR: 0, BOUNDS_STR: 0})
ds[RAW_START_DATE_STR] = avg_start_date.drop([TIME_STR, BOUNDS_STR])
avg_end_date = ds[TIME_BOUNDS_STR].isel(**{TIME_STR: -1, BOUNDS_STR: 1})
ds[RAW_END_DATE_STR] = avg_end_date.drop([TIME_STR, BOUNDS_STR])
ds[RAW_START_DATE_STR] = ds[TIME_BOUNDS_STR].isel(drop=True,
**{TIME_STR: 0,
BOUNDS_STR: 0})
ds[RAW_END_DATE_STR] = ds[TIME_BOUNDS_STR].isel(drop=True,
**{TIME_STR: -1,
BOUNDS_STR: 1})

for coord in [TIME_BOUNDS_STR, RAW_START_DATE_STR, RAW_END_DATE_STR]:
ds[coord].attrs['units'] = ds[TIME_STR].attrs['units']
Expand Down
3 changes: 3 additions & 0 deletions docs/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ Enhancements
- Remove potentially confusing attributes from example netcdf files.
(closes :issue:`214` via :pull:`216`). By `Micah Kim
<https://github.com/micahkim23>`_.
- Cleanup logic for Dataset drop on dimensions with and without
coords. Use Dataset isel instead. (closes :issue:`142` via
:pull:`241`). By `Micah Kim <https://github.com/micahkim23>`_.

Bug Fixes
~~~~~~~~~
Expand Down

0 comments on commit 7ef73e3

Please sign in to comment.