From 42d7e96839f7f5413221ca2b9feeb54bb5508350 Mon Sep 17 00:00:00 2001 From: Martin Landa Date: Sat, 29 Jun 2024 21:55:23 +0200 Subject: [PATCH 1/8] Enable installing grass addon by using gextension (#409) * lazy import * UI synced with QGIS * simplify UI * guidependencies added --- bin/grass/r.smoderp2d/r.smoderp2d.html | 14 +-- bin/grass/r.smoderp2d/r.smoderp2d.py | 127 +++++++++++++------------ 2 files changed, 70 insertions(+), 71 deletions(-) diff --git a/bin/grass/r.smoderp2d/r.smoderp2d.html b/bin/grass/r.smoderp2d/r.smoderp2d.html index 2a552f80c..b2840f195 100644 --- a/bin/grass/r.smoderp2d/r.smoderp2d.html +++ b/bin/grass/r.smoderp2d/r.smoderp2d.html @@ -5,24 +5,17 @@

DESCRIPTION

EXAMPLE

-

Nucice dataset

+

Create GRASS location and import sample dataset

 grass -c EPSG:5514 /tmp/smoderp2d-nucice --exec python3 tests/data/import_grass.py tests/data/nucice
 grass -c /tmp/smoderp2d-nucice/test
 
-

Rain simulation dataset

- -
-grass -c EPSG:5514 /tmp/smoderp2d-rainsim --exec python3 tests/data/import_grass.py tests/data/rain_sim
-grass -c /tmp/smoderp2d-rainsim/test
-
-

Perform computation

-./bin/grass/r.smoderp2d/r.smoderp2d.py \
+r.smoderp2d \
  elevation=dem@PERMANENT \
  soil=soils@PERMANENT \
  soil_type_fieldname=Soil \
@@ -43,8 +36,7 @@ 

SEE ALSO

r.watershed, - r.terraflow, - r.filldir + r.terraflow

REFERENCES

diff --git a/bin/grass/r.smoderp2d/r.smoderp2d.py b/bin/grass/r.smoderp2d/r.smoderp2d.py index eb3d03be0..f8418964e 100755 --- a/bin/grass/r.smoderp2d/r.smoderp2d.py +++ b/bin/grass/r.smoderp2d/r.smoderp2d.py @@ -5,7 +5,7 @@ # MODULE: r.smoderp2d # AUTHOR(S): Martin Landa and SMODERP2D development team # PURPOSE: Performs SMODERP2D soil erosion model. -# COPYRIGHT: (C) 2018-2023 by Martin Landa and Smoderp2d development team +# COPYRIGHT: (C) 2018-2024 by Martin Landa and Smoderp2d development team # # This program is free software under the GNU General Public # License (>=v3.0) and comes with ABSOLUTELY NO WARRANTY. @@ -24,125 +24,132 @@ # %end # %flag # % key: t -# % description: Export temporary data +# % description: Generate also temporary data +# % guisection: Advanced # %end # %option G_OPT_R_ELEV # % description: Input surface raster -# % guisection: Data preparation +# % guisection: Spatial data # %end # %option G_OPT_V_INPUT # % key: soil -# % label: Input soil polygon features -# % guisection: Data preparation +# % label: Soil polygons feature layer +# % guidependency: soil_type_fieldname +# % guisection: Spatial data # %end # %option G_OPT_DB_COLUMN # % key: soil_type_fieldname -# % description: Soil types +# % description: Field with the soil type identifier # % required: yes -# % guisection: Data preparation +# % guisection: Spatial data # %end # %option G_OPT_V_INPUT # % key: vegetation -# % label: Input land use polygon features -# % guisection: Data preparation +# % label: Landuse polygons feature layer +# % guidependency: vegetation_type_fieldname +# % guisection: Spatial data # %end # %option G_OPT_DB_COLUMN # % key: vegetation_type_fieldname -# % description: Land use types +# % description: Field with the landuse type identifier # % required: yes -# % guisection: Data preparation -# %end -# %option G_OPT_F_INPUT -# % key: rainfall_file -# % description: Rainfall file -# % guisection: Computation -# %end -# %option -# % key: maxdt -# % type: double -# % description: Max time step [sec] -# % answer: 30 -# % required: yes -# % guisection: Settings -# %end -# %option -# % key: end_time -# % type: double -# % description: Total running time [min] -# % answer: 5 -# % required: yes -# % guisection: Computation +# % guisection: Spatial data # %end # %option G_OPT_V_INPUT # % key: points -# % label: Input points features +# % label: Input points feature layer # % required: no -# % guisection: Data preparation +# % guidependency: points_fieldname +# % guisection: Spatial data # %end # %option G_OPT_DB_COLUMN # % key: points_fieldname # % description: Field with the input points idenfifier # % required: no -# % guisection: Settings +# % guisection: Spatial data +# %end +# %option G_OPT_V_INPUT +# % key: streams +# % label: Stream network feature layer +# % required: no +# % guisection: Spatial data +# %end +# %option G_OPT_F_INPUT +# % key: rainfall_file +# % description: Definition of the rainfall event +# % guisection: Spatial data # %end # %option G_OPT_DB_TABLE # % key: table_soil_vegetation -# % description: Table of soil and land use information -# % guisection: Settings +# % description: Soils and landuse parameters table +# % guidependency: table_soil_vegetation_fieldname +# % guisection: Model parameters # %end # %option G_OPT_DB_COLUMN # % key: table_soil_vegetation_fieldname -# % description: Soil land use code -# % guisection: Settings -# %end -# %option G_OPT_V_INPUT -# % key: streams -# % label: Reach feature -# % required: no -# % guisection: Data preparation +# % description: Field with the connection between landuse and soil +# % guisection: Model parameters # %end # %option G_OPT_DB_TABLE # % key: channel_properties_table -# % description: Reach shapes table -# % guisection: Settings +# % description: Channel properties table +# % guidependency: streams_channel_type_fieldname +# % guisection: Model parameters # %end # %option G_OPT_DB_COLUMN # % key: streams_channel_type_fieldname -# % description: Reach shape table code -# % guisection: Settings +# % description: Field with the channel type identifier +# % guisection: Model parameters +# %end +# %option G_OPT_M_DIR +# % key: output +# % description: Output directory +# % required: yes +# % guisection: Computation options +# %end +# %option +# % key: maxdt +# % type: double +# % description: Maximum time step [s] +# % answer: 30 +# % required: yes +# % guisection: Computation options +# %end +# %option +# % key: end_time +# % type: double +# % description: Total running time [min] +# % answer: 5 +# % required: yes +# % guisection: Computation options # %end # %option # % key: flow_direction # % description: Flow direction -# % guisection: Settings +# % guisection: Advanced # % options: single,multiple # % answer: single # %end # %option # % key: wave # % description: Wave type -# % guisection: Settings +# % guisection: Advanced # % options: kinematic,diffusion # % answer: kinematic # %end -# %option G_OPT_M_DIR -# % key: output -# % description: Name for output directory where to store results -# % required: yes -# %end import os import sys import grass.script as gs -from smoderp2d.runners.grass import GrassGisRunner -from smoderp2d.providers.base import WorkflowMode -from smoderp2d.exceptions import ProviderError, MaxIterationExceeded - if __name__ == "__main__": options, flags = gs.parser() options['generate_temporary'] = flags['t'] + from smoderp2d.runners.grass import GrassGisRunner + from smoderp2d.providers.base import WorkflowMode + from smoderp2d.exceptions import ProviderError, MaxIterationExceeded + try: runner = GrassGisRunner() runner.set_options(options) From d245cb2bc3d5f38e59a9c56f987f7cb6e801f9e6 Mon Sep 17 00:00:00 2001 From: Martin Landa Date: Sat, 29 Jun 2024 22:03:07 +0200 Subject: [PATCH 2/8] remove duplicated __version__ --- smoderp2d/runners/base.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/smoderp2d/runners/base.py b/smoderp2d/runners/base.py index ace9d79f3..7ae6c083e 100644 --- a/smoderp2d/runners/base.py +++ b/smoderp2d/runners/base.py @@ -8,8 +8,6 @@ from smoderp2d.providers.base.exceptions import DataPreparationInvalidInput from smoderp2d.exceptions import SmoderpError, ProviderError -__version__ = "2.0.dev" - class Runner(object): """Run SMODERP2D.""" From f9b14cacbb8fc75d8c834f5d8f46dfd622224d45 Mon Sep 17 00:00:00 2001 From: Martin Landa Date: Sat, 29 Jun 2024 22:06:19 +0200 Subject: [PATCH 3/8] 2.0.0rc2 -> 2.1.dev --- bin/qgis/smoderp2d-plugin/metadata.txt | 2 +- pyproject.toml | 4 ++-- smoderp2d/__init__.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/qgis/smoderp2d-plugin/metadata.txt b/bin/qgis/smoderp2d-plugin/metadata.txt index 43fb3c04e..7c8734f0a 100644 --- a/bin/qgis/smoderp2d-plugin/metadata.txt +++ b/bin/qgis/smoderp2d-plugin/metadata.txt @@ -6,7 +6,7 @@ name=SMODERP2D qgisMinimumVersion=3.28.10 description=This plugin calculates hydrological and erosion processes on individual plots or small catchments. -version=2.0.0rc2 +version=2.1.dev author=CTU email=petr.kavka@fsv.cvut.cz diff --git a/pyproject.toml b/pyproject.toml index b585382f4..c17aeba5d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,7 @@ build-backend = "setuptools.build_meta" [metadata] name = 'smoderp2d' -version = '2.0.0rc2' +version = '2.1.dev' [tool.setuptools.packages.find] where = [""] @@ -32,7 +32,7 @@ exclude = ["bin*", "utils*", "tests*"] [project] name = 'smoderp2d' -version = '2.0.0rc2' +version = '2.1.dev' description = 'Distributed event-based model for surface and subsurface runoff and erosion.' readme = 'README.md' authors = [ diff --git a/smoderp2d/__init__.py b/smoderp2d/__init__.py index 990897529..08202aee8 100644 --- a/smoderp2d/__init__.py +++ b/smoderp2d/__init__.py @@ -23,4 +23,4 @@ - no """ -__version__ = "2.0.0rc2" +__version__ = "2.1.dev" From 6491908cc73a35df711d695110c92b6541dd7e1e Mon Sep 17 00:00:00 2001 From: Martin Landa Date: Sat, 29 Jun 2024 22:26:15 +0200 Subject: [PATCH 4/8] .dockerignore added --- .dockerignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..8d107b0cc --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +./tests/data/ \ No newline at end of file From dc109ca77cf793c56c82b54a024be459bc4b9172 Mon Sep 17 00:00:00 2001 From: Martin Landa Date: Mon, 15 Jul 2024 15:40:45 +0200 Subject: [PATCH 5/8] fix QGIS plugin packaging --- .../patches/smoderp_2D_dockwidget.patch | 11 +++++------ bin/qgis/smoderp2d-plugin/pb_tool.cfg | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/bin/qgis/smoderp2d-plugin/patches/smoderp_2D_dockwidget.patch b/bin/qgis/smoderp2d-plugin/patches/smoderp_2D_dockwidget.patch index 46ff526d6..6ae4e7ef7 100644 --- a/bin/qgis/smoderp2d-plugin/patches/smoderp_2D_dockwidget.patch +++ b/bin/qgis/smoderp2d-plugin/patches/smoderp_2D_dockwidget.patch @@ -1,8 +1,8 @@ diff --git a/bin/qgis/smoderp2d-plugin/smoderp_2D_dockwidget.py b/bin/qgis/smoderp2d-plugin/smoderp_2D_dockwidget.py -index e751fcf3..92fed2c4 100644 +index 4cef0a8f..be86b6eb 100644 --- a/bin/qgis/smoderp2d-plugin/smoderp_2D_dockwidget.py +++ b/bin/qgis/smoderp2d-plugin/smoderp_2D_dockwidget.py -@@ -26,6 +26,7 @@ import os +@@ -27,6 +27,7 @@ import sys import glob import datetime import tempfile @@ -10,17 +10,16 @@ index e751fcf3..92fed2c4 100644 from pathlib import Path from PyQt5 import QtWidgets -@@ -41,11 +42,12 @@ from qgis.core import ( +@@ -43,10 +44,11 @@ from qgis.core import ( from qgis.utils import iface from qgis.gui import QgsMapLayerComboBox, QgsFieldComboBox +sys.path.insert(0, os.path.dirname(__file__)) from smoderp2d.runners.qgis import QGISRunner - from smoderp2d.core.general import Globals, GridGlobals from smoderp2d.providers import Logger - from smoderp2d.exceptions import ProviderError, ComputationAborted + from smoderp2d.exceptions import ProviderError, ComputationAborted, MaxIterationExceeded -from bin.base import arguments, sections +from base import arguments, sections - from .connect_grass import find_grass_bin from .custom_widgets import HistoryWidget + diff --git a/bin/qgis/smoderp2d-plugin/pb_tool.cfg b/bin/qgis/smoderp2d-plugin/pb_tool.cfg index cb91a06f8..1960bb8f4 100644 --- a/bin/qgis/smoderp2d-plugin/pb_tool.cfg +++ b/bin/qgis/smoderp2d-plugin/pb_tool.cfg @@ -17,7 +17,7 @@ plugin_path: [files] # Python files that should be deployed with the plugin -python_files: __init__.py smoderp_2D.py smoderp_2D_dockwidget.py connect_grass.py custom_widgets.py +python_files: __init__.py smoderp_2D.py smoderp_2D_dockwidget.py custom_widgets.py # The main dialog file that is loaded (not compiled) main_dialog: From a47c3b22f646f60b898f99f6ea4fb458cc1ba7ac Mon Sep 17 00:00:00 2001 From: Martin Landa Date: Sun, 1 Sep 2024 18:50:45 +0200 Subject: [PATCH 6/8] QGIS plugin: Update GRASS version check for new QGIS version (#416) --- bin/qgis/smoderp2d-plugin/scripts/build_package.sh | 3 +++ bin/qgis/smoderp2d-plugin/smoderp_2D_dockwidget.py | 3 ++- smoderp2d/providers/grass/__init__.py | 2 ++ smoderp2d/providers/grass/data_preparation.py | 10 ++++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/bin/qgis/smoderp2d-plugin/scripts/build_package.sh b/bin/qgis/smoderp2d-plugin/scripts/build_package.sh index ce47f3295..fd3395b6d 100755 --- a/bin/qgis/smoderp2d-plugin/scripts/build_package.sh +++ b/bin/qgis/smoderp2d-plugin/scripts/build_package.sh @@ -6,7 +6,10 @@ source $VENV/bin/activate script_dir=$(realpath $(dirname $0)) echo $script_dir +### install released SMODERP2D version pip3 install smoderp2d +### or from git +# (cd ../../.. ;pip3 install .) pv=$(python3 -V | cut -d' ' -f 2 | cut -d'.' -f 1,2) LIB=$VENV/lib/python$pv/site-packages diff --git a/bin/qgis/smoderp2d-plugin/smoderp_2D_dockwidget.py b/bin/qgis/smoderp2d-plugin/smoderp_2D_dockwidget.py index 4cef0a8f9..570c04c5e 100644 --- a/bin/qgis/smoderp2d-plugin/smoderp_2D_dockwidget.py +++ b/bin/qgis/smoderp2d-plugin/smoderp_2D_dockwidget.py @@ -79,7 +79,8 @@ def run(self): for line in islice(fin, 1, 2): if 'SMODERP2D patch applied' not in line: raise ImportError( - 'Your GRASS GIS installation needs to be fixed. Check the ' + 'There is a bug affecting the plugin functionality. Update QGIS to ' + 'version 3.34.10/3.38.2 or higher, or apply the fix manually. Check the ' 'documentation.' ) self.runner.create_location(QgsProject.instance().crs().authid()) diff --git a/smoderp2d/providers/grass/__init__.py b/smoderp2d/providers/grass/__init__.py index 8b1d015db..7a9e1b01d 100644 --- a/smoderp2d/providers/grass/__init__.py +++ b/smoderp2d/providers/grass/__init__.py @@ -111,6 +111,8 @@ def __init__(self, log_handler=GrassGisLogHandler): os.environ['GRASS_OVERWRITE'] = '1' # be quiet os.environ['GRASS_VERBOSE'] = '0' + # allow to run r.hydrodem also when compatibility test fails + os.environ['GRASS_COMPATIBILITY_TEST'] = '0' # define storage writer self.storage = GrassGisWriter() diff --git a/smoderp2d/providers/grass/data_preparation.py b/smoderp2d/providers/grass/data_preparation.py index f491d29ed..15e969c2b 100644 --- a/smoderp2d/providers/grass/data_preparation.py +++ b/smoderp2d/providers/grass/data_preparation.py @@ -32,9 +32,19 @@ def __init__(self, options, writer): super(PrepareData, self).__init__(writer) # install r.hydrodem if not available + install_ext = False ext = Module('g.extension', flags='a', stdout_=PIPE) list_ext = ext.outputs.stdout.splitlines() if 'r.hydrodem' not in list_ext: + install_ext = True + else: + # try to run the module + try: + Module("r.hydrodem", run_=False) + except Exception: + install_ext = True + if install_ext: + Logger.info("Installing r.hydrodem extension...") Module('g.extension', extension='r.hydrodem') def __del__(self): From bfd4626f1bbc62e73c20815a0ca724f00f435f3d Mon Sep 17 00:00:00 2001 From: Martin Landa Date: Sun, 1 Sep 2024 20:35:03 +0200 Subject: [PATCH 7/8] how to release added --- HowToRelease.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 HowToRelease.md diff --git a/HowToRelease.md b/HowToRelease.md new file mode 100644 index 000000000..f4b8a5852 --- /dev/null +++ b/HowToRelease.md @@ -0,0 +1,36 @@ +# How to release + +Update SMODERP2D version in: + +- `smoderp2d/__init__.py` +- `bin/qgis/smoderp2d-plugin/metadata.txt` +- `pyproject.toml` + +Checkout the version: + +``` +export SMODERP2D_VERSION= + +git checkout v$SMODERP2D_VERSION +``` + +Build the package: + +``` +pip3 wheel . +``` + +Upload package to PyPi: + +``` +python3 -m twine upload smoderp2d-${SMODERP2D_VERSION}-py3-none-any.whl +``` + +Build QGIS plugin: + +``` +(cd ./bin/qgis/smoderp2d-plugin/; ./scripts/build_package.sh) +``` + +Upload `bin/qgis/smoderp2d-plugin/zip_build/smoderp2d_plugin.zip` to +QGIS Plugin repository. From 09da730dc972db88c3fe6bc6dcd130cfb795e6f6 Mon Sep 17 00:00:00 2001 From: Martin Landa Date: Sun, 1 Sep 2024 20:36:59 +0200 Subject: [PATCH 8/8] pyproject header cosmetics --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c17aeba5d..c13c4bd88 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ -# Author(s): Petr Kavka, Karel Vrana -# Copyright (C) TODO +# Author(s): Petr Kavka and SMODERP2D Development Team +# Copyright (C) SMODERP2D Development Team # # This file is part of smoderp2d. #