Indexing back to subhalo catalog after removing halos with certain values

Alexandres Lazar
  • 16 Jan '17

Hi Dylan,

Like the title says, im trying to index back into the GroupFirstSub field after removing the indexes of subhalos that are not necessary in my analysis

import illustris_python as il
import numpy as np
import illustris_catalog as catalog
import analysis_kinematics as kinematics
import h5py

# Illustris-1 Public Data
basePath1 = '/users/alexandres/Illustris/Illustris_1/'


halofields = ['GroupVel','Group_M_Crit200','Group_M_Crit500','Group_R_Crit200','GroupNsubs',
          'GroupMass','Group_M_TopHat200', 'Group_R_TopHat200','GroupPos','GroupFirstSub']
halos = il.groupcat.loadHalos(basePath1,135,fields=halofields)


subfields = ['SubhaloMass','SubhaloSpin','SubhaloParent','SubhaloVelDisp','SubhaloVel',\
         'SubhaloVmax','SubhaloGrNr','SubhaloPos','SubhaloVmax', 'SubhaloParent']
sub = il.groupcat.loadSubhalos(basePath1,135,fields=subfields)







###############################
##### Exproting Variables #####
###############################

Mmin = 8e+11
Mmax = 2.4e+12
h0  = 0.704


mask = (
        ( halos['Group_M_TopHat200'] > Mmin*h0/1e+10 ) & ( halos['Group_M_TopHat200'] < Mmax*h0/1e+10  )
        ).nonzero()[0]



# The indexing of the these MW halos most massive subhalo
firstSub = halos['GroupFirstSub'][mask]
firstSub = firstSub.astype('int32')
secondSub = firstSub+1

This is the portion of my analysis that I find values that are unnecessary

sub_pos1 = ( sub['SubhaloPos'] )[firstSub, : ]
sub_pos2 = ( sub['SubhaloPos'] )[secondSub, : ]
sub_vel1 = ( sub['SubhaloVel'] )[firstSub, : ]
sub_vel2 = ( sub['SubhaloVel'] )[secondSub, : ]

h0 = 0.704
lbox = 106.5
Dist = sub_pos2/h0 - sub_pos1/h0
Vel = sub_vel2 - sub_vel1

RadVel = kinematics.radialVel(Dist, Vel)
RelDist = kinematics.boxRelDist(sub_pos2, sub_pos1, h0, lbox)

exposing the indices that has values <10 and >1000

print [(i,value) for i, value in enumerate(RelDist) if value<=10 ]
>>>  [(261, 7.8062749), (389, 8.9522991), (409, 8.4432831), (525, 0.29229844), 
    (592, 9.6027441), (695, 0.70973402), (739, 9.7886152), (831, 9.9757767), 
    (882, 8.1458836), (1211, 7.2971973)]

print [(i,value) for i, value in enumerate(RelDist) if value>=1000 ]
>>> [(2, 1295.8337), (6, 1083.9229), (23, 1191.9043)]

So I now just filters these out.

RelDist = filter(lambda x: 10 <= x <= 1000, RelDist)

Trying to now index back to the subhalo catalog

firstSub = halos['GroupFirstSub'][RelDist]

Now this is where the problem is, when i print out the list of my new subhalo catalog,

print firstSub

>>> [358655 362406 337748 ..., 281617 269755 308748]

But, when I do remove the indices manually (the correct values),

mask = (
        ( halos['Group_M_TopHat200'] > Mmin*h0/1e+10 ) & ( halos['Group_M_TopHat200'] < Mmax*h0/1e+10  )
            ).nonzero()[0]

remove_indices = [2, 6, 23, 261,389,409, 525, 592, 695, 739, 831, 882, 1211]
mask = [i for j, i in enumerate(mask) if j not in remove_indices]




firstSub = halos['GroupFirstSub'][mask]
firstSub = firstSub.astype('int32')

print firstSub
>>> [330938 332508 338209 ..., 460330 462088 463247]

Which are not at all the same.

Any advice on how to fix my first method?

Dylan Nelson
  • 16 Jan '17

Sorry I don't think I'll be able to follow the code, maybe you can describe it more abstractly?

Perhaps I interpret this: you have a list of subhalo indices list_A. Then you go to their parent halos indexed by list_B and select on some property of those halos, giving you list_C of halo indices which is a subset of list_B. Then you take GroupFirstSub[list_C] which gives you a list of subhalo indices list_D which is a subset of the original list_A. I'm not sure what then? You should be able to access the properties of those subhalos with list_D.

  • Page 1 of 1