From bd73194d824a6cc80344f48d58daba203eed422a Mon Sep 17 00:00:00 2001 From: Andrew Annex Date: Tue, 15 Oct 2024 13:20:38 -0700 Subject: [PATCH 1/7] added two failing tests for mars crss --- .gitignore | 4 ++++ morecantile/models.py | 1 - tests/test_models.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 23077b4..788139f 100644 --- a/.gitignore +++ b/.gitignore @@ -130,3 +130,7 @@ dmypy.json # PyCharm: .idea + +# VSCode +.vscode +.vscode/ diff --git a/morecantile/models.py b/morecantile/models.py index c43349c..e5052b0 100644 --- a/morecantile/models.py +++ b/morecantile/models.py @@ -40,7 +40,6 @@ NumType = Union[float, int] BoundsType = Tuple[NumType, NumType] LL_EPSILON = 1e-11 -WGS84_CRS = pyproj.CRS.from_epsg(4326) axesInfo = Annotated[List[str], Field(min_length=2, max_length=2)] diff --git a/tests/test_models.py b/tests/test_models.py index a62078b..d2afb31 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -395,6 +395,35 @@ def test_mars_local_tms(): assert bbox == syrtis_tms.bbox +def test_mars_tms_construction(): + mars_sphere_crs = pyproj.CRS.from_user_input("IAU_2015:49900") + extent = [-90, -180, 90, 180] + mars_tms = morecantile.TileMatrixSet.custom( + extent, mars_sphere_crs, id="MarsGeographicCRS" + ) + assert "4326" not in mars_tms.geographic_crs.to_wkt() + assert "4326" not in mars_tms.rasterio_geographic_crs.to_wkt() + assert mars_tms.xy_bbox.left == pytest.approx(-90.0) + assert mars_tms.xy_bbox.right == pytest.approx(180.0) + assert mars_tms.xy_bbox.bottom == pytest.approx(180.0) + assert mars_tms.xy_bbox.top == pytest.approx(90.0) + + +def test_mars_web_mercator_long_lat(): + wkt_mars_web_mercator = 'PROJCRS["Mars (2015) - Sphere XY / Pseudo-Mercator",BASEGEOGCRS["Mars (2015) - Sphere",DATUM["Mars (2015) - Sphere",ELLIPSOID["Mars (2015) - Sphere",3396190,0,LENGTHUNIT["metre",1,ID["EPSG",9001]]],ANCHOR["Viking 1 lander : 47.95137 W"]],PRIMEM["Reference Meridian",0,ANGLEUNIT["degree",0.0174532925199433,ID["EPSG",9122]]]],CONVERSION["Popular Visualisation Pseudo-Mercator",METHOD["Popular Visualisation Pseudo Mercator",ID["EPSG",1024]],PARAMETER["Latitude of natural origin",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8801]],PARAMETER["Longitude of natural origin",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8802]],PARAMETER["False easting",0,LENGTHUNIT["metre",1],ID["EPSG",8806]],PARAMETER["False northing",0,LENGTHUNIT["metre",1],ID["EPSG",8807]]],CS[Cartesian,2],AXIS["easting (X)",east,ORDER[1],LENGTHUNIT["metre",1,ID["EPSG",9001]]],AXIS["northing (Y)",north,ORDER[2],LENGTHUNIT["metre",1,ID["EPSG",9001]]],USAGE[SCOPE["Web mapping and visualisation."],AREA["World between 85.06 S and 85.06 N."],BBOX[-85.850511287,-180,85.0511287,180]],REMARK["Use semi-major radius as sphere radius for interoperability. Source of IAU Coordinate systems: doi:10.1007/s10569-017-9805-5"]]' + crs_mars_web_mercator = pyproj.CRS.from_wkt(wkt_mars_web_mercator) + extent_wm = [-85.850511287, -180, 85.0511287, 180] + mars_tms_wm = morecantile.TileMatrixSet.custom( + extent_wm, crs_mars_web_mercator, id="MarsWebMercator" + ) + assert "4326" not in mars_tms_wm.geographic_crs.to_wkt() + assert "4326" not in mars_tms_wm.rasterio_geographic_crs.to_wkt() + assert mars_tms_wm.bbox.left == pytest.approx(-180.0) + assert mars_tms_wm.bbox.right == pytest.approx(180.0) + assert mars_tms_wm.bbox.bottom == pytest.approx(-85.850511287) + assert mars_tms_wm.bbox.top == pytest.approx(85.850511287) + + @pytest.mark.parametrize( "identifier, file, crs", [ From 5bf1e3b31ab55a2bfb0ce19de5ae15d313bad5f1 Mon Sep 17 00:00:00 2001 From: "Dr. Andrew Annex" Date: Tue, 15 Oct 2024 15:13:35 -0700 Subject: [PATCH 2/7] Update tests/test_models.py Co-authored-by: Vincent Sarago --- tests/test_models.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_models.py b/tests/test_models.py index d2afb31..a2e70d1 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -399,7 +399,10 @@ def test_mars_tms_construction(): mars_sphere_crs = pyproj.CRS.from_user_input("IAU_2015:49900") extent = [-90, -180, 90, 180] mars_tms = morecantile.TileMatrixSet.custom( - extent, mars_sphere_crs, id="MarsGeographicCRS" + extent, + mars_sphere_crs, + id="MarsGeographicCRS", + matrix_scale=[1, 2], ) assert "4326" not in mars_tms.geographic_crs.to_wkt() assert "4326" not in mars_tms.rasterio_geographic_crs.to_wkt() From e178037adeb04cd4aa5f0c04bc8dfdec6f365adb Mon Sep 17 00:00:00 2001 From: Andrew Annex Date: Tue, 15 Oct 2024 15:32:51 -0700 Subject: [PATCH 3/7] being more specific with the extent_crs's --- tests/test_models.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/test_models.py b/tests/test_models.py index a2e70d1..5ff8578 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -399,9 +399,10 @@ def test_mars_tms_construction(): mars_sphere_crs = pyproj.CRS.from_user_input("IAU_2015:49900") extent = [-90, -180, 90, 180] mars_tms = morecantile.TileMatrixSet.custom( - extent, - mars_sphere_crs, - id="MarsGeographicCRS", + extent, + extent_crs=mars_sphere_crs, + crs=mars_sphere_crs, + id="MarsGeographicCRS", matrix_scale=[1, 2], ) assert "4326" not in mars_tms.geographic_crs.to_wkt() @@ -413,11 +414,15 @@ def test_mars_tms_construction(): def test_mars_web_mercator_long_lat(): + mars_sphere_crs = pyproj.CRS.from_user_input("IAU_2015:49900") wkt_mars_web_mercator = 'PROJCRS["Mars (2015) - Sphere XY / Pseudo-Mercator",BASEGEOGCRS["Mars (2015) - Sphere",DATUM["Mars (2015) - Sphere",ELLIPSOID["Mars (2015) - Sphere",3396190,0,LENGTHUNIT["metre",1,ID["EPSG",9001]]],ANCHOR["Viking 1 lander : 47.95137 W"]],PRIMEM["Reference Meridian",0,ANGLEUNIT["degree",0.0174532925199433,ID["EPSG",9122]]]],CONVERSION["Popular Visualisation Pseudo-Mercator",METHOD["Popular Visualisation Pseudo Mercator",ID["EPSG",1024]],PARAMETER["Latitude of natural origin",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8801]],PARAMETER["Longitude of natural origin",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8802]],PARAMETER["False easting",0,LENGTHUNIT["metre",1],ID["EPSG",8806]],PARAMETER["False northing",0,LENGTHUNIT["metre",1],ID["EPSG",8807]]],CS[Cartesian,2],AXIS["easting (X)",east,ORDER[1],LENGTHUNIT["metre",1,ID["EPSG",9001]]],AXIS["northing (Y)",north,ORDER[2],LENGTHUNIT["metre",1,ID["EPSG",9001]]],USAGE[SCOPE["Web mapping and visualisation."],AREA["World between 85.06 S and 85.06 N."],BBOX[-85.850511287,-180,85.0511287,180]],REMARK["Use semi-major radius as sphere radius for interoperability. Source of IAU Coordinate systems: doi:10.1007/s10569-017-9805-5"]]' crs_mars_web_mercator = pyproj.CRS.from_wkt(wkt_mars_web_mercator) - extent_wm = [-85.850511287, -180, 85.0511287, 180] + extent_wm = [-85.850511287, -180, 85.850511287, 180] mars_tms_wm = morecantile.TileMatrixSet.custom( - extent_wm, crs_mars_web_mercator, id="MarsWebMercator" + extent_wm, + extent_crs=mars_sphere_crs, + crs=crs_mars_web_mercator, + id="MarsWebMercator", ) assert "4326" not in mars_tms_wm.geographic_crs.to_wkt() assert "4326" not in mars_tms_wm.rasterio_geographic_crs.to_wkt() From 56ad6fcd98778fdb5a04766475668455926a3b59 Mon Sep 17 00:00:00 2001 From: Andrew Annex Date: Tue, 15 Oct 2024 15:40:19 -0700 Subject: [PATCH 4/7] fix for bone-headed issues with basic geographic mars test --- tests/test_models.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/test_models.py b/tests/test_models.py index 5ff8578..be41dc1 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -397,19 +397,18 @@ def test_mars_local_tms(): def test_mars_tms_construction(): mars_sphere_crs = pyproj.CRS.from_user_input("IAU_2015:49900") - extent = [-90, -180, 90, 180] + extent = [-180.0, -90.0, 180.0, 90.0] mars_tms = morecantile.TileMatrixSet.custom( extent, - extent_crs=mars_sphere_crs, crs=mars_sphere_crs, id="MarsGeographicCRS", - matrix_scale=[1, 2], + matrix_scale=[2, 1], ) assert "4326" not in mars_tms.geographic_crs.to_wkt() assert "4326" not in mars_tms.rasterio_geographic_crs.to_wkt() - assert mars_tms.xy_bbox.left == pytest.approx(-90.0) + assert mars_tms.xy_bbox.left == pytest.approx(-180.0) + assert mars_tms.xy_bbox.bottom == pytest.approx(-90.0) assert mars_tms.xy_bbox.right == pytest.approx(180.0) - assert mars_tms.xy_bbox.bottom == pytest.approx(180.0) assert mars_tms.xy_bbox.top == pytest.approx(90.0) @@ -417,7 +416,7 @@ def test_mars_web_mercator_long_lat(): mars_sphere_crs = pyproj.CRS.from_user_input("IAU_2015:49900") wkt_mars_web_mercator = 'PROJCRS["Mars (2015) - Sphere XY / Pseudo-Mercator",BASEGEOGCRS["Mars (2015) - Sphere",DATUM["Mars (2015) - Sphere",ELLIPSOID["Mars (2015) - Sphere",3396190,0,LENGTHUNIT["metre",1,ID["EPSG",9001]]],ANCHOR["Viking 1 lander : 47.95137 W"]],PRIMEM["Reference Meridian",0,ANGLEUNIT["degree",0.0174532925199433,ID["EPSG",9122]]]],CONVERSION["Popular Visualisation Pseudo-Mercator",METHOD["Popular Visualisation Pseudo Mercator",ID["EPSG",1024]],PARAMETER["Latitude of natural origin",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8801]],PARAMETER["Longitude of natural origin",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8802]],PARAMETER["False easting",0,LENGTHUNIT["metre",1],ID["EPSG",8806]],PARAMETER["False northing",0,LENGTHUNIT["metre",1],ID["EPSG",8807]]],CS[Cartesian,2],AXIS["easting (X)",east,ORDER[1],LENGTHUNIT["metre",1,ID["EPSG",9001]]],AXIS["northing (Y)",north,ORDER[2],LENGTHUNIT["metre",1,ID["EPSG",9001]]],USAGE[SCOPE["Web mapping and visualisation."],AREA["World between 85.06 S and 85.06 N."],BBOX[-85.850511287,-180,85.0511287,180]],REMARK["Use semi-major radius as sphere radius for interoperability. Source of IAU Coordinate systems: doi:10.1007/s10569-017-9805-5"]]' crs_mars_web_mercator = pyproj.CRS.from_wkt(wkt_mars_web_mercator) - extent_wm = [-85.850511287, -180, 85.850511287, 180] + extent_wm = [-180.0, -85.850511287, 180.0, 85.850511287] mars_tms_wm = morecantile.TileMatrixSet.custom( extent_wm, extent_crs=mars_sphere_crs, @@ -427,8 +426,8 @@ def test_mars_web_mercator_long_lat(): assert "4326" not in mars_tms_wm.geographic_crs.to_wkt() assert "4326" not in mars_tms_wm.rasterio_geographic_crs.to_wkt() assert mars_tms_wm.bbox.left == pytest.approx(-180.0) - assert mars_tms_wm.bbox.right == pytest.approx(180.0) assert mars_tms_wm.bbox.bottom == pytest.approx(-85.850511287) + assert mars_tms_wm.bbox.right == pytest.approx(180.0) assert mars_tms_wm.bbox.top == pytest.approx(85.850511287) From 44b914e90725498740283ef3e3af658d50500432 Mon Sep 17 00:00:00 2001 From: Andrew Annex Date: Tue, 15 Oct 2024 15:54:55 -0700 Subject: [PATCH 5/7] fix for typo in the wkt for mars web mercator --- tests/test_models.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/test_models.py b/tests/test_models.py index be41dc1..a3fc05d 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -413,22 +413,26 @@ def test_mars_tms_construction(): def test_mars_web_mercator_long_lat(): - mars_sphere_crs = pyproj.CRS.from_user_input("IAU_2015:49900") - wkt_mars_web_mercator = 'PROJCRS["Mars (2015) - Sphere XY / Pseudo-Mercator",BASEGEOGCRS["Mars (2015) - Sphere",DATUM["Mars (2015) - Sphere",ELLIPSOID["Mars (2015) - Sphere",3396190,0,LENGTHUNIT["metre",1,ID["EPSG",9001]]],ANCHOR["Viking 1 lander : 47.95137 W"]],PRIMEM["Reference Meridian",0,ANGLEUNIT["degree",0.0174532925199433,ID["EPSG",9122]]]],CONVERSION["Popular Visualisation Pseudo-Mercator",METHOD["Popular Visualisation Pseudo Mercator",ID["EPSG",1024]],PARAMETER["Latitude of natural origin",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8801]],PARAMETER["Longitude of natural origin",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8802]],PARAMETER["False easting",0,LENGTHUNIT["metre",1],ID["EPSG",8806]],PARAMETER["False northing",0,LENGTHUNIT["metre",1],ID["EPSG",8807]]],CS[Cartesian,2],AXIS["easting (X)",east,ORDER[1],LENGTHUNIT["metre",1,ID["EPSG",9001]]],AXIS["northing (Y)",north,ORDER[2],LENGTHUNIT["metre",1,ID["EPSG",9001]]],USAGE[SCOPE["Web mapping and visualisation."],AREA["World between 85.06 S and 85.06 N."],BBOX[-85.850511287,-180,85.0511287,180]],REMARK["Use semi-major radius as sphere radius for interoperability. Source of IAU Coordinate systems: doi:10.1007/s10569-017-9805-5"]]' + wkt_mars_web_mercator = 'PROJCRS["Mars (2015) - Sphere XY / Pseudo-Mercator",BASEGEOGCRS["Mars (2015) - Sphere",DATUM["Mars (2015) - Sphere",ELLIPSOID["Mars (2015) - Sphere",3396190,0,LENGTHUNIT["metre",1,ID["EPSG",9001]]],ANCHOR["Viking 1 lander : 47.95137 W"]],PRIMEM["Reference Meridian",0,ANGLEUNIT["degree",0.0174532925199433,ID["EPSG",9122]]]],CONVERSION["Popular Visualisation Pseudo-Mercator",METHOD["Popular Visualisation Pseudo Mercator",ID["EPSG",1024]],PARAMETER["Latitude of natural origin",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8801]],PARAMETER["Longitude of natural origin",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8802]],PARAMETER["False easting",0,LENGTHUNIT["metre",1],ID["EPSG",8806]],PARAMETER["False northing",0,LENGTHUNIT["metre",1],ID["EPSG",8807]]],CS[Cartesian,2],AXIS["easting (X)",east,ORDER[1],LENGTHUNIT["metre",1,ID["EPSG",9001]]],AXIS["northing (Y)",north,ORDER[2],LENGTHUNIT["metre",1,ID["EPSG",9001]]],USAGE[SCOPE["Web mapping and visualisation."],AREA["World between 85.06 S and 85.06 N."],BBOX[-85.050511287,-180,85.050511287,180]],REMARK["Use semi-major radius as sphere radius for interoperability. Source of IAU Coordinate systems: doi:10.1007/s10569-017-9805-5"]]' crs_mars_web_mercator = pyproj.CRS.from_wkt(wkt_mars_web_mercator) - extent_wm = [-180.0, -85.850511287, 180.0, 85.850511287] + extent_wm = [ + -10669445.554195119, + -10669445.554195119, + 10669445.554195119, + 10669445.554195119, + ] mars_tms_wm = morecantile.TileMatrixSet.custom( extent_wm, - extent_crs=mars_sphere_crs, + # extent_crs=mars_sphere_crs, crs=crs_mars_web_mercator, id="MarsWebMercator", ) assert "4326" not in mars_tms_wm.geographic_crs.to_wkt() assert "4326" not in mars_tms_wm.rasterio_geographic_crs.to_wkt() assert mars_tms_wm.bbox.left == pytest.approx(-180.0) - assert mars_tms_wm.bbox.bottom == pytest.approx(-85.850511287) + assert mars_tms_wm.bbox.bottom == pytest.approx(-85.0511287) assert mars_tms_wm.bbox.right == pytest.approx(180.0) - assert mars_tms_wm.bbox.top == pytest.approx(85.850511287) + assert mars_tms_wm.bbox.top == pytest.approx(85.0511287) @pytest.mark.parametrize( From d5d2aa0aaefe788cd7c2204d850283a75c7b4a27 Mon Sep 17 00:00:00 2001 From: Andrew Annex Date: Tue, 15 Oct 2024 15:56:18 -0700 Subject: [PATCH 6/7] removed commented out line --- tests/test_models.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_models.py b/tests/test_models.py index a3fc05d..bd53e4f 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -423,7 +423,6 @@ def test_mars_web_mercator_long_lat(): ] mars_tms_wm = morecantile.TileMatrixSet.custom( extent_wm, - # extent_crs=mars_sphere_crs, crs=crs_mars_web_mercator, id="MarsWebMercator", ) From 003ec17fffe758d98b4ee45539928ed478ca561d Mon Sep 17 00:00:00 2001 From: Andrew Annex Date: Tue, 15 Oct 2024 16:01:04 -0700 Subject: [PATCH 7/7] another sanity check --- tests/test_models.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_models.py b/tests/test_models.py index bd53e4f..c1a84ca 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -432,6 +432,23 @@ def test_mars_web_mercator_long_lat(): assert mars_tms_wm.bbox.bottom == pytest.approx(-85.0511287) assert mars_tms_wm.bbox.right == pytest.approx(180.0) assert mars_tms_wm.bbox.top == pytest.approx(85.0511287) + extent_wm_geog = [ + -179.9999999999996, + -85.05112877980656, + 179.9999999999996, + 85.05112877980656, + ] + mars_sphere_crs = pyproj.CRS.from_user_input("IAU_2015:49900") + mars_tms_wm_geog_ext = morecantile.TileMatrixSet.custom( + extent_wm_geog, + extent_crs=mars_sphere_crs, + crs=crs_mars_web_mercator, + id="MarsWebMercator", + ) + assert mars_tms_wm_geog_ext.bbox.left == pytest.approx(-180.0) + assert mars_tms_wm_geog_ext.bbox.bottom == pytest.approx(-85.0511287) + assert mars_tms_wm_geog_ext.bbox.right == pytest.approx(180.0) + assert mars_tms_wm_geog_ext.bbox.top == pytest.approx(85.0511287) @pytest.mark.parametrize(