Ejemplo n.º 1
0
def change_plik_cmbonly(inhf, lklfile, outfile, lmin, lmax):
    olmin = 30
    olmax = 2508
    if lmin == -1 or lmin > lmax or lmin < olmin:
        lmin = olmin
    if lmax == -1 or lmax > olmax:
        lmax = olmax
    nb = 215
    blmin = nm.loadtxt(inhf._name + "/clik/lkl_0/_external/blmin.dat")
    blmax = nm.loadtxt(inhf._name + "/clik/lkl_0/_external/blmax.dat")
    bmin = nm.argmin((blmin + olmin - lmin)**2)
    bmax = nm.argmin((blmax + olmin - lmax)**2)

    lmin = blmin[bmin] + olmin
    lmax = blmax[bmax] + olmin

    print("restrict to %d %d [%d %d]" % (lmin, lmax, bmin, bmax))

    hpy.copyfile(lklfile, outfile)
    outhf = hpy.File(outfile, "r+")
    outhf["clik/lkl_0/bin_min_tt"] = bmin + 1
    outhf["clik/lkl_0/bin_max_tt"] = bmax + 1
    outhf["clik/lkl_0/bin_min_te"] = 1
    outhf["clik/lkl_0/bin_max_te"] = 199
    outhf["clik/lkl_0/bin_min_ee"] = 1
    outhf["clik/lkl_0/bin_max_ee"] = 199

    php.remove_selfcheck(root_grp=outhf["clik"])
    outhf.close()
Ejemplo n.º 2
0
def change_simlow(inhf, lklfile, outfile, lmin, lmax):
    hpy.copyfile(lklfile, outfile)
    outhf = hpy.File(outfile, "r+")
    outhf["clik/lmax"] = [-1, lmax, -1, -1, -1, -1]
    outhf["clik/lkl_0/lmin"] = lmin
    outhf["clik/lkl_0/lmax"] = lmax
    php.remove_selfcheck(root_grp=outhf["clik"])
    outhf.close()
def main(argv):
    pars = clik.miniparse(argv[1])

    outhf, lkl_grp = php.copy_and_get_0(pars)
    php.add_free_calib(lkl_grp, pars.str.parname)

    php.remove_selfcheck(root_grp=outhf["clik"])

    outhf.close()
Ejemplo n.º 4
0
def change_gibbs_gauss(inhf, lklfile, outfile, lmin, lmax):
    olmin = inhf["clik/lkl_0/lmin"]
    if lmin == -1 or lmin > lmax:
        lmin = inhf["clik/lkl_0/lmin"]
    if lmax == -1:
        lmax = inhf["clik/lkl_0/lmax"]
    if lmax > 249:
        print("not possible")
        sys.exit(-1)
    hpy.copyfile(lklfile, outfile)
    outhf = hpy.File(outfile, "r+")
    outhf["clik/lmax"] = [lmax, -1, -1, -1, -1, -1]
    outhf["clik/lkl_0/lmin"] = lmin
    outhf["clik/lkl_0/lmax"] = lmax
    outhf["clik/lkl_0/delta_l"] = lmax
    php.remove_selfcheck(root_grp=outhf["clik"])
    outhf.close()
