简体   繁体   中英

How do I set color table ranges in a Paraview python script?

I'm visualizing a time series of spatial data in Paraview, and I would like for my setup script to set the color tables for a given field based on the field's range over the full time series, rather than an individual snapshot. I've tried initializing the lookup table with values computed by the script, but to no avail.

The figure below shows results of running my setup script. The values in the Python Shell window are what the scales should be set to, but the color bar shows another value.

运行安装脚本的结果。 “ Python Shell”窗口中的值是应该设置比例的值,但是颜色栏显示了另一个值

The relevant part of my setup script is here.

# get the scales for the surface fields
mag_os_xdmf = FindSource('mag_os.xdmf')
with h5py.File(mag_os_xdmf.FileName.replace('xdmf', 'h5'), 'r') as h5:
    for comp in ('br', 'bt', 'bp'):
        scale = np.abs(h5[comp].value).max()
        print(comp, scale)
        ctab = [-scale, 0.23137254901960785, 0.2980392156862745, 0.7529411764705882,
                scale, 0.7058823529411765, 0.01568627450980392, 0.14901960784313725]
        DataRep = GetDisplayProperties(mag_os_xdmf)
        lut = GetLookupTableForArray(comp, 1, NanColor=[0.24705882352941178, 0.0, 0.0],
                                     RGBPoints = ctab, ColorSpace='Diverging' )
        DataRep.ColorArrayName = ('POINT_DATA', comp)
        DataRep.LookupTable = lut
Render()

For comparison, here's the output of a python trace when I manually change the colorbar

try: paraview.simple
except: from paraview.simple import *
paraview.simple._DisableFirstRenderCameraReset()

mag_os_xdmf = GetActiveSource()
DataRepresentation6 = GetDisplayProperties(mag_os_xdmf)
a1_br_PVLookupTable = GetLookupTableForArray( "br", 1, RGBPoints=[-0.122, 0.23, 0.299, 0.754, 0.122, 0.706, 0.016, 0.15] )

DataRepresentation6.ScalarOpacityFunction = []
DataRepresentation6.ColorArrayName = ('POINT_DATA', 'br')
DataRepresentation6.LookupTable = a1_br_PVLookupTable

Render()

You should be able to do something like the following:

# get color transfer function/color map for 'br'
lut = GetColorTransferFunction('br')

# get opacity transfer function/opacity map for 'br'
opacityLut = GetOpacityTransferFunction('br')

# Rescale transfer function
lut.RescaleTransferFunction(-scale, scale)

# Rescale transfer function
opacityLut.RescaleTransferFunction(-scale, scale)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM