fields.mixins.components.FieldComponentCoreMixin.in_units#
- FieldComponentCoreMixin.in_units(units: str | Unit, *args, as_array: bool = False, equivalence: str | None = None, buffer_class: Type[BufferBase] | None = None, buffer_registry: BufferRegistry | None = None, equiv_kw: dict | None = None, **kwargs)[source]#
Return a version of this component in the specified physical units.
This returns a new component or a unit-tagged array depending on as_array. It delegates to the underlying buffer and wraps the result if needed.
- Parameters:
units (
str
orunyt.Unit
) – Target units to cast the buffer into.as_array (
bool
, defaultFalse
) – If True, return a unyt_array. If False, return a new FieldComponent.equivalence (
str
, optional) – Optional equivalence for unit conversion.buffer_class (
type
, optional) – Override for buffer resolution (if wrapping).buffer_registry (
BufferRegistry
, optional) – If resolving, specify which registry to use.equiv_kw (
dict
, optional) – Additional arguments to the equivalence logic.*args – Forwarded to the buffer constructor if wrapping.
**kwargs – Forwarded to the buffer constructor if wrapping.
- Returns:
A new component (or array) in the desired units.
- Return type:
FieldComponent
orunyt_array
- Raises:
UnitConversionError – If the conversion is invalid.