ogstools.variables.variable module#
Defines the Scalar, Vector and Matrix Variable classes.
They serve as classes to handle common physical variables in a systematic way (e.g. temperature, pressure, displacement, …). Unit conversion is handled via pint.
- class ogstools.variables.variable.Variable[source]#
Bases:
objectRepresent a generic mesh variable.
- __init__(data_name, data_unit='', output_unit=None, output_name=None, symbol='', mask='', func=identity, mesh_dependent=False, process_with_units=False, cmap='coolwarm', bilinear_cmap=False, categoric=False, color=None)[source]#
- func()#
The function to be applied on the data. .. seealso::
transform()- Return type:
TypeVar(T)
- replace(**changes)[source]#
Create a new Variable object with modified attributes.
Be aware that there is no type check safety here. So make sure, the new attributes and values are correct.
- Parameters:
changes (
Any) – Attributes to be changed.- Return type:
Self- Returns:
A copy of the Variable with changed attributes.
- classmethod from_variable(new_variable, **changes)[source]#
Create a new Variable object with modified attributes.
- Return type:
Self
- classmethod find(variable, mesh)[source]#
Returns a Variable preset or creates one with correct type.
Searches for presets by data_name and output_name and returns if found. If ‘variable’ is given as type Variable this will also look for derived variables (difference, aggregate). Otherwise create Scalar, Vector, or Matrix Variable depending on the shape of data in mesh.
- transform(data, strip_unit=True)[source]#
Return the transformed data values.
Converts the data from data_unit to output_unit and applies the transformation function of this variable. The result is returned by default without units. if strip_unit is False, a quantity is returned.
Note: If self.mesh_dependent is True, self.func is applied directly to the mesh. Otherwise, it is determined by self.process_with_units if the data is passed to the function with units (i.e. as a pint quantity) or without.
- Return type:
- is_mask()[source]#
Check if the variable is a mask.
- Return type:
- Returns:
True if the variable is a mask, False otherwise.