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
55 changes: 37 additions & 18 deletions avaframe/com1DFA/com1DFA.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ def com1DFAPreprocess(cfgMain, cfgInfo, module=com1DFA):
simDict, inputSimFiles, simDFExisting, outDir = com1DFATools.createSimDictFromCfgs(
cfgMain, cfgInfo, module=module
)
# if module is mot based - tif is currently not supported as format for input data
checkForTif(module, inputSimFiles)

return simDict, outDir, inputSimFiles, simDFExisting

# read initial configuration
Expand All @@ -110,24 +113,7 @@ def com1DFAPreprocess(cfgMain, cfgInfo, module=com1DFA):
)

# if module is mot based - tif is currently not supported as format for input data
# TODO:remove when tif to asc conversion for mot is implement
if module.__name__.split(".")[-1].lower() in ["com8motpsa", "com9motvoellmy"]:
testInputType = [
(
True
if (inputSimFilesAll[iType] and iType not in ["relFiles", "relThFiles"])
and ("File" in iType and ".tif" in inputSimFilesAll[iType].suffix)
else False
)
for iType in inputSimFilesAll
]
testInputType = testInputType + [
True if ".tif" in relFile.suffix else False for relFile in inputSimFilesAll["relFiles"]
]
if any(testInputType):
message = ".tif files currently not supported for %s" % module
log.error(message)
raise ValueError(message)
checkForTif(module, inputSimFilesAll)

# create dictionary with one key for each simulation that shall be performed
simDict = dP.createSimDict(avalancheDir, module, cfgStart, inputSimFilesAll, simNameExisting)
Expand Down Expand Up @@ -4009,3 +3995,36 @@ def adaptDEM(dem, fields, cfg):
fields["sfcChangeTotal"] = sfcChangeTotal + sfcChange

return dem, fields


def checkForTif(module, inputSimFilesAll):
"""if com8MoTPSA or com9MoTVoellmy currently .tif files not supported - error if input data is of type .tif

Parameters
-----------
module: module
computational module used for task
inputSimFilesAll: dict
dictionary with fetched input data

"""
# if module is mot based - tif is currently not supported as format for input data
# TODO:remove when tif to asc conversion for mot is implement
modName = module.__name__.split(".")[-1]
if modName.lower() in ["com8motpsa", "com9motvoellmy"]:
testInputType = [
(
True
if (inputSimFilesAll[iType] and iType not in ["relFiles", "relThFile"])
and ("File" in iType and ".tif" in inputSimFilesAll[iType].suffix)
else False
)
for iType in inputSimFilesAll
]
testInputType = testInputType + [
True if ".tif" in relFile.suffix else False for relFile in inputSimFilesAll["relFiles"]
]
if any(testInputType):
message = ".tif files currently not supported for %s" % modName
log.error(message)
raise ValueError(message)
93 changes: 93 additions & 0 deletions avaframe/tests/test_com1DFA.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import avaframe.in3Utils.geoTrans as geoTrans
import avaframe.com1DFA.DFAtools as DFAtls
import avaframe.com1DFA.particleInitialisation as pI
import avaframe.com8MoTPSA.com8MoTPSA as com8
from avaframe.in1Data import getInput


def test_prepareInputData(tmp_path):
Expand Down Expand Up @@ -3662,3 +3664,94 @@ def test_com1DFAPreprocessWithDirectoryPath(tmp_path):
assert len(simDict) == 16
assert simDFExisting is None
assert "demFile" in inputSimFiles


def test_checkForTif(tmp_path):
"""check if in dict .tif files are included"""

# setup required input
avaTestDir = pathlib.Path(tmp_path, "avaTest", "Inputs")

inputSimFiles = {
"demFile": (avaTestDir / "demTest.asc"),
"relFiles": [(avaTestDir / "release1.shp"), (avaTestDir / "release2.shp")],
"secondaryRelFile": (avaTestDir / "secRelFile.asc"),
"muFile": (avaTestDir / "muTest.asc"),
"xiFile": (avaTestDir / "xiTest.asc"),
"resFile": None,
"tauCFile": None,
"entFile": (avaTestDir / "entTest.asc"),
"entResInfo": {
"relThFileType": ".asc",
"flagRel": "Yes",
"flagSecondaryRelease": "Yes",
"secondaryRelThFileType": ".asc",
"flagRes": "No",
"resFileType": None,
"flagEnt": "Yes",
"entThFileType": ".asc",
"dam": "No",
"mu": "Yes",
"xi": "Yes",
"k": "No",
"tauC": "No",
"bhd": "No",
"relRemeshed": "No",
"secondaryRelRemeshed": "No",
"entRemeshed": "No",
"tauCRemeshed": "No",
"kRemeshed": "No",
"muRemeshed": "No",
"xiRemeshed": "No",
"resRemeshed": "No",
"bhdRemeshed": "No",
"timeDepRelCsvAvailable": "No",
},
"timeDepRelCsv": [],
"secondaryRelThFile": (avaTestDir / "secRelFile.asc"),
"entThFile": (avaTestDir / "entTest.asc"),
}

# call function to be tested
com1DFA.checkForTif(com8, inputSimFiles)

# adjust input to produce error
inputSimFiles["relFiles"] = [(avaTestDir / "release1.asc"), (avaTestDir / "release2.tif")]
inputSimFiles["relThFile"] = [(avaTestDir / "release1.asc"), (avaTestDir / "release2.tif")]

with pytest.raises(ValueError) as e:
assert com1DFA.checkForTif(com8, inputSimFiles)
assert ".tif files currently not supported for com8MoTPSA" in str(e.value)

# adjust input to produce error
inputSimFiles["relFiles"] = [(avaTestDir / "release1.shp"), (avaTestDir / "release2.shp")]
inputSimFiles["relThFile"] = [(avaTestDir / "release1.asc"), (avaTestDir / "release2.asc")]
inputSimFiles["muFile"] = avaTestDir / "muTest.tif"

with pytest.raises(ValueError) as e:
assert com1DFA.checkForTif(com8, inputSimFiles)
assert ".tif files currently not supported for com8MoTPSA" in str(e.value)

# read Inputs from existing avaDirs

testDir = pathlib.Path(__file__).parents[0]
avalancheDir = testDir / ".." / "data" / "avaAlr" / "Inputs"
avaTestDir2 = pathlib.Path(tmp_path, "avaTestDir2")
avaTestDir2Input = avaTestDir2 / "Inputs"
shutil.copytree(avalancheDir, avaTestDir2Input)

inputSimFilesTest2 = getInput.getInputDataCom1DFA(avaTestDir2)

with pytest.raises(ValueError) as e:
assert com1DFA.checkForTif(com8, inputSimFilesTest2)
assert ".tif files currently not supported for com8MoTPSA" in str(e.value)

testDir = pathlib.Path(__file__).parents[0]
avalancheDir = testDir / ".." / "data" / "avaParabola" / "Inputs"
avaTestDir3 = pathlib.Path(tmp_path, "avaTestDir3")
avaTestDir3Input = avaTestDir3 / "Inputs"
shutil.copytree(avalancheDir, avaTestDir3Input)

inputSimFilesTest3 = getInput.getInputDataCom1DFA(avaTestDir3)

com1DFA.checkForTif(com8, inputSimFilesTest3)
Loading