From 409ce27a66a7c9c0ed6c55d1bd468a52c87e1560 Mon Sep 17 00:00:00 2001 From: Joachim Ungar Date: Tue, 23 Jul 2024 09:09:14 +0200 Subject: [PATCH] fix issue with providing a custom grid as dict --- mapchete/commands/convert.py | 10 +++++----- test/commands/test_convert.py | 14 +++++++++++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/mapchete/commands/convert.py b/mapchete/commands/convert.py index a1a09f3f..a9fabecb 100644 --- a/mapchete/commands/convert.py +++ b/mapchete/commands/convert.py @@ -90,13 +90,13 @@ def convert( except Exception as e: raise ValueError(e) - # try to read output grid definition from a file - if ( - isinstance(output_pyramid, (MPath, str, dict)) - and output_pyramid not in tilematrix._conf.PYRAMID_PARAMS.keys() + # try to read output grid definition from a file + if not ( + isinstance(output_pyramid, str) + and output_pyramid in tilematrix._conf.PYRAMID_PARAMS.keys() ): try: - output_pyramid = MPath.from_inp(output_pyramid).read_json() + output_pyramid = MPath.from_inp(output_pyramid).read_json() # type: ignore except Exception: # pragma: no cover pass diff --git a/test/commands/test_convert.py b/test/commands/test_convert.py index 7ac89b10..466485af 100644 --- a/test/commands/test_convert.py +++ b/test/commands/test_convert.py @@ -38,7 +38,7 @@ def test_convert_mercator(cleantopo_br_tif, mp_tmpdir): assert data.mask.any() -def test_convert_custom_grid(s2_band, mp_tmpdir, custom_grid_json): +def test_convert_custom_grid_json(s2_band, mp_tmpdir, custom_grid_json): """Automatic mercator tile pyramid creation of raster files.""" convert(s2_band, mp_tmpdir, output_pyramid=custom_grid_json) for zoom, row, col in [(0, 5298, 631)]: @@ -50,6 +50,18 @@ def test_convert_custom_grid(s2_band, mp_tmpdir, custom_grid_json): assert data.mask.any() +def test_convert_custom_grid_dict(s2_band, mp_tmpdir, custom_grid_json): + """Automatic mercator tile pyramid creation of raster files.""" + convert(s2_band, mp_tmpdir, output_pyramid=custom_grid_json.read_json()) + for zoom, row, col in [(0, 5298, 631)]: + out_file = mp_tmpdir / zoom / row / col + ".tif" + with rasterio_open(out_file, "r") as src: + assert src.meta["driver"] == "GTiff" + assert src.meta["dtype"] == "uint16" + data = src.read(masked=True) + assert data.mask.any() + + def test_convert_png(cleantopo_br_tif, mp_tmpdir): """Automatic PNG tile pyramid creation of raster files.""" convert(cleantopo_br_tif, mp_tmpdir, output_pyramid="mercator", output_format="PNG")