コード例 #1
0
def test_cleanModuleFiles(tmp_path):

    # Make sure cleanModuleFile catches:
    # - empty variable
    undefVar = initProj.cleanModuleFiles('', 'Module')
    assert undefVar == 'AvaDir is empty'

    # - non string variable
    notAString = initProj.cleanModuleFiles(2, 'Module')
    assert notAString == 'AvaDir is NOT a string'

    # create test directories
    # then delete and check again
    avaDir = tmp_path / "avaTestDir"
    initProj.initializeFolderStruct(avaDir)

    # make test dirs in outputs
    for dirName in ['com2AB', 'com1DFA', 'TestDir']:
        testDir = os.path.join(avaDir, 'Outputs', dirName)
        os.makedirs(testDir)

    # make test dirs in work
    for dirName in ['com2AB', 'com1DFA', 'TestDir']:
        testDir = os.path.join(avaDir, 'Work', dirName)
        os.makedirs(testDir)

    outputDir = os.path.join(avaDir, 'Outputs')
    workDir = os.path.join(avaDir, 'Work')

    # call the function
    initProj.cleanModuleFiles(str(avaDir), c2)

    # only 2 directories should remain in Work and Output
    assert len(os.listdir(workDir)) == 2
    assert len(os.listdir(outputDir)) == 2

    # call the function this time with the alternativeName
    initProj.cleanModuleFiles(str(avaDir), c2, alternativeName='TestDir')

    # only 1 directory should remain in Work and Output
    assert len(os.listdir(workDir)) == 1
    assert len(os.listdir(outputDir)) == 1
コード例 #2
0
ファイル: runAna3AIMEC.py プロジェクト: avaframe/AvaFrame
# ---------------------------------------------
# Load avalanche directory from general configuration file
cfgMain = cfgUtils.getGeneralConfig()
avalancheDir = cfgMain['MAIN']['avalancheDir']

# Start logging
log = logUtils.initiateLogger(avalancheDir, logName)
log.info('MAIN SCRIPT')
log.info('Current avalanche: %s', avalancheDir)

# Load all input Parameters from config file
# get the configuration of an already imported module
# write config to log file
cfg = cfgUtils.getModuleConfig(ana3AIMEC)

iP.cleanModuleFiles(avalancheDir, ana3AIMEC)

# write configuration to file
cfgUtils.writeCfgFile(avalancheDir, ana3AIMEC, cfg)

cfgSetup = cfg['AIMECSETUP']
anaMod = cfgSetup['anaMod']

# set parameter for standard aimec analysis with mass analysis
cfgSetup['resType'] = 'ppr'
cfgSetup['thresholdValue'] = '1'
cfgSetup['diffLim'] = '5'
cfgSetup['contourLevels'] = '1|3|5|10'
cfg['FLAGS']['flagMass'] = 'True'

