pynbody.halo.hbtplus.HBTPlusCatalogue#

class pynbody.halo.hbtplus.HBTPlusCatalogue(sim, halo_numbers=None, filename=None)[source]#

Bases: HaloCatalogue

A class to represent a HBT+ halo catalogue.

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(halo_number)

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

with_groups_from(other)

Return a new catalogue that combines an HBT+ halo catalogue with a parent group catalogue.

__init__(sim, halo_numbers=None, filename=None)[source]#

Initialize a HBTPlusCatalogue object.

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

  • halo_numbers (str, optional) –

    How to number the halos. If None (default), use a zero-based indexing.

    • If track, use the TrackId from the catalogue.

    • If length-order, order by Nbound (descending), similar to the AHF option of the same name.

  • filename (str, optional) – The filename of the HBTPlus catalogue. If the file is spanned across multiple outputs (e.g. path/to/SubSnap_034.0.hdf5, SubSnap_034.1.hdf5, etc.), pass the filename of the first file or the common prefix (path/to/SubSnap_034). If None (default), attempt to find the file automatically.

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(halo_number) dict[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()

with_groups_from(other: HaloCatalogue) HaloCatalogue[source]#

Return a new catalogue that combines an HBT+ halo catalogue with a parent group catalogue.

For example:

>>> grps = hbt_cat.with_groups_from(subfind_cat)
>>> grps[0] # -> returns subfind_cat[0]
>>> grps[0].properties['children'] # -> returns relevant halo numbers in hbt_cat
>>> grps[0].subhalos # -> returns HBT+ subhalos that are children of subfind_cat[0]

See also HBT+ and parent groups.