pynbody.halo.subfindhdf.Gadget4SubfindHDFCatalogue#
- class pynbody.halo.subfindhdf.Gadget4SubfindHDFCatalogue(sim, filename=None, **kwargs)[source]#
Bases:
SubFindHDFHaloCatalogue
Handles catalogues produced by the SubFind halo finder, in the HDF5 format used by Gadget 4
Warning
At present, this is 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)
usenumber 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.
Returns a dictionary of properties for a single halo, given a halo_number
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.
Deprecated alias for
load_all()
- __init__(sim, filename=None, **kwargs)[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 subclassesGadget4SubfindHDFCatalogue
,ArepoSubfindHDFCatalogue
andTNGSubfindHDFCatalogue
.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 thefof_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
- contains(halo_number: int) bool #
Deprecated alias; instead of
h.contains(number)
usenumber 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 #
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)#
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, includingpynbody.snapshot.simsnap.SimSnap
,pynbody.snapshot.subsnap.SubSnap
, andpynbody.halo.HaloCatalogue
objects.When
physical_units
is called on apynbody.halo.Halo
and convert_parent is True, no immediate action is taken on thepynbody.halo.Halo
itself; rather the request is passed upwards to thepynbody.halo.HaloCatalogue
.The catalogue object then calls
physical_units
on the parent snapshot and on all cached halos, settingconvert_parent=False
so that the units change is then applied to thepynbody.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()