Hi,

I am tying to run a ParaView pipeline that uses a dataset. In this case,
the dataset has both three (time,y,x) and four (time,z,y,x) dimensional
fields. In the pipeline, i am loading the same dataset twice (by changing
dimensions in the properties window) to access different variables because
i am using both 3 and 4 dimensional fields together to create final
visualisation. Until, this point everything is fine and it works.

Then, i am using co-processing plugin to export pipeline as Python script
and wrote a driver to trigger visualisation pipeline (in Python). If i use
only fields with 3 (or 4) dimension, then attached driver script works
without any problem (driver_00.py) but if i use both 3 and 4 dimensional
fields then i need to send two different dataset to DoCoProcessing routine
but i could not make it work. I tried to create two different readers like
following

# read datasets
reader1 = pvsimple.NetCDFReader(FileName=sys.argv[2])
reader1.Dimensions = '(zlev, iy, jx)'
reader1.SphericalCoordinates = False
reader2 = pvsimple.NetCDFReader(FileName=sys.argv[3])
reader2.Dimensions = '(iy, jx)'
reader2.SphericalCoordinates = False

then i tried to send both of them to coProcess

    dset1 = reader1.GetClientSideObject().GetOutputDataObject(0)
    dset2 = reader2.GetClientSideObject().GetOutputDataObject(0)

    coProcess(dset1, dset2, time, step, sys.argv[1])

by adding extra argument to the coProcess routine and run it as follows

    cpscript.RequestDataDescription(datadescription)
    inputdesc1 = datadescription.GetInputDescriptionByName("input")
    if inputdesc1.GetIfGridIsNecessary() == False:
        return
    inputdesc1.SetGrid(grid1)

    datadescription.AddInput("input1")
    inputdesc2 = datadescription.GetInputDescriptionByName("input1")
    if inputdesc2.GetIfGridIsNecessary() == False:
        return
    inputdesc2.SetGrid(grid2)

    cpscript.DoCoProcessing(datadescription)

but it is not working. Somehow, i need to add information about the 3 and
4 dimensional fields to data description object. Right? Anyway, my
question is that how could i send two different dataset to my
visualisation pipeline (coproc_01.py).

Thanks,
Regards,

--ufuk
import sys
print len(sys.argv)
print sys.argv
if len(sys.argv) != 3:
    print 'missing args'
    sys.exit(1)
import paraview
import paraview.vtk as vtk
import paraview.simple as pvsimple

paraview.options.batch = True
paraview.options.symmetric = True

def _refHolderMaker(obj):
    def _refHolder(obj2, string):
        tmp = obj
    return _refHolder

def coProcess(grid1, time, step, scriptname):
    
    import vtkPVCatalystPython as vtkCoProcessorPython
    if scriptname.endswith(".py"):
        scriptname = scriptname[0:len(scriptname)-3]
    try:
        cpscript = __import__(scriptname)
    except:
        print 'Cannot find ', scriptname
        return

    datadescription = vtkCoProcessorPython.vtkCPDataDescription()
    datadescription.SetTimeData(time, step)

    datadescription.AddInput("input")
    cpscript.RequestDataDescription(datadescription)
    inputdesc1 = datadescription.GetInputDescriptionByName("input")
    if inputdesc1.GetIfGridIsNecessary() == False:
        return
    inputdesc1.SetGrid(grid1)

    cpscript.DoCoProcessing(datadescription)

# read datasets
reader1 = pvsimple.NetCDFReader(FileName=sys.argv[2])
reader1.Dimensions = '(zlev, iy, jx)'
reader1.SphericalCoordinates = False

# get time array
timeArray = reader1.TimestepValues

# loop over time array and feed coprocessing
for step in range(len(timeArray)):
    # get time step
    time = reader1.TimestepValues[step]
    print "Processing Time Step = ", time

    reader1.UpdatePipeline(time)
    dset1 = reader1.GetClientSideObject().GetOutputDataObject(0)

    coProcess(dset1, time, step, sys.argv[1])
from paraview.simple import *
from paraview import coprocessing


#--------------------------------------------------------------
# Code generated from cpstate.py to create the CoProcessor.
# ParaView 4.3.1 64 bits


# ----------------------- CoProcessor definition -----------------------

