pisces.particles.gadget.Gadget4ParticleDataset.build_particle_dataset#

classmethod Gadget4ParticleDataset.build_particle_dataset(path: str | Path, number_of_particles: Sequence, box_size: unyt_quantity, *, ntypes: int = 6, unit_system: UnitSystem = None, overwrite: bool = False, fields: dict = None, double_precision: bool = True, coordinates_precision: int = 32, id_precision: int = 32, enable_cooling: bool = False) Gadget4ParticleDataset[source]#

Build a new Gadget-4 particle dataset.

This is the primary public constructor for Gadget-4 style initial condition files. It writes the file header, particle groups, and required fields according to Gadget-4 conventions.

Parameters:
  • path (str or pathlib.Path) – Destination path for the new dataset.

  • number_of_particles (sequence of int) – Particle counts per type. Length must equal ntypes.

  • box_size (unyt.unyt_quantity) – Simulation box size with length units.

  • ntypes (int, default 6) – Number of particle types (Gadget standard).

  • unit_system (unyt.UnitSystem, optional) – Unit system for annotating dataset units. Defaults to galactic unit system.

  • overwrite (bool, default False) – Overwrite the file if it exists. If False, raise an error instead.

  • fields (dict, optional) – Additional fields to populate after dataset creation. Keys must be of the form "ParticleTypeX.FieldName".

  • double_precision (bool, default True) – Use float64 for floating-point fields (except where overridden).

  • coordinates_precision ({32, 64}, default 32) – Precision for Coordinates.

  • id_precision ({32, 64}, default 32) – Precision for ParticleIDs.

  • enable_cooling (bool, default False) – If True, add ElectronAbundance to gas.

Returns:

A dataset object pointing to the newly created file.

Return type:

Gadget4ParticleDataset

Raises:
  • FileExistsError – If the file exists and overwrite=False.

  • ValueError – If particle counts or field shapes are inconsistent.

  • TypeError – If units or parameters are of invalid types.

Examples

Create a simple Gadget-4 IC file with gas and DM:

import unyt as u

ds = (
    Gadget4ParticleDataset.build_particle_dataset(
        "ics_gadget4.hdf5",
        number_of_particles=[
            1000,
            2000,
            0,
            0,
            0,
            0,
        ],
        box_size=1.0 * u.Mpc,
        overwrite=True,
    )
)

Create a Gadget-4 IC file with cooling enabled:

ds = (
    Gadget4ParticleDataset.build_particle_dataset(
        "ics_cooling.hdf5",
        number_of_particles=[
            500,
            500,
            0,
            0,
            0,
            0,
        ],
        box_size=500.0 * u.kpc,
        enable_cooling=True,
    )
)