Skip to content

Commit

Permalink
fix issue with providing a custom grid as dict
Browse files Browse the repository at this point in the history
  • Loading branch information
ungarj committed Jul 23, 2024
1 parent ffe823b commit 409ce27
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
10 changes: 5 additions & 5 deletions mapchete/commands/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 13 additions & 1 deletion test/commands/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]:
Expand All @@ -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")
Expand Down

0 comments on commit 409ce27

Please sign in to comment.