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

Fix staggered coordinate destaggering for dataarray destagger method #101

Merged
merged 2 commits into from
Sep 16, 2022
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
15 changes: 15 additions & 0 deletions tests/test_accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@ def test_dataarray_destagger_with_exclude(test_grid):
assert 'XTIME' in destaggered.coords


@pytest.mark.parametrize('test_grid', ['lambert_conformal', 'mercator'], indirect=True)
def test_dataarray_destagger_with_postprocess(test_grid):
postprocessed = test_grid.xwrf.postprocess()
data = postprocessed['U']
destaggered = data.xwrf.destagger(exclude_staggered_auxiliary_coords=True)

# Check staggered to unstaggered dimension coordinate handling
xr.testing.assert_allclose(destaggered['x'], postprocessed['x'])

# Check attributes are preserved
assert set(destaggered.attrs.keys()) == set(data.attrs.keys()) - {
'stagger',
}


@pytest.mark.parametrize('test_grid', ['lambert_conformal', 'mercator'], indirect=True)
def test_dataset_destagger(test_grid):
destaggered = (
Expand Down
4 changes: 3 additions & 1 deletion xwrf/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ def destagger(
if not exclude_staggered_auxiliary_coords or new_name in new_variable.dims:
# Skip if excluding and this isn't a dimension coordinate of output
new_coords[new_name] = _destag_variable(
coord_data, stagger_dim=stagger_dim, unstag_dim_name=unstaggered_dim_name
coord_data.variable,
stagger_dim=stagger_dim,
unstag_dim_name=unstaggered_dim_name,
)
else:
new_coords[coord_name] = coord_data.variable
Expand Down