pynbody.halo.subfind.SubfindCatalogue#

class pynbody.halo.subfind.SubfindCatalogue(sim, filename=None, subs=None, subhalos=False, ordered=None, _inherit_data_from=None)[source]#

Bases: HaloCatalogue

Handles catalogues produced by the SubFind halo finder (old versions that do not use HDF5 outputs).

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, ordered=None, _inherit_data_from=None)[source]#

Initialise a SubFind 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')
>>> h = f.halos()
>>> h[1].subhalos[2] # returns the third subhalo of FoF group 1

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

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

  • filename (str, optional) – The path to the SubFind output(s). This is expected to be a folder named groups_XXX where XXX is the snapshot number. The code extracts the snapshot number from the folder name and uses it to construct the filename of the catalogue files, for example groups_XXX/subhalo_tab_XXX.0. If no filename is provided, the code will attempt to find a suitable catalogue starting from the simulation’s directory.

  • 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.

  • ordered (bool, optional) – If True, the snapshot must have sequential iords. If False, the iords might be out-of-sequence, and therefore reordering will take place. If None (default), the iords are examined to check whether re-ordering is required or not. Note that re-ordering can be undesirable because it also destroys subfind’s order-by-binding-energy

  • _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()