Пример #1
0
  def hodsubsample(self,marray,flist=[0.682689492137,0.954499736104],nsubsample=1000,
        whichbox=1,cenopt=2,satopt=2,bosswdir='/home/howdiedoo/boss/',whichPB=0,COMVopt=0):

    """
    Subsamples the chain and computes a bands containing flist fractions.
    nsubsample = 1000 by default.
    marray are mass points where you want to evaluate the hod.
    """
#def wgtresult2(wgt,v,flist=[0.682689492137,0.954499736104]):
    sNcen = np.zeros([len(marray),nsubsample])
    sNsat = np.zeros([len(marray),nsubsample])
    sNtot = np.zeros([len(marray),nsubsample])
    sMmed = np.zeros([3,nsubsample])
    sMavg = np.zeros([3,nsubsample])

    for nn in range(nsubsample):
      hh = hod.hodfromchain(self.randomsubsample(),whichbox=whichbox,cenopt=cenopt,satopt=satopt,\
                            bosswdir=bosswdir,whichPB=whichPB,COMVopt=COMVopt)
      sNcen[:,nn] = hh.Ncen(marray)
      sNsat[:,nn] = hh.Ncen(marray) * hh.Nsat(marray) 
      sNtot[:,nn] = sNcen[:,nn] + sNsat[:,nn] 
      ## compute interesting stats on halo masses.
      ctmp = (hh.mf.Nofm*hh.Ncen(hh.mf.m)).cumsum()
      sMmed[0,nn] = hh.mf.m[np.where(ctmp >= 0.5*ctmp[-1])[0].min()]
      sMavg[0,nn] = (hh.mf.m*hh.mf.Nofm*hh.Ncen(hh.mf.m)).sum()/ctmp[-1]
      ctmp = (hh.mf.Nofm*hh.Ncen(hh.mf.m)*(1.+hh.Nsat(hh.mf.m))).cumsum()
      sMmed[2,nn] = hh.mf.m[np.where(ctmp >= 0.5*ctmp[-1])[0].min()]
      sMavg[2,nn] = (hh.mf.m*hh.mf.Nofm*hh.Ncen(hh.mf.m)*(1.+hh.Nsat(hh.mf.m))).sum()/ctmp[-1]
      ctmp = (hh.mf.Nofm*hh.Ncen(hh.mf.m)*(hh.Nsat(hh.mf.m))).cumsum()
      sMmed[1,nn] = hh.mf.m[np.where(ctmp >= 0.5*ctmp[-1])[0].min()]
      sMavg[1,nn] = (hh.mf.m*hh.mf.Nofm*hh.Ncen(hh.mf.m)*(hh.Nsat(hh.mf.m))).sum()/ctmp[-1]


    rr = np.zeros([len(flist)*2+1, len(marray)])
    wgttmp = np.zeros(nsubsample)+1.
    bNcen = np.zeros([5,len(marray)])
    bNsat = np.zeros([5,len(marray)])
    bNtot = np.zeros([5,len(marray)])
 
    Mmed = np.zeros([5,3])
    Mavg = np.zeros([5,3])      
    for ii in range(3):    
      Mmed[:,ii] = wgtresult2raw(wgttmp,sMmed[ii,:])
      Mavg[:,ii] = wgtresult2raw(wgttmp,sMavg[ii,:])

    for mm in range(len(marray)):
#       print bNcen[:,mm].shape
#       print wgtresult2raw(wgttmp,sNcen[mm,:])
#       print wgtresult2raw(wgttmp,sNcen[mm,:]).shape
       bNcen[:,mm] = wgtresult2raw(wgttmp,sNcen[mm,:])
       bNsat[:,mm] = wgtresult2raw(wgttmp,sNsat[mm,:])
       bNtot[:,mm] = wgtresult2raw(wgttmp,sNtot[mm,:])
    self.bNcen = bNcen
    self.bNsat = bNsat
    self.bNtot = bNtot
    self.msub = marray
    self.Mmed = Mmed
    self.Mavg = Mavg
    self.nsubsample = nsubsample
