How to get all the subhaloIDs of the same halo?

Guan-Fu Liu
  • 16 Mar

I wonder how to find all the subhalos's subhaloID residing in the same halo.
I have a subhalo with ID 1234 (a random number, just an example) at 99th snapshot, I know that I can get the haloID of the subhalo 1234 by the following code:

import illustris_python as il
basePath = "/home/tnguser/sims.TNG/TNG50-1/output/"
# snapNum and subhaloID should be given by the user
snapNum = 99
subhaloID = 1234

haloID = -1
subhalo = il.groupcat.loadSingle(basePath, snapNum, haloID, subhaloID)
# Deduce haloID from subhaloID and snapNum
haloID = subhalo['SubhaloGrNr']

Loading the halo:

halo = il.groupcat.loadSingle(basePath, snapNum, haloID)

I can find the subhaloID of the first subhalo by halo[GroupFirstSub]. However, it is just subhaloID of the first subhalo.
One of friend told me that you can load the next halo:

halo_next = il.groupcat.loadSingle(basePath, snapNum, haloID+1)

All the subhaloIDs of the same halo within the range that >=[halo[GroupFirstSub] but <halo_next[GroupFirstSub].
I have tested that

for i in range(halo['GroupFirstSub'], halo_next['GroupFirstSub']):
    subhalo = il.groupcat.loadSingle(basePath, snapNum, -1, i)
    if subhalo['SubhaloGrNr'] != haloID:
        print(i, subhalo['SubhaloGrNr'])

which has no output, i.e., all the subhalos with ID lie in the range that >=[halo[GroupFirstSub] but <halo_next[GroupFirstSub] belong to the halo.
Did I find all of the subhalos?
Or equivalently, Do all the subhaloIDs of the same halo within the range that >=[halo[GroupFirstSub] but <halo_next[GroupFirstSub]?

Dylan Nelson
  • 17 Mar

Instead of looking at the next halo, I would just look at GroupNsubs, for example in this thread.

Guan-Fu Liu
  • 18 Mar

Thanks a lot! I also found that I could use

for i in range(halo['GroupFirstSub'], halo['GroupFirstSub']+halo['GroupNsubs']):
    subhalo = il.groupcat.loadSingle(basePath, snapNum, -1, i)

Actually, halo_next[GroupFirstSub]=halo['GroupFirstSub']+halo['GroupNsubs'].

  • Page 1 of 1