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.
- func: dataclasses.InitVar[ogstools.variables.func.Function | collections.abc.Callable | None] = None#
The function to be applied on the data.
- 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(variable, func, suffix=None, prefix=None, **changes)[source]#
Create a new derived variable.
funcis appended to the stored functions.prefixand/orsuffixare prepended to and appended to the baseoutput_name(separated by “_”); at least one has to be set. To change other attributes pass them as keyword arguments;- Parameters:
- Return type:
Self- Returns:
A new Variable with the applied changes.
- Raises:
KeyError – If neither
prefixnorsuffixis set, or ifoutput_nameorfunctionsare given inchanges.
- classmethod find(variable, data)[source]#
Return a Variable corresponding to
variablefor the givendata.datamay be a mesh or a MeshSeries. The name is resolved against predefined variables (data_nameandoutput_name), mesh data and attributes ofdata(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
variablewhoseoutput_nameis found in the data is returned reading that data directly (functions discarded); one whosedata_nameis 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:
variable (
Variable|str) – The variable to retrieve or its name if a string.data (
DataSet|UnstructuredGrid|Sequence[DataSet|UnstructuredGrid]) – The mesh or mesh series containing the variable data.
- Return type:
- 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_unitis 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_unitsis True data is passed to the function with units (i.e. as a pint quantity).- Return type:
- 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
- rate(time_unit='s')[source]#
return a variable relating to rate change of this quantity.
- Return type:
Self
- is_mask()[source]#
Check if the variable is a mask.
- Return type:
- Returns:
True if the variable is a mask, False otherwise.
- 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)#