ogstools.variables package#

Predefined variables for data and unit transformation.

class ogstools.variables.Matrix[source]#

Bases: Variable

Represent a matrix variable.

Matrix variables should contain either 4 (2D) or 6 (3D) components. Matrix components can be accesses with brackets e.g. stress[0]

__getitem__(index)[source]#

Return a scalar variable as a matrix component.

The following index values correspond to a polar coordinate system:

rr: radial component tt: angular component in theta (azimuthal) direction pp: angular component in phi (polar) direction rt: shear component in the radial-azimuthal plane tp: shear component in the azimuthal-polar plane rp: shear component in the radial-polar plane

Return type:

Scalar

col(index)[source]#

Return a vector variable as the matrix column at index.

Parameters:

index (int) – The index of the column.

Return type:

Vector

Returns:

The column as a Vector.

row(index)[source]#

Return a vector variable as the matrix row at index.

Parameters:

index (int) – The index of the row.

Return type:

Vector

Returns:

The row as a Vector.

to_polar(center=(0, 0, 0), normal=(0, 0, 1))[source]#

Return the Matrix converted to a polar coordinate system.

For 3D only spherical coordinate system is implemented for now.

Return type:

Matrix

property magnitude: Scalar#

A scalar variable as the frobenius norm of the matrix.

property trace: Scalar#

A scalar variable as the trace of the matrix.

property eigenvalues: Vector#

A vector variable as the eigenvalues of the matrix.

property eigenvectors: VectorList#

A vector variable as the eigenvectors of the matrix.

property det: Scalar#

A scalar variable as the determinant of the matrix.

property invariant_1: Scalar#

A scalar variable as the first invariant of the matrix.

property invariant_2: Scalar#

A scalar variable as the second invariant of the matrix.

property invariant_3: Scalar#

A scalar variable as the third invariant of the matrix.

property tensor_mean: Scalar#

A scalar variable as the mean value of the matrix.

property hydrostatic_component: Matrix#

A vector variable as the effective pressure of the matrix.

property deviator: Matrix#

A vector variable as the deviator of the matrix.

property deviator_invariant_1: Scalar#

A scalar variable as the first invariant of the matrix deviator.

property deviator_invariant_2: Scalar#

A scalar variable as the second invariant of the matrix deviator.

property deviator_invariant_3: Scalar#

A scalar variable as the third invariant of the matrix deviator.

property octahedral_shear: Scalar#

A scalar variable as the octahedral shear component of the matrix.

property von_Mises: Scalar#

A scalar variable as the von Mises stress.

property qp_ratio: Scalar#

A scalar variable as the qp stress ratio.

class ogstools.variables.Scalar[source]#

Bases: Variable

Represent a scalar variable.

class ogstools.variables.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 = None#

The output unit of the variable.

output_name: str = None#

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: dataclasses.InitVar[ogstools.variables.func.Function | collections.abc.Callable | None] = None#

The function to be applied on the data.

functions: list[Function]#

Contains this and all previous functions.

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 parent: Variable#

Return the Variable from which self is derived - if None return self.

property function: Function | None#

Returns the final function

property type_name: str#

Return the type of this Variable.

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.

copy(deep=True)[source]#

Return a copy of this Variable (by default a deep copy).

Return type:

Self

classmethod from_variable(variable, func, suffix=None, prefix=None, **changes)[source]#

Create a new derived variable.

func is appended to the stored functions. prefix and/or suffix are prepended to and appended to the base output_name (separated by “_”); at least one has to be set. To change other attributes pass them as keyword arguments;

Parameters:
  • variable (Variable) – The variable to base the new one on.

  • func (Callable | Function) – The function to append to the stored functions.

  • prefix (str | int | None) – Prepend this to the output_name.

  • suffix (str | int | None) – Append this to the output_name.

  • changes (Any) – Other attributes to override in the new variable.

Return type:

Self

Returns:

A new Variable with the applied changes.

Raises:

KeyError – If neither prefix nor suffix is set, or if output_name or functions are given in changes.

classmethod find(variable, data)[source]#

Return a Variable corresponding to variable for the given data.

data may be a mesh or a MeshSeries. The name is resolved against predefined variables (data_name and output_name), mesh data and attributes of data (e.g. points, timevalues). “x”, “y”, “z” and “points*” resolve to the coordinates and “t”, “time”, “timevalues” to the time values; a trailing _-suffix (e.g. "displacement_0") selects a component of a vector/matrix variable.