Пример #2
0
    def fillsig2hod(self,
                    whichbox=1,
                    cenopt=2,
                    satopt=2,
                    bosswdir='/home/howdiedoo/boss/',
                    whichPB=0,
                    COMVopt=0,
                    cenvfrac=0.3,
                    ihvscale=1.0,
                    cenvfromchain=1,
                    ihvfromchain=1):
        """
    Default behavior is to take values for cenvfrac and ihv from the chain, but add cenvfrac from the parameter in quadruture.
    """
        sig2hod = np.zeros(self.nelts)
        mycenvfrac = cenvfrac
        myihv = ihvscale

        for cnt, elt in zip(range(self.nelts), self.chain):
            hh = hod.hodfromchain(elt,
                                  whichbox=whichbox,
                                  cenopt=cenopt,
                                  satopt=satopt,
                                  bosswdir=bosswdir,
                                  whichPB=whichPB,
                                  COMVopt=COMVopt)
            if cenvfromchain == 1:
                mycenvfrac = (elt['cenvfrac']**2 + cenvfrac**2)
                if mycenvfrac > 0.:
                    mycenvfrac = mycenvfrac**0.5
            if ihvfromchain == 1:
                myihv = elt['ihvscale']
            sig2hod[cnt] = hh.sig2hod(cenvfrac=mycenvfrac, ihvscale=myihv)
            #if cnt%100 == 0:
            #  print 'done',cnt,'of ',self.nelts
        self.sig2hod = sig2hod
        self.cenvfrac = cenvfrac
        self.ihvscale = ihvscale
        self.cenvfromchain = cenvfromchain
        self.ihvfromchain = ihvfromchain
Пример #3
0
  def fillsig2hod(self,whichbox=1,cenopt=2,satopt=2,bosswdir='/home/howdiedoo/boss/',whichPB=0,COMVopt=0,cenvfrac=0.3,ihvscale=1.0,cenvfromchain=1,ihvfromchain=1):
    """
    Default behavior is to take values for cenvfrac and ihv from the chain, but add cenvfrac from the parameter in quadruture.
    """
    sig2hod = np.zeros(self.nelts) 
    mycenvfrac = cenvfrac
    myihv = ihvscale

    for cnt, elt in zip(range(self.nelts), self.chain):
      hh = hod.hodfromchain(elt,whichbox=whichbox,cenopt=cenopt,satopt=satopt,bosswdir=bosswdir,whichPB=whichPB,COMVopt=COMVopt) 
      if cenvfromchain == 1:
        mycenvfrac = (elt['cenvfrac']**2 + cenvfrac**2)
        if mycenvfrac > 0.:
          mycenvfrac = mycenvfrac**0.5
      if ihvfromchain == 1:
        myihv = elt['ihvscale']
      sig2hod[cnt] = hh.sig2hod(cenvfrac=mycenvfrac,ihvscale=myihv)
      #if cnt%100 == 0:
      #  print 'done',cnt,'of ',self.nelts
    self.sig2hod = sig2hod
    self.cenvfrac = cenvfrac
    self.ihvscale = ihvscale
    self.cenvfromchain = cenvfromchain
    self.ihvfromchain = ihvfromchain
Пример #4
0
    def plothodsubsample(self,
                         ax=None,
                         popt=0,
                         rebinsize=10,
                         fillopt=0,
                         color='k',
                         renormalize=False,
                         MFwgt=False,
                         flist=[0.954499736104],
                         nsubsample=1000,
                         whichbox=1,
                         cenopt=2,
                         satopt=2,
                         bosswdir='/home/howdiedoo/boss/',
                         whichPB=0,
                         COMVopt=0,
                         alpha=0.5,
                         fsatrescale=1.):
        """
    Computes if necessary the subsample.
    popt = 0: Ncen
    popt = 1: Nsat
    popt = 2: Ntot
    popt = 3: Nsat/fsatrescale; only makes sense on a MFwgt plot.
    """
        try:
            x = self.bNcen[0, 0]
            x = self.bNcen[0, 0]
            x = self.bNcen[0, 0]
            wgt = np.zeros(len(self.msub)) + 1.
            if MFwgt == True:
                hh = hod.hodfromchain(self.chain[0],
                                      whichbox=whichbox,
                                      cenopt=cenopt,
                                      satopt=satopt,
                                      bosswdir=bosswdir,
                                      whichPB=whichPB,
                                      COMVopt=COMVopt)
                wgt = hh.mf.Nofm
                if rebinsize > 1:
                    Nrebin = BRutils.rebin(hh.mf.Nofm, rebinsize=rebinsize)
                    wgt = Nrebin

        except:
            ## need to run subsample.
            hh = hod.hodfromchain(self.chain[0],
                                  whichbox=whichbox,
                                  cenopt=cenopt,
                                  satopt=satopt,
                                  bosswdir=bosswdir,
                                  whichPB=whichPB,
                                  COMVopt=COMVopt)
            Mlist = hh.mf.m
            wgt = np.zeros(len(Mlist)) + 1.
            if MFwgt == True:
                wgt = hh.mf.Nofm
            if rebinsize > 1:
                Mlist = np.exp(
                    BRutils.rebin(np.log(hh.mf.m), rebinsize=rebinsize))
                wgt = np.zeros(len(Mlist)) + 1.
                tmpo = np.log10(Mlist[1:] / Mlist[:-1]).mean()
                assert (
                    np.fabs(np.log10(Mlist[1:]) - np.log10(Mlist[:-1]) - tmpo)
                    < 0.001 * tmpo).all()
                if MFwgt == True:
                    Nrebin = BRutils.rebin(hh.mf.Nofm, rebinsize=rebinsize)
                    wgt = Nrebin
            self.hodsubsample(Mlist,
                              flist=flist,
                              nsubsample=nsubsample,
                              whichbox=whichbox,
                              cenopt=cenopt,
                              satopt=satopt,
                              bosswdir=bosswdir,
                              whichPB=whichPB,
                              COMVopt=COMVopt)
        if ax is None:
            ff = plt.figure(figsize=[6, 6])
            ax = ff.add_subplot(1, 1, 1)
        else:
            ff = None
        if popt == 0:
            myy1 = wgt * self.bNcen[1]
            myy2 = wgt * self.bNcen[2]
        if popt == 1:
            myy1 = wgt * self.bNsat[1]
            myy2 = wgt * self.bNsat[2]
        if popt == 2:
            myy1 = wgt * self.bNtot[1]
            myy2 = wgt * self.bNtot[2]
        if popt == 3:
            myy1 = wgt * self.bNsat[1] / fsatrescale
            myy2 = wgt * self.bNsat[2] / fsatrescale

        if renormalize == True:
            myy1 = myy1 / float(myy1.sum())
            myy2 = myy2 / float(myy2.sum())

        if fillopt == 1:
            ax.fill_between(self.msub,
                            myy1,
                            myy2,
                            facecolor=color,
                            alpha=alpha)
        else:
            ax.plot(self.msub, myy1, color)
            ax.plot(self.msub, myy2, color)


