예제 #1
0
def getOutputParamsFromKPI(kpihash, orderPreservedKeys, ignoreSet):
    outputParams = []
    lookupTable = []
    for kpi in orderPreservedKeys:
        if kpi not in ignoreSet:
            metrichash = kpihash[kpi]
            if data_IO.str2bool(metrichash['IsParaviewMetric']):
                if not data_IO.str2bool(metrichash['extractStats']):
                    continue
            outputTypeList = parseOutputType(
                metrichash['DEXoutputFlag'],
                data_IO.str2bool(metrichash['IsParaviewMetric']))
            for outputType in outputTypeList:
                outputParams.append(kpi)
                lookupTable.append([kpi, outputType])
    return lookupTable
예제 #2
0
def createClip(metrichash, data_reader, data_display):
    camera = GetActiveCamera()
    renderView1 = GetActiveViewOrCreate('RenderView')

    opacity = float(metrichash['opacity'])
    bodyopacity = float(metrichash['bodyopacity'])
    data_display.Opacity = bodyopacity
    data_display.ColorArrayName = ['POINTS', '']
    cliptype = "Plane"
    plane = metrichash['plane']
    if 'invert' in metrichash.keys():
        invert = data_IO.str2bool(metrichash['invert'])
    else:
        invert = 0

    s = Clip(Input=data_reader)
    s.ClipType = cliptype
    s.ClipType.Origin = camera.GetFocalPoint()
    s.InsideOut = invert
    s.ClipType.Origin = setviewposition(metrichash['position'], camera)
    s.ClipType.Normal = planeNormalFromName(plane)
    sDisplay = Show(s, renderView1)
    sDisplay.ColorArrayName = [None, '']
    sDisplay.SetRepresentationType('Surface')
    sDisplay.DiffuseColor = [0.0, 1.0, 0.0]
    sDisplay.Specular = 0
    sDisplay.Opacity = opacity
    colorMetric(s, metrichash)
    try:
        if metrichash['image'].split("_")[1] == "solo":
            Hide(data_reader, renderView1)
    except:
        pass
    return s
예제 #3
0
def getOutImgsFromKPI(kpihash, orderPreservedKeys):
    imgTitles = []
    imgNames = []
    for kpi in orderPreservedKeys:
        metrichash = kpihash[kpi]
        isParaviewMetric = data_IO.str2bool(metrichash["IsParaviewMetric"])
        if not (isParaviewMetric
                or metrichash['DEXoutputFlag'].lower() == "image"):
            continue
        imageName = metrichash['imageName']
        if imageName != "None":
            imgTitles.append(kpi)
            imgNames.append(imageName)
        animation = data_IO.str2bool(metrichash['animation'])
        if animation:
            imgTitles.append(kpi + '_animation')
            imgNames.append(metrichash['animationName'])

    return imgTitles, imgNames
예제 #4
0
def getOutputParamsFromKPI(kpiFile):
    fp_jsonIn = data_IO.open_file(kpiFile)
    kpihash = json.load(fp_jsonIn, object_pairs_hook=OrderedDict)
    orderPreservedKeys = data_IO.byteify(list(kpihash.keys()))
    kpihash = data_IO.byteify(kpihash)
    fp_jsonIn.close()
    outputParams = []
    for kpi in orderPreservedKeys:
        metrichash = kpihash[kpi]
        kpitype = metrichash['type']

        if kpitype == "StreamLines":
            metrichash['extractStats'] = "False"

        if 'extractStats' in metrichash:
            extractStats = data_IO.str2bool(metrichash['extractStats'])
        else:
            extractStats = True

        if extractStats:
            outputParams.append(kpi)
    return outputParams
