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.

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

linestyle: tuple | None = None#

Default linestyle for plotting

__init__(data_name, data_unit='', output_unit='', output_name='', symbol='', mask='', func=<function identity>, mesh_dependent=False, process_with_units=False, cmap='coolwarm', bilinear_cmap=False, categoric=False, color=None, linestyle=None)#
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.

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

get_output_unit()[source]#

Get the output unit.

returns: The output unit.

Return type:

str

property difference: Variable#

returns: A variable relating to differences in 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]#
Returns:

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.

__init__(data_name, data_unit='', output_unit='', output_name='', symbol='', mask='', func=<function identity>, mesh_dependent=False, process_with_units=False, cmap='coolwarm', bilinear_cmap=False, categoric=False, color=None, linestyle=None)#