get_units#
- ENS_GLOBALS.get_units(obj: ENS_VAR | str, format: int = 0, utf8: int = 0, prefix: str = '', suffix: str = '') str | bytes #
Generate a string that represents the appropriate label for a given object.
This method will look at the specified
ENS_VAR
object and get any unit information specified by the UNIT schema. The API can generate labels from DIMS and SYSTEM values if no explicit label string has been specified for the variable object. It will then return a string with the specified prefix and suffix strings added before the units and after the unit string. It is also legal to pass a dimensions string instead of a variable object. For exampleensight.objs.core.get_units("L/TT")
.The format and utf8 keywords control the specific format of the string. The format can be: 0=raw, 1=Unicode or 2=EnSight annotation string. If Unicode is selected, the string will be in unicode unless utf8=2 is specified, in which case an UTF8 encoded bytes object will be returned.
- Args:
- obj:
A variable/part object or a string representing units by dimensional specification. For example, “L/TT” (length/time*time) for acceleration.
- format:
The specific string format. 0=simple raw ASCII, 1=Unicode string, 2=EnSight annotation.
- utf8:
By default, the returned string is in Unicode. If set to 2, a bytes object of the UTF8 representation is returned.
- prefix:
A string used to prefix the unit string.
- suffix:
A string used to suffix the unit string.
- Returns:
A string or bytes array.
- Example:
# For an ENS_VAR ('var') with the ENS_UNITS_LABEL and version 2.0 of the schema specified ensight.objs.core.get_units(var) 'm^2 s^-2' ensight.objs.core.get_units(var, format=1) 'm²/s²' ensight.objs.core.get_units(var, format=1, utf8=2) b'kg/m\xc2\xb3'
- See also: