Exemple #1
0
 def __init__(self,fbase,wdir,nbar2d=None,nbar3d=None,tasklist = [0,1,3],icovlist=[None,None,None]):
   """
   tasklist matches whichtask convention in catalog.callxi
   for each task, you can specify an icov matrix.
   """
   self.fbase = fbase
   self.wdir = wdir
   if 0 in tasklist:
     cut=0.533655
     ## remove the hard-coding here soon!
     try:
       indx = np.where(np.array(tasklist) == 0)[0]
       icovfname = icovlist[indx]
     except:
       icovfname = None
     self.xiell = xiell.xiellfromDR(wdir+"outputdr12-xiell/"+fbase,nell=2,binfile=wdir+"xibinfiles/bin1fineMU.txt",rperpcut=cut,icovfname=icovfname)
   if 1 in tasklist:
     try:
       indx = np.where(np.array(tasklist) == 1)[0]
       icovfname = icovlist[indx]
     except:
       icovfname = None
     self.wp = wp.wpfromDR(fbase=wdir+"outputdr12-xigrid/"+fbase,rpimax=80.0)
   if 3 in  tasklist:
     try:
       indx = np.where(np.array(tasklist) == 3)[0]
       icovfname = icovlist[indx]
     except:
       icovfname = None
     if nbar2d is None or nbar3d is None:
       print 'cannot compute wpcross without number densities!'
     else:
       self.nbar2d = nbar2d
       self.nbar3d = nbar3d
       self.wpcross = wp.wpcrossHogg(wdir+"outputdr12-wpcross/"+fbase,nbar2d=nbar2d,nbar3d=nbar3d)
Exemple #2
0
 def __init__(self,
              fbase,
              wdir,
              nbar2d=None,
              nbar3d=None,
              tasklist=[0, 1, 3],
              icovlist=[None, None, None]):
     """
 tasklist matches whichtask convention in catalog.callxi
 for each task, you can specify an icov matrix.
 """
     self.fbase = fbase
     self.wdir = wdir
     if 0 in tasklist:
         cut = 0.533655
         ## remove the hard-coding here soon!
         try:
             indx = np.where(np.array(tasklist) == 0)[0]
             icovfname = icovlist[indx]
         except:
             icovfname = None
         self.xiell = xiell.xiellfromDR(wdir + "outputdr12-xiell/" + fbase,
                                        nell=2,
                                        binfile=wdir +
                                        "xibinfiles/bin1fineMU.txt",
                                        rperpcut=cut,
                                        icovfname=icovfname)
     if 1 in tasklist:
         try:
             indx = np.where(np.array(tasklist) == 1)[0]
             icovfname = icovlist[indx]
         except:
             icovfname = None
         self.wp = wp.wpfromDR(fbase=wdir + "outputdr12-xigrid/" + fbase,
                               rpimax=80.0)
     if 3 in tasklist:
         try:
             indx = np.where(np.array(tasklist) == 3)[0]
             icovfname = icovlist[indx]
         except:
             icovfname = None
         if nbar2d is None or nbar3d is None:
             print 'cannot compute wpcross without number densities!'
         else:
             self.nbar2d = nbar2d
             self.nbar3d = nbar3d
             self.wpcross = wp.wpcrossHogg(wdir + "outputdr12-wpcross/" +
                                           fbase,
                                           nbar2d=nbar2d,
                                           nbar3d=nbar3d)
Exemple #3
0
def getbootcov(bootfile, basedir, outdirbase = 'outputdr12', covoutfname=None, NSortot=2, nboot = 5000000, \
               rpimax=80.,wpstart=1,wpend=19,\
               nell=3,rperpcut=-1.,smallRRcut=-1.,\
               dfacs=1,dfacmu=1,icovfname=None,smincut=-1.,smaxcut=1.e12,\
               binfname_xiell='xibinfiles/bin1fineMU.txt',\
               nbar2d=[-1.,-1.],nbar3d=[-1.,-1],\
               whichtask=4):
