debrisframe 0.1a6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
File without changes
@@ -0,0 +1,52 @@
1
+ """
2
+ Debris flow overrides for com1DFA
3
+ """
4
+
5
+ # Load modules
6
+ import logging
7
+
8
+
9
+ # Local imports
10
+ from avaframe.in3Utils import cfgUtils
11
+ from avaframe.in3Utils import cfgHandling
12
+ from avaframe.com1DFA import com1DFA
13
+
14
+ # create local logger under avaframe namespace to use its logging configuration
15
+ log = logging.getLogger("avaframe.debrisframe.c1TIF")
16
+
17
+
18
+ def c1TIFMain(cfgMain, debrisCfg):
19
+ """Run and adjust parameters to match debris flow settings for com1DFA run,
20
+ result files, reports and plots are saved analog to a standard com1DFA model run
21
+
22
+ Parameters
23
+ -----------
24
+ cfgMain: configparser object
25
+ main DebrisFrame settings
26
+ debrisCfg: configparser object
27
+ configuration settings for debris flow including com1DFA override parameters
28
+
29
+ """
30
+
31
+ # ++++++++++ set configurations for com1DFA and override ++++++++++++
32
+ # get comDFA configuration and update with debris flow parameter set
33
+ com1DFACfg = cfgUtils.getModuleConfig(
34
+ com1DFA,
35
+ fileOverride="",
36
+ modInfo=False,
37
+ toPrint=False,
38
+ onlyDefault=debrisCfg["com1DFA_com1DFA_override"].getboolean("defaultConfig"),
39
+ )
40
+ com1DFACfg, debrisCfg = cfgHandling.applyCfgOverride(
41
+ com1DFACfg, debrisCfg, com1DFA, addModValues=False
42
+ )
43
+
44
+ # run the com1DFA module with debris flow settings
45
+ dem, plotDict, reportDictList, simDF = com1DFA.com1DFAMain(
46
+ cfgMain, cfgInfo=com1DFACfg
47
+ )
48
+
49
+ # print info about simulation performed to log
50
+ log.info("Com1DFA run performed with debris flow settings")
51
+
52
+ return dem, plotDict, reportDictList, simDF
@@ -0,0 +1,186 @@
1
+ ### Config File - This file contains the main settings for the debris flow simulation run
2
+ ## Copy to local_c1TIFCfg.ini and set your parameters
3
+
4
+
5
+ [GENERAL]
6
+
7
+ # if inputHydrograph is True, the in2TopoHyd module is computed before the c1TIF computation
8
+ # Hydrograph input data need to be provided and the flag timeDependentRelease needs to be set to TRue
9
+ inputHydrograph = False
10
+
11
+
12
+ [com1DFA_com1DFA_override]
13
+
14
+ #####
15
+ # PLEASE NOTE: these settings are untested and highly experimental. Use with caution!
16
+ #####
17
+
18
+ # use default com1DFA config as base configuration (True) and override following parameters
19
+ # if False and local_com1DFACfg is available use local
20
+ defaultConfig = True
21
+
22
+ #++++++++++++++++ Simulation type
23
+ # list of simulations that shall be performed (null, ent, res, entres, available (use all available input data))
24
+ simTypeList = available
25
+ # model type - only for file naming (dfa - dense flow avalanche)
26
+ modelType = dfa
27
+
28
+ #+++++++++++++ Output++++++++++++
29
+ # desired result Parameters (ppr, pft, pfv, pta, FT, FV, P, FM, Vx, Vy, Vz, TA, dmDet, sfcChange, demAdapted, timeInfo, entrDepth, particles) - separated by |
30
+ resType = pft|pfv|ppr
31
+
32
+ #+++++++++Debris flow properties
33
+ # density of debris flow mixture [kg/m³]
34
+ # Override for density of fluid-solid mixture for debris flows
35
+ rho = 2000
36
+ # density of entrained debris [kg/m³]
37
+ # TODO adjusting
38
+ rhoEnt = 2000
39
+
40
+ #++++++++++++++++ Particles
41
+ # mass per particle (if MPPDIR is used) [kg]
42
+ massPerPart = 280000.
43
+
44
+ #+++++++++++++Mesh
45
+ # remesh the input rasters or look for remeshed rasters
46
+ # expected mesh size [m], default in AvaFrame: 5 m
47
+ meshCellSize = 2
48
+
49
+ #+++++++++++++general start conditions: time dependent release
50
+ # if timeDependentRelease is True, provide the the timesteps, thickness and velocity
51
+ # for a releases in a csv-table in the REL folder
52
+ timeDependentRelease = True
53
+ # specify one or multiple particular time dependent release files,
54
+ # provide name of csv file with or without extension .csv
55
+ # multiple files are separated with a |
56
+ # if no file is specified, all csv files in the Inputs/REL folder are computed
57
+ timeDependentReleaseScenarios =
58
+ # when checking if an already existing particle is within a release polygon
59
+ # (that would cause numerical instabilities and rise an error), one can decide to add a buffer
60
+ # around the polygon (0 means take strictly the points inside, a very small value
61
+ # will include the points located on the polygon line)
62
+ thresholdPointInRel = 0.01
63
+
64
+ #++++++++++++Time stepping parameters
65
+ # End time [s]
66
+ tEnd = 600
67
+
68
+ #++++++++++++Friction model
69
+ # add the friction using an explicit formulation (1)
70
+ # or use an implicit method (0)
71
+ explicitFriction = 0
72
+ # friction type. Available options are:
73
+ # Coulomb
74
+ # Voellmy
75
+ # spatialVoellmy
76
+ ## Rheological models for debris-flow simulations
77
+ # OBrienAndJulien
78
+ # HerschelAndBulkley
79
+ # Bingham
80
+ # Please note that each type has their own/separate parameters:
81
+ # https://docs.avaframe.org/en/latest/theoryCom1DFA.html#friction-model
82
+ frictModel = Voellmy
83
+ #+++++++++++++Voellmy friction model
84
+ muvoellmy = 0.155
85
+ xsivoellmy = 200
86
+ #+++++++++++++Coulomb friction model
87
+ mucoulomb = 0.47
88
+ #+++++++++DEBRIS FLOW properties
89
+ # only taken into account when using the O'Brien and Julien friction model
90
+ # density of sediment [kg/m³]
91
+ rhoSediment = 2650
92
+ # mean sediment size [m]
93
+ ## TODO adjusting
94
+ sizeSediment = 0.001
95
+ # maximum concentration of sediment particles [m³/m³]
96
+ cvMaxSediment = 0.615
97
+ # volumetric sediment concentration [m³/m³]
98
+ cvSediment = 0.4
99
+ #++++++++++++++Parameter Rheological models
100
+ # Basically, there are two options for defining the yield shear stress, tauy,
101
+ # and the dynamic viscosity, eta:
102
+ # - set the values directly (default) or
103
+ # - compute them using the alpha and beta parameters (see documentation).
104
+ # Set the eta and tauy values to 0 if you want to use the option
105
+ # that computes eta and tauy using the alpha and beta parameters.
106
+ #++++++++++++O´Brien and Julien
107
+ # viscosity parameter
108
+ etaObrienAndJulien = 25
109
+ # set etaObrienAndJulien to 0 to compute eta from alpha1EtaObrienAndJulien and beta1EtaObrienAndJulien
110
+ alpha1EtaObrienAndJulien = 0.14
111
+ beta1EtaObrienAndJulien = 12.96
112
+ # yield shear stress parameter
113
+ tauyObrienAndJulien = 200
114
+ # set tauyObrienAndJulien to 0 to compute tauy from alpha2TauyObrienAndJulien and beta2TauyObrienAndJulien
115
+ alpha2TauyObrienAndJulien = 0.2511
116
+ beta2TauyObrienAndJulien = 16.7
117
+ # parameter, default value Takahashi (1978)
118
+ alphaObrienAndJulien = 0.01
119
+ #++++++++++++Herschel and Bulkley
120
+ # yield shear stress parameter
121
+ tauyHerschelAndBulkley = 200
122
+ # set tauyHerschelAndBulkley to 0 to compute tauy from alpha2TauyHerschelAndBulkley and beta2TauyHerschelAndBulkley
123
+ alpha2TauyHerschelAndBulkley = 0.2511
124
+ beta2TauyHerschelAndBulkley = 16.7
125
+ # consistency factor K
126
+ kHerschelAndBulkley = 25
127
+ # flow exponent
128
+ nHerschelAndBulkley = 2
129
+ #++++++++++++Bingham
130
+ # viscosity parameter
131
+ etaBingham = 200
132
+ # set etaBingham to 0 to compute eta from alpha1EtaBingham and beta1EtaBingham
133
+ alpha1EtaBingham = 0.2511
134
+ beta1EtaBingham = 16.7
135
+ # yield shear stress parameter
136
+ tauyBingham = 2000
137
+ # set tauyBingham to 0 to compute tauy from alpha2TauyBingham and beta2TauyBingham
138
+ alpha2TauyBingham = 1.613
139
+ beta2TauyBingham = 17.81
140
+
141
+ #++++++++++++ Entrainment Erosion Energy
142
+ # Used to determine speed loss via energy loss due to entrained mass
143
+ entEroEnergy = 5000
144
+
145
+ #++++++++++++ Deposition, Erosion and adaptive surface
146
+ # adapt the topography every time step
147
+ # activate with 1
148
+ # if adaptSfcStopped = 1: stopped particles (velocity = 0 or stopping criterion is reached)
149
+ # are deleted and saved in an additional dictionary (particles["stoppedParticles"])
150
+ adaptSfcStopped = 0
151
+ adaptSfcDetrainment = 0
152
+ adaptSfcEntrainment = 0
153
+ # deposition is only entrainable if it is an entrainment simulation and if adaptSfcStopped = 1 and adaptSfcEntrainment = 1
154
+ # then mass that is stopped can be entrained (also if the entrainment area is not in this stopped area)
155
+ entrainableDeposition = False
156
+ # only adapt topography if changing height in at least one cell is > thresholdAdaptSfc [m]
157
+ thresholdAdaptSfc = 0.1
158
+ # use the adapted topography as background in the report plots
159
+ adaptDemPlot = False
160
+
161
+ # specify a particular release area scenario, provide name of shapefile with or without extension .shp (optional)
162
+ releaseScenario =
163
+
164
+
165
+ [in2TopoHyd_in2TopoHyd_override]
166
+ # use default in2TopoHyd config as base configuration (True) and override following parameters
167
+ # if False and local_in2TopoHydCfg is available use local
168
+ defaultConfig = True
169
+
170
+ #++++++++++++++++ Hydraulic Boundary Conditions
171
+ # Elevation steps in vertical direction to calculate the flow area
172
+ dElev = 0.1
173
+ # method how the flow velocity as initial condition is calculated
174
+ # currently only the method after Rickenmann (1999) is available
175
+ velType = rickenmann
176
+ # mean slope for the cross section in flow direction [m/m]
177
+ # optional; if left blank, the slope is computed automatically
178
+ slope =
179
+ # normal distance to release line where two parallel cross sections are generated on each side of the release line
180
+ # needed for computing the flow direction and the channel slope
181
+ # optional; if left blank, the normal distance is computed automatically
182
+ normalDist =
183
+
184
+ # export cell centers along the release line as points in a csv-file; for plausability check
185
+ # True or False
186
+ exportCrossSectionCells = True
@@ -0,0 +1,38 @@
1
+ ### Config File - This file contains the main settings for Debrisframe
2
+ # This file is part of Debrisframe.
3
+
4
+
5
+ [MAIN]
6
+ # Path to avalanche directory
7
+ #TODO: change avalancheDir to debrisDir
8
+ avalancheDir = data/debrisParabolaChanneled
9
+
10
+ # number of CPU cores to use for the computation of com1DFA
11
+ # possible values are:
12
+ # - auto -> takes up to CPUPercent (see below) % of the available CPU cores
13
+ # - 1, 2, ... number of CPU cores
14
+ nCPU = auto
15
+
16
+ # Percentage of CPU cores to take in case of
17
+ # nCPU = auto. Valid rane 0..100
18
+ CPUPercent = 50
19
+
20
+
21
+ [FLAGS]
22
+ # True if plots shall be plotted to screen
23
+ showPlot = False
24
+
25
+ # True if plots shall be saved
26
+ savePlot = True
27
+
28
+ # True if report shall be generated
29
+ createReport = True
30
+
31
+ # True if plots of all peakFiles shall be saved to report directory
32
+ ReportDir = True
33
+
34
+ # True if report shall be written into one file
35
+ reportOneFile = True
36
+
37
+ # True if debug plots shall be plotted
38
+ debugPlot = False
File without changes
@@ -0,0 +1,43 @@
1
+ """
2
+ Directory and file handling helper functions
3
+ """
4
+
5
+ import pathlib
6
+ import shutil
7
+ import logging
8
+ import pandas as pd
9
+
10
+ log = logging.getLogger("avaframe.debrisframe.in1Utils.fileUtils")
11
+
12
+
13
+ def copyHydrToInput(debrisDir):
14
+ """
15
+ copy the output file from in2TopoHyd into Inputs/REL
16
+ to serve as input data for c1TIF
17
+
18
+ Parameters
19
+ -----------
20
+ debrisDir: str or pathlib path
21
+ path to debris-flow directory
22
+ """
23
+
24
+ debrisDir = pathlib.Path(debrisDir)
25
+
26
+ outputFile = debrisDir / "Outputs" / "in2TopoHyd" / "initCondHyd.csv"
27
+ inputsDir = debrisDir / "Inputs" / "REL"
28
+ inputsDir.mkdir(parents=True, exist_ok=True)
29
+
30
+ inputsHydFile = inputsDir / outputFile.name
31
+
32
+ if not inputsHydFile.exists():
33
+ shutil.copy2(outputFile, inputsHydFile)
34
+ else:
35
+ outputFileDF = pd.read_csv(outputFile)
36
+ inputsHydFileDF = pd.read_csv(inputsHydFile)
37
+
38
+ if not outputFileDF.equals(inputsHydFileDF):
39
+ log.info(f"{inputsHydFile} already exists and is inconsistent with {outputFile}.")
40
+ log.info(f"{inputsHydFile} is overwritten by {outputFile}!")
41
+ shutil.copy2(outputFile, inputsHydFile)
42
+ else:
43
+ log.info(f"{inputsHydFile} already exists and is consistent with {outputFile}")
@@ -0,0 +1,173 @@
1
+ """
2
+ Create generic/idealised topographies
3
+ """
4
+
5
+ # load modules
6
+ import logging
7
+ import numpy as np
8
+ from scipy.stats import norm
9
+ import pathlib
10
+
11
+ # local imports
12
+ import avaframe.in3Utils.generateTopo as genTop
13
+
14
+ # create local logger
15
+ # change log level in calling module to DEBUG to see log messages
16
+ log = logging.getLogger("avaframe.debrisframe.in1Utils")
17
+
18
+ def debrisFlowTopoAverage(cfg):
19
+ """
20
+ Compute coordinates of an average parabolic-shaped slope as a generic topography for debris-flow simulations
21
+ defined by a 2nd-degree polynomial: ax**2 + bx + c
22
+ The parameters of the polynomial function are derived from real watershed profiles (Kessler 2019)
23
+
24
+ Parameters
25
+ ----------------------
26
+ cfg: configparser Object
27
+ configuration setup for topo generation
28
+ """
29
+ # input parameters
30
+ C = cfg["TOPO"].getfloat("C")
31
+ cff = cfg["CHANNELS"].getfloat("cff")
32
+ cRadius = cfg["CHANNELS"].getfloat("cRadius")
33
+ cInit = cfg["CHANNELS"].getfloat("cInit")
34
+ cMustart = cfg["CHANNELS"].getfloat("cMustart")
35
+ cMuend = cfg["CHANNELS"].getfloat("cMuend")
36
+
37
+ # Get grid definitons
38
+ dx, xEnd, yEnd = genTop.getGridDefs(cfg)
39
+
40
+ # Compute coordinate grid
41
+ xv, yv, zv, x, y, nRows, nCols = genTop.computeCoordGrid(dx, xEnd, yEnd)
42
+
43
+ # If a channel shall be introduced
44
+ # Get parabola Parameters
45
+ [A, B, fLen] = genTop.getParabolaParams(cfg)
46
+
47
+ # Set surface elevation
48
+ zv = np.ones((nRows, nCols))
49
+ mask = np.zeros(np.shape(xv))
50
+ mask[np.where(xv < fLen)] = 1
51
+ zv = zv * (A * xv ** 2 + B * xv + C) * mask
52
+
53
+ # If a channel shall be introduced
54
+ if cfg["TOPO"].getboolean("channel"):
55
+ # Compute cumulative distribution function - c1 for upper part (start)
56
+ # of channel and c2 for lower part (end) of channel
57
+ c1 = norm.cdf(xv, cMustart * fLen, cff)
58
+ c2 = 1.0 - norm.cdf(xv, cMuend * fLen, cff)
59
+
60
+ # combine both into one function separated at the the middle of
61
+ # the channel longprofile location
62
+ mask_c1 = np.zeros(np.shape(xv))
63
+ mask_c1[np.where(xv < (fLen * (0.5 * (cMustart + cMuend))))] = 1
64
+ c0 = c1 * mask_c1
65
+
66
+ mask_c2 = np.zeros(np.shape(xv))
67
+ mask_c2[np.where(xv >= (fLen * (0.5 * (cMustart + cMuend))))] = 1
68
+ c0 = c0 + c2 * mask_c2
69
+
70
+ # Is the channel of constant width or narrowing
71
+ if cfg["TOPO"].getboolean("narrowing"):
72
+ # upper part of channel: constant width
73
+ mask_c1 = np.zeros(np.shape(xv))
74
+ mask_c1[np.where(xv < (fLen * (0.5 * (cMustart + cMuend))))] = 1
75
+ cExtent_c1 = np.zeros(np.shape(xv)) + cRadius
76
+
77
+ # lower part of channel: narrowing
78
+ mask_c2 = np.zeros(np.shape(xv))
79
+ mask_c2[np.where(xv >= (fLen * (0.5 * (cMustart + cMuend))))] = 1
80
+ cExtent_c2 = cInit * (1 - c0[:]) + (c0[:] * cRadius)
81
+
82
+ cExtent = cExtent_c1 * mask_c1 + cExtent_c2 * mask_c2
83
+ else:
84
+ cExtent = np.zeros(np.shape(xv)) + cRadius
85
+
86
+ # Set surface elevation
87
+ mask = np.zeros(np.shape(y))
88
+ mask[np.where(abs(y) < cExtent)] = 1
89
+ # Add surface elevation modification introduced by channel
90
+ if cfg["TOPO"].getboolean("topoAdd"):
91
+ zv = zv + cRadius * c0 * (1.0 - np.sqrt(np.abs(1.0 - (np.square(y) / (cExtent ** 2))))) * mask # changed from cExtent to cRadius
92
+ # outside of the channel, add layer of channel thickness
93
+ mask = np.zeros(np.shape(y))
94
+ mask[np.where(abs(y) >= cExtent)] = 1
95
+ mask_c2 = np.ones(np.shape(xv)) #added, smooth transition from upper to lower part of channel
96
+ c0 = c2 * mask_c2 #added to extend lower distribution to upper edge of topography
97
+ zv = zv + cRadius * mask * c0 # changed from cExtent to cRadius
98
+ else:
99
+ zv = zv - cExtent * c0 * np.sqrt(np.abs(1.0 - (np.square(y) / (cExtent ** 2)))) * mask
100
+
101
+ # Log info here
102
+ log.info("Generic debris-flow topography is computed")
103
+
104
+ return x, y, zv
105
+
106
+ def generateTopo(cfg, debrisDir):
107
+ """
108
+ Compute coordinates of desired topography with given inputs
109
+
110
+ Parameters
111
+ ----------------------
112
+ cfg: configparser Object
113
+ configuration setup for topo generation
114
+ debrisDir: string
115
+ directory to data folder
116
+ """
117
+
118
+ # Which DEM type
119
+ demType = cfg["TOPO"]["demType"]
120
+
121
+ log.info("DEM type is set to: %s" % demType)
122
+
123
+ # Set Output directory
124
+ outDir = pathlib.Path(debrisDir, "Inputs")
125
+ if outDir.is_dir():
126
+ log.info("The new DEM is saved to %s" % (outDir))
127
+ else:
128
+ log.error(
129
+ "Required folder structure: NameOfDebrisFlow/Inputs missing! \
130
+ Run runInitializeProject first!"
131
+ )
132
+
133
+ # Call topography type
134
+ if demType == "FP":
135
+ [x, y, z] = genTop.flatplane(cfg)
136
+
137
+ elif demType == "IP":
138
+ [x, y, z] = genTop.inclinedplane(cfg)
139
+
140
+ elif demType == "PF":
141
+ [x, y, z] = genTop.parabola(cfg)
142
+
143
+ elif demType == "TPF":
144
+ [x, y, z] = genTop.parabolaRotation(cfg)
145
+
146
+ elif demType == "HS":
147
+ [x, y, z] = genTop.hockey(cfg)
148
+
149
+ elif demType == "BL":
150
+ [x, y, z] = genTop.bowl(cfg)
151
+
152
+ elif demType == "HX":
153
+ [x, y, z] = genTop.helix(cfg)
154
+
155
+ elif demType == "PY":
156
+ [x, y, z] = genTop.pyramid(cfg)
157
+
158
+ elif demType == "DFTA":
159
+ [x, y, z] = debrisFlowTopoAverage(cfg)
160
+
161
+ # If a drop shall be introduced
162
+ if cfg["TOPO"].getboolean("drop"):
163
+ z = genTop.addDrop(cfg, x, y, z)
164
+
165
+ # moves topo in z direction
166
+ if cfg["DEMDATA"]["zEdit"] != "":
167
+ z = z + cfg["DEMDATA"].getfloat("zEdit")
168
+ log.info("Changed topo elevation by %.2f" % cfg["DEMDATA"].getfloat("zEdit"))
169
+
170
+ # Write DEM to file
171
+ genTop.writeDEM(cfg, z, outDir)
172
+
173
+ return (z, demType, outDir)
@@ -0,0 +1,57 @@
1
+ ### Config File - This file contains the main settings for the topography generation
2
+ ## Set your parameters
3
+ # This file is part of DebrisFrame.
4
+
5
+ # General Topography parameters ----------------------
6
+ [in3Utils_generateTopo_override]
7
+
8
+ # use default generateTopo config as base configuration (True) and override following parameters
9
+ # if False and local_generateTopoCfg is available use local
10
+ defaultConfig = True
11
+
12
+ # total horizontal extent of the domain [m]
13
+ xEnd = 2000
14
+
15
+ # topography type
16
+ # demType - topography type options:
17
+ # FP (Flat plane), IP (Inclined plane) [dx, xEnd, yEnd, zElev]
18
+ # PF (Parabolic slope with flat foreland) [dx, xEnd, yEnd, fLens or meanAlpha, C, optional:channel, dam]
19
+ # TPF (Triple parabolic slope with flat foreland) [dx, xEnd, yEnd, fLens, fFlat, C]
20
+ # HS (Hockeystick with linear slope and flat foreland and smooth transition) [dx, xEnd, yEnd, meanAlpha, z0, rCirc, optional:channel]
21
+ # BL (Bowl-shaped topography) [dx, xEnd, yEnd, rBowl]
22
+ # HX (Helix-shaped topography) [dx, xEnd, yEnd, flens or meanAlpha, C, rHelix, optional:channel]
23
+ # PY (pyramid-shaped topography, optional with flat foreland) [dx, xEnd, yEnd, meanAlpha, z0, optional:flatx, flaty, phi]
24
+ # DFTA (generic debris-flow topography) [dx, xEnd, yEnd, fLens, meanAlpha = 0, channel, narrowing]
25
+ demType = DFTA
26
+
27
+ # distance to point where slope transitions into flat plane [m] - required for PF, HX, DFTA if meanAlpha is not provided
28
+ fLens = 1679
29
+
30
+ # slope angle from max. elevation to start flat plane [°] - or slope of inclined plane [°]
31
+ # this parameter required for IP, HS, PY, (PF, HX - if not fLens is used)
32
+ meanAlpha = 0
33
+
34
+ # total fall height [m] - required for PF, HX, DFTA
35
+ C = 709
36
+
37
+ # flag to set channel
38
+ channel = True
39
+
40
+ #------------------------------------------------------
41
+
42
+ # Channel parameters -----------------------------------
43
+
44
+ # standard channel radius - width of channel
45
+ cRadius = 20
46
+
47
+ # mean mu - represents upper part of the channel (e.g. 10% of sloping topography part)
48
+ cMustart = 0.1
49
+
50
+ # mean mu - represents lower part of the channel (e.g. 62% of sloping topography part)
51
+ cMuend = 0.62
52
+
53
+ # standard deviation sigma
54
+ cff = 120
55
+
56
+
57
+
@@ -0,0 +1,112 @@
1
+ """
2
+ Plotting helper functions
3
+ """
4
+
5
+ # load modules
6
+ import matplotlib.pyplot as plt
7
+
8
+ # local imports
9
+ import avaframe.in3Utils.fileHandlerUtils as fU
10
+
11
+
12
+ def plotCrossSection(crossSection, outputDir):
13
+ """
14
+ This function plots the terrain cross section
15
+
16
+ Parameters
17
+ -----------
18
+ crossSection: dict
19
+ dictionary containing
20
+ the elevation of the cross-section cells and levee points,
21
+ the path along (distance) along the cross-section cells
22
+ outputDir: str or Path
23
+ path to output directory of in2TopoHyd module
24
+
25
+ Returns
26
+ --------
27
+ Plot: .png
28
+ saves plot in debris-flow directory
29
+ """
30
+
31
+ # plot cross section
32
+ fig, ax = plt.subplots(figsize=(10, 8))
33
+
34
+ ax.plot(crossSection["s"], crossSection["elevation"])
35
+ ax.scatter(crossSection["sLevee"], crossSection["elevLevee"], color="red", label="Levee points")
36
+ ax.set_xlabel("distance [m]")
37
+ ax.set_ylabel("elevation [m]")
38
+ ax.grid(color="gray", linestyle="--", linewidth=0.5, alpha=0.6)
39
+ ax.set_title("Cross Section")
40
+
41
+ plt.legend()
42
+ plt.tight_layout()
43
+
44
+ # check if directory already exists
45
+ path = outputDir / "Plots"
46
+ fU.makeADir(path)
47
+
48
+ fig.savefig(path / "crossSection.png")
49
+
50
+
51
+ def plotRatingCurve(ratingCurve, crossSection, outputDir):
52
+ """
53
+ This function plots the terrain cross section
54
+ and the corresponding rating curve
55
+
56
+ Parameters
57
+ -----------
58
+ ratingCurve: dict
59
+ dictionary containing
60
+ thickness values/surface elevations and corresponding flow area
61
+ min and max values of horizontal distance of flow area
62
+ crossSection: dict
63
+ dictionary containing
64
+ the elevation of the cross-section cells,
65
+ the path along (distance) along the cross-section cells
66
+ outputDir: str or Path
67
+ path to output directory of in2TopoHyd module
68
+
69
+ Returns
70
+ --------
71
+ Plot: .png
72
+ saves plot in debris-flow directory
73
+ """
74
+
75
+ thickness = ratingCurve["thickness"]
76
+ flowArea = ratingCurve["flowArea"]
77
+ surfElev = ratingCurve["surfElev"]
78
+ xmin = ratingCurve["xmin"]
79
+ xmax = ratingCurve["xmax"]
80
+
81
+ # plot cross section
82
+ fig, ax = plt.subplots(ncols=1, nrows=2, figsize=(10, 8))
83
+
84
+ ax[0].plot(crossSection["s"], crossSection["elevation"])
85
+ ax[0].scatter(crossSection["sLevee"], crossSection["elevLevee"], color="red", label="Levee points")
86
+ for i, (elev, minimum, maximum) in enumerate(zip(surfElev, xmin, xmax)):
87
+ elev = [elev] * len(minimum)
88
+ ax[0].hlines(
89
+ elev,
90
+ xmin=minimum,
91
+ xmax=maximum,
92
+ linestyles="--",
93
+ colors="black",
94
+ lw=0.5,
95
+ label="elevation increments" if i == 0 else "_nolegend_",
96
+ )
97
+ ax[0].set_xlabel("distance [m]"), ax[0].set_ylabel("elevation [m]")
98
+ ax[0].grid(color="gray", linestyle="--", linewidth=0.5, alpha=0.6)
99
+ ax[0].set_title("Cross Section")
100
+ ax[0].legend()
101
+
102
+ ax[1].plot(flowArea, thickness)
103
+ ax[1].set_xlabel("flow area [m²]")
104
+ ax[1].set_ylabel("flow thickness [m]")
105
+ ax[1].grid(color="gray", linestyle="--", linewidth=0.5, alpha=0.6)
106
+ ax[1].set_title("Rating Curve")
107
+
108
+ plt.tight_layout()
109
+
110
+ path = outputDir / "Plots"
111
+ fU.makeADir(path)
112
+ fig.savefig(path / "ratingCurve.png")
File without changes