pisces.models.galaxy_clusters.spherical.MagnetizedSphericalGalaxyClusterModel.from_components#

classmethod MagnetizedSphericalGalaxyClusterModel.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 or Path) – Path to the output HDF5 model file. If the file already exists and overwrite is False, a FileExistsError will be raised.

  • grid (Grid) – The spatial grid defining the model’s geometry. This object must be a subclass of Grid and will be serialized to the /GRID group via its _save_grid_to_hdf5_group() method.

  • fields (dict of str, (unyt_array or numpy.ndarray)) –

    Dictionary mapping field names to their corresponding arrays.

    Each array’s leading shape must exactly match grid.shape; additional trailing dimensions (e.g., for vector/tensor components) are allowed.

  • profiles (dict of str -> BaseProfile) – Dictionary mapping profile names to fully instantiated analytic profile objects. Each profile must implement to_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 match cls.__name__

  • overwrite (bool, optional) – Whether to overwrite an existing file at filepath. Defaults to False. If set to True, any existing file will be replaced.

Returns:

An instance of the model loaded from the saved file.

Return type:

BaseModel