pynbody.halo.subfindhdf.SubFindHDFHaloCatalogue#

class pynbody.halo.subfindhdf.SubFindHDFHaloCatalogue(sim, filename=None, subs=None, subhalos=False, _inherit_data_from=None)[source]#

Bases: HaloCatalogue

Handles catalogues produced by the SubFind halo finder, in the HDF5 format used by Gadget3, 4 and Arepo.

Since the internal format differs quite substantially between these versions, child classes are provided for Gadget 4, Arepo and TNG. The base class is able to handle the common elements of the format, and is also used for Gadget 3 SubFind outputs.

See Gadget4SubfindHDFCatalogue, ArepoSubfindHDFCatalogue and TNGSubfindHDFCatalogue.

Warning

At present, the Gadget 4, Arepo and TNG subclasses of this class are not tested against multi-file outputs. If you encounter issues with these, please report them to the pynbody developers.

Attributes:
base

The snapshot object that this halo catalogue is based on.

Methods

contains(halo_number)

Deprecated alias; instead of h.contains(number) use number in h.

get_dummy_halo(halo_number)

Return a DummyHalo object containing only the halo properties, no particle information

get_group_array([family, use_index, fill_value])

Return an array with an integer for each particle in the simulation, indicating the halo of that particle.

get_properties_all_halos([with_units])

Returns a dictionary of properties for all halos.

get_properties_one_halo(i)

Returns a dictionary of properties for a single halo, given a halo_number

iter_subclasses()

Iterate over all subclasses of this class, recursively.

iter_subclasses_with_priority(priority)

Iterate over all subclasses, starting with the given priorities

keys()

Return an iterable of all halo numbers in the catalogue.

load_all()

Loads all halos, which is normally more efficient if a large fraction of them will be accessed.

load_copy(halo_number)

Load a fresh SimSnap with only the particles in specified halo

physical_units([distance, velocity, mass, ...])

Converts all arrays' units to be consistent with the distance, velocity, mass basis units specified.

precalculate()

Deprecated alias for load_all()

__init__(sim, filename=None, subs=None, subhalos=False, _inherit_data_from=None)[source]#

Initialise a SubFindHDF catalogue.

By default, the FoF groups are imported, and subhalos are available via the ‘subhalos’ attribute of each halo object, e.g.

>>> f = pynbody.load('path/to/snapshot.hdf5')
>>> h = f.halos()
>>> h[1].subhalos[2] # returns the third subhalo of FoF group 1

However by setting subhalos=True, the FoF groups are ignored and the catalogue is of all subhalos.

Note

Note that this constructor is common between SubFindHDFHaloCatalogue and its subclasses Gadget4SubfindHDFCatalogue, ArepoSubfindHDFCatalogue and TNGSubfindHDFCatalogue.

For Gadget 3 outputs, the SubFind data is stored internally to the snapshot itself. Therefore passing a filename to the constructor for SubFindHDFHaloCatalogue will result in an exception. For Gadget 4, Arepo and TNG SubFind outputs, a filename can be passed that points to the fof_subhalo_tab_XXX.hdf5 file (see below).

Parameters:
  • sim (SimSnap) – The simulation snapshot to which this catalogue applies.

  • filename (str, optional) – The filename of the HDF5 file containing the SubFind catalogue. This is only used for Gadget 4, Arepo and TNG subclasses and must be None when used with the Gadget 3 base class. See the note above.

  • subhalos (bool, optional) – If False (default), catalogue represents the FoF groups and subhalos are available through the subhalos() attribute of each group (see note above). If True, the catalogue represents the subhalos directly and FoF groups are not available.

  • subs (bool, optional) – Deprecated alias for subhalos.

  • _inherit_data_from (SubfindCatalogue, optional) – For internal use only; allows subhalo catalogue to share data with its parent FOF catalogue

property base: SimSnap#

The snapshot object that this halo catalogue is based on.

contains(halo_number: int) bool#

Deprecated alias; instead of h.contains(number) use number in h.

get_dummy_halo(halo_number) DummyHalo#

Return a DummyHalo object containing only the halo properties, no particle information

get_group_array(family=None, use_index=False, fill_value=-1)#

Return an array with an integer for each particle in the simulation, indicating the halo of that particle.

If there are multiple levels (i.e. subhalos), the number returned corresponds to the lowest level, i.e. the smallest subhalo.

Parameters:
  • family (str, optional) – If specified, return only the group array for the specified family.

  • use_index (bool, optional) – If True, return the halo index rather than the halo number. (See the class documentation for the distinction between halo numbers and indices.)

  • fill_value (int, optional) – The value to fill for particles not in any halo.

get_properties_all_halos(with_units=True) dict[source]#

Returns a dictionary of properties for all halos.

If with_units is True, the properties are returned as SimArrays with units if possible. Otherwise, numpy arrays are returned.

Note that the returned properties are in contiguous arrays, and as a result may be in a different order to the halo numbers which are used to access individual halos. To map between halo numbers and properties, use the .number_mapper object; or access individual property dictionaries by halo number using get_properties_one_halo.

get_properties_one_halo(i)[source]#

Returns a dictionary of properties for a single halo, given a halo_number

classmethod iter_subclasses() Iterable[type]#

Iterate over all subclasses of this class, recursively.

This is used by HaloCatalogue and SimSnap to find a suitable loader for a given file.

classmethod iter_subclasses_with_priority(priority: Iterable[str | type]) Iterable[type]#

Iterate over all subclasses, starting with the given priorities

The priorities can be provided either as a string or a class

keys()#

Return an iterable of all halo numbers in the catalogue.

load_all()#

Loads all halos, which is normally more efficient if a large fraction of them will be accessed.

load_copy(halo_number)#

Load a fresh SimSnap with only the particles in specified halo

This relies on the underlying SimSnap being capable of partial loading.

physical_units(distance='kpc', velocity='km s^-1', mass='Msol', persistent=True, convert_parent=False)#

Converts all arrays’ units to be consistent with the distance, velocity, mass basis units specified.

Parameters:
  • distance (string (default = 'kpc')) – The distance unit to convert to.

  • velocity (string (default = 'km s^-1')) – The velocity unit to convert to.

  • mass (string (default = 'Msol')) – The mass unit to convert to.

  • persistent (boolean (default = True)) – Apply units change to future lazy-loaded arrays if True.

  • convert_parent (boolean (default = True)) – Propagate units change from a halo catalogue to a parent snapshot. See note below.

Note

The option convert_parent is only applicable to Halo objects. It is ignored by all other objects, including pynbody.snapshot.simsnap.SimSnap, pynbody.snapshot.subsnap.SubSnap, and pynbody.halo.HaloCatalogue objects.

When physical_units is called on a pynbody.halo.Halo and convert_parent is True, no immediate action is taken on the pynbody.halo.Halo itself; rather the request is passed upwards to the pynbody.halo.HaloCatalogue.

The catalogue object then calls physical_units on the parent snapshot and on all cached halos, setting convert_parent=False so that the units change is then applied to the pynbody.halo.Halo object itself.

This ensures that unit changes propagate through to properties of all halos. Most users will not need to worry about this subtlety; things should ‘just work’ if you ignore the convert_parent option.

precalculate()#

Deprecated alias for load_all()