Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago committed Oct 11, 2024
1 parent fe62d47 commit 81538fb
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ def test_tile_matrix_set(tileset):
assert repr(ts)


@pytest.mark.parametrize("tileset", tilesets)
def test_geographic_crs_bbox(tileset):
"""check that geographic bounds are correct."""
with open(tileset, "r") as f:
ts = TileMatrixSet.model_validate_json(f.read())

if not pyproj.CRS.from_epsg(4326) == ts.geographic_crs:
_to_geographic = pyproj.Transformer.from_crs(
ts.crs._pyproj_crs, pyproj.CRS.from_epsg(4326), always_xy=True
)
bbox = _to_geographic.transform_bounds(*ts.xy_bbox, densify_pts=21)
assert bbox == ts.bbox


def test_tile_matrix_iter():
"""Test iterator"""
tms = morecantile.tms.get("WebMercatorQuad")
Expand Down Expand Up @@ -312,13 +326,12 @@ def test_schema():
assert json_doc["crs"] == "http://www.opengis.net/def/crs/EPSG/0/3031"


MARS2000_SPHERE = pyproj.CRS.from_proj4("+proj=longlat +R=3396190 +no_defs")


def test_mars_tms():
"""The Mars global mercator scheme should broadly align with the Earth
Web Mercator CRS, despite the different planetary radius and scale.
"""
MARS2000_SPHERE = pyproj.CRS.from_proj4("+proj=longlat +R=3396190 +no_defs")

MARS_MERCATOR = pyproj.CRS.from_proj4(
"+proj=merc +R=3396190 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +no_defs"
)
Expand All @@ -335,6 +348,7 @@ def test_mars_tms():
extent_crs=MARS2000_SPHERE,
title="Web Mercator Mars",
)
assert mars_tms.geographic_crs

pos = (35, 40, 3)
mars_tile = mars_tms.tile(*pos)
Expand All @@ -345,9 +359,17 @@ def test_mars_tms():
assert mars_tile.y == earth_tile.y
assert mars_tile.z == earth_tile.z == 3

_to_geographic = pyproj.Transformer.from_crs(
mars_tms.crs._pyproj_crs, MARS2000_SPHERE, always_xy=True
)
bbox = _to_geographic.transform_bounds(*mars_tms.xy_bbox, densify_pts=21)
assert bbox == mars_tms.bbox


def test_mars_local_tms():
"""Local TMS using Mars CRS"""
MARS2000_SPHERE = pyproj.CRS.from_proj4("+proj=longlat +R=3396190 +no_defs")

# A transverse mercator projection for the landing site of the Perseverance rover.
SYRTIS_TM = pyproj.CRS.from_proj4(
"+proj=tmerc +lat_0=17 +lon_0=76.5 +k=0.9996 +x_0=0 +y_0=0 +a=3396190 +b=3376200 +units=m +no_defs"
Expand All @@ -359,12 +381,19 @@ def test_mars_local_tms():
title="Web Mercator Mars",
)
assert SYRTIS_TM == syrtis_tms.crs._pyproj_crs
assert syrtis_tms.geographic_crs
assert syrtis_tms.model_dump(mode="json")

center = syrtis_tms.ul(1, 1, 1)
assert round(center.x, 6) == 76.5
assert round(center.y, 6) == 17

_to_geographic = pyproj.Transformer.from_crs(
syrtis_tms.crs._pyproj_crs, MARS2000_SPHERE, always_xy=True
)
bbox = _to_geographic.transform_bounds(*syrtis_tms.xy_bbox, densify_pts=21)
assert bbox == syrtis_tms.bbox


@pytest.mark.parametrize(
"identifier, file, crs",
Expand Down

0 comments on commit 81538fb

Please sign in to comment.