Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP use isel instead of drop #241

Merged
merged 3 commits into from
Nov 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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