Skip to content

fdray.data.field

source module fdray.data.field

source class Union(*args: Any, **kwargs: Any)

Bases : BaseUnion

Methods

  • from_field Create objects from scalar, vector or tensor fields.

  • from_region Create objects from a discrete region.

source classmethod Union.from_field(field: Sequence | NDArray, obj: Callable[[Any], Object | Iterable[Object] | None], spacing: float | tuple[float, ...] = 1, ndim: int = 1, mask: Sequence | NDArray | None = None, *, as_union: bool = True)Self | list[Object]

Create objects from scalar, vector or tensor fields.

This function generates 3D objects from field data. The last ndim dimensions of the input array are considered as field components.

Parameters

  • field : Sequence | NDArray Array containing field data

  • obj : Callable[[Any], Object | Iterable[Object] | None] Function that takes field data at a position and returns an Object (or None to skip)

  • spacing : float | tuple[float, ...] Distance between objects (scalar or per-dimension)

  • ndim : int Number of dimensions to treat as field components:

    • ndim=0: Scalar field (all dimensions used for positioning)
    • ndim=1: Vector field (last dimension contains vector components)
    • ndim=2: Tensor field (last two dimensions contain tensor components)
  • mask : Sequence | NDArray | None Boolean mask to filter field data

  • as_union : bool Whether to return a Union object or a list of objects

Returns

  • Self | list[Object] Union object or list of objects representing the field

source classmethod Union.from_region(region: Sequence | NDArray, obj: Object | Callable[[Any], Object | Iterable[Object] | None] | None = None, spacing: float | tuple[float, ...] = 1, mapping: Mapping[Any, Any] | None = None, *, as_union: bool = True)Self | list[Object]

Create objects from a discrete region.

This function generates 3D objects from a discrete region, where each unique value in the region corresponds to an object with specific attributes.

The function supports two modes:

  1. Base object + attribute mapping: Provide an Object instance and a mapping of region values to attributes (e.g., colors).
  2. Custom object generation: Provide a callback function that takes a region value and returns an Object (similar to from_field).

Parameters

  • region : Sequence | NDArray Array containing region data (discrete values)

  • obj : Object | Callable[[Any], Object | Iterable[Object] | None] | None Either an Object instance to be used as base, or a function that takes a region value and returns an Object, or None to use a default Cube

  • spacing : float | tuple[float, ...] Distance between objects (scalar or per-dimension)

  • mapping : Mapping[Any, Any] | None Mapping from region values to attributes (used only when obj is an Object)

  • as_union : bool Whether to return a Union object or a list of objects

Returns

  • Self | list[Object] Union object or list of objects representing the region

source iter_objects_from_callable(obj: Callable[[Any], Object | Iterable[Object] | None], field: Sequence | NDArray, spacing: float | tuple[float, ...] = 1, ndim: int = 1, mask: Sequence | NDArray | None = None)Iterator[Object]

source iter_objects_from_dict(objects: dict[Any, Object], region: Sequence | NDArray, spacing: float | tuple[float, ...] = 1)Iterator[Object]

source get_indices(region: Sequence | NDArray)dict[Any, list[tuple[int, ...]]]

source get_default_mapping(region: Sequence | NDArray)dict[Any, Any]

source translate(obj: Object, indices: Iterable[Iterable[float]], spacing: float | Iterable[float] = 1, offset: float | Iterable[float] = 0)Iterator[Object]