From 6e1894219a9f04747bdccd350bd5f2df478f1e28 Mon Sep 17 00:00:00 2001 From: Anna Wirbel Date: Tue, 23 Jun 2026 14:13:47 +0200 Subject: [PATCH] add tiff check to com8/9 move to function use correct parameter rename add pytest --- avaframe/com1DFA/com1DFA.py | 55 +++++++++++++------- avaframe/tests/test_com1DFA.py | 93 ++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+), 18 deletions(-) diff --git a/avaframe/com1DFA/com1DFA.py b/avaframe/com1DFA/com1DFA.py index b4b8cceca..41ce01f81 100644 --- a/avaframe/com1DFA/com1DFA.py +++ b/avaframe/com1DFA/com1DFA.py @@ -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 @@ -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) @@ -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) diff --git a/avaframe/tests/test_com1DFA.py b/avaframe/tests/test_com1DFA.py index 1661f8446..ce13cdee3 100644 --- a/avaframe/tests/test_com1DFA.py +++ b/avaframe/tests/test_com1DFA.py @@ -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): @@ -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)