def CreateCoProcessor():
  def _CreatePipeline(coprocessor, datadescription):
    class Pipeline:
      # state file generated using paraview version 4.3.1

      # ----------------------------------------------------------------
      # setup views used in the visualization
      # ----------------------------------------------------------------

      #### disable automatic camera reset on 'Show'
      paraview.simple._DisableFirstRenderCameraReset()

      # Create a new 'Render View'
      renderView1 = CreateView('RenderView')
      renderView1.ViewSize = [1082, 598]
      renderView1.CenterOfRotation = [28.320641407624976, 42.58488130569458, 4.935059911096651]
      renderView1.StereoType = 0
      renderView1.CameraPosition = [26.01346295275818, -73.05411333827122, 56.4818627174447]
      renderView1.CameraFocalPoint = [30.598477945558454, 156.7532182430825, -45.95618805382433]
      renderView1.CameraViewUp = [0.013218340955547104, 0.4068831426555441, 0.9133845760057102]
      renderView1.CameraParallelScale = 4439538.132797737
      renderView1.Background = [0.32, 0.34, 0.43]

      # register the view with coprocessor
      # and provide it with information such as the filename to use,
      # how frequently to write the images, etc.
      coprocessor.RegisterView(renderView1,
          filename='image_%t.png', freq=1, fittoscreen=1, magnification=1, width=1082, height=598)

      # ----------------------------------------------------------------
      # setup the data processing pipelines
      # ----------------------------------------------------------------

      # create a new 'NetCDF Reader'
      # create a producer from a simulation input
      atmData2 = coprocessor.CreateProducer(datadescription, 'AtmData2')

      # create a new 'Calculator'
      calculator1 = Calculator(Input=atmData2)
      calculator1.ResultArrayName = 'topo_masked'
      calculator1.Function = 'topo*(mask/mask)'

      # create a new 'Threshold'
      threshold1 = Threshold(Input=calculator1)
      threshold1.Scalars = ['POINTS', 'topo_masked']
      threshold1.ThresholdRange = [1e-20, 2510.0]

      # create a new 'Warp By Scalar'
      warpByScalar1 = WarpByScalar(Input=threshold1)
      warpByScalar1.Scalars = ['POINTS', 'topo_masked']
      warpByScalar1.Normal = [0.0, 0.0, 0.0015]
      warpByScalar1.UseNormal = 1

      # create a new 'NetCDF Reader'
      # create a producer from a simulation input
      atmData1 = coprocessor.CreateProducer(datadescription, 'AtmData1')

      # create a new 'Transform'
      transform1 = Transform(Input=atmData1)
      transform1.Transform = 'Transform'

      # init the 'Transform' selected for 'Transform'
      transform1.Transform.Scale = [1.0, 1.0, 0.003]

      # create a new 'Contour'
      contour1 = Contour(Input=transform1)
      contour1.ContourBy = ['POINTS', 'rh']
      contour1.ComputeScalars = 1
      contour1.Isosurfaces = [95.0]
      contour1.PointMergeMethod = 'Uniform Binning'

      # ----------------------------------------------------------------
      # setup color maps and opacity mapes used in the visualization
      # note: the Get..() functions create a new object, if needed
      # ----------------------------------------------------------------

      # get color transfer function/color map for 'topomasked'
      topomaskedLUT = GetColorTransferFunction('topomasked')
      topomaskedLUT.RGBPoints = [-10000.0, 0.6, 0.0, 1.0, -9500.0, 0.6, 0.0, 1.0, -9500.0, 0.6, 0.0, 1.0, -9000.0, 0.6, 0.0, 1.0, -9000.0, 0.6, 0.0, 1.0, -8500.0, 0.6, 0.0, 1.0, -8500.0, 0.533333, 0.0666667, 1.0, -8000.0, 0.466667, 0.133333, 1.0, -8000.0, 0.533333, 0.0666667, 1.0, -7500.0, 0.466667, 0.133333, 1.0, -7500.0, 0.4, 0.2, 1.0, -7000.0, 0.333333, 0.266667, 1.0, -7000.0, 0.4, 0.2, 1.0, -6500.0, 0.333333, 0.266667, 1.0, -6500.0, 0.266667, 0.333333, 1.0, -6000.0, 0.266667, 0.333333, 1.0, -6000.0, 0.2, 0.4, 1.0, -5500.0, 0.2, 0.4, 1.0, -5500.0, 0.133333, 0.466667, 1.0, -5000.0, 0.133333, 0.466667, 1.0, -5000.0, 0.0666667, 0.533333, 1.0, -4500.0, 0.0, 0.6, 1.0, -4500.0, 0.0666667, 0.533333, 1.0, -4000.0, 0.105882, 0.643137, 1.0, -4000.0, 0.0, 0.6, 1.0, -3500.0, 0.211765, 0.686275, 1.0, -3500.0, 0.105882, 0.643137, 1.0, -3000.0, 0.211765, 0.686275, 1.0, -3000.0, 0.317647, 0.729412, 1.0, -2500.0, 0.317647, 0.729412, 1.0, -2500.0, 0.423529, 0.772549, 1.0, -2000.0, 0.423529, 0.772549, 1.0, -2000.0, 0.52549, 0.815686, 1.0, -1500.0, 0.631373, 0.858824, 1.0, -1500.0, 0.52549, 0.815686, 1.0, -1000.0, 0.631373, 0.858824, 1.0, -1000.0, 0.737255, 0.901961, 1.0, -500.0, 0.737255, 0.901961, 1.0, -500.0, 0.843137, 0.945098, 1.0, -200.0, 0.843137, 0.945098, 1.0, -200.0, 0.945098, 0.988235, 1.0, 0.0, 0.945098, 0.988235, 1.0, 0.0, 0.2, 0.6, 0.2, 100.0, 0.466667, 0.847059, 0.486275, 100.0, 0.2, 0.6, 0.2, 200.0, 0.466667, 0.847059, 0.486275, 200.0, 0.866667, 0.878431, 0.65098, 500.0, 0.866667, 0.878431, 0.65098, 500.0, 0.976471, 0.827451, 0.631373, 1000.0, 0.976471, 0.827451, 0.631373, 1000.0, 0.929412, 0.756863, 0.443137, 1500.0, 0.929412, 0.756863, 0.443137, 1500.0, 0.878431, 0.686275, 0.25098, 2000.0, 0.878431, 0.686275, 0.25098, 2000.0, 0.752941, 0.627451, 0.137255, 2500.0, 0.752941, 0.627451, 0.137255, 2500.0, 0.65098, 0.584314, 0.109804, 3000.0, 0.639216, 0.545098, 0.0862745, 3000.0, 0.65098, 0.584314, 0.109804, 3500.0, 0.627451, 0.501961, 0.0627451, 3500.0, 0.639216, 0.545098, 0.0862745, 4000.0, 0.619608, 0.462745, 0.0392157, 4000.0, 0.627451, 0.501961, 0.0627451, 4500.0, 0.619608, 0.462745, 0.0392157, 4500.0, 0.603922, 0.419608, 0.0117647, 5000.0, 0.615686, 0.376471, 0.172549, 5000.0, 0.603922, 0.419608, 0.0117647, 5500.0, 0.615686, 0.376471, 0.172549, 5500.0, 0.666667, 0.407843, 0.407843, 6000.0, 0.666667, 0.407843, 0.407843, 6000.0, 0.705882, 0.517647, 0.517647, 6500.0, 0.705882, 0.517647, 0.517647, 6500.0, 0.741176, 0.631373, 0.631373, 7000.0, 0.741176, 0.631373, 0.631373, 7000.0, 0.780392, 0.745098, 0.745098, 7500.0, 0.847059, 0.847059, 0.847059, 7500.0, 0.780392, 0.745098, 0.745098, 8000.0, 0.847059, 0.847059, 0.847059, 8000.0, 0.92549, 0.92549, 0.92549, 8500.0, 0.92549, 0.92549, 0.92549, 8500.0, 0.972549, 0.972549, 0.972549, 9000.0, 0.972549, 0.972549, 0.972549, 9000.0, 1.0, 1.0, 1.0, 9500.0, 1.0, 1.0, 1.0, 9500.0, 1.0, 1.0, 1.0, 10000.0, 1.0, 1.0, 1.0]
      topomaskedLUT.ColorSpace = 'RGB'
      topomaskedLUT.NanColor = [0.498039, 0.0, 0.0]
      topomaskedLUT.ScalarRangeInitialized = 1.0

      # get opacity transfer function/opacity map for 'topomasked'
      topomaskedPWF = GetOpacityTransferFunction('topomasked')
      topomaskedPWF.Points = [0.0, 0.0, 0.5, 0.0, 2509.11328125, 1.0, 0.5, 0.0]
      topomaskedPWF.ScalarRangeInitialized = 1

      # get color transfer function/color map for 'clw'
      clwLUT = GetColorTransferFunction('clw')
      clwLUT.RGBPoints = [0.0, 0.231373, 0.298039, 0.752941, 0.00025, 0.865003, 0.865003, 0.865003, 0.0005, 0.705882, 0.0156863, 0.14902]
      clwLUT.LockScalarRange = 1
      clwLUT.ScalarRangeInitialized = 1.0

      # get opacity transfer function/opacity map for 'clw'
      clwPWF = GetOpacityTransferFunction('clw')
      clwPWF.Points = [0.0, 0.0, 0.5, 0.0, 0.0005, 1.0, 0.5, 0.0]
      clwPWF.ScalarRangeInitialized = 1

      # ----------------------------------------------------------------
      # setup the visualization in view 'renderView1'
      # ----------------------------------------------------------------

      # show data from contour1
      contour1Display = Show(contour1, renderView1)
      # trace defaults for the display properties.
      contour1Display.ColorArrayName = ['POINTS', 'clw']
      contour1Display.LookupTable = clwLUT
      contour1Display.Opacity = 0.6

      # show color legend
      contour1Display.SetScalarBarVisibility(renderView1, True)

      # show data from warpByScalar1
      warpByScalar1Display = Show(warpByScalar1, renderView1)
      # trace defaults for the display properties.
      warpByScalar1Display.ColorArrayName = ['POINTS', 'topo_masked']
      warpByScalar1Display.LookupTable = topomaskedLUT
      warpByScalar1Display.ScalarOpacityUnitDistance = 5.86105475336638

      # show color legend
      warpByScalar1Display.SetScalarBarVisibility(renderView1, True)

      # setup the color legend parameters for each legend in this view

      # get color legend/bar for clwLUT in view renderView1
      clwLUTColorBar = GetScalarBar(clwLUT, renderView1)
      clwLUTColorBar.Title = 'clw'
      clwLUTColorBar.ComponentTitle = ''

      # get color legend/bar for topomaskedLUT in view renderView1
      topomaskedLUTColorBar = GetScalarBar(topomaskedLUT, renderView1)
      topomaskedLUTColorBar.Position = [0.85, 0.52]
      topomaskedLUTColorBar.Title = 'topo_masked'
      topomaskedLUTColorBar.ComponentTitle = ''
    return Pipeline()

  class CoProcessor(coprocessing.CoProcessor):
    def CreatePipeline(self, datadescription):
      self.Pipeline = _CreatePipeline(self, datadescription)

  coprocessor = CoProcessor()
  # these are the frequencies at which the coprocessor updates.
  freqs = {'AtmData1': [1, 1, 1], 'AtmData2': [1, 1, 1, 1]}
  coprocessor.SetUpdateFrequencies(freqs)
  return coprocessor

