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: object

Represent 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]#
data_name: str#

The name of the variable data in the mesh.

data_unit: str = ''#

The unit of the variable data in the mesh.

output_unit: str = ''#

The output unit of the variable.

output_name: str = ''#

The output name of the variable.

symbol: str = ''#

The symbol representing this variable.

mask: str = ''#

The name of the mask data in the mesh.

func()#

The function to be applied on the data. .. seealso:: transform()

Return type:

T

mesh_dependent: bool = False#

If the function to be applied is dependent on the mesh itself

process_with_units: bool = False#

If true, apply the function on values with units.

cmap: Colormap | str = 'coolwarm'#

Colormap to use for plotting.

bilinear_cmap: bool = False#

Should this variable be displayed with a bilinear cmap?

categoric: bool = False#

Does this variable only have categoric values?

color: str | None = None#

Default color for plotting

property type_name: str#
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.

Returns:

A copy of the Variable with changed attributes.

Return type:

Variable

classmethod from_variable(new_variable, **changes)[source]#

Create a new Variable object with modified attributes.

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.

Parameters:
  • variable (Variable | str) – The variable to retrieve or its name if a string.

  • mesh (DataSet) – The mesh containing the variable data.

Returns:

A corresponding Variable preset or a new Variable of correct type.

Return type:

Variable

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:

ndarray

property get_output_unit: str#

Return the output unit

property difference: Variable#

A variable relating to differences in this quantity.

property abs_error: Variable#

A variable relating to an absolute error of this quantity.

property rel_error: Variable#

A variable relating to a relative error of this quantity.

property anasol: Variable#

A variable relating to an analytical solution of this quantity.

is_mask()[source]#

Check if the variable is a mask.

Returns:

True if the variable is a mask, False otherwise.

Return type:

bool

get_mask()[source]#

A variable representing this variables mask.

Return type:

Variable

property magnitude: Variable#
mask_used(mesh)[source]#

Check whether the mesh contains the mask of this variable.

Return type:

bool

get_label(split_at=None)[source]#

Creates variable label in format ‘variable_name / variable_unit’

Return type:

str

class ogstools.variables.variable.Scalar[source]#

Bases: Variable

Represent a scalar variable.