def readsubhalo(self, subid, parttype=1): snapdir = self.snapdir snapnum = self.snapnum cat = self.cat centre = cat.SubhaloPos[subid] if self.useFOF: raise Exception, 'readsubhalo is incompatible with option useFOF' else: #use central subhalo only pos = snapshot.loadSubhalo(snapdir, snapnum, subid, parttype, ["Coordinates"]) if parttype != 1: mass = snapshot.loadSubhalo(snapdir, snapnum, subid, parttype, ["Masses"]) if type(pos) == dict: assert pos['count'] == 0 #print 'No particles of type {} in subhalo {}'.format(parttype,subid) return 0, None npart = len(pos) try: pos = utils.image(pos - centre, None, self.boxsize) except: print 'readsubhalo failed:', subid, pos.__class__, centre return -1, None #assert npart == len(pos),'Readhalo error! pos={}'.format(pos) if parttype == 1: return pos, None else: return pos, mass
def readhalo(self, groupid, parttype=1): assert parttype in self.parttypes, 'Specified parttype is not available in this run' snapdir = self.snapdir snapnum = self.snapnum cat = self.cat centre = cat.GroupPos[groupid] if self.useFOF: pos = snapshot.loadHalo(snapdir, snapnum, groupid, parttype, ["Coordinates"]) if parttype != 1: mass = snapshot.loadHalo(snapdir, snapnum, groupid, parttype, ["Masses"]) else: #DEFAULT: not NR and use central subhalo only subnum = cat.GroupFirstSub[groupid] pos = snapshot.loadSubhalo(snapdir, snapnum, subnum, parttype, ["Coordinates"]) if parttype != 1: mass = snapshot.loadSubhalo(snapdir, snapnum, subnum, parttype, ["Masses"]) npart = len(pos) try: pos = utils.image(pos - centre, None, self.boxsize) except: print 'readhalo failed:', groupid, pos.__class__, centre return -1, None assert npart == len(pos), 'Readhalo error! pos={}'.format(pos) if parttype == 1: return pos, None else: return pos, mass
def populate_bh_dict(self, snap): """ Use `snapshot.py` to find all the black hole particles in each subhalo that has a black hole in it. You need the snapshot particle chunks and group catalog header information. This tells you the black holes in each subhalo which is important for pairing a black hole to its host galaxy. These values are populated in the bh_dict. """ import snapshot # figure out which subs are in this specific snapshot subs_to_look_in = self.subs[self.snaps == snap] for sub in subs_to_look_in: # load bh particle info from the snapshot folder using `snapshot.py` check_bhs_in_sub = snapshot.loadSubhalo(self.dir_output + '%i/' % snap, snap, sub, 5, fields=None) # need length to fill values for subhalo and snapshot length = len(check_bhs_in_sub['ParticleIDs'][:]) self.bhs_dict['Subhalo']['values'].append( np.full((length, ), sub, dtype=int)) self.bhs_dict['Snapshot']['values'].append( np.full((length, ), snap, dtype=int)) for name in self.bhs_dict: if name == 'Subhalo' or name == 'Snapshot': continue self.bhs_dict[name]['values'].append(check_bhs_in_sub[name]) return
def compute_anisotropy_radii(subfind, snapnum): # First of all loading in stellar positions and velocities (relative to whole object). stellar_pos, stellar_vel = process_subhalo.load_particles_transform_relative(subfind, snapnum, 'star', com=False, basePath=basepath, blen=75000) # loading in masses for all of the particles. masses = ss.loadSubhalo(basepath, 99, id=subfind, partType='star', fields = ['Masses']) # also loading in DM particles. DM_pos, DM_vel = process_subhalo.load_particles_transform_relative(subfind, snapnum, 'DM', com=False, basePath=basepath, blen=75000) # Computing circular r50 stellar. Defining radii as multiples of this. percentiles = np.array([50]) half_radius = fractional_radii.mass_enclosed_radii(stellar_pos, percentiles, weights=masses) num_effective_radii = np.array([0.5, 1, 2, 3, 4, 5]) radii = num_effective_radii * half_radius # Finding radial distances for all stellar particles and then binning. stellar_rad = np.linalg.norm(stellar_pos, axis=1) stellar_inds = np.digitize(stellar_rad, radii) # Finding radial distances for all DM particles and then binning. DM_rad = np.linalg.norm(DM_pos, axis=1) DM_inds = np.digitize(DM_rad, radii) # For each of the radial bins, computing velocity anisotropy. # output arrays. stellar_beta_vel = np.array([]) stellar_beta_vel_err = np.array([]) stellar_beta_sigma = np.array([]) DM_beta_vel = np.array([]) DM_beta_vel_err = np.array([]) DM_beta_sigma = np.array([]) for i in np.arange(radii.size): try: out = velocity_anisotropy.compute_anisotropy(stellar_pos[stellar_inds == i], stellar_vel[stellar_inds == i]) stellar_beta_vel = np.append(stellar_beta_vel, out[0]) stellar_beta_vel_err = np.append(stellar_beta_vel_err, out[1]) stellar_beta_sigma = np.append(stellar_beta_sigma, out[2]) except: stellar_beta_vel = np.append(stellar_beta_vel, np.nan) stellar_beta_vel_err = np.append(stellar_beta_vel_err, np.nan) stellar_beta_sigma = np.append(stellar_beta_sigma, np.nan) try: out = velocity_anisotropy.compute_anisotropy(DM_pos[DM_inds == i], DM_vel[DM_inds == i]) DM_beta_vel = np.append(DM_beta_vel, out[0]) DM_beta_vel_err = np.append(DM_beta_vel_err, out[1]) DM_beta_sigma = np.append(DM_beta_sigma, out[2]) except: DM_beta_vel = np.append(DM_beta_vel, np.nan) DM_beta_vel_err = np.append(DM_beta_vel_err, np.nan) DM_beta_sigma = np.append(DM_beta_sigma, np.nan) return (subfind, snapnum, num_effective_radii, radii, stellar_beta_vel, stellar_beta_vel_err, stellar_beta_sigma, DM_beta_vel, DM_beta_vel_err, DM_beta_sigma)
def loadandwriteDM(self,groupid,savedir): print "GROUP",groupid,savedir self.savedir=savedir cat=self.cat grouppos=cat.GroupPos[groupid] groupvel=cat.SubhaloVel[cat.GroupFirstSub[groupid]] if self.savepartids==True: self.fields[1]=self.fields[1]+["ParticleIDs"] part=snapshot.loadSubhalo(self.catdir,self.snapnum,cat.GroupFirstSub[groupid],1,self.fields[1]) part["Coordinates"]=(common.image(grouppos,part["Coordinates"],75000)-grouppos)/h*kpc part["Velocities"]=part["Velocities"]-groupvel part["Masses"]=np.ones(part["count"])*self.dmpartmass/h #elif self.whichdm=='1820FP': # part["Masses"]=np.ones(part["count"])*0.00044089652436109581/h #elif self.whichdm=='18 #else: # raise ValueError('Cant find DM or FP!') part["rvir"]=self.cat.Group_R_Crit200[groupid]/h*kpc part["groupid"]=groupid #Get rotation matrices if self.GetRotMat==True: self.getrotmat(part) #Rotate particles if needed: if self.RotateParticles: with tables.open_file(savedir+'shape.hdf5','r') as f: rotmat=f.root.rotmat[self.RotateParticles] part["Coordinates"]=(np.dot(part["Coordinates"],rotmat))#.reshape(nn,N,3) part["Velocities"]=(np.dot(part["Velocities"],rotmat))#.reshape(nn,N,3) #Get test particles if self.GetInit: self.getinit(part,100,'init.hdf5') #Get Knlm if self.GetCoef: self.getK(part,'var.hdf5')
galaxy_list = galaxy_list.astype(int) for GalaxyID in galaxy_list: f = h5py.File(snapshot.snapPath(snapshotPath,ssNum),'r') header = dict( f['Header'].attrs.items() ) redshift = header['Redshift'] a = 1.0/(1.0+redshift) # scale factor # get peculiar velocity of group SubPos = groupcat.loadSubhalos(snapshotPath,snapNum, fields = ['SubhaloPos'])[GalaxyID] # ckpc/h CM_x,CM_y,CM_z = SubPos[0],SubPos[1],SubPos[2] print CM_x subhalo_st = snapshot.loadSubhalo(snapshotPath,snapNum,GalaxyID,'stars') coord = subhalo_st['Coordinates'] st_x,st_y,st_z = coord[:,0],coord[:,1],coord[:,2] SFT = subhalo_st['GFM_StellarFormationTime'] # in scale factor #SFT = np.sort(SFT) #print SFT[:100] ## change ref point to subhalo CM st_x,st_y,st_z = st_x-CM_x,st_y-CM_y,st_z-CM_z # ckpc/h st_x,st_y,st_z = st_x*a,st_y*a,st_z*a # kpc/h #mask = SFT>0.60 mask = SFT>np.max(SFT)*0.7 print np.max(SFT)*0.7
boxsize = header['BoxSize'] # ckpc/h redshift = header['Redshift'] a = 1.0/(1.0+redshift) # scale factor # get peculiar velocity of group SubVel = groupcat.loadSubhalos(snapshotPath,snapNum, fields = ['SubhaloVel']) # km/s ## ----------- gas particles subfindID = 347491 idx = list(GalaxyID).index(subfindID) sub_gas = snapshot.loadSubhalo(snapshotPath,snapNum,subfindID,'gas') coord = sub_gas['Coordinates'] gas_x,gas_y,gas_z = coord[:,0],coord[:,1],coord[:,2] if (max(gas_x)-min(gas_x)> 0.5*boxsize): gas_x = boundary(gas_x) if (max(gas_y)-min(gas_y)> 0.5*boxsize): gas_y = boundary(gas_y) if (max(gas_z)-min(gas_z)> 0.5*boxsize): gas_z = boundary(gas_z) ## change ref point to subhalo CM gas_x,gas_y,gas_z = gas_x-CM_x[idx],gas_y-CM_y[idx],gas_z-CM_z[idx] # ckpc/h gas_x,gas_y,gas_z = gas_x*a,gas_y*a,gas_z*a # kpc/h
def loadandwriteFP(self,groupid,savedir): if self.whichdm.find('DM')>0: raise ValueError('Cant use loadandwriteFP for DMO!') print "GROUP",groupid,savedir self.savedir=savedir cat=self.cat grouppos=cat.GroupPos[groupid] groupvel=cat.SubhaloVel[cat.GroupFirstSub[groupid]] subid=cat.GroupFirstSub[groupid] part1=snapshot.loadSubhalo(self.catdir,self.snapnum,subid,1,self.fields[1]) part1["Coordinates"]=(common.image(grouppos,part1["Coordinates"],75000)-grouppos)/h*kpc part1["Velocities"]=part1["Velocities"]-groupvel part1["Masses"]=np.ones(part1["count"])*self.dmpartmass/h part4=snapshot.loadSubhalo(self.catdir,self.snapnum,subid,4,self.fields[4]) part4["Coordinates"]=(common.image(grouppos,part4["Coordinates"],75000)-grouppos)/h*kpc part4["Velocities"]=part4["Velocities"]-groupvel part4["Masses"]=part4["Masses"]/h part0=snapshot.loadSubhalo(self.catdir,self.snapnum,subid,0,self.fields[0]) part0["Coordinates"]=(common.image(grouppos,part0["Coordinates"],75000)-grouppos)/h*kpc part0["Masses"]=part0["Masses"]/h gastemp=conversions.GetTemp(part0["InternalEnergy"],part0["ElectronAbundance"],5./3.) selh=gastemp>=1e5 selc=gastemp<=1e5 part={} part["Coordinates"]=np.vstack((part1["Coordinates"],part4["Coordinates"],part0["Coordinates"])) part["Masses"]=np.hstack((part1["Masses"],part4["Masses"],part0["Masses"])) part["rvir"]=self.cat.Group_R_Crit200[groupid]/h*kpc part["groupid"]=groupid #Get rotation matrices if self.GetRotMat==True: self.getrotmat(part) #Rotate particles if needed: if self.RotateParticles==True: with tables.open_file(self.savedir+'shape.hdf5','r') as f: rotmat=f.root.rotmat[:] part1["Coordinates"]=(np.dot(part1["Coordinates"],rotmat))#.reshape(nn,N,3) part1["Velocities"]=(np.dot(part1["Velocities"],rotmat))#.reshape(nn,N,3) part4["Coordinates"]=(np.dot(part4["Coordinates"],rotmat))#.reshape(nn,N,3) part4["Velocities"]=(np.dot(part4["Velocities"],rotmat))#.reshape(nn,N,3) part0["Coordinates"]=(np.dot(part0["Coordinates"],rotmat))#.reshape(nn,N,3) #Save test particles: if self.GetInit: part1["rvir"]=self.cat.Group_R_Crit200[groupid]/h*kpc self.getinit(part1,100,'init.hdf5') if self.GetInitStar: part4["rvir"]=self.cat.Group_R_Crit200[groupid]/h*kpc self.getinit(part4,100,'initstar.hdf5',range=[0.05,0.5]) #Save Knlm: if self.GetCoef: part["Coordinates"]=np.vstack((part1["Coordinates"],partgas["Coordinates"][selh])) part["Masses"]=np.hstack((part1["Masses"],partgas["Masses"][selh])) self.getK(part,'varh.hdf5') part["Coordinates"]=np.vstack((part4["Coordinates"],partgas["Coordinates"][selc])) part["Masses"]=np.hstack((part4["Masses"],partgas["Masses"][selc])) self.getK(part,'varc.hdf5')
def compute_fraction_2re( subfind_id, snapnum, radius, centre, basePath='/simons/scratch/sgenel/IllustrisTNG/L75n1820TNG/output'): ''' Function that returns integrated black hole properties for a given subhalo at a certain snapshot. Parameters ---------- subfind_id : float/int Subfind_ID associated with subhalo at the supplied snapshot snapnum : float/int Snapshot number for object of interest basePath : str Base directory for output of TNG simulation. Tcrit : float Cutoff to determine cold vs hot gas. Returns (naming convention follows individual BH particles in TNG) ------- cold_gas_frac : float Fraction of gas mass in subhalo that is below temperature threshold. ''' # loading in all gas cells for this subhalo. props = ss.loadSubhalo(basePath=basePath, snapNum=snapnum, id=subfind_id, partType='gas', fields=[ 'Coordinates', 'ElectronAbundance', 'StarFormationRate', 'InternalEnergy', 'Masses' ]) # if no gas cells, then returning -inf for values. if props['count'] == 0: return -np.inf # making radial selection. pos = radial_pos(centre, props['Coordinates'], 75000) radii = np.linalg.norm(pos, axis=1) radial_mask = (radii <= radius) # total mass within radius. gas_mass_total_inRad = np.sum(props['Masses'][radial_mask]) # compute gas temperature for all cells Xh = 0.76 # hydrogen mass fraction mp_cgs = 1.6726231 * 10**-24 # proton mass in cgs. gamma = 5.0 / 3.0 # adiabatic index kb_cgs = 1.38064852 * 10**-16 # boltzmann constant in cgs. mean_molecular_weight = 4 / (1 + 3 * Xh + 4 * Xh * props['ElectronAbundance']) * mp_cgs temp = ( gamma - 1) * props['InternalEnergy'] / kb_cgs * 10**10 * mean_molecular_weight # selecting star forming gas or that which meets lower temperature criteria. cold_phase_mask = (props['StarFormationRate'] > 0) | (temp < 10**4.5) # total cold phase within radius gas_mass_cold_inRad = np.sum(props['Masses'][(radial_mask) & (cold_phase_mask)]) return gas_mass_cold_inRad
SubVel = groupcat.loadSubhalos(snapshotPath,snapNum, fields = ['SubhaloVel']) # km/s R_half=groupcat.loadSubhalos(snapshotPath,snapNum, fields = ['SubhaloHalfmassRadType'])[:,4] # stellar half mass radius [ckpc/h] R_half=R_half*a/cosmopara.h # young star age cut disk_age=0.5 # Gyr Axis = np.zeros((len(subID),3))*np.nan # principle rotational axis of each galaxy theta_i = np.zeros((len(subID),3))*np.nan # inclination angle of three main axis subID=np.array([347491]) for i in range(len(subID)): subhalo_st=snapshot.loadSubhalo(snapshotPath,snapNum,subID[i],'stars') center=pos[subID[i],:] coord = subhalo_st['Coordinates']*a/cosmopara.h # kpc st_x,st_y,st_z = coord[:,0],coord[:,1],coord[:,2] if (max(st_x)-min(st_x)> 0.5*boxsize): st_x = boundary(st_x) if (max(st_y)-min(st_y)> 0.5*boxsize): st_y = boundary(st_y) if (max(st_z)-min(st_z)> 0.5*boxsize): st_z = boundary(st_z) ## change ref point to subhalo center st_x,st_y,st_z = st_x-center[0],st_y-center[1],st_z-center[2]
halo_gas = snapshot.loadHalo(basePath,snapNum,mainID,'gas') coord = halo_gas['Coordinates']/1000./cosmopara.h # cMpc,glamer #coord = halo_gas['Coordinates']*a/1000./cosmopara.h # Mpc #coord = subhalo_gas['Coordinates'] gas_x,gas_y,gas_z = coord[:,0],coord[:,1],coord[:,2] if (max(gas_x)-min(gas_x)> 0.5*boxsize): gas_x[gas_x<0.5*boxsize] = gas_x[gas_x<0.5*boxsize] +boxsize if (max(gas_y)-min(gas_y)> 0.5*boxsize): gas_y[gas_y<0.5*boxsize] = gas_y[gas_y<0.5*boxsize]+boxsize if (max(gas_z)-min(gas_z)> 0.5*boxsize): gas_z[gas_z<0.5*boxsize] = gas_z[gas_z<0.5*boxsize]+boxsize print 'halo gas coord loaded' ''' halo_st = snapshot.loadSubhalo(basePath,snapNum,subID,'stars') coord = halo_st['Coordinates']/1000./cosmopara.h # cMpc,glamer #coord = halo_st['Coordinates']*a/1000./cosmopara.h # Mpc #coord = subhalo_st['Coordinates'] st_x,st_y,st_z = coord[:,0],coord[:,1],coord[:,2] ''' if (max(st_x)-min(st_x)> 0.5*boxsize): st_x[st_x<0.5*boxsize] = st_x[st_x<0.5*boxsize]+boxsize if (max(st_y)-min(st_y)> 0.5*boxsize): st_y[st_y<0.5*boxsize] = st_y[st_y<0.5*boxsize]+boxsize if (max(st_z)-min(st_z)> 0.5*boxsize): st_z[st_z<0.5*boxsize] = st_z[st_z<0.5*boxsize]+boxsize ''' print 'halo stars coord loaded' st_ms = halo_st['Masses']*1e10/cosmopara.h out_file3 = open('../../data/illustris_1/snapshot_'+str(snapNum)+'_particle/particle_'+str(subID)+'_st.dat','w')
for i in ri: kappa.append(anulus_kappa(subhalo_class,i)) plt.plot(ri,kappa) plt.show() ############################ re_cat = open('../../data/illustris_1/GalaxyRe_'+str(snapNum)+'_x.dat','a') #re_cat.write('# GalaxyID R_e \n') for i in range(GalaxyID.size): i = i+196 print GalaxyID[i],i subhalo_dm = snapshot.loadSubhalo(basePath,snapNum,GalaxyID[i],'dm') coord = subhalo_dm['Coordinates'] # ckpc/h dm_x,dm_y,dm_z = coord[:,0],coord[:,1],coord[:,2] if (max(dm_x)-min(dm_x)> 0.5*boxsize): print dm_x.size dm_x = boundary(dm_x) print 'cut x' print max(dm_x),min(dm_x) print dm_x.size if (max(dm_y)-min(dm_y)> 0.5*boxsize): print dm_y.size dm_y = boundary(dm_y) print 'cut y' print max(dm_y),min(dm_y) print dm_y.size
f.create_carray("/", "GroupHalfmassRadType", tables.Float32Col(), (ngroups, 6)) masses = f.create_carray("/", "GroupMassType", tables.Float32Col(), (ngroups, 4, 6)) f.root.Group_M_Crit200[:] = cat.Group_M_Crit200 f.root.GroupMassInRadType[:] = cat.SubhaloMassInRadType[first] f.root.GroupMassInHalfRadType[:] = cat.SubhaloMassInHalfRadType[first] f.root.GroupHalfmassRadType[:] = cat.SubhaloHalfmassRadType[first] f.flush() for grp in groups: for parttype in [0, 4]: subid = cat.GroupFirstSub[grp] pos = snapshot.loadSubhalo(fdir, snap, subid, parttype, ["Coordinates"]) #kpc/h mass = snapshot.loadSubhalo(fdir, snap, subid, parttype, ["Masses"]) #1e10 msun/h if type(pos) is dict: assert pos['count'] == 0 else: pos = utils.image(pos - cat.SubhaloPos[subid], None, header.boxsize) #kpc #pos = ((pos - cat.SubhaloPos[subid])-box/2.)%box - box/2. dist = np.linalg.norm(pos, axis=1) / hubble masses[grp, 0, parttype] = mass[dist < 5].sum() masses[grp, 1, parttype] = mass[dist < 10].sum() masses[grp, 2, parttype] = mass[dist < 30].sum()
massg=cat.Group_M_Crit200/0.704*1e10 N=len(massg) gallist=np.nonzero((massg>10**massrange[0]) & (massg < 10**massrange[1]))[0] edges=10**np.linspace(np.log10(1e-2),np.log10(1),nbins+1) y=(edges[1:]+edges[:-1])/2 with tables.open_file('1820'+which+'VelDisp.hdf5','w') as f: s2=f.create_carray('/','Veldisp2',tables.Float32Col(),(N,nbins)) rs2=f.create_carray('/','RadialVeldisp2',tables.Float32Col(),(N,nbins)) ts2=f.create_carray('/','TanVeldisp2',tables.Float32Col(),(N,nbins)) B=f.create_carray('/','VelAniso',tables.Float32Col(),(N,nbins)) r=f.create_carray('/','Radius',tables.Float32Col(),(nbins,)) for gal in gallist: part=snapshot.loadSubhalo(dir,snapnum,cat.GroupFirstSub[gal],1,["Coordinates","Velocities"]) pos=part["Coordinates"]-cat.GroupPos[gal] vel=part["Velocities"]-cat.GroupVel[gal] dist=np.sqrt((pos**2).sum(axis=1))/cat.Group_R_Crit200[gal] for i in np.arange(nbins): v=vel[(dist<=edges[i+1]) & (dist > edges[i])] binpos = pos[(dist<=edges[i+1]) & (dist > edges[i])] vr=binpos*((v*binpos).sum(axis=1)/(binpos**2).sum(axis=1))[:,np.newaxis] #s2[gal,i]=np.mean((v**2).sum(axis=1))-((np.mean(v,axis=0))**2).sum() s2[gal,i]=np.mean((v**2).sum(axis=1)) rs2[gal,i]=np.mean(( vr**2 ).sum(axis=1)) ts2[gal,i]=np.mean(( (v-vr)**2 ).sum(axis=1)) B[gal]=1-ts2[gal]/(2*rs2[gal])
def compute_params( subfind_id, snapnum, basePath='/simons/scratch/sgenel/IllustrisTNG/L75n1820TNG/output'): ''' Function that returns integrated black hole properties for a given subhalo at a certain snapshot. Parameters ---------- subfind_id : float/int Subfind_ID associated with subhalo at the supplied snapshot snapnum : float/int Snapshot number for object of interest basePath : str Base directory for output of TNG simulation. Returns (naming convention follows individual BH particles in TNG) ------- BH_CumEgyInjection_QM : float (units: Msol / h (ckpc/h)^2 / (0.978Gyr/h)^2 ) Cumulative amount of thermal AGN feedback energy injected into surrounding gas in the high-accretion-state (quasar) mode, total over the entire lifetime of all blackhole particles in this subhalo. BH_CumEgyInjection_RM : float (units: Msol / h (ckpc/h)^2 / (0.978Gyr/h)^2 ) Cumulative amount of kinetic AGN feedback energy injected into surrounding gas in the low-accretion-state (wind) mode, total over the entire lifetime of all blackhole particles in this subhalo. BH_CumMassGrowth_QM : float (units: Msol / h) Total mass accreted onto the BH while in the high-accretion-state (quasar) mode, total over the entire lifetime of all blackhole particles in this subhalo. BH_CumMassGrowth_RM : float (units: Msol / h) Total mass accreted onto the BH while in the low-accretion-state (kinetic wind) mode, total over the entire lifetime of all blackhole particles in this subhalo. BH_Density : float (units: Msol/h / (ckpc/h)^3) Local comoving gas density averaged over the nearest neighbors of the BH. Returns the mean value for all BH particles. count : float/int Number of black hole particles in the subhalo total_progenitors : float/int Total number of black hole progenitor particles (BH_Progs summed over all BH particles.) ''' # loading in all black hole particles in this subhalo. props = ss.loadSubhalo(basePath=basePath, snapNum=snapnum, id=subfind_id, partType='BH', fields=[ 'BH_CumEgyInjection_QM', 'BH_CumEgyInjection_RM', 'BH_CumMassGrowth_QM', 'BH_CumMassGrowth_RM', 'BH_Density', 'BH_Progs' ]) if props['count'] == 0: # If no black hole in the subhalo returning -inf for all values. return -np.inf, -np.inf, -np.inf, -np.inf, -np.inf, 0, 0 elif props['count'] == 1: return 1e10 * props['BH_CumEgyInjection_QM'][0], 1e10 * props[ 'BH_CumEgyInjection_RM'][0], 1e10 * props['BH_CumMassGrowth_QM'][ 0], 1e10 * props['BH_CumMassGrowth_RM'][0], 1e10 * props[ 'BH_Density'][0], props['count'], props['BH_Progs'][0] else: # finding summations and averages. return 1e10 * np.sum(props['BH_CumEgyInjection_QM']), 1e10 * np.sum( props['BH_CumEgyInjection_RM']), 1e10 * np.sum( props['BH_CumMassGrowth_QM']), 1e10 * np.sum( props['BH_CumMassGrowth_RM']), np.mean( 1e10 * props['BH_Density']), props['count'], np.sum( props['BH_Progs'])
Axis = np.zeros((GalaxyID.size,3))*np.nan # principle ratational axis of each galaxy theta_i = np.zeros((GalaxyID.size,3))*np.nan # inclination angle of three main axis in_cat.write('# Galaxy ID theta_x theta_y theta_z \n') for i in range(GalaxyID.size): print GalaxyID[i] subID = GalaxyID[i] GalaxyVel = SubVel[subID] # only use star particles subhalo_st = snapshot.loadSubhalo(basePath,snapNum,GalaxyID[i],'stars') coord = subhalo_st['Coordinates'] st_x,st_y,st_z = coord[:,0],coord[:,1],coord[:,2] if (max(st_x)-min(st_x)> 0.5*boxsize): st_x = boundary(st_x) if (max(st_y)-min(st_y)> 0.5*boxsize): st_y = boundary(st_y) if (max(st_z)-min(st_z)> 0.5*boxsize): st_z = boundary(st_z) ## change ref point to subhalo CM st_x,st_y,st_z = st_x-CM_x[i],st_y-CM_y[i],st_z-CM_z[i] # ckpc/h st_x,st_y,st_z = st_x*a,st_y*a,st_z*a # kpc/h vel = subhalo_st['Velocities']