[Python] Calculator formulae

In line with the recent improvements to the Programmable filters and python editor [1], we are thinking of improving the calculator and python calculator formulaes managements.

One could think to rely on the python editor in the same way as the programmable filters, however, this has a few issues:

  1. Both calculator supports only one liner, not in line with a text editor
  2. Calculator formulaes are not python, which would be confusing to edit in a python editor.

So here is what I have in mind:

  1. Make the formula line edit as wide as possible for both calculator
  2. Make the formula line edit multiline with automatic wrapping so that long one liner can be seen whole
  3. Add a setting to store and manage named python and calculator one liner. Think “Tools->Formulae Manager”.
  4. Let the user access these formulae in a searchable combo box in the [python] calculator
  5. Let the user add the current formula in a new saved formula
  6. Let the user open the Formulae Manager from the [python] calculator

@utkarsh.ayachit @cory.quammen

That sounds like a nice feature. I don’t have any major concerns about what you’ve described.

One additional idea - it might be nice for users to be able to import and export formulae to others

Most definitely !

This sounds great. I suggest not using the term formulae as the definition does not exactly fit: “A statement, especially an equation, of a fact, rule, principle, or other logical relation.” I would suggest using something like “calculation” or “expression”.
Another related suggestion is that we have a pull-down menu for the Python calculator that lists the available functions. Or some similar way for people to discover what is possible.

I suggest not using the term formulae as the definition does not exactly fit: “A statement, especially an equation, of a fact, rule, principle, or other logical relation.” I would suggest using something like “calculation” or “expression”.

Good point

Another related suggestion is that we have a pull-down menu for the Python calculator that lists the available functions. Or some similar way for people to discover what is possible.

This is point 4 :slight_smile:

+1
@vgweirs

OK I am confused :slight_smile: When we say Formulae, are we talking about user level expressions or built-in functions? For example, is it gradient(foo) / mag(gradient(foo)) or is it just gradient()? I assumed it was the first. I was suggesting a drop-down menu for the second also.

When we say Formulae, are we talking about user level expressions or built-in functions? For example, is it gradient(foo) / mag(gradient(foo)) or is it just gradient()? I assumed it was the first. I was suggesting a drop-down menu for the second also.

User defined expression. gradient(foo) / mag(gradient(foo))

The calculator already have built-in methods that the user can click on.
The python calculator do not have that but rely on the python/numpy knowledge of the user.
We do not plan to improve this in this context.

Thanks for the clarification.

The python calculator do not have that but rely on the python/numpy knowledge of the user.

The problem is that we have a bunch of VTK-level functions available to the calculator that are not listed anywhere (I think). For example, who knows that we have functions like max_per_block()? I always have to look it up in the algorithms.py module… I totally get that it is out of scope for this work but I wanted to put it in writing so that we are aware that this is an issue.

1 Like

I’ve recently udpated the doc, but the list of function is not yet complete:

https://docs.paraview.org/en/latest/UsersGuide/filteringData.html?highlight=python%20calculator#functions

It should indeed contains all our custom defined methods.

3 Likes

This is great! I didn’t know.

All I can say is ‘’‘Thank you!’’’. This will be a most welcome feature. It really helps with quick checks involving (somewhat) longer expressions involving vector algebra/calculus.

1 Like

We will move forward with this developpement.