Ejemplo n.º 5
0
def change_smica(inhf, lklfile, outfile, lmin, lmax):
    olmin = inhf["clik/lkl_0/lmin"]
    olmax = inhf["clik/lkl_0/lmax"]
    if lmin == -1 or lmin > lmax or lmin < olmin:
        lmin = olmin
    if lmax == -1 or lmax > olmax:
        lmax = olmax

    nb = inhf["clik/lkl_0/nbins"]

    blmin = inhf["clik/lkl_0/bin_lmin"]
    blmax = inhf["clik/lkl_0/bin_lmax"]

    bmin = nm.argmin((blmin + olmin - lmin)**2)
    bmax = nm.argmin((blmax + olmin - lmax)**2)

    lmin = blmin[bmin] + olmin
    lmax = blmax[bmax] + olmin

    print("restrict to %d %d" % (lmin, lmax))

    hascl = inhf["clik/lkl_0/has_cl"]
    assert hascl[1:].sum() == 0, "do not work yet on polar data"
    mT = inhf["clik/lkl_0/m_channel_T"]

    ord = inhf["clik/lkl_0/criterion_gauss_ordering"]
    ord.shape = (-1, 2)
    nmsk = inhf["clik/lkl_0/criterion_gauss_mask"]
    nmsk.shape = (nb, mT, mT)

    kp = []
    mx = 0
    for i, j in ord:
        cur = nm.arange(nb)[nmsk[:, i, j] == 1]
        kp += [nm.where((cur < bmax + 1) * (cur > bmin - 1))[0] + mx]
        mx += len(cur)
    kp = nm.concatenate(kp)

    siginv = inhf["clik/lkl_0/criterion_gauss_mat"]
    siginv.shape = (siginv.shape[0]**.5, -1)
    sig = nm.linalg.inv(siginv)
    del(siginv)
    nsig = ((sig[kp])[:, kp]) * 1.
    del(sig)
    nsiginv = nm.linalg.inv(nsig)
    del(nsig)

    hpy.copyfile(lklfile, outfile)
    outhf = hpy.File(outfile, "r+")

    outhf["clik/lmax"] = [lmax, -1, -1, -1, -1, -1]

    outhf["clik/lkl_0/lmin"] = lmin
    outhf["clik/lkl_0/lmax"] = lmax

    outhf["clik/lkl_0/nbins"] = bmax + 1 - bmin
    cutarr(inhf, outhf, 0, nb - 1, bmin, bmax, "clik/lkl_0/bin_lmin")
    outhf["clik/lkl_0/bin_lmin"] = outhf["clik/lkl_0/bin_lmin"] - \
        (lmin - olmin)
    cutarr(inhf, outhf, 0, nb - 1, bmin, bmax, "clik/lkl_0/bin_lmax")
    outhf["clik/lkl_0/bin_lmax"] = outhf["clik/lkl_0/bin_lmax"] - \
        (lmin - olmin)
    cutarr(inhf, outhf, olmin, olmax, lmin, lmax, "clik/lkl_0/bin_ws")

    cutarr(inhf, outhf, 0, nb - 1, bmin, bmax, "clik/lkl_0/Rq_hat")

    cutarr(inhf, outhf, 0, nb - 1, bmin, bmax, "clik/lkl_0/wq")
    cutarr(inhf, outhf, 0, nb - 1, bmin, bmax,
           "clik/lkl_0/criterion_gauss_mask")
    outhf["clik/lkl_0/criterion_gauss_mat"] = nsiginv.flat[:]

    for i in range(1, inhf["clik/lkl_0/n_component"]):
        if "lmin" not in inhf["clik/lkl_0/component_%d" % i]:
            continue
        outhf["clik/lkl_0/component_%d/lmin" % i] = lmin
        outhf["clik/lkl_0/component_%d/lmax" % i] = lmax

    php.remove_selfcheck(root_grp=outhf["clik"])
    outhf.close()
