-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix the cell centers computation (#61)
* expose the grid info object * use the grid info methods to implement the reconstruction of cell ids * add a method to retrieve the cell centers using the accessor * forward to the grid object * remove the left-over conversion methods on the index base class * add a test to make sure the accessor returns the right cell centers * inverse the order of coordinates for H3 * fix the old `assign_latlon_coords` method * change the expectations in the h3 tests now we always expect longitude, then latitude as a tuple
- Loading branch information
Showing
5 changed files
with
160 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import pytest | ||
import xarray as xr | ||
|
||
import xdggs | ||
|
||
|
||
@pytest.mark.parametrize( | ||
["obj", "expected"], | ||
( | ||
( | ||
xr.DataArray( | ||
[0], | ||
coords={ | ||
"cell_ids": ( | ||
"cells", | ||
[3], | ||
{ | ||
"grid_name": "healpix", | ||
"resolution": 1, | ||
"indexing_scheme": "ring", | ||
}, | ||
) | ||
}, | ||
dims="cells", | ||
), | ||
xr.Dataset( | ||
coords={ | ||
"latitude": ("cells", [66.44353569089877]), | ||
"longitude": ("cells", [315.0]), | ||
} | ||
), | ||
), | ||
( | ||
xr.Dataset( | ||
coords={ | ||
"cell_ids": ( | ||
"cells", | ||
[0x832830FFFFFFFFF], | ||
{"grid_name": "h3", "resolution": 3}, | ||
) | ||
} | ||
), | ||
xr.Dataset( | ||
coords={ | ||
"latitude": ("cells", [38.19320895]), | ||
"longitude": ("cells", [-122.19619676]), | ||
} | ||
), | ||
), | ||
), | ||
) | ||
def test_cell_centers(obj, expected): | ||
obj_ = obj.pipe(xdggs.decode) | ||
|
||
actual = obj_.dggs.cell_centers() | ||
|
||
xr.testing.assert_allclose(actual, expected) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
["obj", "expected"], | ||
( | ||
( | ||
xr.DataArray( | ||
[0], | ||
coords={ | ||
"cell_ids": ( | ||
"cells", | ||
[3], | ||
{ | ||
"grid_name": "healpix", | ||
"resolution": 1, | ||
"indexing_scheme": "ring", | ||
}, | ||
) | ||
}, | ||
dims="cells", | ||
), | ||
xr.DataArray( | ||
[0], | ||
coords={ | ||
"latitude": ("cells", [66.44353569089877]), | ||
"longitude": ("cells", [315.0]), | ||
"cell_ids": ( | ||
"cells", | ||
[3], | ||
{ | ||
"grid_name": "healpix", | ||
"resolution": 1, | ||
"indexing_scheme": "ring", | ||
}, | ||
), | ||
}, | ||
dims="cells", | ||
), | ||
), | ||
( | ||
xr.Dataset( | ||
coords={ | ||
"cell_ids": ( | ||
"cells", | ||
[0x832830FFFFFFFFF], | ||
{"grid_name": "h3", "resolution": 3}, | ||
) | ||
} | ||
), | ||
xr.Dataset( | ||
coords={ | ||
"latitude": ("cells", [38.19320895]), | ||
"longitude": ("cells", [-122.19619676]), | ||
"cell_ids": ( | ||
"cells", | ||
[0x832830FFFFFFFFF], | ||
{"grid_name": "h3", "resolution": 3}, | ||
), | ||
} | ||
), | ||
), | ||
), | ||
) | ||
def test_assign_latlon_coords(obj, expected): | ||
obj_ = obj.pipe(xdggs.decode) | ||
|
||
actual = obj_.dggs.assign_latlon_coords() | ||
|
||
xr.testing.assert_allclose(actual, expected) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters