-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
167 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# pylint: disable=missing-function-docstring,missing-module-docstring,too-many-statements | ||
from __future__ import annotations | ||
|
||
from datetime import datetime | ||
from types import SimpleNamespace as _sn | ||
from typing import Dict, Mapping, Sequence | ||
|
||
import pytest | ||
from odc.geo.geobox import GeoBox | ||
|
||
from ._builder import mk_dataset | ||
from .types import FixedCoord, RasterLoadParams | ||
|
||
time = [datetime(2020, 1, 1)] | ||
gbox = GeoBox.from_bbox((-180, -90, 180, 90), shape=(160, 320), tight=True) | ||
shape = (len(time), *gbox.shape.yx) | ||
dims = ("time", *gbox.dimensions) | ||
|
||
_rlp = RasterLoadParams | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"bands,extra_coords,extra_dims,expect", | ||
[ | ||
[ | ||
{"a": _rlp("uint8")}, | ||
None, | ||
None, | ||
{"a": _sn(dims=dims, shape=shape)}, | ||
], | ||
[ | ||
{"a": _rlp("uint8", dims=("y", "x", "B"))}, | ||
[FixedCoord("B", ["r", "g", "b"])], | ||
None, | ||
{"a": _sn(dims=(*dims, "B"), shape=(*shape, 3))}, | ||
], | ||
[ | ||
{"a": _rlp("uint8", dims=("y", "x", "W"))}, | ||
[FixedCoord("W", ["r", "g", "b", "a"])], | ||
{"b": 4}, | ||
{"a": _sn(dims=(*dims, "W"), shape=(*shape, 4))}, | ||
], | ||
], | ||
) | ||
def test_mk_dataset( | ||
bands: Dict[str, RasterLoadParams], | ||
extra_coords: Sequence[FixedCoord] | None, | ||
extra_dims: Mapping[str, int] | None, | ||
expect: Mapping[str, _sn], | ||
): | ||
assert gbox.crs == "EPSG:4326" | ||
xx = mk_dataset( | ||
gbox, | ||
time, | ||
bands=bands, | ||
extra_coords=extra_coords, | ||
extra_dims=extra_dims, | ||
) | ||
assert xx is not None | ||
|
||
for n, e in expect.items(): | ||
assert n in xx.data_vars | ||
v = xx[n] | ||
assert v.dims == e.dims | ||
assert v.shape == e.shape | ||
|
||
if extra_coords is not None: | ||
for c in extra_coords: | ||
assert c.name in xx.coords | ||
assert xx.coords[c.name].shape == (len(c.values),) |
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