11"""
2- Run script for running python com1DFA kernel
2+ Run script for running python com1DFA kernel
33"""
4+
45# Load modules
56# importing general python modules
67import time
1617from avaframe .in3Utils import logUtils
1718from avaframe .in3Utils import fileHandlerUtils as fU
1819
19- def runCom1DFA (avalancheDir = '' , calibration = '' ):
20- """ Run com1DFA in the default configuration with only an
20+
21+ def runCom1DFA (avalancheDir = "" , calibration = "" ):
22+ """Run com1DFA in the default configuration with only an
2123 avalanche directory as input and the (optional) friction calibration
2224 size
2325
@@ -38,21 +40,21 @@ def runCom1DFA(avalancheDir='', calibration=''):
3840 startTime = time .time ()
3941
4042 # log file name; leave empty to use default runLog.log
41- logName = ' runCom1DFA'
43+ logName = " runCom1DFA"
4244
4345 # Load avalanche directory from general configuration file
4446 # More information about the configuration can be found here
4547 # on the Configuration page in the documentation
4648 cfgMain = cfgUtils .getGeneralConfig ()
47- if avalancheDir != '' :
48- cfgMain [' MAIN' ][ ' avalancheDir' ] = avalancheDir
49+ if avalancheDir != "" :
50+ cfgMain [" MAIN" ][ " avalancheDir" ] = avalancheDir
4951 else :
50- avalancheDir = cfgMain [' MAIN' ][ ' avalancheDir' ]
52+ avalancheDir = cfgMain [" MAIN" ][ " avalancheDir" ]
5153
5254 # Start logging
5355 log = logUtils .initiateLogger (avalancheDir , logName )
54- log .info (' MAIN SCRIPT' )
55- log .info (' Current avalanche: %s' , avalancheDir )
56+ log .info (" MAIN SCRIPT" )
57+ log .info (" Current avalanche: %s" , avalancheDir )
5658
5759 # ----------------
5860 # Clean input directory(ies) of old work and output files
@@ -63,42 +65,50 @@ def runCom1DFA(avalancheDir='', calibration=''):
6365 # Set friction model according to cmd argument
6466 cfgCom1DFA = cfgUtils .getModuleConfig (com1DFA , avalancheDir , toPrint = False )
6567
66- if calibration .lower () == 'small' :
67- cfgCom1DFA ['GENERAL' ]['frictModel' ] = 'samosATSmall'
68- elif calibration .lower () == 'medium' :
69- cfgCom1DFA ['GENERAL' ]['frictModel' ] = 'samosATMedium'
70- elif calibration .lower () == 'large' :
71- cfgCom1DFA ['GENERAL' ]['frictModel' ] = 'samosAT'
72- elif calibration .lower () == 'auto' :
73- cfgCom1DFA ['GENERAL' ]['frictModel' ] = 'samosATAuto'
68+ if isinstance (cfgCom1DFA , pathlib .Path ):
69+ log .warning ("Expert mode detected - friction calibration override is ignored" )
70+ elif calibration .lower () == "small" :
71+ cfgCom1DFA ["GENERAL" ]["frictModel" ] = "samosATSmall"
72+ elif calibration .lower () == "medium" :
73+ cfgCom1DFA ["GENERAL" ]["frictModel" ] = "samosATMedium"
74+ elif calibration .lower () == "large" :
75+ cfgCom1DFA ["GENERAL" ]["frictModel" ] = "samosAT"
76+ elif calibration .lower () == "auto" :
77+ cfgCom1DFA ["GENERAL" ]["frictModel" ] = "samosATAuto"
7478 else :
75- log .info (' no friction calibration override given - using ini' )
79+ log .info (" no friction calibration override given - using ini" )
7680
7781 # ----------------
7882 # Run dense flow
7983 dem , plotDict , reportDictList , simDF = com1DFA .com1DFAMain (cfgMain , cfgInfo = cfgCom1DFA )
8084
8185 # Get peakfiles to return to QGIS
8286 avaDir = pathlib .Path (avalancheDir )
83- inputDir = avaDir / ' Outputs' / ' com1DFA' / ' peakFiles'
87+ inputDir = avaDir / " Outputs" / " com1DFA" / " peakFiles"
8488 peakFilesDF = fU .makeSimDF (inputDir , avaDir = avaDir )
8589
8690 # Print time needed
8791 endTime = time .time ()
88- log .info (' Took %6.1f seconds to calculate.' % (endTime - startTime ))
92+ log .info (" Took %6.1f seconds to calculate." % (endTime - startTime ))
8993
9094 return peakFilesDF
9195
9296
93- if __name__ == '__main__' :
94-
95- parser = argparse .ArgumentParser (description = 'Run com1DFA workflow' )
96- parser .add_argument ('avadir' , metavar = 'avalancheDir' , type = str , nargs = '?' , default = '' ,
97- help = 'the avalanche directory' )
98- parser .add_argument ('-fc' , '--friction_calibration' , choices = ['auto' , 'large' , 'medium' , 'small' , 'ini' ],
99- type = str , default = 'ini' ,
100- help = 'friction calibration override, possible values are large, medium , small, auto and ini.' +
101- 'Overrides default AND local configs' )
97+ if __name__ == "__main__" :
98+
99+ parser = argparse .ArgumentParser (description = "Run com1DFA workflow" )
100+ parser .add_argument (
101+ "avadir" , metavar = "avalancheDir" , type = str , nargs = "?" , default = "" , help = "the avalanche directory"
102+ )
103+ parser .add_argument (
104+ "-fc" ,
105+ "--friction_calibration" ,
106+ choices = ["auto" , "large" , "medium" , "small" , "ini" ],
107+ type = str ,
108+ default = "ini" ,
109+ help = "friction calibration override, possible values are large, medium , small, auto and ini."
110+ + "Overrides default AND local configs" ,
111+ )
102112
103113 args = parser .parse_args ()
104114 runCom1DFA (str (args .avadir ), str (args .friction_calibration ))
0 commit comments