예제 #5
0
def colorMetric(d, metrichash):
    display = GetDisplayProperties(d)
    kpifld = metrichash['field']
    kpifldcomp = metrichash['fieldComponent']
    ColorBy(display, ('POINTS', kpifld, kpifldcomp))

    Render()
    UpdateScalarBars()
    ctf = GetColorTransferFunction(kpifld)
    try:
        ctf.ApplyPreset(metrichash["colorscale"], True)
    except:
        pass
    try:
        if data_IO.str2bool(metrichash["invertcolor"]):
            ctf.InvertTransferFunction()
    except:
        pass

    try:
        datarange = getdatarange(d, kpifld, kpifldcomp)
        min = datarange[0]
        max = datarange[1]
        if metrichash["min"] != "auto":
            min = float(metrichash["min"])
        if metrichash["max"] != "auto":
            max = float(metrichash["max"])
        ctf.RescaleTransferFunction(min, max)
        if int(metrichash["discretecolors"]) > 0:
            ctf.Discretize = 1
            ctf.NumberOfTableValues = int(metrichash["discretecolors"])
        else:
            ctf.Discretize = 0
    except:
        pass

    renderView1 = GetActiveViewOrCreate('RenderView')
    ctfColorBar = GetScalarBar(ctf, renderView1)

    ctfColorBar.Orientation = "Horizontal"

    # Properties modified on uLUTColorBar
    if 'barTitle' in metrichash:
        ctfColorBar.Title = metrichash["barTitle"]
    if 'ComponentTitle' in metrichash:
        ctfColorBar.ComponentTitle = metrichash["ComponentTitle"]
    if 'FontColor' in metrichash:
        ctfColorBar.TitleColor = data_IO.read_floats_from_string(
            metrichash["FontColor"])
        ctfColorBar.LabelColor = data_IO.read_floats_from_string(
            metrichash["FontColor"])
    else:
        ctfColorBar.TitleColor = [0, 0, 0]
        ctfColorBar.LabelColor = [0, 0, 0]
    if 'FontSize' in metrichash:
        ctfColorBar.TitleFontSize = int(metrichash["FontSize"])
        ctfColorBar.LabelFontSize = int(metrichash["FontSize"])
    if 'LabelFormat' in metrichash:
        ctfColorBar.LabelFormat = metrichash["LabelFormat"]
        ctfColorBar.RangeLabelFormat = metrichash["LabelFormat"]

    imgtype = metrichash['image'].split("_")[0]
    PVversion = getParaviewVersion()
    if (imgtype != "iso"):
        # center
        if PVversion < 5.04:
            ctfColorBar.Position = [0.25, 0.05]
            ctfColorBar.Position2 = [0.5, 0]  # no such property in PV 5.04
        else:
            ctfColorBar.WindowLocation = 'LowerCenter'
    else:
        # left
        if PVversion < 5.04:
            ctfColorBar.Position = [0.05, 0.025]
            ctfColorBar.Position2 = [0.4, 0]  # no such property in PV 5.04
        else:
            ctfColorBar.WindowLocation = 'LowerLeftCorner'
예제 #6
0
    if 'imageflip' in metrichash:
        kpiimageflip = metrichash['imageflip']
    else:
        kpiimageflip = "None"

    if individualImages:
        HideAll()
        Show(dataReader, renderView1)
        if kpiimage != "None" and kpiimage != "" and kpiimage != "plot":
            pvutils.adjustCamera(kpiimage, renderView1, metrichash,
                                 kpiimageflip)

    print(kpi)

    if 'extractStats' in metrichash:
        extractStats = data_IO.str2bool(metrichash['extractStats'])
    else:
        extractStats = True

    ave = []
    if kpitype == "Slice":
        d = pvutils.createSlice(metrichash, dataReader, readerDisplay,
                                individualImages)
    elif kpitype == "Clip":
        d = pvutils.createClip(metrichash, dataReader, readerDisplay,
                               individualImages)
    elif kpitype == "Probe":
        d = pvutils.createProbe(metrichash, dataReader)
    elif kpitype == "Line":
        d, ave = pvutils.createLine(metrichash, kpi, dataReader, outputDir)
    elif kpitype == "StreamLines":
kpiFile = sys.argv[2]
basepath=sys.argv[3]
deCSVFile = sys.argv[4]
imagesdir = data_IO.setOptionalSysArgs(sys.argv, "outputs/png", 5)
resultsDirRootName = data_IO.setOptionalSysArgs(sys.argv, "outputs/case", 6)
outputParamStatsFile = data_IO.setOptionalSysArgs(sys.argv, '', 7)

#ignoreList_default = ['PMV0', 'PPD0', 'WriteIntervalTime', 'ZoneRefineLevel', 'comfort_CLO', 'comfort_MET', 'comfort_RH', 'comfort_WME',
#     'comfort_ZULUFT', 'main_Floor_T', 'main_Floor_gradT']
ignoreList_default = []
ignoreList_default = ",".join(ignoreList_default)
ignoreList = data_IO.setOptionalSysArgs(sys.argv, ignoreList_default, 8)
ignoreSet = set(ignoreList.split(","))