#--------------------------------------------------------------
# Global variables that will hold the pipeline for each timestep
# Creating the CoProcessor object, doesn't actually create the ParaView pipeline.
# It will be automatically setup when coprocessor.UpdateProducers() is called the
# first time.
coprocessor = CreateCoProcessor()

#--------------------------------------------------------------
# Enable Live-Visualizaton with ParaView
coprocessor.EnableLiveVisualization(False, 1)


# ---------------------- Data Selection method ----------------------

def RequestDataDescription(datadescription):
    "Callback to populate the request for current timestep"
    global coprocessor
    if datadescription.GetForceOutput() == True:
        # We are just going to request all fields and meshes from the simulation
        # code/adaptor.
        for i in range(datadescription.GetNumberOfInputDescriptions()):
            datadescription.GetInputDescription(i).AllFieldsOn()
            datadescription.GetInputDescription(i).GenerateMeshOn()
        return

    # setup requests for all inputs based on the requirements of the
    # pipeline.
    coprocessor.LoadRequestedData(datadescription)

# ------------------------ Processing method ------------------------

def DoCoProcessing(datadescription):
    "Callback to do co-processing for current timestep"
    global coprocessor

    # Update the coprocessor by providing it the newly generated simulation data.
    # If the pipeline hasn't been setup yet, this will setup the pipeline.
    coprocessor.UpdateProducers(datadescription)

    # Write output data, if appropriate.
    coprocessor.WriteData(datadescription);

    # Write image capture (Last arg: rescale lookup table), if appropriate.
    coprocessor.WriteImages(datadescription, rescale_lookuptable=False)

    # Live Visualization, if enabled.
    coprocessor.DoLiveVisualization(datadescription, "localhost", 22222)
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the ParaView Wiki at: 
http://paraview.org/Wiki/ParaView

Search the list archives at: http://markmail.org/search/?q=ParaView

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/paraview

Reply via email to