Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions avaframe/com1DFA/com1DFA.py
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,7 @@ def initializeFields(cfg, dem, particles, releaseLine):
fields["sfcChange"] = np.zeros((nrows, ncols)) # depth that changes the surface [m]
fields["sfcChangeTotal"] = np.zeros((nrows, ncols)) # total depth that changed the surface [m]
fields["demAdapted"] = np.zeros((nrows, ncols)) # adapted topography [m]
fields["timeInfo"] = np.zeros((nrows, ncols)) # first time
# for optional fields, initialize with dummys (minimum size array). The cython functions then need something
# even if it is empty to run properly
if ("TA" in resTypesLast) or ("pta" in resTypesLast):
Expand Down Expand Up @@ -2674,6 +2675,9 @@ def computeEulerTimeStep(
particles = DFAfunC.computeTrajectoryAngleC(particles, zPartArray0)
particles, fields = DFAfunC.updateFieldsC(cfg, particles, dem, fields)

# update field that indicates when cell was first affected by mass
fields = com1DFATools.updateTimeField(fields, particles["t"])

# adapt DEM considering erosion and deposition
# only adapt DEM when in one grid cell the changing height > threshold
thresholdAdaptSfc = cfg.getfloat("thresholdAdaptSfc")
Expand Down
4 changes: 2 additions & 2 deletions avaframe/com1DFA/com1DFACfg.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ simTypeList = available
modelType = dfa

#+++++++++++++ Output++++++++++++
# desired result Parameters (ppr, pft, pfv, pta, FT, FV, P, FM, Vx, Vy, Vz, TA, dmDet, sfcChange, demAdapted, particles) - separated by |
resType = ppr|pft|pfv
# desired result Parameters (ppr, pft, pfv, pta, FT, FV, P, FM, Vx, Vy, Vz, TA, dmDet, sfcChange, demAdapted, timeInfo, particles) - separated by |
resType = ppr|pft|pfv|timeInfo
# saving time step, i.e. time in seconds (first and last time step are always saved)
# option 1: give an interval with start:interval in seconds (tStep = 0:5 - this will save desired results every 5 seconds for the full simulation)
# option 2: explicitly list all desired time steps (closest to actual computational time step) separated by | (example tSteps = 1|50.2|100)
Expand Down
24 changes: 24 additions & 0 deletions avaframe/com1DFA/com1DFATools.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,3 +481,27 @@ def chooseDemPlot(dem, adaptedDemBackground=False):
demPlot["rasterData"] = dem["originalRasterData"]
log.info("The original DEM is used in the plots.")
return demPlot


def updateTimeField(fields, timeStep):
"""update filed indicating first time step mass entered a cell

Parameters
-----------
fields: dict
dictionary with fields
timeStep: float
actual time step

Returns
---------
fields: dict
updated timeInfo field
"""

FT = fields["FT"]

# set time step to previously not affected cells
fields["timeInfo"] = np.where(((fields["timeInfo"] == 0) & (FT != 0)), timeStep, fields["timeInfo"])

return fields
13 changes: 13 additions & 0 deletions avaframe/com1DFA/deriveParameterSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def checkResType(fullCfg, section, key, value):
"FTDet",
"sfcChange",
"demAdapted",
"timeInfo",
]
message = "The parameter % s is not a valid resType. It will not be saved"
newResType = []
Expand Down Expand Up @@ -411,6 +412,18 @@ def checkThicknessSettings(cfg, thName, inputSimFiles):
)
log.error(message)
raise AssertionError(message)
# Check: If raster input file but thFromFile = False, error
elif (
not cfg["GENERAL"].getboolean(thFlag)
and inputSimFiles["entResInfo"][thName + "FileType"] in [".asc", ".tif"]
and inputSimFiles["entResInfo"]["flag" + nameTypes[thName]] == "Yes"
):
message = "If %s input file is of type .asc or .tif - %s needs to be set to True" % (
nameStrings[thName],
thFlag,
)
log.error(message)
raise AssertionError(message)
else:
message = "Check %s - needs to be True or False" % thFlag
log.error(message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ initPartDistType = random

#+++++++++SNOW properties
# True if release thickness should be read from shapefile file; if False - relTh read from ini file
relThFromFile = False
relThFromFile = True

#++++++++++++Time stepping parameters
# End time [s]
Expand Down
16 changes: 12 additions & 4 deletions avaframe/out1Peak/outPlotAllPeak.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
matplotlib.use("agg")
from matplotlib import pyplot as plt
import pathlib
from mpl_toolkits.axes_grid1 import make_axes_locatable

import avaframe.out3Plot.plotUtils as pU
import avaframe.in1Data.getInput as gI
Expand Down Expand Up @@ -306,9 +305,18 @@ def addConstrainedDataField(fileName, resType, demField, ax, cellSize, alpha=1.0
if len(np.nonzero(data)[0]) > 0.0:
# add Colorbar
fig = ax.get_figure()
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.05)
fig.colorbar(im1, cax=cax)
cax = ax.inset_axes([1.05, 0.075, 0.05, 0.925], transform=ax.transAxes)
fig.colorbar(im1, ax=ax, cax=cax)
cax2 = ax.inset_axes([1.0, 0.0, 0.05, 0.075], transform=ax.transAxes)
plt.text(
0.5,
0.5,
("[%s]" % unit),
horizontalalignment="left",
verticalalignment="center",
transform=cax2.transAxes,
)
cax2.set_visible(False)

return ax, rowsMinPlot, colsMinPlot, extentCellCorners

Expand Down
28 changes: 28 additions & 0 deletions avaframe/out3Plot/plotUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,31 @@
]
cmapSfcChange = copy.copy(cmapCrameri.nuuk.reversed())

