Skip to content

Commit

Permalink
update standard processes & associated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ungarj committed Mar 22, 2020
1 parent 6c8bddc commit ab22436
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 165 deletions.
42 changes: 20 additions & 22 deletions mapchete/processes/contours.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

def execute(
mp,
dem=None,
clip=None,
resampling="nearest",
interval=100,
field='elev',
Expand All @@ -19,17 +21,14 @@ def execute(
**kwargs
):
"""
Generate hillshade from DEM.
Generate contours from DEM.
Inputs
------
Parameters
----------
dem
Input DEM.
clip (optional)
Vector data used to clip output.
Parameters
----------
resampling : str (default: 'nearest')
Resampling used when reading from TileDirectory.
interval : integer
Expand Down Expand Up @@ -64,26 +63,25 @@ def execute(
list of GeoJSON-like features
"""
# read clip geometry
if "clip" in mp.params["input"]:
clip_geom = mp.open("clip").read()
if clip is None:
clip_geom = []
else:
clip_geom = clip.read()
if not clip_geom:
logger.debug("no clip data over tile")
return "empty"
else:
clip_geom = []

with mp.open("dem",) as dem:
logger.debug("reading input raster")
dem_data = dem.read(
resampling=resampling,
matching_method=td_matching_method,
matching_max_zoom=td_matching_max_zoom,
matching_precision=td_matching_precision,
fallback_to_higher_zoom=td_fallback_to_higher_zoom
)
if dem_data.mask.all():
logger.debug("raster empty")
return "empty"
logger.debug("reading input raster")
dem_data = dem.read(
resampling=resampling,
matching_method=td_matching_method,
matching_max_zoom=td_matching_max_zoom,
matching_precision=td_matching_precision,
fallback_to_higher_zoom=td_fallback_to_higher_zoom
)
if dem_data.mask.all():
logger.debug("raster empty")
return "empty"

logger.debug("calculate hillshade")
contours = mp.contours(
Expand Down
42 changes: 20 additions & 22 deletions mapchete/processes/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

def execute(
mp,
raster=None,
clip=None,
resampling="nearest",
band_indexes=None,
td_matching_method="gdal",
Expand All @@ -21,15 +23,12 @@ def execute(
"""
Convert and optionally clip input raster data.
Inputs
------
Parameters
----------
raster
Singleband or multiband data input.
clip (optional)
Vector data used to clip output.
Parameters
----------
resampling : str (default: 'nearest')
Resampling used when reading from TileDirectory.
band_indexes : list
Expand Down Expand Up @@ -66,27 +65,26 @@ def execute(
np.ndarray
"""
# read clip geometry
if "clip" in mp.params["input"]:
clip_geom = mp.open("clip").read()
if clip is None:
clip_geom = []
else:
clip_geom = clip.read()
if not clip_geom:
logger.debug("no clip data over tile")
return "empty"
else:
clip_geom = []

with mp.open("raster",) as raster:
logger.debug("reading input raster")
raster_data = raster.read(
indexes=band_indexes,
resampling=resampling,
matching_method=td_matching_method,
matching_max_zoom=td_matching_max_zoom,
matching_precision=td_matching_precision,
fallback_to_higher_zoom=td_fallback_to_higher_zoom
)
if raster_data.mask.all():
logger.debug("raster empty")
return "empty"
logger.debug("reading input raster")
raster_data = raster.read(
indexes=band_indexes,
resampling=resampling,
matching_method=td_matching_method,
matching_max_zoom=td_matching_max_zoom,
matching_precision=td_matching_precision,
fallback_to_higher_zoom=td_fallback_to_higher_zoom
)
if raster_data.mask.all():
logger.debug("raster empty")
return "empty"

if scale_offset != 0.:
logger.debug("apply scale offset %s", scale_offset)
Expand Down
42 changes: 20 additions & 22 deletions mapchete/processes/hillshade.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

def execute(
mp,
dem=None,
clip=None,
resampling="nearest",
azimuth=315.0,
altitude=45.0,
Expand All @@ -18,17 +20,14 @@ def execute(
**kwargs
):
"""
Extract contour lines from DEM.
Calculate hillshade from DEM.
Inputs
------
Parameters
----------
dem
Input DEM.
clip (optional)
Vector data used to clip output.
Parameters
----------
resampling : str (default: 'nearest')
Resampling used when reading from TileDirectory.
azimuth : float
Expand Down Expand Up @@ -66,26 +65,25 @@ def execute(
np.ndarray
"""
# read clip geometry
if "clip" in mp.params["input"]:
clip_geom = mp.open("clip").read()
if clip is None:
clip_geom = []
else:
clip_geom = clip.read()
if not clip_geom:
logger.debug("no clip data over tile")
return "empty"
else:
clip_geom = []

with mp.open("dem",) as dem:
logger.debug("reading input raster")
dem_data = dem.read(
resampling=resampling,
matching_method=td_matching_method,
matching_max_zoom=td_matching_max_zoom,
matching_precision=td_matching_precision,
fallback_to_higher_zoom=td_fallback_to_higher_zoom
)
if dem_data.mask.all():
logger.debug("raster empty")
return "empty"
logger.debug("reading input DEM")
dem_data = dem.read(
resampling=resampling,
matching_method=td_matching_method,
matching_max_zoom=td_matching_max_zoom,
matching_precision=td_matching_precision,
fallback_to_higher_zoom=td_fallback_to_higher_zoom
)
if dem_data.mask.all():
logger.debug("raster empty")
return "empty"

logger.debug("calculate hillshade")
hillshade = mp.hillshade(
Expand Down
13 changes: 13 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ def cleantopo_tl_tif():
return os.path.join(TESTDATA_DIR, "cleantopo_tl.tif")


@pytest.fixture
def cleantopo_landpoly_tif():
"""Fixture for cleantopo_landpoly.tif"""
return os.path.join(TESTDATA_DIR, "cleantopo_landpoly.tif")


@pytest.fixture
def dummy1_3857_tif():
"""Fixture for dummy1_3857.tif"""
Expand Down Expand Up @@ -309,6 +315,13 @@ def dem_to_hillshade():
return ExampleConfig(path=path, dict=_dict_from_mapchete(path))


@pytest.fixture
def dem_to_contours():
"""Fixture for dem_to_contours.mapchete."""
path = os.path.join(TESTDATA_DIR, "dem_to_contours.mapchete")
return ExampleConfig(path=path, dict=_dict_from_mapchete(path))


@pytest.fixture
def files_bounds():
"""Fixture for files_bounds.mapchete."""
Expand Down
Loading

0 comments on commit ab22436

Please sign in to comment.