A Variable variable whose output_name is found in the data is returned reading that data directly (functions discarded); one whose data_name is found is returned unchanged. Otherwise a new Scalar, Vector or Matrix Variable is created depending on the shape of the data in the mesh.

Parameters:
Return type:

Variable

Returns:

A matching predefined or new Variable.

Raises:

KeyError – If the variable cannot be found in the data.

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 applied on a mesh or a meshseries, the data_name is read from the dataset and passed to the stored function. If applied on numeric data, it is passed to the function. if process_with_units is True data is passed to the function with units (i.e. as a pint quantity).

Return type:

ndarray | PlainQuantity

property get_output_unit: str#

Return the output unit

property aggregations: int#

Returns the number of aggregating function stored in this Variable.

aggregation_variable(func)[source]#

Return an aggregating Variable corresponding to the function.

Return type:

Self

aggregate(func, **kwargs)[source]#

Create a Variable aggregating the data with func.

Return type:

Self

normalize_aggregation(func=None)[source]#

Return a variable with exactly one aggregation function.

If all previous functions plus the optionally given one contain not exactly one aggregating function an Error is thrown.

Return type:

Self

change_axis(axis)[source]#

Variable with an updated axis of its last aggregation function.

Return type:

Self

property min: Self#

A variable relating to the minimum of this quantity.

property max: Self#

A variable relating to the maximum of this quantity.

property mean: Self#

A variable relating to the mean of this quantity.

property median: Self#

A variable relating to the median of this quantity.

property sum: Self#

A variable relating to the sum of this quantity.

property std: Self#

A variable relating to the standard deviation of this quantity.

property var: Self#

A variable relating to the variance of this quantity.

property argmin: Self#

A variable relating to the minimum index of this quantity.

property argmax: Self#

A variable relating to the maximum index of this quantity.

property time_of_min: Self#

A variable relating to the time of the minimum of this quantity.

property time_of_max: Self#

A variable relating to the time of the maximum of this quantity.

property abs: Self#

A variable relating to absolute value of this quantity.

property difference: Variable#

A variable relating to differences in this quantity.

rate(time_unit='s')[source]#

return a variable relating to rate change of this quantity.

Return type:

Self

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.

Return type:

bool

Returns:

True if the variable is a mask, False otherwise.

get_mask()[source]#

Return a variable representing this variables mask.

Return type:

Variable

property magnitude: Variable#

Return a variable representing this variables magnitude.

convert_stress(to, biot=1.0, bishop=1.0, pressure='pressure')[source]#

Convert from effective to total stress or vice versa on a deep copy.

The conversion is applied before any other stored function. Tension is positive, the pore pressure is positive in compression:

\[\sigma' = \sigma_\mathrm{total} \pm \alpha_B \chi p \mathbf{I}\]
Parameters:
  • biot (float | str) – Biot coefficient \(\alpha_B\), either a constant or the name of a data field (e.g. set per material from the MaterialIDs) in the mesh.

  • bishop (float | str) – Bishop’s coefficient \(\chi\), either a constant or the name of a data field (e.g. a precomputed \(\chi(S_L)\)) in the mesh.

  • pressure (str) – Name of the pore pressure data field in the mesh.

Return type:

Self

__init__(data_name, data_unit='', output_unit=None, output_name=None, symbol='', mask='', func=None, functions=<factory>, process_with_units=False, cmap='coolwarm', bilinear_cmap=False, categoric=False, color=None, _parent=None)#
mask_used(mesh)[source]#

Check whether the mesh contains the mask of this variable.

Return type:

bool

get_label(split_at=None)[source]#

Create a variable label in format ‘variable_name / variable_unit’

Return type:

str

property gradient: Vector | Matrix#

Return a variable representing this variables gradient.

property divergence: Vector | Scalar#

Return a variable representing this variables divergence.

property vorticity: Vector#

Return a variable representing this variables vorticity.

property qcriterion: Vector | Scalar#

Return a variable representing this variables qcriterion.

class ogstools.variables.Vector[source]#

Bases: Variable

Represent a vector variable.

Vector variables should contain either 2 (2D) or 3 (3D) components. Vector components can be accesses with brackets e.g. displacement[0]

__getitem__(index)[source]#

Get a scalar variable as a specific component of the vector variable.

Parameters:

index (Union[int, Literal['x', 'y', 'z']]) – The index of the component.

Return type:

Scalar

Returns:

A scalar variable as a vector component.

property magnitude: Scalar#
Returns:

A scalar variable as the magnitude of the vector.

Submodules#