Skip to content

Commit

Permalink
Add test with xgcm
Browse files Browse the repository at this point in the history
  • Loading branch information
jthielen committed Feb 15, 2022
1 parent e6e4f84 commit 8b02525
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions ci/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies:
- pytest-cov
- pytest-sugar
- xarray>=0.18,!=0.20.0,!=0.20.1
- xgcm
- pooch
- pip:
- -r ../requirements.txt
21 changes: 21 additions & 0 deletions tests/test_postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import xwrf

from . import importorskip


@pytest.fixture(scope='session', params=['dummy'])
def dummy_dataset(request):
Expand All @@ -14,6 +16,11 @@ def dummy_attrs_only_dataset(request):
return xwrf.tutorial.open_dataset(request.param)


@pytest.fixture(scope='session')
def test_grid(request):
return xwrf.tutorial.open_dataset(request.param)


@pytest.mark.parametrize('variable', ('Q2', 'PSFC'))
def test_cf_attrs_added(dummy_dataset, variable):
dataset = xwrf.postprocess._modify_attrs_to_cf(dummy_dataset)
Expand All @@ -36,6 +43,20 @@ def test_include_projection_coordinates(dummy_dataset):
assert dataset['Q2'].attrs['grid_mapping'] == 'wrf_projection'


@importorskip('xgcm')
@pytest.mark.parametrize('test_grid', ['lambert_conformal', 'mercator'], indirect=True)
def test_include_projection_coordinates_with_xgcm(test_grid):
from xgcm import Grid

dataset = xwrf.postprocess._include_projection_coordinates(test_grid)
grid = Grid(dataset)

assert grid.axes['Y'].coords['center'] == 'south_north'
assert grid.axes['Y'].coords['outer'] == 'south_north_stag'
assert grid.axes['X'].coords['center'] == 'west_east'
assert grid.axes['X'].coords['outer'] == 'west_east_stag'


def test_warning_on_projection_coordinate_failure(dummy_attrs_only_dataset):
with pytest.warns(UserWarning):
dataset = xwrf.postprocess._include_projection_coordinates(dummy_attrs_only_dataset)
Expand Down

0 comments on commit 8b02525

Please sign in to comment.