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

TST: add test for merging and clipping tiffs to desired bbox #24

Merged
merged 1 commit into from
Feb 18, 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
16 changes: 16 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,19 @@ def geojson_bbox():
]
],
}


@pytest.fixture
def geojson_bbox_two_stac_items():
yield {
"type": "Polygon",
"coordinates": [
[
[8.631413, 41.318388],
[8.631413, 41.762435],
[9.685828, 41.762435],
[9.685828, 41.318388],
[8.631413, 41.318388],
]
],
}
30 changes: 29 additions & 1 deletion tests/test_mapa.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import math

from mapa import convert_bbox_to_stl
import rasterio as rio

from mapa import _fetch_merge_and_clip_tiffs, _get_tiff_for_bbox, convert_bbox_to_stl
from mapa.caching import get_hash_of_geojson
from mapa.stac import _turn_geojson_into_bbox
from mapa.stl_file import get_dimensions_of_stl_file
from mapa.utils import _path_to_clipped_tiff, _path_to_merged_tiff


def test_create_stl_for_bbox__success(output_file, geojson_bbox) -> None:
Expand Down Expand Up @@ -94,3 +99,26 @@ def test_convert_bbox_to_stl__verify_x_y_dimensions(output_file) -> None:
assert x == 2 * y == 200
# z dimension should stay the same
assert z1 == z2


def test__get_tiff_for_bbox(geojson_bbox) -> None:
tiff = _get_tiff_for_bbox(geojson_bbox, allow_caching=True)
assert tiff.is_file()


def test__fetch_merge_and_clip_tiffs(geojson_bbox_two_stac_items) -> None:
bbox_hash = get_hash_of_geojson(geojson_bbox_two_stac_items)
assert isinstance(bbox_hash, str)
tiff = _fetch_merge_and_clip_tiffs(geojson_bbox_two_stac_items, bbox_hash, allow_caching=True)
assert tiff.is_file()
assert _path_to_merged_tiff(bbox_hash).is_file()
assert _path_to_clipped_tiff(bbox_hash).is_file()

# verify coordinates of resulting tiff is in line with the coordinates of the input bbox
bbox = _turn_geojson_into_bbox(geojson_bbox_two_stac_items)
left, bottom, right, top = bbox[0], bbox[1], bbox[2], bbox[3]
data = rio.open(tiff)
assert math.isclose(data.bounds.left, left, rel_tol=0.0001)
assert math.isclose(data.bounds.bottom, bottom, rel_tol=0.0001)
assert math.isclose(data.bounds.right, right, rel_tol=0.0001)
assert math.isclose(data.bounds.top, top, rel_tol=0.0001)