report.Expression#
- class Expression#
Bases:
GenericOperationRepresents 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)#
Loads a
Flow360BaseModelfrom .json, or .yaml file.- Parameters:
filename (str) – Full path to the .yaml or .json file to load the
Flow360BaseModelfrom.- Returns:
An instance of the component class calling load.
- Return type:
Flow360BaseModel
Example
>>> params = Flow360BaseModel.from_file(filename='folder/sim.json')
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.
- calculate(data, case, cases, variables, new_variable_name)#
Executes the expression evaluation for the given simulation data and returns the result.
- help(methods=False)#
Prints message describing the fields and methods of a
Flow360BaseModel.- Parameters:
methods (bool = False) – Whether to also print out information about object’s methods.
- Return type:
None
Example
>>> params.help(methods=True)