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:
BaseModelSet 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:
- Parameters:
data (
Any)
- __call__(array, _)¶
Set the array to the contents of the file.
- model_config: ClassVar[ConfigDict]¶
Configuration for
pydantic.BaseModel.
- class pigreads.schema.setter.SetterSlices(**data)¶
Bases:
BaseModelSet slices of an array to a value.
The slices are defined by a list of
pigreads.schema.basic.Sliceobjects. Only where all slices are true, the value is set.- Parameters:
data (
Any)
- __call__(array, _)¶
Set the slices of the array to the value.
- 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.
- class pigreads.schema.setter.SetterSpherical(**data)¶
Bases:
BaseModelSet 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:
sim (
Simulation) – Simulation object with the grid information, seepigreads.schema.simulation.Simulation.
- Return type:
- Returns:
Modified array.
- model_config: ClassVar[ConfigDict]¶
Configuration for
pydantic.BaseModel.
- 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.