pisces.models.stars.polytropes.PolytropicStarModel.from_components#
- classmethod PolytropicStarModel.from_components(filepath: str | Path, grid: Grid, fields: dict[str, unyt_array | ndarray], profiles: dict[str, BaseProfile], metadata: dict[str, Any], overwrite: bool = False) BaseModel #
Create and save a Pisces model from in-memory components.
This method assembles a fully specified model from its constituent parts— spatial grid, physical fields, analytic profiles, and metadata—and writes it to disk in Pisces HDF5 format. The resulting file can be loaded directly using the class constructor.
The output file will follow the standard Pisces model layout:
/ ├── FIELDS/ # Physical field arrays (e.g., density, temperature) ├── PROFILES/ # Serialized analytic profile definitions ├── GRID/ # Serialized spatial grid object └── attrs/ # Model metadata and identity tags
- Parameters:
filepath (
str
orPath
) – Path to the output HDF5 model file. If the file already exists andoverwrite
is False, aFileExistsError
will be raised.grid (
Grid
) – The spatial grid defining the model’s geometry. This object must be a subclass ofGrid
and will be serialized to the/GRID
group via its_save_grid_to_hdf5_group()
method.fields (
dict
ofstr
,(unyt_array
ornumpy.ndarray)
) –Dictionary mapping field names to their corresponding arrays.
Keys: Field names (e.g.,
"density"
or"temperature"
)Values: Either a
unyt.array.unyt_array
with units or a plainnumpy.ndarray
for unitless data.
Each array’s leading shape must exactly match
grid.shape
; additional trailing dimensions (e.g., for vector/tensor components) are allowed.profiles (
dict
ofstr -> BaseProfile
) – Dictionary mapping profile names to fully instantiated analytic profile objects. Each profile must implementto_hdf5()
for serialization.metadata (
dict
) –Dictionary of model metadata to store as root-level attributes in the HDF5 file. This can include descriptive information, provenance tags, and other auxiliary data. The following keys are generally recommended:
"description"
: Short summary of the model"source"
: Origin or generating process"date_created"
: Will be set automatically if not provided"__model_class__"
: Will be set automatically to matchcls.__name__
overwrite (
bool
, optional) – Whether to overwrite an existing file atfilepath
. Defaults toFalse
. If set toTrue
, any existing file will be replaced.
- Returns:
An instance of the model loaded from the saved file.
- Return type:
BaseModel