コード例 #1
0
 def populatemap(self,n=None):
     t0=self.cat.snap[0][2]
     self.lbt=t0-[self.cat.snap[snap][2] for snap in self.snapshotindex]
     indices_tree(self.cat,self.snapshotindex[0],self.snapshotindex[-1])
     for snapshotnum in self.snapshotindex[1:]: #fill the halis dictionary at all snapshots after snapshot 0 with the index numbers of the parents of the snapshot 0 halos
         self.halis[snapshotnum]=indices_tree(self.cat,0,snapshotnum,self.halis[0])
     massmap=np.zeros([len(self.halis[0]),len(self.snapshotindex)])
     pbar=ProgressBar()
     for snapshotnum in pbar(self.snapshotindex):    
         for massmaprow, halindexnum in enumerate(self.halis[snapshotnum]): #massmap rows are halos. massmap columns are snapshots (each at a specific redshift). This loop populates the massmap by putting each halo's mass at the given redshift in the corresponding row and column.
             if halindexnum<0: #If the parent ID is negative, the halo doesn't exist yet, so keep its mass at 0.
                 continue
             else:
                 massmap[massmaprow,snapshotnum]=self.cat[snapshotnum][self.mkind][halindexnum]
     #avgratio=np.average(massmap[:,snap]/massmap[:,0] for snap in self.snapshotindex)
     self.avgratios=[np.average(10.**massmap[:,snap]/10.**massmap[:,0]) for snap in self.snapshotindex]
     self.massmap=massmap
コード例 #2
0
def mM0s_add_f_new(hosti0):
    mtype = 'm.fof'
    mM0s = []
    M0 = hostcat[0][mtype][hosti0]
    for zi in allzis[:-1]:
        i_primary = indices_tree(hostcat, 0, zi, hosti0)
        if i_primary < 1:
            return mM0s
        is_prog = hostcat[zi + 1]['chi.i'] == i_primary
        is_prog[hostcat[zi]['par.i'][
            i_primary]] = False  #is_prog is a bool array. This line sets the elements corresponding to the main progentior to false, so we're not incorrectly counting a merger of the main progenitor with itself.
        ms = hostcat[zi + 1][mtype][is_prog]
        mM0s_add = ms - M0
        mM0s += list(mM0s_add)
    return mM0s
コード例 #3
0
def mM0s_add_f(hosti0, excl=False):
    mM0s = []
    M0 = hostcat[0]['m.fof'][hosti0]
    subis_prev = []
    for zi in allzis:
        #print'\n\nsnapshot %i'%zi
        hosti = indices_tree(hostcat, 0, zi, hosti0)
        #print'\nhost idx: %i'%hosti
        if hosti < 1:
            return mM0s

        #The following commented block of code uses the getinfall method to count when subhalos entered host halos. It may come in handy later, so I'm not deleting it.
        '''
        subis=getsubs(hosti,zi)
        isnew=np.array([not subi in subis_prev for subi in subis],
                       dtype=bool)
        subis_inf,zis_inf=getinfall(subis,zi)
        infhaps=subis_inf>0 #If the subhalo is part of the host for the whole simulation, the indices will be -1.
        #subis_inf,zis_inf=subis_inf[infhaps],zis_inf[infhaps]
        subis_b4inf,zis_b4inf=subis_inf[infhaps],zis_inf[infhaps]
        zis_inf=zis_b4inf-1
        subis_inf=[indices_tree(subcat,zi_b4inf,zi_inf,subi_b4inf) 
                   for zi_b4inf,zi_inf,subi_b4inf 
                   in zip(zis_b4inf,zis_inf,subis_b4inf)]
        ms=[subcat[zi_inf][msubtype][subi_inf] 
            for zi_inf,subi_inf 
            in zip(zis_inf,subis_inf)] 
        mM0s_add=ms-M0
        mM0s+=list(mM0s_add)
        subis_prev=subis
        '''

        if not excl:
            nhosti = hostcat[zi]['par.n.i'][hosti]
            while nhosti > 0:
                #print'next host idx: %i'%nhosti
                m = hostcat[zi]['m.fof'][nhosti]
                mM0_add = m - M0
                #print mM0s[-1]
                mM0s += list(mM0_add.flatten())
                #print mM0s[-2:]
                nhosti = hostcat[zi]['par.n.i'][nhosti]
    return mM0s