## resurrect these later.
#               splitxi0=5,splitxi2=6,splitwp=7):
  """
  Get covariance matrix.
  We're going to do all tasks at once by default (4).
  whichtask = 0: xiell
  whichtask = 1: wp (compute xi(rp,rpi))
  whichtask = 2: wtheta
  whichtask = 3: Hogg spec-im cross-correlation.
  whichtask = 4: combine xiell and wp in usual way.

  Third tier of stuff goes directly to xiellfromDR
  rpimax is for wp, default is 80.
  nbar2d,nbar3d needs to be computed separately for N and S.
  """

  nsub, nsubdir, pixelfname, fbase, fbasetotN, fbasetotS = parsebootinfo(bootfile=basedir+bootfile)

  NSlist = [0,1]
  NStaglist = ['N','S']

  for xx in [nsub, nsubdir, pixelfname, fbase, fbasetotN, fbasetotS]:
    if xx is None:
      print 'bad bootfile!'
      return None

  b = boot.bootpix()
  b.readregions(basedir + pixelfname)
  assert b.nsub == nsub

  ## this list will be filled
  DRinfolist = [-1,-1,-1,-1]

  taglist= ['-xiell','-xigrid','-wtheta','-wpcross']

  ## get global DR factors for taglist.
  for ii in range(len(taglist)-1):
    tag = taglist[ii]
    tmp = np.zeros([2,2]) # first index is N or S.  DRfac, fixRR stored for each.

    for NS, NStag, ff in zip(NSlist, NStaglist,[fbasetotN,fbasetotS]):
      try:
      #if 0==0:
        tmp[NS,0], tmp[NS,1] = ximisc.getDRfactors(basedir + '/'+outdirbase + tag +'/'+ff)
      except:
        tmp[NS,:] = -1.
    DRinfolist[ii] = tmp.copy()

  ## now get DR info for wpcross.
  ### nevermind! we reduce this to two ratios.
  ## DRinfolist[3] = np.zeros([2,4,2])
  DRinfolist[3] = np.zeros([2,2])
  tag = taglist[3]
  for NS, NStag, ff in zip(NSlist, NStaglist,[fbasetotN,fbasetotS]):
    try:
      normfac = ximisc.getDRnormswpcross(basedir + '/'+outdirbase + tag +'/'+ff) 
      DRinfolist[3][NS][0] = normfac[0,0]/normfac[2,0]
      DRinfolist[3][NS][1] = normfac[0,1]/normfac[1,1]
    except:
      DRinfolist[3][NS][:] = -1.

  tasklist = np.zeros(4,dtype='int')
  if whichtask == 4:
    tasklist = np.array([1,1,0,1],dtype='int')
  else:
    tasklist[whichtask] = 1

  if tasklist[3] > 0:
    assert (nbar2d[:] > 0).all()
    assert (nbar3d[:] > 0).all()
    assert (DRinfolist[3][:,:].flatten() > 0).all()

  for ns in range(nsub):
    xx = np.where(b.pixlist['PID'] == ns)[0]
    assert len(xx) == 1
    assert xx[0] == ns
    NorSval = b.pixlist['NorS'][xx[0]]
    for tt in range(len(tasklist)):
      if tasklist[tt] == 0: continue
      tag = taglist[tt]
      ff = basedir+'/'+outdirbase + tag +'/' + nsubdir + '/' + fbase + '.%04d.Np' % (ns) 
      if tt == 0: #xiell
        xitmp = xiell.xiellfromDR(ff,binfile=binfname_xiell,rperpcut=rperpcut,nell=nell,smallRRcut=smallRRcut,dfacs=dfacs,dfacmu=dfacmu,smincut=smincut,smaxcut=smaxcut,DRfacinfo=DRinfolist[tt][NorSval]) 
        dvec = xitmp.xilong
      if tt == 1: #wp
        wptmp = wp.wpfromDR(ff,DRfacinfo=DRinfolist[tt][NorSval],rpimax=rpimax)
        dvec = wptmp.wp

      if tt == 2: #wtheta
        wttmp = wtheta.wthetafromDR(ff,DRfacinfo=DRinfolist[tt][NorSval])
        dvec = wttmp.wtheta

      if tt == 3: #wpcross
        wpcrosstmp = wp.wpcrossHogg(ff,DRfacinfo=DRinfolist[tt][NorSval],nbar2d=nbar2d[NorSval],nbar3d=nbar3d[NorSval])
        dvec = wpcrosstmp.wp

    if whichtask == 4:
      dvec = xiwpvec(xitmp,wptmp,wpcrosstmp,wpstart,wpend)

    if ns == 0:  ## allocate!
      ndata = len(dvec)
      dveclist = np.zeros([nsub,ndata],dtype='float128')
    dveclist[ns,:] = dvec[:]

  ## check means with total counts.
  nindx = np.where(b.pixlist['NorS'] == 0)[0]
  sindx = np.where(b.pixlist['NorS'] == 1)[0]
  nsindx = np.where((b.pixlist['NorS'] == 0) | (b.pixlist['NorS'] == 1))[0]
  print 'N/S: ',len(nindx), len(sindx), len(nsindx)
  assert len(nsindx) == nsub
  assert (nsindx == np.arange(0,nsub,1,dtype='int')).all()
  myindx= nsindx
  ## assume we want nsindx for this, but can restore N/S option later if I want.

  dmean = (dveclist[myindx,:]).sum(axis=0)/float(len(myindx))
  ntot = len(myindx)
  ntotflt = float(ntot)

  print 'hi beth'
  print dmean

  Cmat = np.zeros([ndata,ndata],dtype='float128')
  for b in range(nboot):
    rr = np.random.random_integers(0,ntot-1,ntot)
    dtrial = (dveclist[rr,:]).sum(axis=0)/ntotflt
    xvec = np.matrix([dtrial-dmean])
    Cmat += (xvec.T*xvec)

  Cmat = Cmat/float(nboot-1)
  Cmat = np.matrix(Cmat,dtype='float64')
  iCmat = Cmat.I ##
  print 'not assuming any bootstrap unbias factor for now!'
  if covoutfname is not None:
    printcov(Cmat,covoutfname)
    printcov(iCmat,covoutfname+'.inv')
    printmean(dmean,covoutfname+'.mean')
  return Cmat, iCmat, dmean
