Skip to content
Open
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
Binary file not shown.
Binary file not shown.
382 changes: 382 additions & 0 deletions avaframe/data/avaArzlerAlm/Inputs/dem10m.asc

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions avaframe/data/avaArzlerAlm/Inputs/dem10m.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROJCS["MGI_Austria_GK_West",GEOGCS["GCS_MGI",DATUM["D_MGI",SPHEROID["Bessel_1841",6377397.155,299.1528128]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",-5000000.0],PARAMETER["Central_Meridian",10.3333333333333],PARAMETER["Scale_Factor",1.0],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]
Binary file not shown.
157 changes: 157 additions & 0 deletions avaframe/data/avaParabChannelPaperFP/Inputs/channel.asc

Large diffs are not rendered by default.

175 changes: 175 additions & 0 deletions avaframe/runStandardTestsCom4FlowPy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
"""
Run script for running the standard tests with com4FlowPy
in this test all the available tests tagged standardTest are performed
"""

# Load modules
import time
import pathlib
import numpy as np
from datetime import datetime
import os

# Local imports
from avaframe.com4FlowPy import com4FlowPy
from avaframe.runCom4FlowPy import readFlowPyinputs
from avaframe.ana1Tests import testUtilities as tU
from avaframe.in3Utils import fileHandlerUtils as fU
from avaframe.in3Utils import initializeProject as initProj
from avaframe.in3Utils import cfgUtils
from avaframe.in3Utils import logUtils
import avaframe.in2Trans.rasterUtils as rasterUtils


def compareRasters(path, pathRef):
"""
compare two rasters and compute teh difference between them

Parameters
----------
path: string or pathlib.Path
path to raster file
pathRef: string or pathlib.Path
path to reference raster file

Returns
-------
diff: np.array
difference of teh rasters in every rastercell
equal: boolean
True if the rasters are equal
closePercentage: float
the proportion of cells that match closely between both rasters, out of all cells that were actually processed
"""
rasterDict = rasterUtils.readRaster(path, noDataToNan=False)
raster = rasterDict["rasterData"]
rasterRefDict = rasterUtils.readRaster(pathRef, noDataToNan=False)
rasterRef = rasterRefDict["rasterData"]
# difference of both rasters
diff = rasterRef - raster

equal = np.array_equal(rasterRef, raster)

closeArray = np.isclose(raster, rasterRef, rtol=1e-04, equal_nan=True)
mask = np.logical_or(raster > 0, rasterRef > 0)
num_close = np.count_nonzero(closeArray[mask])
total = rasterRef[mask].size
closePercent = num_close / total

return diff, equal, closePercent


# Which result types for comparison plots
outputVariable = ['fpTravelAngleMax', 'zDelta', 'flux', 'cellCounts']

# log file name; leave empty to use default runLog.log
logName = 'runStandardTestsCom4FlowPy'

# Load settings from general configuration file
cfgMain = cfgUtils.getGeneralConfig()

# load all benchmark info as dictionaries from description files
testDictList = tU.readAllBenchmarkDesDicts(info=False, inDir=pathlib.Path('..', 'benchmarksCom4FlowPy'))

# filter benchmarks for tag standardTest
# filterType = 'TAGS'
# valuesList = ['resistance']
filterType = 'TAGS'
valuesList = ['standardTest']
testList = tU.filterBenchmarks(testDictList, filterType, valuesList, condition='or')

# Set directory for full standard test report
outDir = pathlib.Path.cwd() / 'tests' / 'reportsCom4FlowPy'
fU.makeADir(outDir)

# Start writing markdown style report for standard tests
reportFile = outDir / 'standardTestsReportCom4FlowPy.md'
with open(reportFile, 'w') as pfile:

# Write header
pfile.write('# Standard Tests Report \n')
pfile.write('## Compare com4FlowPy simulations to benchmark results \n')

log = logUtils.initiateLogger(outDir, logName)
log.info('The following benchmark tests will be fetched ')
for test in testList:
log.info('%s' % test['NAME'])

# run Standard Tests sequentially

for test in testList:

with open(reportFile, 'a') as pfile:
pfile.write("\n")
pfile.write(f"### Test: {test['NAME']}\n")
pfile.write("\n")

avaDir = test['AVADIR']
cfgMain['MAIN']['avalancheDir'] = avaDir

# Fetch benchmark test info
refDir = pathlib.Path('..', 'benchmarksCom4FlowPy', test['NAME'])

# Clean input directory(ies) of old work and output files
initProj.cleanSingleAvaDir(avaDir)

# Load input parameters from configuration file for standard tests
standardCfg = refDir / ('%s_com4FlowPyCfg.ini' % test['AVANAME'])
modName = 'com4FlowPy'
cfg = cfgUtils.getModuleConfig(com4FlowPy, fileOverride=standardCfg)
cfgGen = cfg["GENERAL"]
cfgGen["cpuCount"] = str(cfgUtils.getNumberOfProcesses(cfgMain, 9999))

compDir = pathlib.Path(avaDir, 'Outputs', modName, 'peakFiles')
avalancheDir = cfgMain["MAIN"]["avalancheDir"]
cfgPath = readFlowPyinputs(avalancheDir, cfg, log)
cfgPath["customDirs"] = False
cfgPath["resDir"] = compDir
fU.makeADir(cfgPath["resDir"])
cfgPath["thalwegDir"] = cfgPath["resDir"] / "thalwegData"
cfgPath["tempDir"] = cfgPath["workDir"] / "temp"
fU.makeADir(cfgPath["tempDir"])
cfgPath["deleteTemp"] = "False"
cfgPath["outputFiles"] = cfg["PATHS"]["outputFiles"]
cfgPath["outputNoDataValue"] = cfg["PATHS"].getfloat("outputNoDataValue")
cfgPath["useCompression"] = cfg["PATHS"].getboolean("useCompression")
cfgPath["uid"] = cfgUtils.cfgHash(cfg)
cfgPath["timeString"] = datetime.now().strftime("%Y%m%d_%H%M%S")

# Set timing
startTime = time.time()
# call com4FlowPy run
com4FlowPy.com4FlowPyMain(cfgPath, cfgGen)
endTime = time.time()
timeNeeded = endTime - startTime
log.info(('Took %s seconds to calculate.' % (timeNeeded)))

for variable in outputVariable:

for file in os.listdir(refDir):
if file.endswith('%s.tif' % variable):
pathRasterRef = refDir / file
break
else:
continue
if os.path.isfile(pathRasterRef) is False:
raise FileExistsError("in %s does not exist a file for variable %s" %(refDir, variable))

for file in os.listdir(compDir):
if file.endswith('%s.tif' % variable):
pathRaster = compDir / file
break
else:
continue
if os.path.isfile(pathRaster) is False:
raise FileExistsError("in %s does not exist a file for variable %s" %(compDir, variable))
diff, eq, close = compareRasters(pathRaster, pathRasterRef)

if eq and np.sum(abs(diff[diff != 0])) == 0:
message = f"for {variable}: rasters are equal \n"
else:
message = f"for {variable}: rasters are *NOT* equal, but {np.round(close, 4) * 100}% \
of the affected area is close (relative tolerance: 10^-4) \n"
log.info(f"{test['NAME']}: {message}")
with open(reportFile, 'a') as pfile:
pfile.write(message)
Loading
Loading