swiftsimio.reader module

Main objects for reading SWIFT datasets.

These include:

  • SWIFTUnits, which is a unit system that can be queried for units (and converts arrays to relevant unyt arrays when read from the HDF5 file)

  • SWIFTMetadata, which contains all of the metadata from the file

  • __SWIFTGroupDataset, which contains particle information but should never be directly accessed. Use _generate_datasets to create one of these. The reasoning here is that properties can only be added to the class afterwards, and not directly in an _instance_ of the class.

  • SWIFTDataset, a container class for all of the above.

class swiftsimio.reader.SWIFTDataset(filename: Path, mask: SWIFTMask | None = None, handle: File | None = None)[source]

Bases: HandleProvider

A collection object for units, metadata and data objects.

It contains:

  • a SWIFTUnits,

  • a SWIFTMetadata,

  • several SWIFTGroupDataset

This object, in essence, completely represents a SWIFT snapshot. You can access the different particles as follows:

  • SWIFTDataset.gas.particle_ids

  • SWIFTDataset.dark_matter.masses

  • SWIFTDataset.gas.smoothing_lengths

These arrays all have units that are determined by the unit system in the file.

The unit system is available as SWIFTDataset.units and the metadata as SWIFTDataset.metadata.

Parameters:
  • filename (str) – Name of file containing snapshot.

  • mask (SWIFTMask, optional) – Mask object containing dataset to selected particles.

  • handle (h5py.File, optional) – File handle to read metadata.

filename: Path
get_units() None[source]

Load the units from the SWIFT snapshot.

Ordinarily this happens automatically, but you can call this function again if you mess things up.

get_metadata() None[source]

Load the metadata from the SWIFT snapshot.

Ordinarily this happens automatically, but you can call this function again if you mess things up.

create_datasets() None[source]

Create datasets for present groups.

Present groups are specified in metadata.present_group_names.

These can then be accessed using their underscore names, e.g. gas.