Skip to content

Commit

Permalink
fix tests that rely on test layer with tile size 4
Browse files Browse the repository at this point in the history
The spec demands that TIFF tiles have a tile size that is a multiple of 16. We write GeoTIFFs
with a tile size that is equal to the TileLayerRDD's tile size so a tile size of 4 will produce GeoTiffs
that are not compliant. Some tools cope, like gdalinfo (with a warning), but some will simply fail,
like tiffset.

Open-EO/openeo-geotrellis-extensions#317
  • Loading branch information
bossie committed Sep 26, 2024
1 parent 272d1ff commit 81614a5
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 18 deletions.
19 changes: 9 additions & 10 deletions openeogeotrellis/collections/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ def dates_between(start: datetime, end: datetime) -> List[datetime]:


def load_test_collection(
collection_id: str,
collection_metadata: GeopysparkCubeMetadata,
extent, srs: str,
from_date: str, to_date: str,
bands=None,
correlation_id: str = "NA",
tile_size: int,
collection_metadata: GeopysparkCubeMetadata,
extent,
srs: str,
from_date: str,
to_date: str,
bands=None,
correlation_id: str = "NA",
) -> Dict[int, geopyspark.TiledRasterLayer]:
"""
Load synthetic data as test collection
:param collection_id:
:param tile_size:
:param collection_metadata:
:param extent:
:param srs:
Expand All @@ -45,10 +47,7 @@ def load_test_collection(
:param correlation_id:
:return:
"""
# TODO: support more test collections
assert collection_id == "TestCollection-LonLat4x4"
grid_size: float = 1.0
tile_size = 16

# TODO: support other srs'es?
assert srs == "EPSG:4326"
Expand Down
14 changes: 11 additions & 3 deletions openeogeotrellis/layercatalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,10 +689,18 @@ def file_agera5_pyramid():
elif layer_source_type == 'accumulo':
pyramid = accumulo_pyramid()
elif layer_source_type == 'testing':
import re

tile_cols, tile_rows = map(int, re.match(r".*?(\d+)x(\d+)", collection_id).groups())
assert tile_cols == tile_rows

pyramid = load_test_collection(
collection_id=collection_id, collection_metadata=metadata,
extent=extent, srs=srs,
from_date=from_date, to_date=to_date,
tile_size=tile_cols,
collection_metadata=metadata,
extent=extent,
srs=srs,
from_date=from_date,
to_date=to_date,
bands=bands,
correlation_id=correlation_id
)
Expand Down
2 changes: 1 addition & 1 deletion tests/data_collections/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_load_test_collection():

extent = get_jvm().geotrellis.vector.Extent(1.0, 2.0, 2.0, 4.0)
pyramid = load_test_collection(
collection_id="TestCollection-LonLat4x4",
tile_size=4,
collection_metadata=collection_metadata,
extent=extent,
srs="EPSG:4326",
Expand Down
63 changes: 61 additions & 2 deletions tests/layercatalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -908,12 +908,71 @@
"x": {
"type": "spatial",
"axis": "x",
"reference_system": {"$schema":"https://proj.org/schemas/v0.2/projjson.schema.json","type":"GeodeticCRS","name":"AUTO 42001 (Universal Transverse Mercator)","datum":{"type":"GeodeticReferenceFrame","name":"World Geodetic System 1984","ellipsoid":{"name":"WGS 84","semi_major_axis":6378137,"inverse_flattening":298.257223563}},"coordinate_system":{"subtype":"ellipsoidal","axis":[{"name":"Geodetic latitude","abbreviation":"Lat","direction":"north","unit":"degree"},{"name":"Geodetic longitude","abbreviation":"Lon","direction":"east","unit":"degree"}]},"area":"World","bbox":{"south_latitude":-90,"west_longitude":-180,"north_latitude":90,"east_longitude":180},"id":{"authority":"OGC","version":"1.3","code":"Auto42001"}}
"reference_system": 4326
},
"y": {
"type": "spatial",
"axis": "y",
"reference_system": {"$schema":"https://proj.org/schemas/v0.2/projjson.schema.json","type":"GeodeticCRS","name":"AUTO 42001 (Universal Transverse Mercator)","datum":{"type":"GeodeticReferenceFrame","name":"World Geodetic System 1984","ellipsoid":{"name":"WGS 84","semi_major_axis":6378137,"inverse_flattening":298.257223563}},"coordinate_system":{"subtype":"ellipsoidal","axis":[{"name":"Geodetic latitude","abbreviation":"Lat","direction":"north","unit":"degree"},{"name":"Geodetic longitude","abbreviation":"Lon","direction":"east","unit":"degree"}]},"area":"World","bbox":{"south_latitude":-90,"west_longitude":-180,"north_latitude":90,"east_longitude":180},"id":{"authority":"OGC","version":"1.3","code":"Auto42001"}}
"reference_system": 4326
},
"t": {
"type": "temporal"
},
"bands": {
"type": "bands",
"values": [
"Flat:0",
"Flat:1",
"Flat:2",
"TileCol",
"TileRow",
"TileColRow:10",
"Longitude",
"Latitude",
"Year",
"Month",
"Day"
]
}
},
"extent": {
"spatial": {
"bbox": [
[
-180,
-56,
180,
83
]
]
},
"temporal": {
"interval": [
[
"2000-01-01",
null
]
]
}
}
},
{
"id": "TestCollection-LonLat16x16",
"_vito": {
"data_source": {
"type": "testing"
}
},
"cube:dimensions": {
"x": {
"type": "spatial",
"axis": "x",
"reference_system": 4326
},
"y": {
"type": "spatial",
"axis": "y",
"reference_system": 4326
},
"t": {
"type": "temporal"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_batch_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -1333,13 +1333,13 @@ def test_geotiff_scale_offset(tmp_path):
# TODO: support asset_per_band/other flags?
# TODO: test sync requests as well

tmp_path = Path("/tmp/test_geotiff_scale_offset") # TODO: remove
# tmp_path = Path("/tmp/test_geotiff_scale_offset") # TODO: remove

process_graph = {
"loadcollection1": {
"process_id": "load_collection",
"arguments": {
"id": "TestCollection-LonLat4x4",
"id": "TestCollection-LonLat16x16",
"temporal_extent": ["2021-01-05", "2021-01-06"],
"spatial_extent": {"west": 0.0, "south": 50.0, "east": 5.0, "north": 55.0},
"bands": ["Flat:2"],
Expand Down

0 comments on commit 81614a5

Please sign in to comment.