Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add optional input dir for aimec analysis #896

Merged
merged 8 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
10 changes: 8 additions & 2 deletions avaframe/ana3AIMEC/aimecTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def readAIMECinputs(avalancheDir, pathDict, dirName='com1DFA'):
return pathDict


def fetchReferenceSimNo(avaDir, inputsDF, comModule, cfg):
def fetchReferenceSimNo(avaDir, inputsDF, comModule, cfg, inputDir=''):
""" Define reference simulation used for aimec analysis.

if the configuration files are available and a varParList is provided, the simulations
Expand All @@ -108,6 +108,9 @@ def fetchReferenceSimNo(avaDir, inputsDF, comModule, cfg):
computational module used to produce the results to analyze
cfg: configParser object
configuration for aimec - referenceSimValue, varParList used here
inputDir: str or pathlib path
optional- directory where peak files are located, if '',
avaDir/Outputs/comMod/peakFiles is set

Returns
--------
Expand All @@ -126,7 +129,10 @@ def fetchReferenceSimNo(avaDir, inputsDF, comModule, cfg):
"""

cfgSetup = cfg['AIMECSETUP']
inputDir = pathlib.Path(avaDir, 'Outputs', comModule, 'peakFiles')
if inputDir != '':
inputDir = pathlib.Path(inputDir)
else:
inputDir = pathlib.Path(avaDir, 'Outputs', comModule, 'peakFiles')
if not inputDir.is_dir():
message = 'Input directory %s does not exist - check anaMod' % inputDir
log.error(message)
Expand Down
14 changes: 8 additions & 6 deletions avaframe/ana3AIMEC/ana3AIMEC.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
log = logging.getLogger(__name__)


def fullAimecAnalysis(avalancheDir, cfg):
def fullAimecAnalysis(avalancheDir, cfg, inputDir=''):
""" fetch all data required to run aimec analysis, setup pathDict and reference sim,
read the inputs, perform checks if all required data is available, run main aimec

Expand All @@ -30,6 +30,9 @@ def fullAimecAnalysis(avalancheDir, cfg):
path to avalanche directory
cfg: configparser object
main aimec configuration settings
inputDir: str or pathlib path
optional- directory where peak files are located, if '',
avaDir/Outputs/comMod/peakFiles is set

Returns
--------
Expand All @@ -49,10 +52,10 @@ def fullAimecAnalysis(avalancheDir, cfg):
anaMod = cfgSetup['anaMod']

# Setup input from computational module
inputsDF, resTypeList = dfa2Aimec.mainDfa2Aimec(avalancheDir, anaMod, cfg)
inputsDF, resTypeList = dfa2Aimec.mainDfa2Aimec(avalancheDir, anaMod, cfg, inputDir=inputDir)
# define reference simulation
refSimRowHash, refSimName, inputsDF, colorParameter, valRef = aimecTools.fetchReferenceSimNo(avalancheDir, inputsDF, anaMod,
cfg)
cfg, inputDir=inputDir)
pathDict = {'refSimRowHash': refSimRowHash, 'refSimName': refSimName, 'compType': ['singleModule', anaMod],
'colorParameter': colorParameter, 'resTypeList': resTypeList, 'valRef': valRef}
pathDict = aimecTools.readAIMECinputs(avalancheDir, pathDict, dirName=anaMod)
Expand Down Expand Up @@ -317,9 +320,8 @@ def postProcessAIMEC(cfg, rasterTransfo, pathDict, resAnalysisDF, newRasters, ti
fnameMass = resAnalysisDF.loc[simRowHash, 'massBal']
resAnalysisDF, timeMass = aimecTools.analyzeMass(fnameMass, simRowHash, refSimRowHash, resAnalysisDF, time=timeMass)

if simRowHash != refSimRowHash:
massPlotName = outAimec.visuMass(resAnalysisDF, pathDict, simRowHash, refSimRowHash, timeMass)
resAnalysisDF.loc[simRowHash, 'massPlotName'] = massPlotName
massPlotName = outAimec.visuMass(resAnalysisDF, pathDict, simRowHash, refSimRowHash, timeMass)
resAnalysisDF.loc[simRowHash, 'massPlotName'] = massPlotName
else:
timeMass = None

Expand Down
7 changes: 5 additions & 2 deletions avaframe/ana3AIMEC/dfa2Aimec.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def getCompDirs(avaDir, cfgSetup):
return inputDirRef, inputDirComp, pathDict


def mainDfa2Aimec(avaDir, comModule, cfg):
def mainDfa2Aimec(avaDir, comModule, cfg, inputDir=''):
""" Fetch available raster results path from comModule to be used by Aimec