extractedFileName = data_IO.setOptionalSysArgs(sys.argv, "metrics.csv", 9)
writeSingleValueInputs = data_IO.str2bool(data_IO.setOptionalSysArgs(sys.argv, "False", 10))


# Read the input parameters from the cases.list file (also works with a sweep.run file but
# make sure the order is the same as cases.list files used for running the cases)
cases = paramUtils.readParamsFile(paramsFile)
print(" Read " + str(len(cases)) + " Cases")

# Get the list of input parameters from the first case
inputVarNames = paramUtils.getParamNamesFromCase(cases[0])
inputVarNames = list(set(inputVarNames)-ignoreSet)

# Add the values of input parameters for each case to caselist
caselist = paramUtils.writeInputParamVals2caselist(cases, inputVarNames)

# Read the desired output metrics
예제 #8
0
print("Generating KPIs")

# Set the default values for missing fields in the kpihash
for kpi in kpihash:
    kpihash[kpi] = metricsJsonUtils.setKPIFieldDefaults(kpihash[kpi], kpi)
    if not (kpihash[kpi]['field'] == 'None'):
        kpihash[kpi] = pvutils.correctfieldcomponent(dataReader, kpihash[kpi])

fp_csv_metrics = data_IO.open_file(metricFile, "w")
fp_csv_metrics.write(",".join(['metric', 'ave', 'min', 'max', 'sd']) + "\n")

renderView1.InteractionMode = '2D'
renderView1.OrientationAxesVisibility = 0

for kpi in kpihash:
    if not data_IO.str2bool(kpihash[kpi]['IsParaviewMetric']):
        continue
    metrichash = kpihash[kpi]
    kpitype = metrichash['type']
    kpifield = metrichash['field']
    kpiComp = metrichash['fieldComponent']
    kpiimage = metrichash['image']
    extractStats = data_IO.str2bool(metrichash['extractStats'])
    makeAnim = data_IO.str2bool(metrichash['animation'])
    export2Blender = data_IO.str2bool(metrichash['blender'])

    HideAll()
    Show(dataReader, renderView1)
    if kpiimage != "None" and kpiimage != "plot":
        pvutils.adjustCamera(kpiimage, renderView1, metrichash)
예제 #9
0
if len(sys.argv) < 6:
    print("Number of provided arguments: ", len(sys.argv) - 1)
    print("Usage: python2 writeDEcsv.py <sweepParams.run> <outputParams.txt> <DesignExplorer.csv> <extractedFileName>"
          " <resultsDirRootName>")
    print("[writeSingleValuedOutputs=True]")
    sys.exit()


inputParamsFileAddress = sys.argv[1]
outputParamsFileAddress = sys.argv[2]
outcsvFileAddress = sys.argv[3]
extractedFileName = sys.argv[4]
resultsDirRootName = sys.argv[5]

if len(sys.argv) >= 7:
    writeSingleValueInputs = data_IO.str2bool(sys.argv[6])
else:
    writeSingleValueInputs = True


with open(inputParamsFileAddress) as f:
    content = f.read().splitlines()

pvals = {}
for x in content:
    if "null" not in x and x != "":
        pname = x.split(";")[0]
        pval = x.split(";")[1]
        if " " in pval:
            pval = pval.split(" ")
        elif ":" in pval:
    elif kpitype == "Slice":
        # get kpi field value and area - average = value/area
        integrateVariables = IntegrateVariables(Input=d)
        average= pvutils.getdatarange(integrateVariables, kpifield, kpiComp)[0]\
                 / integrateVariables.CellData['Area'].GetRange()[0]
    elif kpitype == "Volume" or kpitype == "Clip":
        integrateVariables = IntegrateVariables(Input=d)
        average= pvutils.getdatarange(integrateVariables, kpifield, kpiComp)[0]\
                 / integrateVariables.CellData['Volume'].GetRange()[0]

    fp_csv_metrics.write(",".join([kpi,str(average),str(datarange[0]),str(datarange[1])])
                         +"\n")

    if individualImages:
        if kpiimage != "None" and kpiimage != "" and kpiimage != "plot":
            if not (os.path.exists(outputDir)):
                os.makedirs(outputDir)
            SaveScreenshot(outputDir + "/out_" + kpi + ".png", magnification=magnification, quality=100)

    if 'animation' in metrichash:
        makeAnim = data_IO.str2bool(metrichash['animation'])
    else:
        makeAnim = False
    if makeAnim:
        pvutils.makeAnimation(outputDir, kpi, magnification)


