pynbody.snapshot.gadgethdf.HDFArrayLoader

pynbody.snapshot.gadgethdf.HDFArrayLoader#

class pynbody.snapshot.gadgethdf.HDFArrayLoader(hdf_files: _GadgetHdfMultiFileManager, all_families: list[Family], family_to_group_map: dict[Family, list[str]], take: ndarray | None = None)[source]#

Bases: object

A helper class to handle the loading of particle data arrays from Gadget HDF5 files.

This class abstracts the logic for reading data from potentially multiple HDF5 files, mapping the on-disk particle types to pynbody’s family structure, and handling partial loading of snapshots (i.e., loading only a subset of particles). It also handles chunked reading of the data to keep memory usage under control (see pynbody.chunk.LoadControl).

Methods

load_arrays(all_fams_to_load, sim, ...)

Load an array from the HDF files into the simulation snapshot.

__init__(hdf_files: _GadgetHdfMultiFileManager, all_families: list[Family], family_to_group_map: dict[Family, list[str]], take: ndarray | None = None)[source]#

Initializes the HDFArrayLoader.

Parameters:
  • hdf_files (_GadgetHdfMultiFileManager) – The manager for the set of HDF5 files belonging to the snapshot.

  • all_families (list of pynbody.family.Family) – A list of all pynbody families present in the simulation, correctly ordered.

  • family_to_group_map (dict[pynbody.family.Family, list[str]]) – A dictionary mapping each pynbody family to a list of Gadget HDF particle group names (e.g., ‘PartType0’, ‘PartType1’).

  • take (np.ndarray or None, optional) – If not None, this is an array of particle indices to load from the snapshot. This enables partial loading. If None, all particles are loaded. Default is None.

load_arrays(all_fams_to_load: list[Family], sim: SimSnap, array_name: str, translated_names: list[str])[source]#

Load an array from the HDF files into the simulation snapshot.

Parameters:
  • all_fams_to_load (list of pynbody.family.Family) – A list of pynbody families for which to load the array.

  • sim (SimSnap) – The parent SimSnap object.

  • array_name (str) – The pynbody standard name for the array to load.

  • translated_names (list of str) – A list of possible names for the array in the Gadget HDF file.