Parameters
Expand All @@ -273,6 +273,9 @@ def mainDfa2Aimec(avaDir, comModule, cfg):
computational module name that has been used to produce simulation results
cfg: configParser object
configuration for aimec
inputDir: str or pathlib path
optional- directory where peak files are located, if '',
avaDir/Outputs/comMod/peakFiles is set

Returns
--------
Expand All @@ -281,7 +284,7 @@ def mainDfa2Aimec(avaDir, comModule, cfg):
"""

# create data frame that lists all available simulations and path to their result type result files
inputsDF, resTypeList = fU.makeSimFromResDF(avaDir, comModule)
inputsDF, resTypeList = fU.makeSimFromResDF(avaDir, comModule, inputDir=inputDir)

# check if mass analysis shall be performed
if cfg['FLAGS'].getboolean('flagMass'):
Expand Down
2 changes: 1 addition & 1 deletion avaframe/com1DFA/com1DFACfg.ini
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ Bsamosatmedium = 4.13
#+++++++++++++Voellmy friction model
muvoellmy = 0.155
xsivoellmy = 4000.
#+++++++++++++VoellymMinShear friction model
#+++++++++++++VoellmyMinShear friction model
muvoellmyminshear = 0.155
xsivoellmyminshear = 4000.
tau0voellmyminshear = 70
Expand Down
20 changes: 15 additions & 5 deletions avaframe/in1Data/getInput.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,18 +733,28 @@ def getInputPaths(avaDir):
full path to DEM .asc file
relFiles : list
list of full paths to release area scenario .shp files found in avaDir/Inputs/REL
relFieldFiles : list
list of full paths to release area thickness .asc files found in avaDir/Inputs/RELTH

"""

# Set directories for inputs, outputs and current work
inputDir = pathlib.Path(avaDir, 'Inputs')


releaseDir = 'REL'
releaseDir = inputDir / 'REL'
relFiles = sorted(list(releaseDir.glob('*.shp')))
# fetch release area shp files
releaseShpDir = inputDir / 'REL'
relFiles = sorted(list(releaseShpDir.glob('*.shp')))
log.info('Release area files are: %s' % [str(relFilestr) for relFilestr in relFiles])

# fetch release thickness fields
releaseFieldDir = inputDir / 'RELTH'
relFieldFiles = sorted(list(releaseFieldDir.glob('*.asc')))
if len(relFieldFiles) > 0:
log.info('Release area files are: %s' % [str(relFFilestr) for relFFilestr in relFieldFiles])
else:
relFieldFiles = None

# Initialise DEM
demFile = getDEMPath(avaDir)

return demFile, relFiles
return demFile, relFiles, relFieldFiles
29 changes: 16 additions & 13 deletions avaframe/out3Plot/outAIMEC.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,30 +353,33 @@ def visuMass(resAnalysisDF, pathDict, simRowHash, refSimRowHash, timeMass):
for ax, field, title, unit in zip(axes.flatten(), fieldList, Title, Unit):
refArray = resAnalysisDF.loc[refSimRowHash, field]
simArray = resAnalysisDF.loc[simRowHash, field]
if refSimRowHash != simRowHash:
ax.plot(timeMass, simArray, '-b', label='Simulation : %s ' % simName)
ax.plot(timeMass, refArray, '-k', label='Reference : %s ' % refSimName)
ax.plot(timeMass, simArray, '-b', label='Simulation : %s ' % simName)

