Setters

Setters for arrays

pigreads.schema.setter.Setter

A setter is a command to set an array to a given value or to modify the array in a specific way.

One of:

class pigreads.schema.setter.SetterFile(**data)

Bases: BaseModel

Set an array to the contents of a file.

The file should contain a numpy array with the same shape as the array to be set.

See:

numpy.load()

Parameters:

data (Any)

__call__(array, _)

Set the array to the contents of the file.

Parameters:
Return type:

ndarray[Any, Any]

Returns:

Array set to the contents of the file.

cmd: Literal['file']

Identifier for this setter.

file: Path

Path to the file containing the array.

model_config: ClassVar[ConfigDict]

Configuration for pydantic.BaseModel.

class pigreads.schema.setter.SetterSlices(**data)

Bases: BaseModel

Set slices of an array to a value.

The slices are defined by a list of pigreads.schema.basic.Slice objects. Only where all slices are true, the value is set.

Parameters:

data (Any)

__call__(array, _)

Set the slices of the array to the value.

Parameters:
Return type:

ndarray[Any, Any]

Returns:

Array with the slices set to the value.

cmd: Literal['slice', 'slices']

Identifier for this setter.

model_config: ClassVar[ConfigDict]

Configuration for pydantic.BaseModel.

classmethod normalise(values)

Normalise the setter.

If there is only one slice, it is converted to a list of slices.

Parameters:

values (Any) – Any data to try to interpret.

Return type:

Any

Returns:

Normalised data.

slices: list[Slice]

List of slices.

value: float

Value to set in the slices.

class pigreads.schema.setter.SetterSpherical(**data)

Bases: BaseModel

Set an array to a value inside or outside a sphere or ellipsoid.

The ellipsoid is defined by a center and a radii in each dimension. If not none, the inside and outside values are set to given values.

If not given, the radius is set to half the size of the array in each dimension, and the center is set to the center of the array.

Parameters:

data (Any)

__call__(array, sim)

Modify the array to set values inside or outside a sphere or ellipsoid.

The array is modified in place to set the values inside or outside the sphere or ellipsoid to the given values.

Parameters:
Return type:

ndarray[Any, Any]

Returns:

Modified array.

center: Vector3D | None

Center of the ellipsoid, None for the center of the array.

cmd: Literal['spherical']

Identifier for this setter.

exponent: Vector3D | float

Exponent for the norm, usually 2 for a sphere or ellipsoid.

inside: float | None

Value to set inside the ellipsoid, None for no change.

model_config: ClassVar[ConfigDict]

Configuration for pydantic.BaseModel.

outside: float | None

Value to set outside the ellipsoid, None for no change.

radius: Vector3D | float | None

Radius of the sphere or radii of the ellipsoid, None for half the size of the array.

pigreads.schema.setter.normalise_list_of_setters(values)

Normalise a list of setters.

Instead of the full representation:

setters:
- cmd: spherical
  outside: 0

The command string can also be given as the only key of a dictionary:

setters:
- spherical:
    outside: 0

Also instead of a list, a dictionary can be given with the command as key:

setters:
  spherical:
    outside: 0

If there is a single string given, it is interpreted as a file setter:

setters: "file.npy"

If a setter is given as a string:

setters:
  file: "file.npy"

It is converted to a dictionary:

setters:
  file:
    file: "file.npy"

This function is used in the schema to normalise the input and to allow more flexible input formats.

Parameters:

values (Any) – Any data to try to interpret.

Return type:

Any

Returns:

Normalised data.