# Find maximum and minimum of a scalar field

**URL:** https://discourse.paraview.org/t/find-maximum-and-minimum-of-a-scalar-field/4522
**Category:** ParaView Support
**Tags:** python
**Created:** [June 6, 2020, 10:09am UTC](https://discourse.paraview.org/t/find-maximum-and-minimum-of-a-scalar-field/4522 "2020-06-06T10:09:54Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![Gambenius](https://discourse.paraview.org/user_avatar/discourse.paraview.org/gambenius/32/4013_2.png) [@Gambenius](https://discourse.paraview.org/u/Gambenius)
#### Post date: [June 6, 2020, 10:09am UTC](https://discourse.paraview.org/t/find-maximum-and-minimum-of-a-scalar-field/4522/1 "2020-06-06T10:09:54Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Yoshino](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/y/bcef8e/32.png) [@Yoshino](https://discourse.paraview.org/u/Yoshino)
#### Post date: [June 6, 2020, 11:57am UTC](https://discourse.paraview.org/t/find-maximum-and-minimum-of-a-scalar-field/4522/2 "2020-06-06T11:57:26Z")

</div>

Did you mean `Temporal -> Temporal Statistics` filter?

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.paraview.org/user_avatar/discourse.paraview.org/cory.quammen/32/11193_2.png) [@cory.quammen](https://discourse.paraview.org/u/cory.quammen)
#### Post date: [June 7, 2020, 9:52pm UTC](https://discourse.paraview.org/t/find-maximum-and-minimum-of-a-scalar-field/4522/3 "2020-06-07T21:52:29Z")

</div>

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`.

---

<div class="post-metadata">

### Author: ![Gambenius](https://discourse.paraview.org/user_avatar/discourse.paraview.org/gambenius/32/4013_2.png) [@Gambenius](https://discourse.paraview.org/u/Gambenius)
#### Post date: [June 8, 2020, 12:14pm UTC](https://discourse.paraview.org/t/find-maximum-and-minimum-of-a-scalar-field/4522/4 "2020-06-08T12:14:35Z")

</div>

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?

> [@cory.quammen](#):
>
> 2\*(RTData - min(RTData)) / (max(RTData) - min(RTData))-1

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

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.paraview.org/user_avatar/discourse.paraview.org/cory.quammen/32/11193_2.png) [@cory.quammen](https://discourse.paraview.org/u/cory.quammen)
#### Post date: [June 8, 2020, 1:20pm UTC](https://discourse.paraview.org/t/find-maximum-and-minimum-of-a-scalar-field/4522/5 "2020-06-08T13:20:56Z")

</div>

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`

---

<div class="post-metadata">

### Author: ![PBrockmann](https://discourse.paraview.org/user_avatar/discourse.paraview.org/pbrockmann/32/13223_2.png) [@PBrockmann](https://discourse.paraview.org/u/PBrockmann)
#### Post date: [December 19, 2023, 11:23pm UTC](https://discourse.paraview.org/t/find-maximum-and-minimum-of-a-scalar-field/4522/6 "2023-12-19T23:23:13Z")

</div>

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](https://discourse.paraview.org/uploads/default/original/2X/2/2445337952184e59e4e3655135a52989a75027c0.png)

and it gives:  
 ![image](https://discourse.paraview.org/uploads/default/original/2X/7/7cb34daad6bc460e12d4536dd8b21da86299041f.png)

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

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [December 20, 2023, 12:59pm UTC](https://discourse.paraview.org/t/find-maximum-and-minimum-of-a-scalar-field/4522/7 "2023-12-20T12:59:12Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![PBrockmann](https://discourse.paraview.org/user_avatar/discourse.paraview.org/pbrockmann/32/13223_2.png) [@PBrockmann](https://discourse.paraview.org/u/PBrockmann)
#### Post date: [December 20, 2023, 1:30pm UTC](https://discourse.paraview.org/t/find-maximum-and-minimum-of-a-scalar-field/4522/8 "2023-12-20T13:30:17Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [January 2, 2024, 9:32am UTC](https://discourse.paraview.org/t/find-maximum-and-minimum-of-a-scalar-field/4522/9 "2024-01-02T09:32:20Z")

</div>

> [@PBrockmann](#):
>
> Very unclear why in the first one the min or max functions do not give one single value.

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

---

<div class="post-metadata">

### Author: ![wascott](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/w/8e8cbc/32.png) [@wascott](https://discourse.paraview.org/u/wascott)
#### Post date: [January 2, 2024, 5:07pm UTC](https://discourse.paraview.org/t/find-maximum-and-minimum-of-a-scalar-field/4522/10 "2024-01-02T17:07:28Z")

</div>

@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…

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [January 3, 2024, 8:23am UTC](https://discourse.paraview.org/t/find-maximum-and-minimum-of-a-scalar-field/4522/11 "2024-01-03T08:23:44Z")

</div>

> [@wascott](#):
>
> 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.

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.paraview.org/user_avatar/discourse.paraview.org/cory.quammen/32/11193_2.png) [@cory.quammen](https://discourse.paraview.org/u/cory.quammen)
#### Post date: [January 4, 2024, 6:24pm UTC](https://discourse.paraview.org/t/find-maximum-and-minimum-of-a-scalar-field/4522/12 "2024-01-04T18:24:53Z")

</div>

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](https://docs.paraview.org/en/latest/UsersGuide/filteringData.html#calculator).

---

<div class="post-metadata">

### Author: ![wascott](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/w/8e8cbc/32.png) [@wascott](https://discourse.paraview.org/u/wascott)
#### Post date: [January 4, 2024, 7:47pm UTC](https://discourse.paraview.org/t/find-maximum-and-minimum-of-a-scalar-field/4522/13 "2024-01-04T19:47:44Z")

</div>

@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?

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.paraview.org/user_avatar/discourse.paraview.org/cory.quammen/32/11193_2.png) [@cory.quammen](https://discourse.paraview.org/u/cory.quammen)
#### Post date: [January 5, 2024, 12:34am UTC](https://discourse.paraview.org/t/find-maximum-and-minimum-of-a-scalar-field/4522/14 "2024-01-05T00:34:55Z")

</div>

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](https://github.com/ArashPartow/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.

---

<div class="post-metadata">

### Author: ![wascott](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/w/8e8cbc/32.png) [@wascott](https://discourse.paraview.org/u/wascott)
#### Post date: [January 5, 2024, 12:37am UTC](https://discourse.paraview.org/t/find-maximum-and-minimum-of-a-scalar-field/4522/15 "2024-01-05T00:37:55Z")

</div>

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

---

<div class="post-metadata">

### Author: ![PBrockmann](https://discourse.paraview.org/user_avatar/discourse.paraview.org/pbrockmann/32/13223_2.png) [@PBrockmann](https://discourse.paraview.org/u/PBrockmann)
#### Post date: [January 5, 2024, 9:38am UTC](https://discourse.paraview.org/t/find-maximum-and-minimum-of-a-scalar-field/4522/16 "2024-01-05T09:38:25Z")

</div>

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))` ?

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.paraview.org/user_avatar/discourse.paraview.org/cory.quammen/32/11193_2.png) [@cory.quammen](https://discourse.paraview.org/u/cory.quammen)
#### Post date: [January 5, 2024, 9:32pm UTC](https://discourse.paraview.org/t/find-maximum-and-minimum-of-a-scalar-field/4522/17 "2024-01-05T21:32:26Z")

</div>

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.
