fields.mixins.base.DFieldCoreMixin.from_array#

classmethod DFieldCoreMixin.from_array(*args, **kwargs) _SupDFieldCore[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 a numpy.ndarray, unyt.unyt_array, or other compatible type.

  • grid (GridBase) – The grid over which the field is defined.

  • axes (list of str) – 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.

  • buffer_class (str or BufferBase, 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.

  • *args – Additional keyword arguments forwarded to the buffer constructor (e.g., units if supported).

  • **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.