## how do we fill between two curves instead.
        ax.set_xscale('log')
        return ff, ax
Пример #5
0
    def hodsubsample(self,
                     marray,
                     flist=[0.682689492137, 0.954499736104],
                     nsubsample=1000,
                     whichbox=1,
                     cenopt=2,
                     satopt=2,
                     bosswdir='/home/howdiedoo/boss/',
                     whichPB=0,
                     COMVopt=0):
        """
    Subsamples the chain and computes a bands containing flist fractions.
    nsubsample = 1000 by default.
    marray are mass points where you want to evaluate the hod.
    """
        #def wgtresult2(wgt,v,flist=[0.682689492137,0.954499736104]):
        sNcen = np.zeros([len(marray), nsubsample])
        sNsat = np.zeros([len(marray), nsubsample])
        sNtot = np.zeros([len(marray), nsubsample])
        sMmed = np.zeros([3, nsubsample])
        sMavg = np.zeros([3, nsubsample])

        for nn in range(nsubsample):
            hh = hod.hodfromchain(self.randomsubsample(),whichbox=whichbox,cenopt=cenopt,satopt=satopt,\
                                  bosswdir=bosswdir,whichPB=whichPB,COMVopt=COMVopt)
            sNcen[:, nn] = hh.Ncen(marray)
            sNsat[:, nn] = hh.Ncen(marray) * hh.Nsat(marray)
            sNtot[:, nn] = sNcen[:, nn] + sNsat[:, nn]
            ## compute interesting stats on halo masses.
            ctmp = (hh.mf.Nofm * hh.Ncen(hh.mf.m)).cumsum()
            sMmed[0, nn] = hh.mf.m[np.where(ctmp >= 0.5 * ctmp[-1])[0].min()]
            sMavg[0, nn] = (hh.mf.m * hh.mf.Nofm *
                            hh.Ncen(hh.mf.m)).sum() / ctmp[-1]
            ctmp = (hh.mf.Nofm * hh.Ncen(hh.mf.m) *
                    (1. + hh.Nsat(hh.mf.m))).cumsum()
            sMmed[2, nn] = hh.mf.m[np.where(ctmp >= 0.5 * ctmp[-1])[0].min()]
            sMavg[2, nn] = (hh.mf.m * hh.mf.Nofm * hh.Ncen(hh.mf.m) *
                            (1. + hh.Nsat(hh.mf.m))).sum() / ctmp[-1]
            ctmp = (hh.mf.Nofm * hh.Ncen(hh.mf.m) *
                    (hh.Nsat(hh.mf.m))).cumsum()
            sMmed[1, nn] = hh.mf.m[np.where(ctmp >= 0.5 * ctmp[-1])[0].min()]
            sMavg[1, nn] = (hh.mf.m * hh.mf.Nofm * hh.Ncen(hh.mf.m) *
                            (hh.Nsat(hh.mf.m))).sum() / ctmp[-1]

        rr = np.zeros([len(flist) * 2 + 1, len(marray)])
        wgttmp = np.zeros(nsubsample) + 1.
        bNcen = np.zeros([5, len(marray)])
        bNsat = np.zeros([5, len(marray)])
        bNtot = np.zeros([5, len(marray)])

        Mmed = np.zeros([5, 3])
        Mavg = np.zeros([5, 3])
        for ii in range(3):
            Mmed[:, ii] = wgtresult2raw(wgttmp, sMmed[ii, :])
            Mavg[:, ii] = wgtresult2raw(wgttmp, sMavg[ii, :])

        for mm in range(len(marray)):
            #       print bNcen[:,mm].shape
            #       print wgtresult2raw(wgttmp,sNcen[mm,:])
            #       print wgtresult2raw(wgttmp,sNcen[mm,:]).shape
            bNcen[:, mm] = wgtresult2raw(wgttmp, sNcen[mm, :])
            bNsat[:, mm] = wgtresult2raw(wgttmp, sNsat[mm, :])
            bNtot[:, mm] = wgtresult2raw(wgttmp, sNtot[mm, :])
        self.bNcen = bNcen
        self.bNsat = bNsat
        self.bNtot = bNtot
        self.msub = marray
        self.Mmed = Mmed
        self.Mavg = Mavg
        self.nsubsample = nsubsample
