Esempio n. 1
0
cfg = cfgUtils.getModuleConfig(com1DFAOrig)

startTime = time.time()

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

# Run Standalone DFA
reportDictList = com1DFAOrig.com1DFAOrigMain(cfg, avalancheDir)

# Print time needed
endTime = time.time()
log.info(('Took %s seconds to calculate.' % (endTime - startTime)))

# append parameters from logFile
for reportD in reportDictList:
    simName = reportD['simName']['name']
    parameterDict, reportD = fU.extractParameterInfo(avalancheDir, simName, reportD)


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

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

# write configuration to file
cfgUtils.writeCfgFile(avalancheDir, com1DFAOrig, cfg)
Esempio n. 2
0
    reportDictListcom1DFAOrig = com1DFAOrig.com1DFAOrigMain(
        cfgCom1DFAOrig, avaDir)

    for reportD1 in reportDictListcom1DFAOrig:
        simName1 = reportD1['simName']['name']
        parameterDict = fU.extractParameterInfo(avaDir, simName1, reportD1)

    # Generata plots for all peakFiles
    modNameOrig = 'com1DFAOrig'
    plotDictcom1DFAOrig = oP.plotAllPeakFields(avaDir, cfgCom1DFAOrig,
                                               cfgMain['FLAGS'], modNameOrig)

    # Set directory for com1DFA report
    reportDirOrig = os.path.join(outDir, 'com1DFAOrig', 'reports')
    # write report
    gR.writeReport(reportDirOrig, reportDictListcom1DFAOrig, cfgMain['FLAGS'],
                   plotDictcom1DFAOrig)

    #####################################################################
    # ######################### Run Com1DFA #############################
    # Run python DFA
    # 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)

    #######################################################
Esempio n. 3
0
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
Esempio n. 4
0
def test_writeReport(tmp_path):
    """ Test generation markdown report file """

    # Initialise input dictionary
    testDict = {
        'title info': {
            'name': 'This is my report title',
            'type': 'title',
            'testNo': 'this should not appear in the report if working fine!'
        },
        'simName': {
            'type': 'simName',
            'name': 'this is my simulation name'
        },
        'Testing Parameters': {
            'release area': 'release1HS2',
            'Mu': '0.155',
            'type': 'list'
        },
        'Release area': {
            'release area scenario': 'my test release area',
            'type': 'columns'
        },
        'Special Input': {
            'Additional snow-covered area': 'Area 1',
            'type': 'columns'
        },
        'Additional Info': {
            'type':
            'text',
            'Report Info':
            'This simulations were performed with a developement version.'
        },
        'Fancy plots': {
            'type':
            'image',
            'Peak Pressure Field of my test':
            'release1HS2_entres_dfa_0.750_pfd.png'
        }
    }

    # make a list of input dictionaries
    reportDictList = [testDict]

    # initialise cfg object and test directory
    cfg = configparser.ConfigParser()
    cfg['FLAGS'] = {'reportOneFile': True}

    # Call function to be tested
    gR.writeReport(tmp_path, reportDictList, cfg['FLAGS'])

    # Load simulation report
    reportFile = open(os.path.join(tmp_path, 'fullSimulationReport.md'), 'r')
    lines = reportFile.readlines()
    lineVals = []
    for line in lines:
        lineVals.append(line)

    # Test
    assert lineVals[0] == '# This is my report title \n'
    assert lineVals[7] == '| ---------- | ------ | \n'
    assert lineVals[8] == '| release area | release1HS2 | \n'
    assert lineVals[19] == '| Additional snow-covered area | \n'
    assert lineVals[20] == '| ----------| \n'
    assert lineVals[
        -3] == '![Peak Pressure Field of my test](release1HS2_entres_dfa_0.750_pfd.png) \n'