diff --git a/dem_blender.py b/dem_blender.py deleted file mode 100644 index 9d6bcf8..0000000 --- a/dem_blender.py +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env python3 -# Authors: Piero Toffanin, Stephen Mather -# License: AGPLv3 - -import os -import glob -import sys -sys.path.insert(0, os.path.join("..", "..", os.path.dirname(__file__))) - -import argparse -import multiprocessing -import merge - -parser = argparse.ArgumentParser(description='Merge and blend DEMs using OpenDroneMap\'s approach.') -parser.add_argument('input_dems', - type=str, - help='Path to input dems (.tif)') - -args = parser.parse_args() - -if not os.path.exists(args.input_dems): - print("%s does not exist" % args.input_dems) - exit(1) - -output_dem = os.path.join(args.input_dems, 'merged_blended_dem.tif') -input_dem_path = os.path.join(args.input_dems, '*.tif') -input_dems = glob.glob(input_dem_path) - -merge.euclidean_merge_dems(input_dems - ,output_dem=output_dem - ) diff --git a/dem_blender/__init__.py b/dem_blender/__init__.py new file mode 100644 index 0000000..cc4660f --- /dev/null +++ b/dem_blender/__init__.py @@ -0,0 +1,11 @@ +"""DEM Blender. Seamless merging of Digital Terrain Models with overlap from different sources.""" + +__version__ = "0.1.0" + +from .cli import * +from . import dem_blender + +__all__ = [ + "dem_blender", + "cli" +] diff --git a/arghelpers.py b/dem_blender/arghelpers.py similarity index 100% rename from arghelpers.py rename to dem_blender/arghelpers.py diff --git a/dem_blender/cli/__init__.py b/dem_blender/cli/__init__.py new file mode 100644 index 0000000..c6a7b5b --- /dev/null +++ b/dem_blender/cli/__init__.py @@ -0,0 +1 @@ +"""DEM blender command-line interface.""" diff --git a/dem_blender/cli/main.py b/dem_blender/cli/main.py new file mode 100644 index 0000000..688ba07 --- /dev/null +++ b/dem_blender/cli/main.py @@ -0,0 +1,40 @@ +import click +from pathlib import Path +from dem_blender import dem_blender + +def print_info(ctx, param, value): + if not value: + return {} + click.echo(f"DEM Blender, Copyright Localdevices, OpenDroneMap.org") + ctx.exit() + +def print_license(ctx, param, value): + if not value: + return {} + click.echo(f"GNU Affero General Public License v3 (AGPLv3). See https://www.gnu.org/licenses/agpl-3.0.en.html") + ctx.exit() + +path_opt = click.option( + "-p", + "--path", + type=click.Path(exists=True, resolve_path=True, dir_okay=True, file_okay=False), + help="Path to directory containing terrain models", + # callback=validate_files_in_dir, # TODO: write a validator that confirms that all files in folder are valid geospatial raster files + required=True +) + +@click.command() +@click.argument( + 'OUTPUT', + type=click.Path(resolve_path=True, dir_okay=False, file_okay=True), + required=True +) +@path_opt +def merge( + output: Path, + path: Path, +): + """Single CLI command for blending terrain models.""" + print(f"Input path: {path}") + print(f"Output path file: {output}") + raise NotImplementedError \ No newline at end of file diff --git a/dem_blender/dem_blender.py b/dem_blender/dem_blender.py new file mode 100644 index 0000000..461a634 --- /dev/null +++ b/dem_blender/dem_blender.py @@ -0,0 +1,30 @@ +"""Main API to DEM blender.""" +import os +import glob +import sys +sys.path.insert(0, os.path.join("..", "..", os.path.dirname(__file__))) + +import argparse +import merge + +# TODO: modify to API callend from click interface + +###### +# parser = argparse.ArgumentParser(description='Merge and blend DEMs using OpenDroneMap\'s approach.') +# parser.add_argument('input_dems', +# type=str, +# help='Path to input dems (.tif)') +# +# args = parser.parse_args() + +# if not os.path.exists(args.input_dems): +# print("%s does not exist" % args.input_dems) +# exit(1) + +# output_dem = os.path.join(args.input_dems, 'merged_blended_dem.tif') +# input_dem_path = os.path.join(args.input_dems, '*.tif') +# input_dems = glob.glob(input_dem_path) +# +# merge.euclidean_merge_dems(input_dems +# ,output_dem=output_dem +# ) diff --git a/euclid.py b/dem_blender/euclid.py similarity index 100% rename from euclid.py rename to dem_blender/euclid.py diff --git a/gdal_fillnodata.py b/dem_blender/gdal_fillnodata.py similarity index 100% rename from gdal_fillnodata.py rename to dem_blender/gdal_fillnodata.py diff --git a/log.py b/dem_blender/log.py similarity index 100% rename from log.py rename to dem_blender/log.py diff --git a/merge.py b/dem_blender/merge.py similarity index 100% rename from merge.py rename to dem_blender/merge.py diff --git a/odm_system.py b/dem_blender/odm_system.py similarity index 100% rename from odm_system.py rename to dem_blender/odm_system.py diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..792015d --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,82 @@ +[build-system] +requires = ["flit_core >=3.4.0,<4"] +build-backend = "flit_core.buildapi" + +[project] +name = "dem_blender" +authors = [ + { name = "Stephen Mather", email = "stephen.mather@opendronemap.org" }, +] +packages = [ + { include = "dem_blender" } +] + +dependencies = [ + "click", + "numpy", + "scipy", + "rasterio>=1.3.11", + "python-dateutil", + "joblib" +] + +requires-python =">=3.9" +readme = "README.md" +classifiers = [ + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Intended Audience :: Science/Research", + "Topic :: Scientific/Engineering :: Hydrology", + "Topic :: Scientific/Engineering :: Image Processing", + "License :: OSI Approved :: GNU Affero General Public License v3", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11" +] +dynamic = ['version', 'description'] + +[project.optional-dependencies] +extra = [ + "matplotlib", + "notebook" +] +test = [ + "pytest", + "pytest-cov", +] + +full = ["dem_blender[extra,test]"] + +[project.scripts] +dem_blender = "dem_blender.cli.main:merge" + +[project.urls] +Source = "https://github.com/localdevices/dem_blender" + +[tool.flit.sdist] +include = ["dem_blender"] + +[tool.flit.module] +name = "dem_blender" + +[tool.pytest.ini_options] +addopts = "--ff " +testpaths = ["tests"] +filterwarnings = [ +] + +# [tool.ruff] +# line-length = 120 +# target-version = "py39" +# exclude = ["docs"] +# +# [tool.ruff.lint] +# # enable pydocstyle (E), pyflake (F) and isort (I), pytest-style (PT), bugbear (B) +# select = ["E", "F", "I", "PT", "D", "B", "ICN", "TID"] +# ignore = ["D211", "D213", "D206", "E741", "D105", "D203", "E712", "B904"] # "E501" line length +# +# [tool.ruff.lint.per-file-ignores] +# "tests/**" = ["D100", "D101", "D102", "D103", "D104"] +# "pivnumba/__init__.py" = ["E402", "F401", "F403"] +# "tests/conftest.py" = ["E402"] diff --git a/requirements.txt b/requirements.txt index 0034c7b..b57db24 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ -dateutil numpy scipy rasterio>=1.3.11 +python-dateutil joblib # osgeo # gdal