From ab4935ba3533d473bfa84994b2c687897997b8e6 Mon Sep 17 00:00:00 2001 From: Julia Haas Date: Thu, 4 Jan 2024 11:49:14 +0100 Subject: [PATCH] changes for using gui --- Dockerfile | 2 +- .../r.trees.mlapply.worker.py | 4 +-- .../r.trees.postprocess.py | 27 ++++++++++--------- .../v.trees.param/v.trees.param.py | 5 ++-- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index ce02cee..5c45750 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ ENV GRASS_ADDON_BASE=/usr/local/grass84 # install external dependencies # RUN apt install musl-dev ?? -RUN pip3 install py7zr tqdm requests psutil scikit-learn pyproj +RUN pip3 install py7zr tqdm requests psutil scikit-learn pyproj pandas # install official addons RUN grass --tmp-location EPSG:4326 --exec g.extension r.mapcalc.tiled -s diff --git a/grass-gis-addons/m.analyse.trees/r.trees.mlapply.worker/r.trees.mlapply.worker.py b/grass-gis-addons/m.analyse.trees/r.trees.mlapply.worker/r.trees.mlapply.worker.py index 0dd22c2..6af1ed7 100644 --- a/grass-gis-addons/m.analyse.trees/r.trees.mlapply.worker/r.trees.mlapply.worker.py +++ b/grass-gis-addons/m.analyse.trees/r.trees.mlapply.worker/r.trees.mlapply.worker.py @@ -81,8 +81,8 @@ def main(): except Exception: grass.fatal("m.analyse.trees library is not installed") - area = options["area"] - group = options["group"] + area = options["area"].split("@")[0] + group = options["group"].split("@")[0] output = options["output"] model = options["model"] new_mapset = options["new_mapset"] diff --git a/grass-gis-addons/m.analyse.trees/r.trees.postprocess/r.trees.postprocess.py b/grass-gis-addons/m.analyse.trees/r.trees.postprocess/r.trees.postprocess.py index a21fc2c..4f1b4c0 100644 --- a/grass-gis-addons/m.analyse.trees/r.trees.postprocess/r.trees.postprocess.py +++ b/grass-gis-addons/m.analyse.trees/r.trees.postprocess/r.trees.postprocess.py @@ -228,6 +228,7 @@ def main(): blue = options["blue_raster"] nir = options["nir_raster"] ndvi = options["ndvi_raster"] + ndvi_split = ndvi.split('@')[0] ndwi = options["ndwi_raster"] ndgb = options["ndgb_raster"] ndsm = options["ndsm"] @@ -284,7 +285,7 @@ def main(): grass.run_command( "r.neighbors", input=ndvi, - output=f"{ndvi}_min1", + output=f"{ndvi_split}_min1", size=3, method="minimum", nprocs=nprocs, @@ -292,8 +293,8 @@ def main(): ) grass.run_command( "r.neighbors", - input=f"{ndvi}_min1", - output=f"{ndvi}_min2", + input=f"{ndvi_split}_min1", + output=f"{ndvi_split}_min2", size=3, method="minimum", nprocs=nprocs, @@ -301,8 +302,8 @@ def main(): ) grass.run_command( "r.neighbors", - input=f"{ndvi}_min2", - output=f"{ndvi}_max1", + input=f"{ndvi_split}_min2", + output=f"{ndvi_split}_max1", size=3, method="maximum", nprocs=nprocs, @@ -310,24 +311,24 @@ def main(): ) grass.run_command( "r.neighbors", - input=f"{ndvi}_max1", - output=f"{ndvi}_max2", + input=f"{ndvi_split}_max1", + output=f"{ndvi_split}_max2", size=3, method="maximum", nprocs=nprocs, memory=memory_max100mb, ) - rm_rasters.append(f"{ndvi}_min1") - rm_rasters.append(f"{ndvi}_min2") - rm_rasters.append(f"{ndvi}_max1") - rm_rasters.append(f"{ndvi}_max2") + rm_rasters.append(f"{ndvi_split}_min1") + rm_rasters.append(f"{ndvi_split}_min2") + rm_rasters.append(f"{ndvi_split}_max1") + rm_rasters.append(f"{ndvi_split}_max2") grass.mapcalc( f"trees_ml_nearest = if({tree_pixels} == 2, {nearest}, null())" ) rm_rasters.append("trees_ml_nearest") grass.mapcalc( - f"trees_ml_pixel_ndvi = if({ndvi}_max2 < {ndvi_threshold}, null(), trees_ml_nearest)" + f"trees_ml_pixel_ndvi = if({ndvi_split}_max2 < {ndvi_threshold}, null(), trees_ml_nearest)" ) rm_rasters.append("trees_ml_pixel_ndvi") @@ -441,7 +442,7 @@ def main(): grass.run_command( "r.stats.zonal", base="trees_ml_object_ndsm", - cover=f"{ndvi}_max2", + cover=f"{ndvi_split}_max2", method="average", output="trees_ml_object_ndviavg", ) diff --git a/grass-gis-addons/m.analyse.trees/v.trees.param/v.trees.param.py b/grass-gis-addons/m.analyse.trees/v.trees.param/v.trees.param.py index 6f01df4..2419abf 100644 --- a/grass-gis-addons/m.analyse.trees/v.trees.param/v.trees.param.py +++ b/grass-gis-addons/m.analyse.trees/v.trees.param/v.trees.param.py @@ -37,7 +37,7 @@ # %option G_OPT_R_INPUT # % key: ndom -# % label: Raster map of nDOM +# % label: Raster map of nDSM # % required: no # % guisection: Input # %end @@ -135,7 +135,7 @@ def main(): pid = os.getpid() - treecrowns = options["treecrowns"] + treecrowns = options["treecrowns"].split("@")[0] ndom = options["ndom"] ndvi = options["ndvi"] buildings = options["buildings"] @@ -289,6 +289,7 @@ def main(): if nprocs > 1: for subset_name, mapset_name in zip(subset_names, mapset_names): treecrown_subset_mapset.append(f"{subset_name}@{mapset_name}") + grass.message(len(mapset_names)) grass.run_command( "v.patch", input=treecrown_subset_mapset,