# colormap for timeInfo
levtimeInfo = list(fU.splitIniValueToArraySteps(cfgPlotUtils["timeInfoColorLevels"]))
# lipari reversed color map
colorstimInfo = [
"#fdf5da",
"#f2debb",
"#e9c99f",
"#e5b58a",
"#e7a37a",
"#ea906d",
"#e57b62",
"#d46b5e",
"#bc6461",
"#a36267",
"#8e616c",
"#7c6071",
"#6b5f76",
"#5b5d79",
"#45587a",
"#294b70",
"#13385a",
"#082540",
"#031326",
]
cmaptimeInfo = copy.copy(cmapCrameri.lipari.reversed())

###############################################
# Set colormaps to use
Expand All @@ -237,6 +262,8 @@

cmapSfcChange = {"cmap": cmapSfcChange, "colors": colorsSfcC, "levels": levSfcC}

cmapTime = {"cmap": cmaptimeInfo, "colors": colorstimInfo, "levels": levtimeInfo}

# for zdelta
# Remark FSO: the try except comes from cmcrameri v1.5 not having lipari, but it is still
# widely used (Okt 2024). TODO: remove in future versions
Expand Down Expand Up @@ -269,6 +296,7 @@
"dmDet": cmapDmDet,
"demAdapted": cmapGreys,
"sfcChange": cmapSfcChange,
"timeInfo": cmapTime,
}

cmapDEM = cmapGreys
Expand Down
6 changes: 5 additions & 1 deletion avaframe/out3Plot/plotUtilsCfg.ini
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ unitzdelta = m
unitdmDet = kg
unitsfcChange = m
unitdemAdapted = m
unittimeInfo = s
# threshold levels
elevMaxppr = 100
elevMaxpft = 1
Expand All @@ -112,6 +113,8 @@ travelAngleColorLevels = 28|29|30|31|32|33|34
probaColorLevels = 0|0.25|0.50|0.75|1.
# for thicknessChange
surfaceChangeLevels = -1|-0.3|-0.1|0|0.1|0.3|1
# for time Info
timeInfoColorLevels = 10|20|30|40|50|60|70|80|90|100|110|120|130|140|150|160|170|180|200
# contour levels (when adding contour lines on a plot)
contourLevelsppr = 1|3|5|10|25|50|100|250
contourLevelspft = 0.1|0.25|0.5|0.75|1
Expand Down Expand Up @@ -144,4 +147,5 @@ nameVy = y velocity
nameVz = z velocity
nameTA = travel angle
namezdelta = energy line height
namedmDet = detrained mass
namedmDet = detrained mass
nametimeInfo = firstTime
108 changes: 0 additions & 108 deletions avaframe/tests/data/testSimiSol/simiSol_com1DFACfg.ini