コード例 #4
0
    def tracker_with_opt(self,zis=np.arange(35),kind='merger'):
        mfrackey='m.frac.min'
        thresh=0.1
        his=np.arange(len(self.cat[self.snapshotindex[-1]]['halo.i']))
        
        '''
        #FOR TESTING####
        n=int(1e5)
        his=np.array(random.sample(his,n)) #Take a radom sample for testing
        #FOR TESTING####
        '''
        
        print'starting with %i halos' %len(his)
        m_M0s=[]
        M0s=[]
        
        #This next line might be redundant, because it may have been originally intended to feed the line after itself, and that line after is now commented.
        iscen=self.cat[self.snapshotindex[-1]]['ilk'][his]==1 #specifying his here in the first step is usually redundant, but I'm including it to cover special case where we start with less than the full catalog of his
        #mfracsprev=np.repeat(1.,sum(~iscen))
        
        #mfracsprev=np.repeat(1.,len(his))
        mfracsprev=np.zeros(len(his))
        
        pbar=ProgressBar()
        #for zi in pbar(self.snapshotindex[::-1]): 
        for zi in zis[::-1]: 
            print'\nsnapshot %i' %zi
            iscen=self.cat[zi]['ilk'][his]==1
            #print'%i non-centrals'%sum(~iscen)
            #his_nc=his[~iscen] #Do I really want to be removing centrals here? I think so, but verify this.
            mfracs=self.cat[zi][mfrackey][his]
            
            smaller=mfracs<mfracsprev
            destd=mfracs<=thresh #qualifies as destroyed
            isev=smaller & ~iscen #qualifies as an event
            if kind=='merger':
                isev=smaller & destd & ~iscen #qualifies as an event
            else:
                isev=smaller & ~iscen
            his_ev=his[isev] 
            #print'%i newly destroyed non-central halos' %len(his_ev)
            mmaxs_ev=self.cat[zi]['m.max'][his_ev]
            mfracs_ev=mfracs[isev]
            ms_inst=(mmaxs_ev*mfracs_ev) #The program currently does not use this data
            
            chis=self.cat[zi]['halo.i'][his_ev] #central halo indices---Don't confuse with chiis (child halo indices)
            #fchis=np.array(indices_tree(self.cat,zi,0,chis)) #z=0 indices of central halos
            fchis=indices_tree(self.cat,zi,0,chis) #z=0 indices of central halos
            has_fchi=fchis>=0 #if indices_tree returns a negative for the final central halo index, there is no central at z=0.
            fchis=fchis[has_fchi]
            #print'%i final halos for %i newly destroyed halos' %(len(fchis),len(his_ev))
            #M0s=self.cat[0]['m.max'][fchis]
            M0s_add=self.cat[0]['m.max'][fchis]
            #inmbin=(M0s<self.mhal0+self.mwidth/2.)&(M0s>self.mhal0-self.mwidth/2)
            #ms=ms[has_fchi][inmbin] #Cut the ms array down to elements whose central exists at z=0. Then pull elements of that array (the shape of which matches fchis) whose centrals are in the mbin. 
            ms=mmaxs_ev[has_fchi].flatten() #Cut the mmaxs_ev array down to elements whose central exists at z=0. I'm not going to eliminate elements outside the mbin, because I want to only run this once, and it's probably a better idea to just record m_M0 along with what the M0 is and then narrow down the m_M0's later.
            #The reason I need to flatten the array: If mmaxs_ev has only one element, the mmaxs_ev[has_fchi] array returns a nested array, apparently because it evaluates both the single element and the dtype=float32 descriptor. I have no idea why it does this, but flattening the resulting masked array is a work around. 
            #M0s=M0s[inmbin] #M0s was made from fchis, so we don't need to cut anything before taking inmbin mask.
            m_M0s_add=ms-M0s_add
            m_M0s_add=np.minimum(m_M0s_add,-m_M0s_add)
            #print'new m_M0 ratios:'
            #print m_M0s_add
            '''
            print"from m.max's:"
            print ms
            print"from M0's:"
            print M0s_add
            '''
            M0s+=list(M0s_add)
            m_M0s+=list(m_M0s_add)

            #prep for next run:
            his=his[~isev] #Remove affected subhalos from next evaluation.
            mfracsprev=mfracs[~isev] #Remove mfracs for affected subhalos 
            #print 'removing %i destroyed halos. %i halos remaining'%(sum(destd),len(his))
            chiis=self.cat[zi]['chi.i'][his] #child indices
            his=chiis

        self.M0s=np.array(M0s)
        self.m_M0s=np.array(m_M0s)
        #print''
        #print m_M0s

	timestmp='{:%Y%m%d}'.format(datetime.datetime.now())
	#filename='./dat/true_m_M0_{0:0.0f}_{2}_{1}.h5'.format(mmid,timestmp,self.mkind)
	filename='./dat/true_m_M0_{1}_{0}.h5'.format(timestmp,self.mkind)
	f = h5py.File(filename, 'w')
	f.create_dataset('m_M0s', data=self.m_M0s)
        f.create_dataset('M0s',data=self.M0s)
        f.create_dataset('N_fc',data=len(self.halis[0]))
	f.close()