ibfoamrig.core.Sampler#

class ibfoamrig.core.Sampler(centres, values, *, names=None, ids=None, neighbours=8)[source]#

Bases: object

Evaluates cell-centered values at arbitrary points.

Variables:
  • names – Names of the sampled value columns.

  • dimensions – Number of axes along which the cell centres vary.

  • neighbours – Number of cell centres used by the "linear" method.

classmethod from_data(data, fields=None, *, neighbours=8)[source]#

Builds a sampler over the cells of a FieldData.

Parameters:
  • data (FieldData) – The cells to sample from.

  • fields (Sequence[str] | None) – Field columns to sample. If None, all fields are used.

  • neighbours (int) – Number of nearest cell centres for the "linear" method.

Returns:

A sampler whose value columns are named after the fields and whose nearest returns cellI.

Raises:
  • TypeError – If fields is a single string.

  • ValueError – If no fields are selected or a field is missing.

Return type:

Self

at(points, *, method='linear', max_distance=None)[source]#

Samples the values at the given points.

Parameters:
  • points (Points) – Sample points. If a frame is given, all its columns are kept and the sampled values are appended.

  • method (Method) – Interpolation method, see the module description.

  • max_distance (float | None) – If given, samples whose nearest cell centre is farther away are set to NaN. Use to avoid extraplating outside the domain or across holes.

Returns:

The points (or the input frame) with one column per value.

Raises:

ValueError – If the points are malformed, method is unknown, or a value name is already a column of the input frame.

Return type:

DataFrame

line(start, end, count=200, *, method='linear', max_distance=None)[source]#

Samples the values at evenly spaced points along a line segment.

Parameters:
  • start (Point) – First end point (x , y, z).

  • end (Point) – Second end point (x, y, z).

  • count (int) – Number of points, including both end points.

  • method (Method) – Interpolation method, see the module description.

  • max_distance (float | None) – If given, samples whose nearest cell centre is farther away are set to NaN.

Returns:

A frame with s, x, y, z and one column per value.

Raises:

ValueError – If count is below 2, start and end coincide, or method is unknown.

Return type:

DataFrame

nearest(points)[source]#

Finds the nearest cell for each point.

Parameters:

points (Points) – Sample points.

Returns:

The ids of the nearest cells with shape (m,) – cellI for a sampler built with from_data, otherwise the given ids or row indices.

Raises:

ValueError – If the points are malformed.

Return type:

ndarray[tuple[Any, …], dtype[int64]]