# Path: mapchete/processes/examples/example_process.py
# def execute(mp):
# 
# Path: mapchete/processes/contours.py
# def execute(
#     mp,
#     resampling="nearest",
#     interval=100,
#     field="elev",
#     base=0,
#     td_matching_method="gdal",
#     td_matching_max_zoom=None,
#     td_matching_precision=8,
#     td_fallback_to_higher_zoom=False,
#     clip_pixelbuffer=0,
#     **kwargs
# ):
# 
# Path: mapchete/processes/convert.py
# def execute(
#     mp,
#     resampling="nearest",
#     band_indexes=None,
#     td_matching_method="gdal",
#     td_matching_max_zoom=None,
#     td_matching_precision=8,
#     td_fallback_to_higher_zoom=False,
#     clip_pixelbuffer=0,
#     scale_ratio=1.0,
#     scale_offset=0.0,
#     clip_to_output_dtype=None,
#     **kwargs,
# ):
# 
# Path: mapchete/processes/hillshade.py
# def execute(
#     mp,
#     resampling="nearest",
#     azimuth=315.0,
#     altitude=45.0,
#     z=1.0,
#     scale=1.0,
#     td_matching_method="gdal",
#     td_matching_max_zoom=None,
#     td_matching_precision=8,
#     td_fallback_to_higher_zoom=False,
#     clip_pixelbuffer=0,
#     **kwargs
# ):
# 
# Path: mapchete/testing.py
# def get_process_mp(tile=None, zoom=0, input=None, params=None, metatiling=1, **kwargs):
#     pyramid = BufferedTilePyramid("geodetic", metatiling=metatiling)
#     initialized_inputs = initialize_inputs(
#         input,
#         config_dir=None,
#         pyramid=pyramid,
#         delimiters=None,
#         readonly=False,
#     )
#     if tile:
#         tile = pyramid.tile(*tile)
#     else:
#         if zoom is None:  # pragma: no cover
#             raise ValueError("either tile or tile_zoom have to be provided")
#         tile = next(
#             pyramid.tiles_from_geom(
#                 unary_union(
#                     [v.bbox(out_crs=pyramid.crs) for v in initialized_inputs.values()]
#                 ),
#                 zoom,
#             )
#         )
#     logger.debug(f"tile is {tile}")
#     inputs = OrderedDict(open_inputs(initialized_inputs, tile))
#     return mapchete.MapcheteProcess(
#         tile=tile, input=inputs, params=params or {}, **kwargs
#     )


import numpy as np
import numpy.ma as ma
import mapchete
from mapchete.processes.examples import example_process
from mapchete.processes import contours, convert, hillshade
from mapchete.testing import get_process_mp
    )


def test_contours(cleantopo_tl_tif, landpoly):
    process_mp = get_process_mp(input=dict(dem=cleantopo_tl_tif), zoom=5, metatiling=8)
    output = contours.execute(process_mp)
    assert isinstance(output, list)
    assert output

    # execute on empty tile
    process_mp = get_process_mp(
        input=dict(dem=cleantopo_tl_tif), tile=(5, 3, 7), metatiling=8
    )
    assert contours.execute(process_mp) == "empty"

    process_mp = get_process_mp(
        input=dict(dem=cleantopo_tl_tif, clip=landpoly), zoom=5, metatiling=8
    )
    output = contours.execute(process_mp)
    assert isinstance(output, list)
    assert output

    process_mp = get_process_mp(
        input=dict(dem=cleantopo_tl_tif, clip=landpoly), tile=(5, 3, 7), metatiling=8
    )
    assert contours.execute(process_mp) == "empty"


def test_hillshade(cleantopo_tl_tif, landpoly):
    process_mp = get_process_mp(input=dict(dem=cleantopo_tl_tif), zoom=5, metatiling=8)

# Path: mapchete/processes/examples/example_process.py
# def execute(mp):
# 
# Path: mapchete/processes/contours.py
# def execute(
#     mp,
#     resampling="nearest",
#     interval=100,
#     field="elev",
#     base=0,
#     td_matching_method="gdal",
#     td_matching_max_zoom=None,
#     td_matching_precision=8,
#     td_fallback_to_higher_zoom=False,
#     clip_pixelbuffer=0,
#     **kwargs
# ):
# 
# Path: mapchete/processes/convert.py
# def execute(
#     mp,
#     resampling="nearest",
#     band_indexes=None,
#     td_matching_method="gdal",
#     td_matching_max_zoom=None,
#     td_matching_precision=8,
#     td_fallback_to_higher_zoom=False,
#     clip_pixelbuffer=0,
#     scale_ratio=1.0,
#     scale_offset=0.0,
#     clip_to_output_dtype=None,
#     **kwargs,
# ):
# 
# Path: mapchete/processes/hillshade.py
# def execute(
#     mp,
#     resampling="nearest",
#     azimuth=315.0,
#     altitude=45.0,
#     z=1.0,
#     scale=1.0,
#     td_matching_method="gdal",
#     td_matching_max_zoom=None,
#     td_matching_precision=8,
#     td_fallback_to_higher_zoom=False,
#     clip_pixelbuffer=0,
#     **kwargs
# ):
# 
# Path: mapchete/testing.py
# def get_process_mp(tile=None, zoom=0, input=None, params=None, metatiling=1, **kwargs):
#     pyramid = BufferedTilePyramid("geodetic", metatiling=metatiling)
#     initialized_inputs = initialize_inputs(
#         input,
#         config_dir=None,
#         pyramid=pyramid,
#         delimiters=None,
#         readonly=False,
#     )
#     if tile:
#         tile = pyramid.tile(*tile)
#     else:
#         if zoom is None:  # pragma: no cover
#             raise ValueError("either tile or tile_zoom have to be provided")
#         tile = next(
#             pyramid.tiles_from_geom(
#                 unary_union(
#                     [v.bbox(out_crs=pyramid.crs) for v in initialized_inputs.values()]
#                 ),
#                 zoom,
#             )
#         )
#     logger.debug(f"tile is {tile}")
#     inputs = OrderedDict(open_inputs(initialized_inputs, tile))
#     return mapchete.MapcheteProcess(
#         tile=tile, input=inputs, params=params or {}, **kwargs
#     )


# Path: test/test_processes.py
import numpy as np
import numpy.ma as ma
import mapchete
from mapchete.processes.examples import example_process
from mapchete.processes import contours, convert, hillshade
from mapchete.testing import get_process_mp

    )


def test_contours(cleantopo_tl_tif, landpoly):
    process_mp = get_process_mp(input=dict(dem=cleantopo_tl_tif), zoom=5, metatiling=8)
    output = contours.execute(process_mp)
    assert isinstance(output, list)
    assert output

    # execute on empty tile
    process_mp = get_process_mp(
        input=dict(dem=cleantopo_tl_tif), tile=(5, 3, 7), metatiling=8
    )
    assert contours.execute(process_mp) == "empty"

    process_mp = get_process_mp(
        input=dict(dem=cleantopo_tl_tif, clip=landpoly), zoom=5, metatiling=8
    )
    output = contours.execute(process_mp)
    assert isinstance(output, list)
    assert output

    process_mp = get_process_mp(
        input=dict(dem=cleantopo_tl_tif, clip=landpoly), tile=(5, 3, 7), metatiling=8
    )
    assert contours.execute(process_mp) == "empty"


def test_hillshade(cleantopo_tl_tif, landpoly):
    process_mp = get_process_mp(input=dict(dem=cleantopo_tl_tif), zoom=5, metatiling=8)

    assert isinstance(hillshade.execute(process_mp), np.ndarray)