viscid.calculator.evaluator module

Used for evaluating equations given to a script from the user

This tries very feebly to limit the namespace available to the equation which is done using eval. As a result, this functionality should NOT be used on untrusted input. To make this super clear, the user MUST enable this functionality on a per-script basis, or by setting calculator.evaluator.enabled: true in their viscidrc.

viscid.calculator.evaluator.evaluate(grid, result_name, eqn, try_numexpr=True, slc=Ellipsis)[source]

Evaluate an equation on a grid

Examples

To use this function directly

>>> evaluator.enabled = True
>>> f = viscid.load_file("...")
>>> evaluator.evaluate(f.get_grid(),
                       "sqrt(vx**2+vy**2+vz**2)",
                       "speed")
<viscid.field.ScalarField object at ...>

Or, for short, you can as a grid to evaluate implicitly,

>> evaluator.enabled = True >> f = viscid.load_file(“…”) >> speed = f[“speed=sqrt(vx**2+vy**2+vz**2)”] <viscid.field.ScalarField object at …>
Parameters:
  • grid – a grid instance where the fields live
  • result_name (str) – Used for the name and pretty_name of the resulting field
  • eqn (str) – the equation, if a symbol exists in the numpy namespace, then that’s how it is interpreted, otherwise, the symbol will be looked up in the grid
Returns:

Field instance