From 4c1d5c16d738284408b8710a79a26722ef595359 Mon Sep 17 00:00:00 2001 From: Paula Date: Tue, 10 Nov 2026 16:22:58 +0100 Subject: [PATCH 1/6] in2TopoHyd and simulation results are named as the XSECT shp file --- debrisframe/in1Utils/fileUtils.py | 17 ++++++++++++++++- debrisframe/in2TopoHyd/in2TopoHyd.py | 10 +++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/debrisframe/in1Utils/fileUtils.py b/debrisframe/in1Utils/fileUtils.py index 30cec7a..6b6063d 100644 --- a/debrisframe/in1Utils/fileUtils.py +++ b/debrisframe/in1Utils/fileUtils.py @@ -7,6 +7,8 @@ import logging import pandas as pd +from avaframe.in1Data import getInput as gI + log = logging.getLogger("avaframe.debrisframe.in1Utils.fileUtils") @@ -23,7 +25,17 @@ def copyHydrToInput(debrisDir): debrisDir = pathlib.Path(debrisDir) - outputFile = debrisDir / "Outputs" / "in2TopoHyd" / "initCondHyd.csv" + # in2TopoHyd names its output csv-file after the release-line shapefile in Inputs/XSECT + xsectFile, *_ = gI.getAndCheckInputFiles( + inputDir=debrisDir / "Inputs", folder="XSECT", inputType="Release line" + ) + if xsectFile is None: + message = "No Release line shp-file in Inputs/XSECT!" + log.error(message) + raise FileNotFoundError(message) + outputName = pathlib.Path(xsectFile).stem + + outputFile = debrisDir / "Outputs" / "in2TopoHyd" / f"{outputName}.csv" inputsDir = debrisDir / "Inputs" / "REL" inputsDir.mkdir(parents=True, exist_ok=True) @@ -31,6 +43,9 @@ def copyHydrToInput(debrisDir): if not inputsHydFile.exists(): shutil.copy2(outputFile, inputsHydFile) + log.info( + f"c1TIF simulation input file derived from debris-flow hydrograph is saved to {inputsHydFile}.csv" + ) else: outputFileDF = pd.read_csv(outputFile) inputsHydFileDF = pd.read_csv(inputsHydFile) diff --git a/debrisframe/in2TopoHyd/in2TopoHyd.py b/debrisframe/in2TopoHyd/in2TopoHyd.py index fbe5e03..b3b0abc 100644 --- a/debrisframe/in2TopoHyd/in2TopoHyd.py +++ b/debrisframe/in2TopoHyd/in2TopoHyd.py @@ -805,6 +805,8 @@ def getInputShapeFiles(inputDir, folder, fileType, dem, idField=None): shapeFile["ID"] = fieldValues + shapeFile["fname"] = pathlib.Path(fname) + log.info(f"{fileType} used: {fname}") return shapeFile @@ -1018,4 +1020,10 @@ def in2TopoHydMain(debrisDir, topoHydCfg, debrisCfg): } ) - output.to_csv(outputDir / "initCondHyd.csv", sep=",", decimal=".", header=True, index=False) + # name the output file after the release-line shapefile in Inputs/XSECT + outputName = releaseLine["fname"].stem + + output.to_csv(outputDir / f"{outputName}.csv", sep=",", decimal=".", header=True, index=False) + + log.info( + f"c1TIF simulation input file derived from debris-flow hydrograph is saved to {outputDir}/{outputName}.csv") From 3a3cf711e6f846b38240540203a989e8afa7187f Mon Sep 17 00:00:00 2001 From: Paula Date: Tue, 10 Nov 2026 16:26:07 +0100 Subject: [PATCH 2/6] formatting --- debrisframe/in2TopoHyd/in2TopoHyd.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/debrisframe/in2TopoHyd/in2TopoHyd.py b/debrisframe/in2TopoHyd/in2TopoHyd.py index b3b0abc..df7609d 100644 --- a/debrisframe/in2TopoHyd/in2TopoHyd.py +++ b/debrisframe/in2TopoHyd/in2TopoHyd.py @@ -1026,4 +1026,5 @@ def in2TopoHydMain(debrisDir, topoHydCfg, debrisCfg): output.to_csv(outputDir / f"{outputName}.csv", sep=",", decimal=".", header=True, index=False) log.info( - f"c1TIF simulation input file derived from debris-flow hydrograph is saved to {outputDir}/{outputName}.csv") + f"c1TIF simulation input file derived from debris-flow hydrograph is saved to {outputDir}/{outputName}.csv" + ) From e5eb957b12c41052590a7de468ca6356216f245b Mon Sep 17 00:00:00 2001 From: Paula Date: Tue, 10 Nov 2026 16:42:10 +0100 Subject: [PATCH 3/6] adapt test --- debrisframe/tests/test_fileUtils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/debrisframe/tests/test_fileUtils.py b/debrisframe/tests/test_fileUtils.py index 9e64c4c..fdecf49 100644 --- a/debrisframe/tests/test_fileUtils.py +++ b/debrisframe/tests/test_fileUtils.py @@ -16,8 +16,12 @@ def _writeHydFile(path, flowArea): def test_copyHydrToInput_doesNotOverwriteConsistentFile(tmp_path): """Check that an already consistent Inputs/REL hydrograph is left untouched.""" debrisDir = tmp_path / "avaDir" - outputFile = debrisDir / "Outputs" / "in2TopoHyd" / "initCondHyd.csv" - inputsHydFile = debrisDir / "Inputs" / "REL" / "initCondHyd.csv" + # in2TopoHyd output is named after the release-line shapefile in Inputs/XSECT + xsectFile = debrisDir / "Inputs" / "XSECT" / "crossSection.shp" + outputFile = debrisDir / "Outputs" / "in2TopoHyd" / "crossSection.csv" + inputsHydFile = debrisDir / "Inputs" / "REL" / "crossSection.csv" + xsectFile.parent.mkdir(parents=True) + xsectFile.touch() outputFile.parent.mkdir(parents=True) inputsHydFile.parent.mkdir(parents=True) From 4ae960bddeb7682a46c18477fe1ccda3d5eb8bc9 Mon Sep 17 00:00:00 2001 From: Paula Date: Tue, 10 Nov 2026 16:50:42 +0100 Subject: [PATCH 4/6] update docu --- debrisframe/in1Utils/fileUtils.py | 2 +- docs/source/moduleIn2TopoHyd.rst | 10 +++++----- docs/source/workflow.rst | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/debrisframe/in1Utils/fileUtils.py b/debrisframe/in1Utils/fileUtils.py index 6b6063d..d13c95f 100644 --- a/debrisframe/in1Utils/fileUtils.py +++ b/debrisframe/in1Utils/fileUtils.py @@ -44,7 +44,7 @@ def copyHydrToInput(debrisDir): if not inputsHydFile.exists(): shutil.copy2(outputFile, inputsHydFile) log.info( - f"c1TIF simulation input file derived from debris-flow hydrograph is saved to {inputsHydFile}.csv" + f"c1TIF simulation input file derived from debris-flow hydrograph is saved to {inputsHydFile}" ) else: outputFileDF = pd.read_csv(outputFile) diff --git a/docs/source/moduleIn2TopoHyd.rst b/docs/source/moduleIn2TopoHyd.rst index 2978637..8ca8fe7 100644 --- a/docs/source/moduleIn2TopoHyd.rst +++ b/docs/source/moduleIn2TopoHyd.rst @@ -137,11 +137,11 @@ folder structure described below. DEM raster file HYDR/ - hydrograph csv-file LEVEE/ - levee points - XSECT/ - release line + XSECT/ - cross section line Outputs/ in2TopoHyd/ - initCondHyd.csv - crossSectionCells.csv (optional) + .csv (named after the XSECT shapefile) + crossSectionCells.csv (optional) Plots/ crossSection.png ratingCurve.png @@ -217,7 +217,7 @@ Output Initial hydraulic conditions ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -The main output is ``initCondHyd.csv``. +The main output is ``.csv``, named same as the release-line shapefile in ``Inputs/XSECT`` For every wet cross-section cell and hydrograph timestep, the file contains: @@ -277,4 +277,4 @@ To run The complete workflow reads the DEM and release information, generates the release cross section, calculates the rating curve, -derives the hydraulic conditions from the discharge hydrograph and writes the resulting initial conditions to ``Outputs/in2TopoHyd/initCondHyd.csv``. +derives the hydraulic conditions from the discharge hydrograph and writes the resulting initial conditions to ``Outputs/in2TopoHyd/.csv``. diff --git a/docs/source/workflow.rst b/docs/source/workflow.rst index 2a8b308..a2624bf 100644 --- a/docs/source/workflow.rst +++ b/docs/source/workflow.rst @@ -51,7 +51,7 @@ Inputs: .. note:: - The ``initCondHyd.csv`` produced by the Hydrograph Starting Condition (in2TopoHyd) tool can be + The ``.csv`` (named after the ``XSECT`` shapefile) produced by the Hydrograph Starting Condition (in2TopoHyd) tool can be used here as the time dependent release input. * ``Secondary release layer`` (optional) - only one is allowed. @@ -73,7 +73,7 @@ Computes the initial conditions at a release line via module :py:mod:`in2TopoHyd .. note:: - The resulting ``initCondHyd.csv`` can be used as the time dependent release input + The resulting ``.csv`` (named after the ``XSECT`` shapefile) can be used as the time dependent release input (``Time dependent release values / release geometry``) for the Thickness integrated flow (c1) tool. Inputs: From f49db469503e40ec4d82d8fe6c73f90bf0dbd63e Mon Sep 17 00:00:00 2001 From: Paula Date: Wed, 11 Nov 2026 13:38:50 +0100 Subject: [PATCH 5/6] add crossSectionName to plot file name --- debrisframe/in1Utils/plotUtils.py | 12 ++++++++---- debrisframe/in2TopoHyd/in2TopoHyd.py | 11 ++++++----- debrisframe/tests/test_plotUtils.py | 4 ++-- docs/source/moduleIn2TopoHyd.rst | 8 ++++---- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/debrisframe/in1Utils/plotUtils.py b/debrisframe/in1Utils/plotUtils.py index b380242..1a6e879 100644 --- a/debrisframe/in1Utils/plotUtils.py +++ b/debrisframe/in1Utils/plotUtils.py @@ -9,7 +9,7 @@ import avaframe.in3Utils.fileHandlerUtils as fU -def plotCrossSection(crossSection, outputDir): +def plotCrossSection(crossSection, outputDir, outputName): """ This function plots the terrain cross section @@ -21,6 +21,8 @@ def plotCrossSection(crossSection, outputDir): the path along (distance) along the cross-section cells outputDir: str or Path path to output directory of in2TopoHyd module + outputName: str + name of the cross section-line shapefile, used as prefix of the plot name Returns -------- @@ -45,10 +47,10 @@ def plotCrossSection(crossSection, outputDir): path = outputDir / "Plots" fU.makeADir(path) - fig.savefig(path / "crossSection.png") + fig.savefig(path / f"{outputName}_crossSection.png") -def plotRatingCurve(ratingCurve, crossSection, outputDir): +def plotRatingCurve(ratingCurve, crossSection, outputDir, outputName): """ This function plots the terrain cross section and the corresponding rating curve @@ -65,6 +67,8 @@ def plotRatingCurve(ratingCurve, crossSection, outputDir): the path along (distance) along the cross-section cells outputDir: str or Path path to output directory of in2TopoHyd module + outputName: str + name of the cross section-line shapefile, used as prefix of the plot name Returns -------- @@ -109,4 +113,4 @@ def plotRatingCurve(ratingCurve, crossSection, outputDir): path = outputDir / "Plots" fU.makeADir(path) - fig.savefig(path / "ratingCurve.png") + fig.savefig(path / f"{outputName}_ratingCurve.png") diff --git a/debrisframe/in2TopoHyd/in2TopoHyd.py b/debrisframe/in2TopoHyd/in2TopoHyd.py index df7609d..00fb6ac 100644 --- a/debrisframe/in2TopoHyd/in2TopoHyd.py +++ b/debrisframe/in2TopoHyd/in2TopoHyd.py @@ -936,6 +936,8 @@ def in2TopoHydMain(debrisDir, topoHydCfg, debrisCfg): leveePoints = getInputShapeFiles( inputDir=inputDir, folder="LEVEE", fileType="Levee points", dem=dem, idField=None ) + # output files are named after the release-line shapefile in Inputs/XSECT + outputName = releaseLine["fname"].stem # +++ 2. get all cells along the release line log.info("Get all cells along the release line") @@ -956,7 +958,7 @@ def in2TopoHydMain(debrisDir, topoHydCfg, debrisCfg): path = outputDir / "crossSectionCells.csv" file.to_csv(path, sep=",", decimal=".", header=True, index=False) - pltUtls.plotCrossSection(crossSection=crossSection, outputDir=outputDir) + pltUtls.plotCrossSection(crossSection=crossSection, outputDir=outputDir, outputName=outputName) # +++ 4. calculate hydraulic boundary conditions log.info("Calculate hydraulic boundary conditions") @@ -965,7 +967,9 @@ def in2TopoHydMain(debrisDir, topoHydCfg, debrisCfg): ratingCurve = computeRatingCurve(crossSection, topoHydCfg) # plot cross section and rating curve for plausibility check - pltUtls.plotRatingCurve(ratingCurve=ratingCurve, crossSection=crossSection, outputDir=outputDir) + pltUtls.plotRatingCurve( + ratingCurve=ratingCurve, crossSection=crossSection, outputDir=outputDir, outputName=outputName + ) # get hydrograph data hydrograph = getHydrograph(inputDir) @@ -1020,9 +1024,6 @@ def in2TopoHydMain(debrisDir, topoHydCfg, debrisCfg): } ) - # name the output file after the release-line shapefile in Inputs/XSECT - outputName = releaseLine["fname"].stem - output.to_csv(outputDir / f"{outputName}.csv", sep=",", decimal=".", header=True, index=False) log.info( diff --git a/debrisframe/tests/test_plotUtils.py b/debrisframe/tests/test_plotUtils.py index 219c504..0e2884e 100644 --- a/debrisframe/tests/test_plotUtils.py +++ b/debrisframe/tests/test_plotUtils.py @@ -23,6 +23,6 @@ def test_plotRatingCurve_createsPlotsDirectory(tmp_path): "elevLevee": np.array([5.0, 5.0]), } - plotUtils.plotRatingCurve(ratingCurve, crossSection, tmp_path) + plotUtils.plotRatingCurve(ratingCurve, crossSection, tmp_path, "crossSection") - assert (tmp_path / "Plots" / "ratingCurve.png").is_file() + assert (tmp_path / "Plots" / "crossSection_ratingCurve.png").is_file() diff --git a/docs/source/moduleIn2TopoHyd.rst b/docs/source/moduleIn2TopoHyd.rst index 8ca8fe7..9f64804 100644 --- a/docs/source/moduleIn2TopoHyd.rst +++ b/docs/source/moduleIn2TopoHyd.rst @@ -143,8 +143,8 @@ folder structure described below. .csv (named after the XSECT shapefile) crossSectionCells.csv (optional) Plots/ - crossSection.png - ratingCurve.png + _crossSection.png + _ratingCurve.png Work/ @@ -249,11 +249,11 @@ Plots Two plots are generated for plausibility checks. -* ``crossSection.png`` +* ``_crossSection.png`` Shows the terrain elevation along the release cross section and the location of the levee points. -* ``ratingCurve.png`` +* ``_ratingCurve.png`` Contains both the terrain cross section with the calculated flow-surface elevation steps and the resulting relationship between flow thickness and flow area. From 971d67701568d7d77add93e0a5c8e6262f188bbf Mon Sep 17 00:00:00 2001 From: Paula Date: Wed, 11 Nov 2026 13:55:47 +0100 Subject: [PATCH 6/6] rename cross section csv --- debrisframe/in2TopoHyd/in2TopoHyd.py | 2 +- docs/source/moduleIn2TopoHyd.rst | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/debrisframe/in2TopoHyd/in2TopoHyd.py b/debrisframe/in2TopoHyd/in2TopoHyd.py index 00fb6ac..7177460 100644 --- a/debrisframe/in2TopoHyd/in2TopoHyd.py +++ b/debrisframe/in2TopoHyd/in2TopoHyd.py @@ -955,7 +955,7 @@ def in2TopoHydMain(debrisDir, topoHydCfg, debrisCfg): file = pd.DataFrame( {"x": crossSection["x"], "y": crossSection["y"], "elev": crossSection["elevation"]} ) - path = outputDir / "crossSectionCells.csv" + path = outputDir / f"{outputName}_crossSectionCells.csv" file.to_csv(path, sep=",", decimal=".", header=True, index=False) pltUtls.plotCrossSection(crossSection=crossSection, outputDir=outputDir, outputName=outputName) diff --git a/docs/source/moduleIn2TopoHyd.rst b/docs/source/moduleIn2TopoHyd.rst index 9f64804..74412e1 100644 --- a/docs/source/moduleIn2TopoHyd.rst +++ b/docs/source/moduleIn2TopoHyd.rst @@ -141,7 +141,7 @@ folder structure described below. Outputs/ in2TopoHyd/ .csv (named after the XSECT shapefile) - crossSectionCells.csv (optional) + _crossSectionCells.csv (optional) Plots/ _crossSection.png _ratingCurve.png @@ -234,7 +234,7 @@ The file therefore provides spatially distributed hydraulic initial conditions a Cross-section cells ^^^^^^^^^^^^^^^^^^^ -If ``exportCrossSectionCells = True``, the module additionally writes ``crossSectionCells.csv``. +If ``exportCrossSectionCells = True``, the module additionally writes ``_crossSectionCells.csv``. The file contains: