fields.mixins.base.DTensorFieldCoreMixin.from_array#
- classmethod DTensorFieldCoreMixin.from_array(*args, signature: SignatureInput | None = None, **kwargs) _SupDTFieldCore [source]#
Construct a
FieldComponent
from an existing array-like object.This method creates a
FieldComponent
by wrapping a NumPy array, unyt array, or similar backend-supported array in a compatible buffer. The shape of the input array must match the combined spatial and element-wise shape implied by grid and axes.- Parameters:
array_like (
array-like
) – The array to wrap. This can be anumpy.ndarray
,unyt.unyt_array
, or other compatible type.grid (
GridBase
) – The grid over which the field is defined.axes (
list
ofstr
) – The spatial axes of the coordinate system over which the array is defined. The shape of the array must begin with the grid shape corresponding to these axes.signature (
int
orlist
ofint
, optional) – The signature of the tensor field being generated. This should be a sequence of 1 and -1 with 1 marking a contravariant index and -1 a covariant index. The length must match that of rank. If not specified, signature defaults to a fully contravariant form.buffer_class (
str
orBufferBase
, optional) – The buffer class to use for wrapping the data. This can be a class or string identifier. If not provided, defaults to ArrayBuffer.buffer_registry (
BufferRegistry
, optional) – Custom registry to use for resolving string buffer types.**kwargs – Additional keyword arguments forwarded to the buffer constructor (e.g., units if supported).
- Returns:
A new component wrapping the given array.
- Return type:
FieldComponent
- Raises:
ValueError – If the input array shape is incompatible with the grid and axes.