# Setup input from com1DFA
コード例 #3
0
ファイル: runCom1DFA.py プロジェクト: avaframe/AvaFrame
def runCom1DFA(avaDir='', cfgFile='', relThField='', variationDict=''):
    """ run com1DFA module """

    # +++++++++SETUP CONFIGURATION++++++++++++++++++++++++
    # log file name; leave empty to use default runLog.log
    logName = 'runCom1DFA'

    # Load avalanche directory from general configuration file
    cfgMain = cfgUtils.getGeneralConfig()
    if avaDir != '':
        avalancheDir = avaDir
    else:
        avalancheDir = cfgMain['MAIN']['avalancheDir']
    # set module name, reqiured as long we are in dev phase
    # - because need to create e.g. Output folder for com1DFA to distinguish from
    # current com1DFA
    modName = 'com1DFA'

    # Clean input directory(ies) of old work and output files
    # initProj.cleanSingleAvaDir(avalancheDir, keep=logName, deleteOutput=False)
    initProj.cleanModuleFiles(avalancheDir, com1DFA, modName)

    # Start logging
    log = logUtils.initiateLogger(avalancheDir, logName)
    log.info('MAIN SCRIPT')
    log.info('Current avalanche: %s', avalancheDir)

    # Create output and work directories
    # - because need to create e.g. Output folder for com1DFA to distinguish from
    workDir, outDir = inDirs.initialiseRunDirs(avalancheDir, modName)

    # generate list of simulations from desired configuration
    if variationDict == '':
        # Load full configuration
        modCfg, modInfo = cfgUtils.getModuleConfig(com1DFA,
                                                   fileOverride=cfgFile,
                                                   modInfo=True)
        variationDict = dP.getVariationDict(avalancheDir, modCfg, modInfo)
    else:
        # check if variationDict items exist and are provided in correct format
        # Load standard/ default configuration
        modCfg = cfgUtils.getDefaultModuleConfig(com1DFA)
        variationDict = dP.validateVarDict(variationDict, modCfg)
        log.info('Variations are performed for:')
        for key in variationDict:
            log.info('%s: %s' % (key, variationDict[key]))

    # add avalanche directory info to cfg
    modCfg['GENERAL']['avalancheDir'] = avalancheDir

    # fetch input data - dem, release-, entrainment- and resistance areas
    inputSimFiles = gI.getInputDataCom1DFAPy(avalancheDir, modCfg['FLAGS'])

    # write full configuration file to file
    cfgUtils.writeCfgFile(avalancheDir,
                          com1DFA,
                          modCfg,
                          fileName='sourceConfiguration')

    # create a list of simulations
    # if need to reproduce exactely the hash - need to be strings with exactely the same number of digits!!
    simDict = com1DFA.prepareVarSimDict(modCfg, inputSimFiles, variationDict)

    log.info('The following simulations will be performed')
    for key in simDict:
        log.info('Simulation: %s' % key)

    reportDictList = []
    # loop over all simulations
    for cuSim in simDict:

        # load configuration dictionary for cuSim
        cfg = simDict[cuSim]['cfgSim']

        # save configuration settings for each simulation
        simHash = simDict[cuSim]['simHash']
        cfgUtils.writeCfgFile(avalancheDir, com1DFA, cfg, fileName=cuSim)

        # log simulation name
        log.info('Run simulation: %s' % cuSim)

        # set release area scenario
        inputSimFiles['releaseScenario'] = simDict[cuSim]['relFile']

        # +++++++++++++++++++++++++++++++++
        # ------------------------
        particlesList, fieldsList, Tsave, dem, reportDict, cfgFinal = com1DFA.com1DFAMain(
            cfg, avalancheDir, cuSim, inputSimFiles, outDir, relThField)

        # +++++++++EXPORT RESULTS AND PLOTS++++++++++++++++++++++++
        # Generate plots for all peakFiles
        plotDict = oP.plotAllPeakFields(avalancheDir, cfg, cfgMain['FLAGS'],
                                        modName)

        reportDictList.append(reportDict)

        # export for visulation
        if cfg['VISUALISATION'].getboolean('writePartToCSV'):
            outDir = os.path.join(avalancheDir, 'Outputs', modName)
            com1DFA.savePartToCsv(cfg['VISUALISATION']['particleProperties'],
                                  particlesList, outDir)

        # create hash to check if config didnt change
        simHashFinal = cfgUtils.cfgHash(cfgFinal)
        if simHashFinal != simHash:
            log.warning(
                'simulation configuration has been changed since start')
            cfgUtils.writeCfgFile(avalancheDir,
                                  com1DFA,
                                  cfg,
                                  fileName='%s_butModified' % simHash)

    # Set directory for report
    reportDir = os.path.join(avalancheDir, 'Outputs', 'com1DFA', 'reports')
    # write report
    gR.writeReport(reportDir, reportDictList, cfgMain['FLAGS'], plotDict)

    # read all simulation configuration files and return dataFrame and write to csv
    standardCfg = cfgUtils.getDefaultModuleConfig(com1DFA)
    simDF = cfgUtils.createConfigurationInfo(avalancheDir,
                                             standardCfg,
                                             writeCSV=True)

    return particlesList, fieldsList, Tsave, dem, plotDict, reportDictList
