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 (
strorpathlib.Path) – Destination path for the new dataset.number_of_particles (
sequenceofint) – Particle counts per type. Length must equalntypes.box_size (
unyt.unyt_quantity) – Simulation box size with length units.ntypes (
int, default6) – Number of particle types (Gadget standard).unit_system (
unyt.UnitSystem, optional) – Unit system for annotating dataset units. Defaults to galactic unit system.overwrite (
bool, defaultFalse) – 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, defaultTrue) – Use float64 for floating-point fields (except where overridden).coordinates_precision (
{32, 64}, default32) – Precision forCoordinates.id_precision (
{32, 64}, default32) – Precision forParticleIDs.enable_cooling (
bool, defaultFalse) – If True, addElectronAbundanceto gas.
- Returns:
A dataset object pointing to the newly created file.
- Return type:
- 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, ) )