ogstools.variables package#
Predefined variables for data and unit transformation.
- class ogstools.variables.Matrix[source]#
Bases:
VariableRepresent 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:
- 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:
- property eigenvectors: VectorList#
A vector variable as the eigenvectors 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.
- class ogstools.variables.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)#
- class ogstools.variables.Vector[source]#
Bases:
VariableRepresent 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]
Submodules#
- ogstools.variables.custom_colormaps module
- ogstools.variables.func module
- ogstools.variables.integrity module
- ogstools.variables.matrix module
MatrixMatrix.__getitem__()Matrix.col()Matrix.row()Matrix.to_polar()Matrix.magnitudeMatrix.traceMatrix.eigenvaluesMatrix.eigenvectorsMatrix.detMatrix.invariant_1Matrix.invariant_2Matrix.invariant_3Matrix.tensor_meanMatrix.hydrostatic_componentMatrix.deviatorMatrix.deviator_invariant_1Matrix.deviator_invariant_2Matrix.deviator_invariant_3Matrix.octahedral_shearMatrix.von_MisesMatrix.qp_ratio
- ogstools.variables.scalar module
- ogstools.variables.tensor_math module
sym_tensor_to_mat()mat_to_sym_tensor()trace()matrix_trace()column()row()eigenvalues()eigenvectors()det()frobenius_norm()invariant_1()invariant_2()invariant_3()mean()effective_pressure()hydrostatic_component()deviator()deviator_invariant_1()deviator_invariant_2()deviator_invariant_3()octahedral_shear()von_mises()qp_ratio()to_polar()add_pore_pressure()
- ogstools.variables.unit_registry module
- ogstools.variables.variable module
VariableVariable.data_nameVariable.data_unitVariable.output_unitVariable.output_nameVariable.symbolVariable.maskVariable.funcVariable.functionsVariable.process_with_unitsVariable.cmapVariable.bilinear_cmapVariable.categoricVariable.colorVariable.parentVariable.functionVariable.type_nameVariable.replace()Variable.copy()Variable.from_variable()Variable.find()Variable.transform()Variable.get_output_unitVariable.aggregationsVariable.aggregation_variable()Variable.aggregate()Variable.normalize_aggregation()Variable.change_axis()Variable.minVariable.maxVariable.meanVariable.medianVariable.sumVariable.stdVariable.varVariable.argminVariable.argmaxVariable.time_of_minVariable.time_of_maxVariable.absVariable.differenceVariable.rate()Variable.abs_errorVariable.rel_errorVariable.anasolVariable.is_mask()Variable.get_mask()Variable.magnitudeVariable.convert_stress()Variable.__init__()Variable.mask_used()Variable.get_label()Variable.gradientVariable.divergenceVariable.vorticityVariable.qcriterion
spatial_var()time_var()
- ogstools.variables.vector module