コード例 #4
0
ファイル: runDamBreak.py プロジェクト: avaframe/AvaFrame
from avaframe.in3Utils import fileHandlerUtils as fU
from avaframe.ana1Tests import damBreak
import avaframe.in3Utils.initializeProject as initProj
from avaframe.in3Utils import cfgUtils
from avaframe.in3Utils import logUtils

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

# Load settings from general configuration file
cfgMain = cfgUtils.getGeneralConfig()
avaDir = 'data/avaDamBreak'
cfgMain['MAIN']['avalancheDir'] = avaDir

# Clean input directory(ies) of old work and output files
initProj.cleanModuleFiles(avaDir, com1DFA, 'com1DFA')

# Start logging
log = logUtils.initiateLogger(avaDir, logName)
log.info('MAIN SCRIPT')
log.info('Current avalanche: %s', avaDir)

# Load configuration
damBreakCfg = os.path.join(avaDir, 'Inputs', 'damBreak_com1DFACfg.ini')
cfg = cfgUtils.getModuleConfig(com1DFA, damBreakCfg)
cfgGen = cfg['GENERAL']

# Load flow depth from analytical solution
hL, hR, uR, phi, xR = damBreak.damBreakSol(avaDir, cfgMain, cfg)
xR = xR * np.cos(phi)  # projected on the horizontal plane
dtAnalysis = cfg['DAMBREAK'].getfloat('dtStep')
コード例 #5
0
    # call com1DFA to perform simulation - provide configuration file and release thickness function
    _, _, _, _, plotDictcom1DFA, reportDictListcom1DFA = runCom1DFA.runCom1DFA(
        avaDir=avaDir, cfgFile='', relThField='')

    # Set directory for com1DFA report
    reportDir = os.path.join(outDir, 'com1DFA', 'reports')
    # write report
    gR.writeReport(reportDir, reportDictListcom1DFA, cfgMain['FLAGS'],
                   plotDictcom1DFA)

    #######################################################
    # ########### Analyze results ##########################
    # Aimec analysis
    # load configuration
    cfgAimec = cfgUtils.getModuleConfig(ana3AIMEC)
    initProj.cleanModuleFiles(avaDir, ana3AIMEC)
    # get release area scenarios
    relArea = []
    for dict in reportDictListcom1DFA:
        relArea.append(dict['Simulation Parameters']['Release Area Scenario'])
    relAreaSet = sorted(set(relArea))

    for rel in relAreaSet:
        reportDcom1DFAOrig = ''
        for dict in reportDictListcom1DFAOrig:
            com1DFASimName = dict['simName']['name']
            if (rel == dict['Simulation Parameters']['Release Area Scenario']):
                if simTypeString in com1DFASimName:
                    reportDcom1DFAOrig = dict
                    log.info(
                        'Comparison based on releaseScenario: %s and simType: %s'
コード例 #6
0
# from avaframe.DFAkernel.setParam import *
from avaframe.in3Utils import cfgUtils
from avaframe.in3Utils import logUtils
import avaframe.out3Plot.makePalette as makePalette

# +++++++++SETUP CONFIGURATION++++++++++++++++++++++++
# log file name; leave empty to use default runLog.log
logName = 'runFlatPlaneTest'

# Load avalanche directory from general configuration file
cfgMain = cfgUtils.getGeneralConfig()
avalancheDir = 'data/avaFPtest'
modName = 'com1DFA'

# Clean input directory(ies) of old work and output files
initProj.cleanModuleFiles(avalancheDir, com1DFA, modName)

# Start logging
log = logUtils.initiateLogger(avalancheDir, logName)
log.info('MAIN SCRIPT')
log.info('Current avalanche: %s', avalancheDir)

# Load configuration
FPCfg = os.path.join(avalancheDir, 'Inputs', 'FlatPlane_com1DFACfg.ini')
cfg = cfgUtils.getModuleConfig(com1DFA, FPCfg)
cfgGen = cfg['GENERAL']
cfgFP = cfg['FPSOL']

# for timing the sims
startTime = time.time()
# create output directory for test result plots