Skip to content

Commit

Permalink
Merge 789ba37 into dad4fc5
Browse files Browse the repository at this point in the history
  • Loading branch information
ungarj committed Jun 4, 2019
2 parents dad4fc5 + 789ba37 commit af540d3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 44 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Expand Up @@ -10,7 +10,9 @@ Changelog

* output drivers must now provide `OutputDataWriter` and `OutputDataReader` classes instead of a single `OutputData` class
* `OutputDataWriter.close()` method must accept `exc_type=None, exc_value=None, exc_traceback=None` keywords
* `mapchete pyramid` CLI was removed and is replaced by the more versatile `mapchete convert`
* `mapchete pyramid` CLI was removed and is replaced by the more versatile `mapchete convert` (#157)
* all CLI multiword options are separated by an hyphen (`-`) instead of underscore (`_`)
(#189)

* fixed `area_at_zoom()` when using input groups (#181)
* fixed single GeoTIFF output bounds should use process area (#182)
Expand Down
40 changes: 13 additions & 27 deletions mapchete/cli/utils.py
Expand Up @@ -92,15 +92,15 @@ def _setup_logfile(ctx, param, logfile):
# click options #
#################
opt_out_path = click.option(
"--out_path", "-op", type=click.Path(), default=os.path.join(os.getcwd(), "output"),
"--out-path", "-op", type=click.Path(), default=os.path.join(os.getcwd(), "output"),
help="Process output path."
)
opt_idx_out_dir = click.option(
"--idx_out_dir", "-od", type=click.Path(),
"--idx-out-dir", "-od", type=click.Path(),
help="Index output directory."
)
opt_input_file = click.option(
"--input_file", "-i", type=click.Path(),
"--input-file", "-i", type=click.Path(),
help=(
"""Specify an input file via command line (in mapchete file, """
"""set 'input_file' parameter to 'from_command_line')."""
Expand All @@ -119,7 +119,7 @@ def _setup_logfile(ctx, param, logfile):
help="Process tiles over single point location."
)
opt_wkt_geometry = click.option(
"--wkt_geometry", "-g", type=click.STRING,
"--wkt-geometry", "-g", type=click.STRING,
help="Take boundaries from WKT geometry in tile pyramid CRS.",
)
opt_tile = click.option(
Expand Down Expand Up @@ -147,23 +147,23 @@ def _setup_logfile(ctx, param, logfile):
help="Print info for each process tile."
)
opt_no_pbar = click.option(
"--no_pbar", is_flag=True,
"--no-pbar", is_flag=True,
help="Deactivate progress bar."
)
opt_debug = click.option(
"--debug", "-d", is_flag=True, callback=_set_debug_log_level,
help="Deactivate progress bar and print debug log output."
)
opt_max_chunksize = click.option(
"--max_chunksize", "-c", type=click.INT, default=1,
"--max-chunksize", "-c", type=click.INT, default=1,
help="Maximum number of process tiles to be queued for each worker. (default: 1)"
)
opt_input_formats = click.option(
"--input_formats", "-i", is_flag=True,
"--input-formats", "-i", is_flag=True,
help="Show only input formats."
)
opt_output_formats = click.option(
"--output_formats", "-o", is_flag=True,
"--output-formats", "-o", is_flag=True,
help="Show only output formats."
)
opt_geojson = click.option(
Expand Down Expand Up @@ -195,47 +195,33 @@ def _setup_logfile(ctx, param, logfile):
help="Use other base path than given process output path."
)
opt_for_gdal = click.option(
"--for_gdal", is_flag=True,
"--for-gdal", is_flag=True,
help="Make remote paths readable by GDAL (not applied for txt output)."
)
opt_output_format = click.option(
"--output_format", "-of", type=click.Choice(["GTiff", "PNG"]), default="GTiff",
"--output-format", "-of", type=click.Choice(["GTiff", "PNG"]), default="GTiff",
help="Output data format (GTiff or PNG)."
)
opt_pyramid_type = click.option(
"--pyramid_type", "-pt", type=click.Choice(tilematrix._conf.PYRAMID_PARAMS.keys()),
"--pyramid-type", "-pt", type=click.Choice(tilematrix._conf.PYRAMID_PARAMS.keys()),
default="geodetic",
help="Output pyramid type. (default: geodetic)"
)
opt_pyramid_type_mercator = click.option(
"--pyramid_type", "-pt", type=click.Choice(tilematrix._conf.PYRAMID_PARAMS.keys()),
default="mercator",
help="Output pyramid type. (default: mercator)"
)
opt_resampling_method = click.option(
"--resampling_method", "-r", type=click.Choice([
"--resampling-method", "-r", type=click.Choice([
"nearest", "bilinear", "cubic", "cubic_spline", "lanczos", "average", "mode"
]), default="nearest",
help=(
"""Resampling method to be used (nearest, bilinear, cubic, cubic_spline, """
"""lanczos, average or mode)."""
),
)
opt_scale_method = click.option(
"--scale_method", "-s", type=click.Choice(
["dtype_scale", "minmax_scale", "crop", ""]
), default="",
help=(
"""Scale method if input bands have more than 8 bit (dtype_scale, """
"""minmax_scale or crop)."""
),
)
opt_port = click.option(
"--port", "-p", type=click.INT, default=5000,
help="Port process is hosted on. (default: 5000)",
)
opt_internal_cache = click.option(
"--internal_cache", "-c", type=click.INT, default=1024,
"--internal-cache", "-c", type=click.INT, default=1024,
help="Number of web tiles to be cached in RAM. (default: 1024)",
)
opt_readonly = click.option(
Expand Down
32 changes: 16 additions & 16 deletions test/test_cli.py
Expand Up @@ -48,9 +48,9 @@ def test_main(mp_tmpdir):


def test_missing_input_file(mp_tmpdir):
"""Check if IOError is raised if input_file is invalid."""
"""Check if IOError is raised if input-file is invalid."""
run_cli(
["execute", "process.mapchete", "--input_file", "invalid.tif"],
["execute", "process.mapchete", "--input-file", "invalid.tif"],
expected_exit_code=2,
output_contains='Path "process.mapchete" does not exist.',
raise_exc=False
Expand All @@ -66,7 +66,7 @@ def test_create_and_execute(mp_tmpdir, cleantopo_br_tif):
run_cli(
[
'create', temp_mapchete, temp_process, out_format,
"--pyramid_type", "geodetic"
"--pyramid-type", "geodetic"
],
expected_exit_code=0
)
Expand All @@ -81,7 +81,7 @@ def test_create_and_execute(mp_tmpdir, cleantopo_br_tif):
run_cli(
[
'execute', temp_mapchete, '--tile', '6', '62', '124',
'--input_file', cleantopo_br_tif, '-d'
'--input-file', cleantopo_br_tif, '-d'
],
expected_exit_code=-1
)
Expand All @@ -94,7 +94,7 @@ def test_create_existing(mp_tmpdir):
out_format = "GTiff"
# create files from template
args = [
'create', temp_mapchete, temp_process, out_format, "--pyramid_type", "geodetic"
'create', temp_mapchete, temp_process, out_format, "--pyramid-type", "geodetic"
]
run_cli(args)
# try to create again
Expand All @@ -109,7 +109,7 @@ def test_execute_multiprocessing(mp_tmpdir, cleantopo_br, cleantopo_br_tif):
out_format = "GTiff"
# create from template
run_cli([
'create', temp_mapchete, temp_process, out_format, "--pyramid_type", "geodetic"
'create', temp_mapchete, temp_process, out_format, "--pyramid-type", "geodetic"
])
# edit configuration
with open(temp_mapchete, "r") as config_file:
Expand All @@ -120,7 +120,7 @@ def test_execute_multiprocessing(mp_tmpdir, cleantopo_br, cleantopo_br_tif):
# run process with multiprocessing
with pytest.raises(MapcheteProcessOutputError):
run_cli([
'execute', temp_mapchete, '--zoom', '5', '--input_file', cleantopo_br_tif,
'execute', temp_mapchete, '--zoom', '5', '--input-file', cleantopo_br_tif,
'-m', '2', '-d'
])
# run example process with multiprocessing
Expand All @@ -147,7 +147,7 @@ def test_execute_vrt(mp_tmpdir, cleantopo_br):

# run again, this time with custom output directory
run_cli(
['execute', cleantopo_br.path, "-z", "5", "--vrt", "--idx_out_dir", mp_tmpdir]
['execute', cleantopo_br.path, "-z", "5", "--vrt", "--idx-out-dir", mp_tmpdir]
)
with mapchete.open(cleantopo_br.dict) as mp:
vrt_path = os.path.join(mp_tmpdir, "5.vrt")
Expand Down Expand Up @@ -183,7 +183,7 @@ def test_execute_logfile(mp_tmpdir, example_mapchete):

def test_execute_wkt_bounds(mp_tmpdir, example_mapchete, wkt_geom):
"""Using bounds from WKT."""
run_cli(['execute', example_mapchete.path, "--wkt_geometry", wkt_geom])
run_cli(['execute', example_mapchete.path, "--wkt-geometry", wkt_geom])


def test_execute_point(mp_tmpdir, example_mapchete, wkt_geom):
Expand Down Expand Up @@ -479,13 +479,13 @@ def test_serve_cli_params(cleantopo_br, mp_tmpdir):
for args in [
['serve', cleantopo_br.path],
['serve', cleantopo_br.path, "--port", "5001"],
['serve', cleantopo_br.path, "--internal_cache", "512"],
['serve', cleantopo_br.path, "--internal-cache", "512"],
['serve', cleantopo_br.path, "--zoom", "5"],
['serve', cleantopo_br.path, "--bounds", "-1", "-1", "1", "1"],
['serve', cleantopo_br.path, "--overwrite"],
['serve', cleantopo_br.path, "--readonly"],
['serve', cleantopo_br.path, "--memory"],
['serve', cleantopo_br.path, "--input_file", cleantopo_br.path],
['serve', cleantopo_br.path, "--input-file", cleantopo_br.path],
]:
run_cli(args)

Expand All @@ -511,15 +511,15 @@ def test_serve(client, mp_tmpdir):
# get alpha band and assert not all are masked
assert not data[3].all()
# test outside zoom range
response = client.get(tile_base_url+"6/31/63.png")
response = client.get(tile_base_url + "6/31/63.png")
assert response.status_code == 200
img = response.data
with MemoryFile(img) as memfile:
with memfile.open() as dataset:
data = dataset.read()
assert not data.any()
# test invalid url
response = client.get(tile_base_url+"invalid_url")
response = client.get(tile_base_url + "invalid_url")
assert response.status_code == 404


Expand Down Expand Up @@ -584,7 +584,7 @@ def test_index_geojson_for_gdal(mp_tmpdir, cleantopo_br):
# index and rename "location" to "new_fieldname"
run_cli([
'index', cleantopo_br.path, '-z', '3', '--geojson', '--debug',
'--basepath', basepath, '--for_gdal'
'--basepath', basepath, '--for-gdal'
])
with mapchete.open(cleantopo_br.dict) as mp:
files = os.listdir(mp.config.output.path)
Expand All @@ -611,11 +611,11 @@ def test_index_geojson_tile(mp_tmpdir, cleantopo_tl):

def test_index_geojson_wkt_geom(mp_tmpdir, cleantopo_br, wkt_geom):
# execute process at zoom 3
run_cli(['execute', cleantopo_br.path, '--debug', "--wkt_geometry", wkt_geom])
run_cli(['execute', cleantopo_br.path, '--debug', "--wkt-geometry", wkt_geom])

# generate index for zoom 3
run_cli([
'index', cleantopo_br.path, '--geojson', '--debug', "--wkt_geometry", wkt_geom
'index', cleantopo_br.path, '--geojson', '--debug', "--wkt-geometry", wkt_geom
])

with mapchete.open(cleantopo_br.dict) as mp:
Expand Down

0 comments on commit af540d3

Please sign in to comment.