예제 #1
0
def plotOpenfastError(testSolution, baselineSolution, attribute):
    testSolution, baselineSolution, attribute = _validateAndExpandInputs(
        [testSolution, baselineSolution, attribute])
    dict1, info1 = _parseSolution(testSolution)
    dict2, info2 = _parseSolution(baselineSolution)

    try:
        channel = info1['attribute_names'].index(attribute)
    except Exception as e:
        rtl.exitWithError("Error: Invalid channel name--{}".format(e))

    title1 = attribute + " (" + info1["attribute_units"][channel] + ")"
    title2 = "Max norm"
    xlabel = 'Time (s)'

    timevec = dict1[:, 0]
    y1series = np.array(dict1[:, channel], dtype=np.float)
    y2series = np.array(dict2[:, channel], dtype=np.float)
    plt = _plotError(timevec, y1series, y2series, xlabel, title1, title2)

    basePath = os.path.sep.join(testSolution.split(os.path.sep)[:-1])
    plotPath = os.path.join(basePath, "plots")
    rtl.validateDirOrMkdir(plotPath)
    _savePlot(plt, plotPath, attribute)

    plt.close()
def initializePlotDirectory(testSolution, plotList, relativeNorm, maxNorm):
    basePath = os.path.sep.join(testSolution.split(os.path.sep)[:-1])
    plotPath = os.path.join(basePath, "plots")
    caseName = basePath.split(os.path.sep)[-1]
    rtl.validateDirOrMkdir(plotPath)
    
    with open(os.path.join(plotPath, "plots.html"), "w") as html:
        
        html.write( _htmlHead(caseName) )
        
        html.write('<body>' + '\n')
        html.write('  <h2 class="text-center">{}</h2>'.format(caseName) + '\n')
        html.write('  <div class="container">' + '\n')
        html.write('  <h4 class="text-center">Maximum values for each norm are highlighted</h2>' + '\n')
        
        # Channel - Relative Norm - Max Norm
        data = [('<a href="#{0}">{0}</a>'.format(plot), relativeNorm[i], maxNorm[i]) for i,plot in enumerate(plotList)]    
        maxRelNorm = max(relativeNorm)
        maxMaxNorm = max(maxNorm)
        table = _tableHead(['Channel', 'Relative Max Norm', 'Infinity Norm'])
        body = '      <tbody>' + '\n'
        for i, d in enumerate(data):
            body += '        <tr>' + '\n'
            body += '          <th scope="row">{}</th>'.format(i+1) + '\n'
            body += '          <td>{0:s}</td>'.format(d[0]) + '\n'
            
            fmt = '{0:0.4e}'
            if d[1] == maxRelNorm:
                body += ('          <td class="cell-highlight">' + fmt + '</td>').format(d[1]) + '\n'
            else:
                body += ('          <td>' + fmt + '</td>').format(d[1]) + '\n'
                    
            if d[2] == maxMaxNorm:
                body += ('          <td class="cell-highlight">' + fmt + '</td>').format(d[2]) + '\n'
            else:
                body += ('          <td>' + fmt + '</td>').format(d[2]) + '\n'
            body += '        </tr>' + '\n'
        body += '      </tbody>' + '\n'
        table += body
        table += '    </table>' + '\n'
        html.write(table)
        
        html.write('    <br>' + '\n')
        html.write('    <div class="row">' + '\n')
        for i,plot in enumerate(plotList):
            html.write('      <div id={} class="col-sm-12 col-md-6 col-lg-6">'.format(plot) + '\n')
            html.write('        <img src="{}" class="center-block img-responsive thumbnail">'.format(plot+".png") + '\n')
            html.write('      </div>' + '\n')
        html.write('    </div>' + '\n')
        html.write('  </div>' + '\n')
        html.write('</body>' + '\n')
        html.write( _htmlTail() )
    html.close()