Exemple #4
0
def getbootcov(bootfile, basedir, outdirbase = 'outputdr12', covoutfname=None, NSortot=2, nboot = 5000000, \
               rpimax=80.,wpstart=1,wpend=19,\
               nell=3,rperpcut=-1.,smallRRcut=-1.,\
               dfacs=1,dfacmu=1,icovfname=None,smincut=-1.,smaxcut=1.e12,\
               binfname_xiell='xibinfiles/bin1fineMU.txt',\
               nbar2d=[-1.,-1.],nbar3d=[-1.,-1],\
               whichtask=4):
    ## resurrect these later.
    #               splitxi0=5,splitxi2=6,splitwp=7):
    """
  Get covariance matrix.
  We're going to do all tasks at once by default (4).
  whichtask = 0: xiell
  whichtask = 1: wp (compute xi(rp,rpi))
  whichtask = 2: wtheta
  whichtask = 3: Hogg spec-im cross-correlation.
  whichtask = 4: combine xiell and wp in usual way.

  Third tier of stuff goes directly to xiellfromDR
  rpimax is for wp, default is 80.
  nbar2d,nbar3d needs to be computed separately for N and S.
  """

    nsub, nsubdir, pixelfname, fbase, fbasetotN, fbasetotS = parsebootinfo(
        bootfile=basedir + bootfile)

    NSlist = [0, 1]
    NStaglist = ['N', 'S']

    for xx in [nsub, nsubdir, pixelfname, fbase, fbasetotN, fbasetotS]:
        if xx is None:
            print 'bad bootfile!'
            return None

    b = boot.bootpix()
    b.readregions(basedir + pixelfname)
    assert b.nsub == nsub

    ## this list will be filled
    DRinfolist = [-1, -1, -1, -1]

    taglist = ['-xiell', '-xigrid', '-wtheta', '-wpcross']

    ## get global DR factors for taglist.
    for ii in range(len(taglist) - 1):
        tag = taglist[ii]
        tmp = np.zeros(
            [2, 2])  # first index is N or S.  DRfac, fixRR stored for each.

        for NS, NStag, ff in zip(NSlist, NStaglist, [fbasetotN, fbasetotS]):
            try:
                #if 0==0:
                tmp[NS, 0], tmp[NS, 1] = ximisc.getDRfactors(basedir + '/' +
                                                             outdirbase + tag +
                                                             '/' + ff)
            except:
                tmp[NS, :] = -1.
        DRinfolist[ii] = tmp.copy()

    ## now get DR info for wpcross.
    ### nevermind! we reduce this to two ratios.
    ## DRinfolist[3] = np.zeros([2,4,2])
    DRinfolist[3] = np.zeros([2, 2])
    tag = taglist[3]
    for NS, NStag, ff in zip(NSlist, NStaglist, [fbasetotN, fbasetotS]):
        try:
            normfac = ximisc.getDRnormswpcross(basedir + '/' + outdirbase +
                                               tag + '/' + ff)
            DRinfolist[3][NS][0] = normfac[0, 0] / normfac[2, 0]
            DRinfolist[3][NS][1] = normfac[0, 1] / normfac[1, 1]
        except:
            DRinfolist[3][NS][:] = -1.

    tasklist = np.zeros(4, dtype='int')
    if whichtask == 4:
        tasklist = np.array([1, 1, 0, 1], dtype='int')
    else:
        tasklist[whichtask] = 1

    if tasklist[3] > 0:
        assert (nbar2d[:] > 0).all()
        assert (nbar3d[:] > 0).all()
        assert (DRinfolist[3][:, :].flatten() > 0).all()

    for ns in range(nsub):
        xx = np.where(b.pixlist['PID'] == ns)[0]
        assert len(xx) == 1
        assert xx[0] == ns
        NorSval = b.pixlist['NorS'][xx[0]]
        for tt in range(len(tasklist)):
            if tasklist[tt] == 0: continue
            tag = taglist[tt]
            ff = basedir + '/' + outdirbase + tag + '/' + nsubdir + '/' + fbase + '.%04d.Np' % (
                ns)
            if tt == 0:  #xiell
                xitmp = xiell.xiellfromDR(ff,
                                          binfile=binfname_xiell,
                                          rperpcut=rperpcut,
                                          nell=nell,
                                          smallRRcut=smallRRcut,
                                          dfacs=dfacs,
                                          dfacmu=dfacmu,
                                          smincut=smincut,
                                          smaxcut=smaxcut,
                                          DRfacinfo=DRinfolist[tt][NorSval])
                dvec = xitmp.xilong
            if tt == 1:  #wp
                wptmp = wp.wpfromDR(ff,
                                    DRfacinfo=DRinfolist[tt][NorSval],
                                    rpimax=rpimax)
                dvec = wptmp.wp

            if tt == 2:  #wtheta
                wttmp = wtheta.wthetafromDR(ff,
                                            DRfacinfo=DRinfolist[tt][NorSval])
                dvec = wttmp.wtheta

            if tt == 3:  #wpcross
                wpcrosstmp = wp.wpcrossHogg(ff,
                                            DRfacinfo=DRinfolist[tt][NorSval],
                                            nbar2d=nbar2d[NorSval],
                                            nbar3d=nbar3d[NorSval])
                dvec = wpcrosstmp.wp

        if whichtask == 4:
            dvec = xiwpvec(xitmp, wptmp, wpcrosstmp, wpstart, wpend)

        if ns == 0:  ## allocate!
            ndata = len(dvec)
            dveclist = np.zeros([nsub, ndata], dtype='float128')
        dveclist[ns, :] = dvec[:]

    ## check means with total counts.
    nindx = np.where(b.pixlist['NorS'] == 0)[0]
    sindx = np.where(b.pixlist['NorS'] == 1)[0]
    nsindx = np.where((b.pixlist['NorS'] == 0) | (b.pixlist['NorS'] == 1))[0]
    print 'N/S: ', len(nindx), len(sindx), len(nsindx)
    assert len(nsindx) == nsub
    assert (nsindx == np.arange(0, nsub, 1, dtype='int')).all()
    myindx = nsindx
    ## assume we want nsindx for this, but can restore N/S option later if I want.

    dmean = (dveclist[myindx, :]).sum(axis=0) / float(len(myindx))
    ntot = len(myindx)
    ntotflt = float(ntot)

    print 'hi beth'
    print dmean

    Cmat = np.zeros([ndata, ndata], dtype='float128')
    for b in range(nboot):
        rr = np.random.random_integers(0, ntot - 1, ntot)
        dtrial = (dveclist[rr, :]).sum(axis=0) / ntotflt
        xvec = np.matrix([dtrial - dmean])
        Cmat += (xvec.T * xvec)

    Cmat = Cmat / float(nboot - 1)
    Cmat = np.matrix(Cmat, dtype='float64')
    iCmat = Cmat.I  ##
    print 'not assuming any bootstrap unbias factor for now!'
    if covoutfname is not None:
        printcov(Cmat, covoutfname)
        printcov(iCmat, covoutfname + '.inv')
        printmean(dmean, covoutfname + '.mean')
    return Cmat, iCmat, dmean