def change_smica(inhf,lklfile,outfile,lmins,lmaxs,beg,nd):
  olmin = inhf["clik/lkl_0/lmin"]
  olmax = inhf["clik/lkl_0/lmax"]
  lmaxs = nm.array([olmax if (lm == -1 or lm>olmax) else lm for lm in lmaxs])
  lmins = nm.array([olmin if (lm == -1 or lm<olmin) else lm for lm in lmins])
  beg_notch = nm.array([lmx if (lm == -1 or lm>lmx) else lm for lm,lmx in zip(beg,lmaxs)])
  end_notch = nm.array([lmx if (lm == -1 or lm<lmx) else lm for lm,lmx in zip(nd,lmins)])
  
  kpp =  lmaxs>lmins
  
  nb = inhf["clik/lkl_0/nbins"]

  hascl = inhf["clik/lkl_0/has_cl"]
  mT = inhf["clik/lkl_0/m_channel_T"]
  mP = inhf["clik/lkl_0/m_channel_P"]  
  mE = mT*hascl[0]
  mB = mE + mP*hascl[1]
  m =  mB + mP*hascl[2]
  
  blmin = inhf["clik/lkl_0/bin_lmin"][:nb/nm.sum(hascl)]
  blmax = inhf["clik/lkl_0/bin_lmax"][:nb/nm.sum(hascl)]
  
  
  bmins = nm.array([nm.argmin((blmin+olmin-lm)**2) for lm in lmins])
  bmaxs = nm.array([nm.argmin((blmax+olmin-lm)**2) for lm in lmaxs])

  
  bbeg_notch = nm.array([nm.argmin((blmin+olmin-lm)**2) for lm in beg_notch])
  bend_notch = nm.array([nm.argmin((blmin+olmin-lm)**2) for lm in end_notch])

  lmins = nm.array([blmin[bm]+olmin for bm in bmins])
  lmaxs = nm.array([blmax[bm]+olmin for bm in bmaxs])

  
  beg_notch = nm.array([blmin[bm]+olmin for bm in bbeg_notch])
  end_notch = nm.array([blmax[bm]+olmin for bm in bend_notch])

  
  dnames = inhf["clik/lkl_0/dnames"]
  dnames = [dnames[i*256:(i+1)*256].strip("\0") for i in range(len(dnames)/256)]
  print "restrict to"
  cc = 0
  for a in range(3):
    aT = "TEB"[a]
    for ii in range(mT if a==0 else mP*hascl[a]):
      for b in range(3):
        bT = "TEB"[b]
        for jj in range(mT if b==0 else mP*hascl[b]):
          print "  %s%s %s%s lmin = %d, lmax = %d"%(aT,dnames[mT*(a!=0)+ii][:-1],bT,dnames[mT*(b!=0)+jj][:-1],lmins[cc]*kpp[cc],lmaxs[cc]*kpp[cc]),
          if beg_notch[cc]*kpp[cc]<end_notch[cc]*kpp[cc]:
            print "[notch %d -> %d]"%(beg_notch[cc]*kpp[cc],end_notch[cc]*kpp[cc],),
          print ""
          cc+=1


  lmin = min(lmins[kpp])
  lmax = max(lmaxs[kpp])
  bmin = min(bmins[kpp])
  bmax = max(bmaxs[kpp])
  
  #sys.exit(-1)

  ord = inhf["clik/lkl_0/criterion_gauss_ordering"]
  ord.shape=(-1,2)
  nmsk = inhf["clik/lkl_0/criterion_gauss_mask"]
  nmsk.shape=(nb/nm.sum(hascl),m,m)

  kp = []
  mx = 0
  bmins.shape=(m,m)
  bmaxs.shape=(m,m)
  bbeg_notch.shape=(m,m)
  bend_notch.shape=(m,m)
  kpp.shape=(m,m)
  nnmsk = nmsk*1

  for i,j in ord:
    cur = nm.arange(nb/nm.sum(hascl))[nmsk[:,i,j]==1]
    nnmsk[:bmins[i,j],i,j] = 0
    nnmsk[bmaxs[i,j]+1:,i,j] = 0
    nnmsk[bbeg_notch[i,j]:bend_notch[i,j]+1,i,j]=0
    if kpp[i,j]:
      kp += [nm.where((cur<bmaxs[i,j]+1) * (cur>bmins[i,j]-1) * (((cur>bbeg_notch[i,j]-1) * (cur<bend_notch[i,j]+1))==False))[0]+mx]
      #print "cur",cur+mx
      #print "kp",kp[-1]
      #print i,j,len(cur),len(kp[-1])
      #print (cur<bmaxs[i,j]+1)
      #print (cur>bmins[i,j]-1)
      #print (cur<bbeg_notch[i,j]+1),bbeg_notch[i,j]
      #print (cur>bend_notch[i,j]-1),bend_notch[i,j]
    else:
      nnmsk[:,i,j] = 0
    mx += len(cur)
    
  kp = nm.concatenate(kp)
  
  siginv = inhf["clik/lkl_0/criterion_gauss_mat"]
  siginv.shape=(siginv.shape[0]**.5,-1)
  sig = nm.linalg.inv(siginv)
  del(siginv)
  
  nsig = ((sig[kp])[:,kp])*1.
  del(sig)
  nsiginv = nm.linalg.inv(nsig)
  del(nsig)

  hpy.copyfile(lklfile,outfile)
  outhf = hpy.File(outfile,"r+")
  
  #outhf["clik/lmax"] = [lmax,-1,-1,-1,-1,-1]
  
  #outhf["clik/lkl_0/lmin"] = lmin
  #outhf["clik/lkl_0/lmax"] = lmax
  
  #outhf["clik/lkl_0/nbins"] = bmax + 1 - bmin
  #cutarr(inhf,outhf,0,nb-1,bmin,bmax,"clik/lkl_0/bin_lmin")
  #outhf["clik/lkl_0/bin_lmin"] = outhf["clik/lkl_0/bin_lmin"]-(lmin-olmin)
  #cutarr(inhf,outhf,0,nb-1,bmin,bmax,"clik/lkl_0/bin_lmax")
  #outhf["clik/lkl_0/bin_lmax"] = outhf["clik/lkl_0/bin_lmax"]-(lmin-olmin)
  #cutarr(inhf,outhf,olmin,olmax,lmin,lmax,"clik/lkl_0/bin_ws")

  #cutarr(inhf,outhf,0,nb-1,bmin,bmax,"clik/lkl_0/Rq_hat")

  #cutarr(inhf,outhf,0,nb-1,bmin,bmax,"clik/lkl_0/wq")
  #cutarr(inhf,outhf,0,nb-1,bmin,bmax,"clik/lkl_0/criterion_gauss_mask",nnmsk)
  outhf["clik/lkl_0/criterion_gauss_mask"] = nnmsk.flat[:]
  outhf["clik/lkl_0/criterion_gauss_mat"] = nsiginv.flat[:]

  #for i in range(1,inhf["clik/lkl_0/n_component"]):
  #  if "lmin" not in inhf["clik/lkl_0/component_%d"%i]:
  #    continue
  #  outhf["clik/lkl_0/component_%d/lmin"%i]=lmin
  #  outhf["clik/lkl_0/component_%d/lmax"%i]=lmax

  php.remove_selfcheck(root_grp=outhf["clik"])
  outhf.close()