Find maximum and minimum of a scalar field

Hi everyone, i have a transient simulation and i need to normalize a scalar field for every step so that the range is always [-1,1], is there any way trough the calculator to do this?
I’ll be applying isoVolumes so every little change in the range will give changes in volume size which I do not want, also I’ll be postprocessing trough a python script if that makes any difference.
Thanks in advance

Did you mean Temporal -> Temporal Statistics filter?

There is no normalization built into the Calculator filter, but you can do this with the Python Calculator. Set the expression to 2*(RTData - min(RTData)) / (max(RTData) - min(RTData))-1 and substitute your array name for RTData.

1 Like

How do I set the array equal to the expression you wrote?
I have this that gives me the Helicity array which i need to normalize:

calculator1 = Calculator(Input=openFOAMReader2)
calculator1.ResultArrayName = 'Helicity'
calculator1.Function = '(U_X*vorticity_X+U_Y*vorticity_Y+U_Z*vorticity_Z)/(sqrt(U_X^2+U_Y^2+U_Z^2+vorticity_X^2+vorticity_Y^2+vorticity_Z^2)'

What should i set equal to this code you wrote?

Thanks for all the help, i’m not very good at python

Probably the easiest thing to do is add a PythonCalculator filter to your script that takes calculator1 as the Input argument. Then the expression would be

2*(Helicity - min(Helicity)) / (max(Helicity) - min(Helicity))-1

Hi,

Using last release 5.12.0-RC1, I have found a problem with a simple
m̀in(myVar) expressed in the Calculator filter.

The minimum of scalar point data array is not calculated as a single scalar but keep a range.

image

and it gives:
image

My purpuse is to normalize my point data array called XCO2 with the expression:
(XCO2 - min(XCO2)) / (max(XCO2) - min(XCO2))

What is my mistake ?
Thks

HI @PBrockmann

As @cory.quammen said above, you want to use the PythonCalculator, not the calculator.

Although the fact that the calculator expose reduction operation like min and max and very error prone ad displaying a warning in that case may be a good idea.

Yes thank you. Indeed I made a confusion between Calculator and the PythonCalculator.
Very unclear why in the first one the min or max functions do not give one single value.

1 Like

These methods should not even be available in the calculator imo.
https://gitlab.kitware.com/paraview/paraview/-/issues/22432

@utkarsh.ayachit @Kenneth_Moreland Thoughts on removing the min and max functionality from the calculator? I’m wondering if it should remain for users that know nothing about Python…

Hi @wascott

It’s not really related to python. the method themselves are not behaving the way users expect them to behave. min(val) does not reduce the data and this is the behavior users are expecting.

For the Calculator, the behavior of min, and max is indeed different from the equivalent in the Python Calculator, which may be surprising but does not make it incorrect. The behavior is documented in 5. Filtering Data — ParaView Documentation 5.11.0 documentation.

@cory.quammen What you say makes sense, but exposes an error imho. From what I understand, the Python calculator formula max(variable1) will reply with the maximum value across the mesh of variable1. The calculator, on the other hand, is used as max(variable1, variable2), and will return a new variable (result) that is the max of variable1 or variable 2 on a per cell or point basis.

However, in the calculator, max(variable1) works with insufficient inputs, and without warning returns a bad result. Isn’t this a bug?

I don’t see that an error is occurring with one input. I checked and max(variable1) works just fine - for scalar arrays, it just returns a copy of the array, and for vector arrays, it returns the maximum component of each vector. If you provide multiple arrays, it selects the maximum vector component (or scalar) from all the inputs point- or cell-wise.

We are using the ExprTk expression evaluation library which is much more robust that the previous calculator implementation. Unforuntately, we wouldn’t easily be able to implement min/max or other reduction operations easily. I think the best we can convey is that the Calculator always operates on each component and does not offer reduction operations.

1 Like

Sounds good, reasonable explination and we are documented. I see Mathieu closed #22432 as well.

Indeed it is documented.
Just to close nicely this thread, how to normalize a variable with the Calculator ie calculate (var-min(var)) / (max(var)-min(var)) ?

It’s not a great answer, but I’m afraid I don’t think it is possible to do that with the Calculator filter - you would have to enter the array minimum and maximum values in your expression manually. Python Calculator is more versatile in this regard.