Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_hillshade(cleantopo_tl):
"""Render hillshade from array."""
with mapchete.open(cleantopo_tl.path) as mp:
tile = next(mp.get_process_tiles(zoom=4))
tile_process = MapcheteProcess(tile, params=mp.config.params_at_zoom(4))
with tile_process.open("file1") as dem:
shade = tile_process.hillshade(dem.read())
assert isinstance(shade, np.ndarray)
def test_open_data_error(cleantopo_tl):
"""Try to open data not specified as input."""
with mapchete.open(cleantopo_tl.path) as mp:
tile = mp.config.process_pyramid.tile(5, 0, 0)
# read written data from within MapcheteProcess object
user_process = mapchete.MapcheteProcess(
tile=tile,
config=mp.config,
)
with pytest.raises(ValueError):
user_process.open("invaild_input_id")
def test_clip(geojson):
"""Clip an array with a vector."""
with mapchete.open(geojson.path) as mp:
tile = next(mp.get_process_tiles(zoom=4))
tile_process = MapcheteProcess(tile, params=mp.config.params_at_zoom(4))
with tile_process.open("file1") as vector_file:
test_array = ma.masked_array(np.ones(tile_process.tile.shape))
clipped = tile_process.clip(test_array, vector_file.read())
# default params
assert isinstance(clipped, ma.masked_array)
assert clipped.mask.any()
assert not clipped.mask.all()
# inverted clip
clipped_inverted = tile_process.clip(
test_array, vector_file.read(), inverted=True)
assert isinstance(clipped_inverted, ma.masked_array)
assert clipped_inverted.mask.any()
assert not clipped_inverted.mask.all()
# compare results
assert (clipped+clipped_inverted).mask.all()
# using empty Geometries
def test_read_input_order(file_groups):
"""Assert input objects are represented in the same order as configured."""
with mapchete.open(file_groups.path) as mp:
inputs = yaml.load(open(file_groups.path).read())["input"]
tile = mp.config.process_pyramid.tile(0, 0, 0)
# read written data from within MapcheteProcess object
user_process = mapchete.MapcheteProcess(
tile=tile,
params=mp.config.params_at_zoom(tile.zoom),
input=mp.config.get_inputs_for_tile(tile),
)
assert inputs.keys() == user_process.input.keys()
zoom = max(mp.config.zoom_levels)
# execute without clip
tile = next(mp.get_process_tiles(zoom))
user_process = mapchete.MapcheteProcess(
tile=tile,
params=mp.config.params_at_zoom(tile.zoom),
input=mp.config.get_inputs_for_tile(tile),
)
assert isinstance(convert.execute(user_process), np.ndarray)
# execute on empty tile
tile = mp.config.process_pyramid.tile(
zoom,
mp.config.process_pyramid.matrix_height(zoom) - 1,
mp.config.process_pyramid.matrix_width(zoom) - 1
)
user_process = mapchete.MapcheteProcess(
tile=tile,
params=mp.config.params_at_zoom(tile.zoom),
input=mp.config.get_inputs_for_tile(tile),
)
assert convert.execute(user_process) == "empty"
with mapchete.open(
dict(cleantopo_tl.dict, input=dict(raster=cleantopo_tl_tif, clip=landpoly))
) as mp:
zoom = max(mp.config.zoom_levels)
tile = next(mp.get_process_tiles(zoom))
user_process = mapchete.MapcheteProcess(
tile=tile,
params=mp.config.params_at_zoom(tile.zoom),
input=mp.config.get_inputs_for_tile(tile),
)
def test_example_process(cleantopo_tl):
with mapchete.open(cleantopo_tl.path) as mp:
zoom = max(mp.config.zoom_levels)
# tile containing data
tile = next(mp.get_process_tiles(zoom))
user_process = mapchete.MapcheteProcess(
tile=tile,
params=mp.config.params_at_zoom(tile.zoom),
input=mp.config.get_inputs_for_tile(tile),
)
output = example_process.execute(user_process)
assert isinstance(output, ma.masked_array)
# empty tile
tile = mp.config.process_pyramid.tile(
zoom,
mp.config.process_pyramid.matrix_height(zoom) - 1,
mp.config.process_pyramid.matrix_width(zoom) - 1,
)
user_process = mapchete.MapcheteProcess(
tile=tile,
params=mp.config.params_at_zoom(tile.zoom),
def test_read_from_raster_file(cleantopo_br):
"""Read different bands from source raster."""
with mapchete.open(cleantopo_br.path) as mp:
tile = mp.config.process_pyramid.tile(5, 0, 0)
user_process = mapchete.MapcheteProcess(
tile=tile,
params=mp.config.params_at_zoom(tile.zoom),
input=mp.config.get_inputs_for_tile(tile),
)
with user_process.open("file1") as f:
assert f.read().shape == f.read([1]).shape == f.read(1).shape
def test_contours(cleantopo_tl):
"""Extract contours from array."""
with mapchete.open(cleantopo_tl.path) as mp:
tile = next(mp.get_process_tiles(zoom=4))
tile_process = MapcheteProcess(tile, params=mp.config.params_at_zoom(4))
with tile_process.open("file1") as dem:
arr = dem.read()
# valid contours
contours = tile_process.contours(arr)
assert contours
assert isinstance(contours, list)
# no contours
contours = tile_process.contours(arr, interval=10000)
assert isinstance(contours, list)
assert not contours
# base bigger than values
contours = tile_process.contours(arr, base=10000)
assert isinstance(contours, list)
assert contours
def test_process_tile_open(example_mapchete):
"""Raise ValueError on MapcheteProcess.open()."""
config = MapcheteConfig(example_mapchete.path)
tile = BufferedTilePyramid("mercator").tile(7, 1, 1)
user_process = mapchete.MapcheteProcess(
tile=tile,
params=config.params_at_zoom(tile.zoom),
input=config.get_inputs_for_tile(tile),
)
with pytest.raises(ValueError):
user_process.open("nonexisting_id")