report.Expression#

class Expression#

Bases: GenericOperation

Represents a mathematical expression to be evaluated on simulation result data.

This operation allows for defining and calculating custom expressions using variables extracted from simulation results. The results of the expression evaluation can be added as a new column to a dataframe for further analysis.

Example

expr = Expression(expr=”totalCD * area”) result = expr.calculate(data, case, cases, variables, new_variable_name)

Raises:
  • ValueError – If variables in the expression are missing from the dataframe or if the expression cannot be evaluated due to syntax or other issues.

  • NotImplementedError – If the data type is unsupported by the calculate method.

Attributes

expr: str#

The mathematical expression to evaluate. It should be written in a syntax compatible with the numexpr library, using variable names that correspond to columns in the dataframe or user-defined variables.

Additional Constructors

classmethod from_file(filename)#

Load a Flow360BaseModel from a .json file.

Parameters:

filename (str)

Return type:

Flow360BaseModel

Methods

classmethod get_variables(expr)#

Parses the given expression and returns a set of variable names used in it.

classmethod evaluate_expression(df, expr, variables, new_variable_name, case)#

Evaluates the given expression on the provided dataframe, using the specified variables. The result is added as a new column in the dataframe.

Parameters:

variables (List[Variable])

calculate(data, case, cases, variables, new_variable_name)#

Executes the expression evaluation for the given simulation data and returns the result.

help(methods=False)#

Print fields and methods of a Flow360BaseModel using rich.

Parameters:

methods (bool)

Return type:

None

to_file(filename, **kwargs)#

Export Flow360BaseModel instance to a .json file.

Parameters:
Return type:

None