pisces.models.galaxy_clusters.spherical.SphericalGalaxyClusterModel.add_field#
- SphericalGalaxyClusterModel.add_field(name: str, element_shape: tuple[int, ...] = (), units: str | Unit = None, data: unyt_array | ndarray = None, overwrite: bool = False, **kwargs)#
Add a new physical field to the model.
Fields represent physical quantities (e.g., density, temperature, velocity) defined on the model’s spatial grid. This method creates a new field with optional initialization from user-provided data.
- Parameters:
name (
str
) – Name of the field (e.g.,"density"
).element_shape (
tuple
ofint
, optional) – Extra trailing dimensions for vector/tensor fields (e.g.,(3,)
). Defaults to()
.units (
str
orunyt.Unit
, optional) – Units for the field. IfNone
, the field is unitless.data (
unyt_array
ornumpy.ndarray
, optional) – Values to initialize the field. IfNone
, initialized to zeros. Must have shapegrid.shape + element_shape
.overwrite (
bool
, optional) – IfTrue
, replaces an existing field with the same name. IfFalse
, raisesKeyError
if the field already exists.
- Raises:
ValueError – If provided data does not match the expected shape.
KeyError – If the field already exists and
overwrite=False
.
Notes
The field is written to both memory and the on-disk HDF5 file under
/FIELDS/{name}
.Unit handling is powered by
unyt
.