ax.set_title(title + ' function of time')
ax.legend(loc=1)
ax.set_xlabel('t [s]')
ax.set_ylabel(unit)

ax2 = axes.flatten()[1].twinx()
ax2.spines['right'].set_color('r')
ax2.tick_params(axis='y', colors='r')
ax2.plot(timeMass, (simArray-refArray) / refArray*100, 'r', label='total mass')
if refSimRowHash != simRowHash:
ax2 = axes.flatten()[1].twinx()
ax2.spines['right'].set_color('r')
ax2.tick_params(axis='y', colors='r')
# after loop this refers o the totalMassArray field as final item in fieldList
ax2.plot(timeMass, (simArray-refArray) / refArray*100, 'r--', label='total mass')

if np.any(entMass):
axes.flatten()[1].text(timeMass[-1]/4, (np.nanmin(refArray) + np.nanmax(refArray))/2,
'Entrained Mass Difference : %.2f kg \n Relative to total mass : %.2f %% ' %
((entMassRef-entMass), (entMassRef-entMass)/finalMassRef*100),
bbox=dict(boxstyle="square", ec='white', fc='white'),
horizontalalignment='left', verticalalignment='bottom')
if np.any(entMass):
axes.flatten()[1].text(timeMass[-1]/4, (np.nanmin(refArray) + np.nanmax(refArray))/2,
'Entrained Mass Difference : %.2f kg \n Relative to total mass : %.2f %% ' %
((entMassRef-entMass), (entMassRef-entMass)/finalMassRef*100),
bbox=dict(boxstyle="square", ec='white', fc='white'),
horizontalalignment='left', verticalalignment='bottom')

ax2.set_ylabel('Entrained Mass Difference relative to total mass[%]', color='r')
ax2.set_ylabel('Total Mass Difference [%]', color='r')

outFileName = '_'.join([projectName, str(simName), 'massAnalysis'])
pU.putAvaNameOnPlot(ax2, pathDict['projectName'])
pU.putAvaNameOnPlot(ax, pathDict['projectName'])
outFilePath = pU.saveAndOrPlot(pathDict, outFileName, fig)

return outFilePath
Expand Down
4 changes: 2 additions & 2 deletions avaframe/runScripts/runAna3AIMEC.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
# ---------------------------------------------


def runAna3AIMEC(avalancheDir, cfg):
def runAna3AIMEC(avalancheDir, cfg, inputDir=''):
""" run script for AIMEC analysis
proceeds to AIMEC analysis and produces plots and reports
"""

rasterTransfo, resAnalysisDF, plotDict, _, pathDict = ana3AIMEC.fullAimecAnalysis(avalancheDir, cfg)
rasterTransfo, resAnalysisDF, plotDict, _, pathDict = ana3AIMEC.fullAimecAnalysis(avalancheDir, cfg, inputDir=inputDir)

return pathDict, rasterTransfo, resAnalysisDF, plotDict

Expand Down
7 changes: 7 additions & 0 deletions docs/moduleAna3AIMEC.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ To run

python3 runScripts/runAna3AIMEC.py

.. Note::
In the default configuration, the analysis is performed on the simulation result files located in ``NameOfAvalanche/Outputs/anaMod/peakFiles``, where anaMod is specified in the aimecCfg.ini. There is also the option to directly provide a path to an input directory to the :py:func:`ana3AIMEC.ana3AIMEC.fullAimecAnalysis`. However, the peak field file names need to have a specific format: *A_B_C_D_E.asc*, where:

- A - *releaseAreaScenario*: refers to the name of the release shape file
- B - *simType*: refers to null (no entrainment, no resistance)
awirb marked this conversation as resolved.
Show resolved Hide resolved
- C - *simulationID*: needs to be unique for the respective simulation and include the model name
fso42 marked this conversation as resolved.
Show resolved Hide resolved
- D - *modelType*: can be any descriptive string of the employed model (here dfa for dense flow avalanche) * E - *result type*: is pft (peak flow thickness) and pfv (peak flow velocity)

Theory
-----------
Expand Down