This file was deleted.

7 changes: 5 additions & 2 deletions avaframe/tests/test_com1DFA.py
Original file line number Diff line number Diff line change
Expand Up @@ -1915,13 +1915,14 @@ def test_initializeFields():
# print("compute TA", fields["computeTA"])
# print("compute P", fields["computeP"])

assert len(fields) == 23
assert len(fields) == 24
assert fields["computeTA"] is False
assert fields["computeKE"] is False
assert fields["computeP"]
assert np.sum(fields["pfv"]) == 0.0
assert np.sum(fields["pta"]) == 0.0
assert np.sum(fields["ppr"]) == 0.0
assert np.sum(fields["pke"]) == 0.0
assert np.sum(fields["FV"]) == 0.0
assert np.sum(fields["P"]) == 0.0
assert np.sum(fields["TA"]) == 0.0
Expand All @@ -1937,6 +1938,8 @@ def test_initializeFields():
assert np.sum(fields["FTDet"]) == 0.0
assert np.sum(fields["FTStop"]) == 0.0
assert np.sum(fields["FTEnt"]) == 0.0
assert np.sum(fields["timeInfo"]) == 0.0
assert np.sum(fields["sfcChangeTotal"]) == 0.0

cfg["REPORT"] = {"plotFields": "pft|pfv"}
cfg["GENERAL"] = {
Expand All @@ -1947,7 +1950,7 @@ def test_initializeFields():
}
# call function to be tested
particles, fields = com1DFA.initializeFields(cfg, dem, particles, "")
assert len(fields) == 23
assert len(fields) == 24
assert fields["computeTA"]
assert fields["computeKE"]
assert fields["computeP"] is False
Expand Down
24 changes: 24 additions & 0 deletions avaframe/tests/test_com1DFATools.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,27 @@ def test_updateResCoeffFields(tmp_path):
assert fields["detRaster"][0, 0] == 3
assert fields["cResRaster"][2, 3] == 0
assert fields["detRaster"][2, 3] == 3


def test_updateTimeField():
"""test updating the field of timeInfo"""

nrows = 5
ncols = 6

timeInfo = np.zeros((nrows, ncols))
timeInfo[0, 1:3] = 1.0

FT = np.zeros((nrows, ncols))
FT[0, 1:3] = 0.5
FT[1, 2:4] = 2.5
timeStep = 5.0
fields = {"timeInfo": timeInfo, "FT": FT}

fields = com1DFATools.updateTimeField(fields, timeStep)

assert fields["timeInfo"][0, 1] == 1.0
assert fields["timeInfo"][0, 2] == 1.0
assert fields["timeInfo"][1, 2] == 5.0
assert fields["timeInfo"][1, 3] == 5.0
assert not fields["timeInfo"][2:6, :].any()
9 changes: 6 additions & 3 deletions avaframe/tests/test_deriveParameterSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,14 @@ def test_checkThicknessSettings():

thName = "relTh"

thicknessSettingsCorrect = dP.checkThicknessSettings(cfg, thName, inputSimFiles)

assert thicknessSettingsCorrect
with pytest.raises(AssertionError) as e:
assert dP.checkThicknessSettings(cfg, "relTh", inputSimFiles)
assert str(e.value) == (
"If Release area input file is of type .asc or .tif - relThFromFile needs to be set to True"
)

cfg["GENERAL"]["relThRangeVariation"] = "50$4"
cfg["GENERAL"]["relThFromFile"] = "True"

with pytest.raises(AssertionError) as e:
assert dP.checkThicknessSettings(cfg, "relTh", inputSimFiles)
Expand Down
Loading
Loading