Reducing 3D data to 1D

I have some 3D data that I need to average out across two dimensions. Specifically, I have an XYZ representation of something that is spherically symmetric, and I want to compute the average value of a cell quantity across shells of constant radius. My attempts so far go as follows:

  • Compute spherical coordinates using Calculator, and use them as the new coordinates.
  • Define a planar Slice.
  • Use IntegrateVariables to find average quantity (density in this case).

This does what I want, but only for a single value of R. I need to compute this as a function of R (at something like all of the R values I have points at). I will then use the result to define new cell data, so that I can compute the deviation of the cartesian density field from the spherical average at every point.

I assume that I will have to do this using a Programmable filter, but I haven’t been able to figure out how to do that. All I have so far is the Trace of the operations described above. I can’t figure out how to access the data from the IntegrateVariables object, nor can I figure out how to use the results to make a new Cell Data field. Can anyone give me some kind of starting point?

I will need to make this into a Programmable Filter eventually, if that’s relevant.

Thanks in advance,

Nathan Woods

# trace generated using paraview version 5.8.0-RC2
#
# To ensure correct image size when batch processing, please search
# for and uncomment the line `# renderView*.ViewSize = [*,*]`
#### import the simple module from the paraview
from paraview.simple import *
#### disable automatic camera reset on 'Show'
paraview.simple._DisableFirstRenderCameraReset()
# create a new 'EnSight Reader'
engoldcase = EnSightReader(CaseFileName=<PATH_TO_DATA>)
engoldcase.CellArrays = ['den', 'pres', 'ie', 'flg', 'vol', 'u', 'v', 'w', 'tau11', 'tau22', 'tau33', 'tau12', 'tau13', 'tau23', 'vf00', 'd00']
engoldcase.PointArrays = ['vel', 'kfix']
# create a new 'Calculator'
calculator1 = Calculator(Input=engoldcase)
calculator1.Function = ''                                                                                                                     calculator1.CoordinateResults = 1
# Properties modified on calculator1
calculator1.ResultArrayName = 'CoordR'
calculator1.Function = 'mag(coords)*iHat+atan(sqrt(coordsX^2+coordsY^2)/coordsZ)*jHat+atan(coordsY/coordsX)*kHat'
# create a new 'Slice'
slice1 = Slice(Input=calculator1)
slice1.SliceType = 'Plane'
slice1.HyperTreeGridSlicer = 'Plane'
slice1.SliceOffsetValues = [0.0]
# create a new 'Integrate Variables'
integrateVariables1 = IntegrateVariables(Input=slice1)

Your trace is unrelated to the ProgrammableFilter.

You will need to implement the algorithm your own way in the programmable filter.

See here for examples :
https://www.paraview.org/Wiki/Python_Programmable_Filter
https://www.paraview.org/Wiki/Python_calculator_and_programmable_filter

I had seen those before (in the Paraview Guide). I have a hard time following what is going on with those, and they seem to be working on much lower-level objects than I expected.

I need to have access to something I can work with interactively. Is there another way to do that besides the programmable filter?

I had seen those before (in the Paraview Guide). I have a hard time following what is going on with those, and they seem to be working on much lower-level objects than I expected.

These are basically VTK filter, which is indeed quite low level and requires some programmation knowledge.

I need to have access to something I can work with interactively.

Not sure what you mean by “interactively”. You can edit the filter on the fly and reexecute it.

Is there another way to do that besides the programmable filter?

Actual C++ VTK filter and plugin, but it is even more “low level”.
You problem seems quite specific to be able to solve with available filter.

@wascott @patchett2002

When I said that I need to work with it interactively, I meant that I would need to apply additional filters and use the result in further computations within the GUI.

You’re basically confirming what I had suspected, but didn’t want to admit. I disagree that looking at partial reductions of data is that uncommon (I found several similar questions on the old mailing list), however I do agree that it would be hard to reduce all the possible reductions to just a handful of options for inclusion as additional filters, which is why I figured I’d be in Python-land. Still, I’m disappointed that I can’t construct something specific by looping over a pipeline of existing filters.

I guess I’ll go dig into the VTK documentation next.

Note that you can create spherical “slices” with the Slice filter, then integrate over those. That may save you some work in the first step.

Is the new cell data going to be associated with the shell geometry? Or will it be associated with the original XYZ data?

The idea is to associate the new data with the original XYZ data. I will need to compute the difference between fields and the spherical average, for instance.

Is there any way to use existing Paraview filters within the Programmable Filter? Defining a slice, for instance?

Not in a sense where you would see the slice as with the Slice filter.

However you can add a Slice filter, then your programmable filter to do the computation on the slice.