pynbody.halo.ahf.AHFCatalogue#

class pynbody.halo.ahf.AHFCatalogue(sim, filename=None, make_grp=None, get_all_parts=None, use_iord=None, ahf_basename=None, dosort=None, only_stat=None, write_fpos=True, halo_numbers='file-order', ignore_missing_substructure=True, **kwargs)[source]#

Bases: HaloCatalogue

Class to handle catalogues produced by Amiga Halo Finder (AHF).

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, make_grp=None, get_all_parts=None, use_iord=None, ahf_basename=None, dosort=None, only_stat=None, write_fpos=True, halo_numbers='file-order', ignore_missing_substructure=True, **kwargs)[source]#

Initialize an AHFCatalogue.

Parameters:
  • *sim* (SimSnap) – the simulation snapshot to which this catalogue refers

  • *filename* (str | pathlib.Path) – specify a path to an AHF halo catalog. Note that AHF actually outputs multiple files; you can specify the path to the AHF_halos or AHF_particles file and the code will infer the other filenames from this. Alternatively you can specify the path up to the AHF_ prefix and the code will similarly infer the full set of filenames.

  • *halo_numbers* (str) –

    specify how to number the halos. Options are:

    • ’ahf’ (default): use the halo numbers written in the AHF halos file if present, or a zero-based indexing

    • ’file-order’: zero-based indexing of the halos

    • ’v1’: one-based indexing of the halos, compatible with pynbody v1 default behaviour

    • ’length-order’: sort by the number of particles in each halo, with the halo with most particles being halo 0

    • ’length-order-v1’: as length-order, but indexing from halo 1, compatible with dosort=True in pynbody v1

  • *ignore_missing_substructure* (bool) – If True (default), the code will not raise an exception if the substructure file is missing or corrupt. If False, it will raise an exception.

  • *use_iord* (bool) – if True, the particle IDs in the Amiga catalogue are taken to refer to the iord array. If False, they are the particle offsets within the file. If None, the parameter defaults to True for GadgetSnap, False otherwise.

  • *ahf_basename* (str) – Deprecated way to specify the location of the catalogue

  • *make_grp* – Deprecated. If True a ‘grp’ array is created in the underlying snapshot specifying the lowest level halo that any given particle belongs to. If it is False, no such array is created; if None, the behaviour is determined by the configuration system.

  • *get_all_parts* – Deprecated; use the load_all() method instead.

  • *dosort* – Deprecated; equivalent to halo_numbers='length-order'

  • *only_stat* – Deprecated; this keyword is now ignored. To obtain halo information without loading the particles, use the methods get_properties_one_halo() or get_properties_all_halos().

property base#

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