### How to get TNG primary halo mass from local request

Mei-Ting Lin
• 2
• 27 Mar

I currently use TNF100-1 simulation data, and want to sort a dataset from all subhaloes with all keys in z=0.

And I am not sure how to access primary halo mass of subhalo

Here is my code

``````import pandas as pd
import numpy as np
import illustris_python as il
basePath = '/Users/glin/TNG100-1/output/'

halos = il.groupcat.loadHalos(basePath, 99, fields=['GroupFirstSub', 'Group_M_Crit200'])
primary_halo_mass = np.zeros(subhalos['count'])

for i in range(subhalos['count']):
# Find Subhalo's group
group_id = subhalos['SubhaloGrNr'][i]
# find the group's primary subhalo
primary_subhalo_id = halos['GroupFirstSub'][group_id]
# primary halo mass
if primary_subhalo_id >= 0:
primary_halo_mass[i] = halos['Group_M_Crit200'][group_id] * 1e10 / 0.704
else
primary_halo_mass[i] = 0

subhalo_data['PrimaryHaloMass'] = primary_halo_mass
``````

Did I sort the right primary_halo_mass to subhalos?
Thanks

Dylan Nelson
• 27 Mar

You want to calculate: for each subhalo (including satellites), the M200c mass of its parent halo?

Then this should just be:

``````primary_halo_mass = np.zeros(subhalos['count'], dtype='float32')

for i in range(subhalos['count']):
# Find Subhalo's group
group_id = subhalos['SubhaloGrNr'][i]
# primary halo mass
primary_halo_mass[i] = halos['Group_M_Crit200'][group_id] * 1e10 / 0.704
``````

but it can also be done simply without loops:

``````primary_halo_mass = halos['Group_M_Crit200'][subhalos['SubhaloGrNr']]
``````
• Page 1 of 1