fp_csv_metrics.close()

SaveScreenshot(outputDir + "/out_stl.png", magnification=magnification, quality=100)
def setKPIFieldDefaults(metrichash, kpi, caseNumber=""):

    # Set component to "Magnitude" if not given for vector/tensor fields
    if not ('field' in metrichash):
        metrichash['field'] = 'None'
        metrichash['fieldComponent'] = 'None'

    if not ('IsParaviewMetric' in metrichash):
        metrichash['IsParaviewMetric'] = 'True'

    if not ('DEXoutputFlag' in metrichash):
        if data_IO.str2bool(metrichash['IsParaviewMetric']):
            metrichash['DEXoutputFlag'] = 'all'
        else:
            metrichash['DEXoutputFlag'] = ''

    # If not a Paraview Metric, make sure the information for extracting
    # data/images from a generic file is provided.
    if not data_IO.str2bool(metrichash['IsParaviewMetric']):
        if metrichash['DEXoutputFlag'].lower() == "image":
            if not ('imageName' in metrichash):
                metrichash['imageName'] = "out_" + kpi + ".png"

        if metrichash['DEXoutputFlag'].lower() == "animation":
            if not ('animation' in metrichash):
                metrichash['animation'] = 'True'
            if not data_IO.str2bool(metrichash['animation']):
                warnings.warn('Setting {}.animation to True'.format(kpi))
                metrichash['animation'] = 'True'
            if not ('animationName' in metrichash):
                metrichash['animationName'] = "out_" + kpi + ".gif"
        else:
            metrichash['animation'] = 'False'

        if not (metrichash['DEXoutputFlag'].lower()
                in {"none", "image", "animation"}):
            if not ('resultFile' in metrichash):
                warningMsg = 'Please provide resultFile for {}. Setting ' \
                             '{}.DEXoutputFlag to "none".'.format(kpi, kpi)
                warnings.warn(warningMsg)
                metrichash['DEXoutputFlag'] = 'none'
            if not ("delimiter" in metrichash):
                metrichash["delimiter"] = ""
            if not ("locationInFile" in metrichash):
                metrichash["locationInFile"] = "1"
        return metrichash

    # Set default image properties
    if not ('image' in metrichash):
        metrichash['image'] = 'None'
        metrichash['imageName'] = 'None'
    if not ('bodyopacity' in metrichash):
        metrichash['bodyopacity'] = "0.3"
    if not ('min' in metrichash):
        metrichash['min'] = 'auto'
    if not ('max' in metrichash):
        metrichash['max'] = 'auto'
    if not ('discretecolors' in metrichash):
        metrichash['discretecolors'] = '20'
    if not ('colorscale' in metrichash):
        metrichash['colorscale'] = 'Blue to Red Rainbow'
    if not ('invertcolor' in metrichash):
        metrichash['invertcolor'] = 'False'
    if not ('opacity' in metrichash):
        metrichash['opacity'] = "1"

    # Set image name
    if not ('image' == 'None'):
        if not ('imageName' in metrichash):
            if metrichash['image'] == "plot":
                metrichash['imageName'] = "plot_" + kpi + ".png"
            else:
                metrichash['imageName'] = "out_" + kpi + ".png"

    # Set default streamline properties
    if metrichash['type'] == "StreamLines":
        if not ('seedType' in metrichash):
            metrichash['seedType'] = 'Line'

    if not ('extractStats' in metrichash):
        if metrichash['field'] == 'None':
            metrichash['extractStats'] = 'False'
        else:
            metrichash['extractStats'] = 'True'

    if not data_IO.str2bool(metrichash['extractStats']):
        metrichash['DEXoutputFlag'] = 'none'

    if not ('animation' in metrichash):
        metrichash['animation'] = 'False'

    if data_IO.str2bool(metrichash['animation']):
        if not ('animationName' in metrichash):
            metrichash['animationName'] = "out_" + kpi + ".gif"

    if not ('blender' in metrichash):
        metrichash['blender'] = 'False'
    else:
        try:
            metrichash['blendercontext'] = metrichash['blendercontext'].split(
                ",")
        except:
            metrichash['blendercontext'] = []
        try:
            metrichash['blenderbody'] = metrichash['blenderbody'].split(",")
        except:
            metrichash['blenderbody'] = False

    return metrichash