Пример #6
0
  def plothodsubsample(self,ax=None,popt=0,rebinsize=10,fillopt=0,color='k',renormalize=False,MFwgt=False,flist=[0.954499736104],nsubsample=1000,
        whichbox=1,cenopt=2,satopt=2,bosswdir='/home/howdiedoo/boss/',whichPB=0,COMVopt=0,alpha=0.5,fsatrescale=1.):
    """
    Computes if necessary the subsample.
    popt = 0: Ncen
    popt = 1: Nsat
    popt = 2: Ntot
    popt = 3: Nsat/fsatrescale; only makes sense on a MFwgt plot.
    """
    try:
      x = self.bNcen[0,0]
      x = self.bNcen[0,0]
      x = self.bNcen[0,0]
      wgt = np.zeros(len(self.msub))+1.
      if MFwgt == True:
        hh = hod.hodfromchain(self.chain[0],whichbox=whichbox,cenopt=cenopt,satopt=satopt,bosswdir=bosswdir,whichPB=whichPB,COMVopt=COMVopt) 
        wgt = hh.mf.Nofm
        if rebinsize > 1:
          Nrebin = BRutils.rebin(hh.mf.Nofm,rebinsize=rebinsize)
          wgt = Nrebin
          
    except:
      ## need to run subsample.
      hh = hod.hodfromchain(self.chain[0],whichbox=whichbox,cenopt=cenopt,satopt=satopt,bosswdir=bosswdir,whichPB=whichPB,COMVopt=COMVopt) 
      Mlist = hh.mf.m
      wgt = np.zeros(len(Mlist))+1.
      if MFwgt == True:
        wgt = hh.mf.Nofm
      if rebinsize > 1:
        Mlist = np.exp(BRutils.rebin(np.log(hh.mf.m),rebinsize=rebinsize))
        wgt = np.zeros(len(Mlist))+1.
        tmpo = np.log10(Mlist[1:]/Mlist[:-1]).mean()
        assert (np.fabs(np.log10(Mlist[1:]) - np.log10(Mlist[:-1]) - tmpo) < 0.001*tmpo).all()
        if MFwgt == True:
          Nrebin = BRutils.rebin(hh.mf.Nofm,rebinsize=rebinsize)
          wgt = Nrebin
      self.hodsubsample(Mlist,flist=flist,nsubsample=nsubsample,whichbox=whichbox,cenopt=cenopt,satopt=satopt,bosswdir=bosswdir,whichPB=whichPB,COMVopt=COMVopt)
    if ax is None:
      ff = plt.figure(figsize=[6,6])
      ax = ff.add_subplot(1,1,1)
    else:
      ff = None
    if popt == 0:
      myy1 = wgt*self.bNcen[1]
      myy2 = wgt*self.bNcen[2]
    if popt == 1:
      myy1 = wgt*self.bNsat[1]
      myy2 = wgt*self.bNsat[2]
    if popt == 2:
      myy1 = wgt*self.bNtot[1]
      myy2 = wgt*self.bNtot[2]
    if popt == 3:
      myy1 = wgt*self.bNsat[1]/fsatrescale
      myy2 = wgt*self.bNsat[2]/fsatrescale

    if renormalize == True:
      myy1 = myy1/float(myy1.sum())
      myy2 = myy2/float(myy2.sum())

    if fillopt == 1:
      ax.fill_between(self.msub,myy1,myy2,facecolor=color,alpha=alpha)
    else:
      ax.plot(self.msub,myy1,color)
      ax.plot(self.msub,myy2,color)
## how do we fill between two curves instead.
    ax.set_xscale('log')
    return ff, ax