예제 #1
0
def make_plot(Nmu=4):
    """Does the work of making the real-space xi(r) and b(r) figure."""

    mubins = np.linspace(0, 1, Nmu + 1)
    mus = 0.5 * (mubins[1:] + mubins[:-1])
    fig, axar = plt.subplots(2, 3, figsize=(9, 6), sharex=True, sharey=True)

    #fits
    linestyle = ['-', '--']
    colors = ['C0', 'C1', 'C2']
    lww = 2

    for ia, aa in enumerate([0.3333, 0.2000, 0.1429]):
        zz = 1 / aa - 1
        for iw, wopt in enumerate(['opt', 'pess']):
            lss = linestyle[iw]
            #for it, thopt in enumerate(['opt', 'pess', 'reas']):
            for it, thopt in enumerate(['reas']):
                if rank == 0: print(aa, wopt, thopt)
                cc = colors[ia]
                try:
                    angle = np.round(mapn.wedge(zz, att=wopt, angle=True), 0)
                    dpath = '/global/cscratch1/sd/chmodi/m3127/21cm_cleaning/recon/fastpm_%0.4f/wedge_kmin%0.2f_%s/' % (
                        aa, 0.03, wopt)
                    dpath += 'L%04d-N%04d-R//thermal-%s-hex/ZA/opt_s999_h1massA_fourier_rsdpos/' % (
                        bs, nc, thopt)
                    ofolder = '../../data/ZArecon-rsd/kmin-003_wedge-%s/thermal-%s-hex/Nmu%d/' % (
                        wopt, thopt, Nmu)
                    if args.pp: suff = '-up'
                    else: suff = ''
                    k2d = np.loadtxt(ofolder + 'recon-L%04d_%0.4f%s-k.txt' %
                                     (bs, aa, suff))
                    pxr = np.loadtxt(ofolder + 'recon-L%04d_%0.4f%s-xs.txt' %
                                     (bs, aa, suff))
                    pr = np.loadtxt(ofolder + 'recon-L%04d_%0.4f%s-ps1.txt' %
                                    (bs, aa, suff))
                    ps = np.loadtxt(ofolder + 'recon-L%04d_%0.4f%s-ps2.txt' %
                                    (bs, aa, suff))
                    pstd = np.loadtxt(ofolder + 'std-L%04d_%0.4f%s.txt' %
                                      (bs, aa, suff))
                    pxstd = np.loadtxt(ofolder + 'xstd-L%04d_%0.4f%s.txt' %
                                       (bs, aa, suff))
                    rcc2d = pxr / (pr * ps)**0.5
                    rccstd2d = pxstd / (pstd * ps)**0.5

                    ofolder = '../../data/ZArecon-rsd/kmin-003_wedge-%s/thermal-%s-hex/' % (
                        wopt, thopt)
                    if args.pp: suff = '-up'
                    else: suff = ''
                    recon = np.loadtxt(ofolder + 'recon-L%04d_%0.4f%s.txt' %
                                       (bs, aa, suff))
                    pstd = np.loadtxt(ofolder + 'std-L%04d_%0.4f%s.txt' %
                                      (bs, aa, suff))[:, 1]
                    pxstd = np.loadtxt(ofolder + 'xstd-L%04d_%0.4f%s.txt' %
                                       (bs, aa, suff))[:, 1]
                    k = recon[:, 0]
                    rcc = recon[:, 2] / (recon[:, 6] * recon[:, 7])**0.5
                    rccstd = pxstd / (pstd * recon[:, 7])**0.5

                    lbl, lbl1, lbl2 = None, None, None
                    if iw == 0:
                        lbl1 = 'z = %0.1f' % zz
                    if ia == 0:
                        lbl2 = 'Wedge = %s' % wopt

                    ax = axar.T
                    ax[0, 0].plot(k, rcc, ls=lss, lw=lww, color=cc, label=lbl1)
                    ax[0, 1].plot(k,
                                  rccstd,
                                  ls=lss,
                                  lw=lww,
                                  color=cc,
                                  label=lbl2)
                    ax[1, 0].plot(k,
                                  rcc2d[:, 0],
                                  ls=lss,
                                  lw=lww,
                                  color=cc,
                                  label=lbl)
                    ax[1, 1].plot(k,
                                  rccstd2d[:, 0],
                                  ls=lss,
                                  lw=lww,
                                  color=cc,
                                  label=lbl)
                    ax[2, 0].plot(k,
                                  rcc2d[:, -1],
                                  ls=lss,
                                  lw=lww,
                                  color=cc,
                                  label=lbl)
                    ax[2, 1].plot(k,
                                  rccstd2d[:, -1],
                                  ls=lss,
                                  lw=lww,
                                  color=cc,
                                  label=lbl)

                    ax[1, 0].text(0.01,
                                  0.4,
                                  'Iterative\nRecon',
                                  color='black',
                                  ha='left',
                                  va='top',
                                  fontdict=font)
                    ax[1, 1].text(0.01,
                                  0.8,
                                  'Standard\nRecon',
                                  color='black',
                                  ha='left',
                                  va='top',
                                  fontdict=font)
                    ax[0, 0].text(1.5,
                                  1,
                                  r'1D',
                                  color='black',
                                  ha='right',
                                  va='bottom',
                                  fontdict=font)
                    ax[1,
                       0].text(1.5,
                               1,
                               r'$\mu=%0.3f-%0.3f$' % (mubins[0], mubins[1]),
                               color='black',
                               ha='right',
                               va='bottom',
                               fontdict=font)
                    ax[2,
                       0].text(1.5,
                               1,
                               r'$\mu=%0.3f-%0.3f$' % (mubins[-2], mubins[-1]),
                               color='black',
                               ha='right',
                               va='bottom',
                               fontdict=font)

                except Exception as e:
                    if rank == 0: print(e)

    #axar[0, 0].set_title('Iterative', fontdict=font)
    #axar[0, 1].set_title('Standard', fontdict=font)

    for axis in axar[:, 0]:
        axis.set_ylabel('$r_{cc}$', fontdict=font)
        axis.set_ylim(-0.1, 1.15)
        axis.legend(prop=fontmanage, loc=0)
    for axis in axar[1, :]:
        axis.set_xlabel(r'$k\quad [h\,{\rm Mpc}^{-1}]$', fontdict=font)
    for axis in axar.flatten():
        axis.axhline(1, color='k', ls=':', lw=0.5)
        axis.set_xscale('log')
        axis.grid(which='both', lw=0.2, alpha=0.2, color='gray')

    # Put on some more labels.
    for axis in axar.flatten():
        for tick in axis.xaxis.get_major_ticks():
            tick.label.set_fontproperties(fontmanage)
        for tick in axis.yaxis.get_major_ticks():
            tick.label.set_fontproperties(fontmanage)
    ##and finish
    plt.tight_layout(rect=[0, 0, 1, 0.95])
    if rank == 0 and not args.pp:
        plt.savefig(figpath + '/rccstd12d_L%04d-Nmu%d-hex.pdf' % (bs, Nmu))
    if rank == 0 and args.pp:
        plt.savefig(figpath + '/rccstd12d_L%04d-Nmu%d-hexup.pdf' % (bs, Nmu))
예제 #2
0
def make_rep_plot():
    """Does the work of making the real-space xi(r) and b(r) figure."""

    fig, axar = plt.subplots(3, 2, figsize=(9, 9), sharex=True)

    #fits
    linestyle = ['-', '--']
    colors = ['C0', 'C1', 'C2']
    lww = 2

    for ia, aa in enumerate([0.3333, 0.2000, 0.1429]):
        #for ia, aa  in enumerate([0.3333]):
        zz = 1 / aa - 1
        for iw, wopt in enumerate(['opt', 'pess']):
            lss = linestyle[iw]
            for it, thopt in enumerate(['opt', 'pess', 'reas']):
                if rank == 0: print(aa, wopt, thopt)
                cc = colors[it]
                ax = axar[ia]
                try:
                    angle = np.round(mapn.wedge(zz, att=wopt, angle=True), 0)
                    #dpath = '/global/cscratch1/sd/chmodi/m3127/21cm_cleaning/recon/fastpm_%0.4f/wedge_kmin%0.2f_ang%0.1f/'%(aa, 0.03, angle)
                    dpath = '/global/cscratch1/sd/chmodi/m3127/21cm_cleaning/recon/fastpm_%0.4f/wedge_kmin%0.2f_%s/' % (
                        aa, 0.03, wopt)
                    dpath += 'L%04d-N%04d-R//thermal-%s-hex/ZA/opt_s999_h1massA_fourier_rsdpos/' % (
                        bs, nc, thopt)
                    datapp = mapp.Observable.load(dpath + '/datap')
                    bfit = mapp.Observable.load(dpath + '/dataw')
                    #bfit = mapp.Observable.load(dpath+'ZA/opt_s999_h1massA_fourier_rsdpos/best-fit/')
                    rpfit = rp.evaluate1(bfit, datapp, field='mapp')[:-2]
                    if ia == 0 and iw == 0:
                        lbl = 'Noise - %s' % thopt
                    elif ia == 1 and it == 0:
                        lbl = 'Wedge = %s' % wopt
                    else:
                        lbl = None
                    ax[0].plot(rpfit[0]['k'],
                               rpfit[0]['power'] /
                               (rpfit[1]['power'] * rpfit[2]['power'])**0.5,
                               ls=lss,
                               lw=lww,
                               color=cc,
                               label=lbl)
                    ax[1].plot(rpfit[0]['k'],
                               (rpfit[1]['power'] / rpfit[2]['power'])**0.5,
                               ls=lss,
                               lw=lww,
                               color=cc)
                    ax[1].text(1,
                               0.4,
                               r'$z = %.2f$' % zz,
                               color='black',
                               ha='right',
                               va='bottom',
                               fontdict=font)
                except Exception as e:
                    if rank == 0: print(e)

    for axis in axar[:, 0]:
        axis.set_ylabel('$r_{cc}$', fontdict=font)
        axis.set_ylim(0, 1.05)
    #for axis in axar[:, 1]: axis.set_ylabel(r'$\sqrt{P_{\rm mod}/P_{hh}}$', fontdict=font)
    for axis in axar[:, 1]:
        axis.set_ylabel(r'$T_f$', fontdict=font)
    for axis in axar[2, :]:
        axis.set_xlabel(r'$k\quad [h\,{\rm Mpc}^{-1}]$', fontdict=font)
    for axis in axar.flatten():
        axis.axhline(1, color='k', ls=':')
        axis.set_xscale('log')
        axis.grid(which='both')
        axis.legend(prop=fontmanage)

    # Put on some more labels.
    for axis in axar.flatten():
        for tick in axis.xaxis.get_major_ticks():
            tick.label.set_fontproperties(fontmanage)
        for tick in axis.yaxis.get_major_ticks():
            tick.label.set_fontproperties(fontmanage)
    ##and finish
    plt.tight_layout(rect=[0, 0, 1, 0.95])
    if rank == 0: plt.savefig(figpath + '/allcomparedata_L%04d-hex.pdf' % (bs))
예제 #3
0
def fishintrep1d():
    '''1D'''

    A0 = 0.4529
    silk = 7.76
    vol = bs**3
    fac = vol * A0**2

    for ia, aa in enumerate([0.3333, 0.2000, 0.1429]):
        zz = 1 / aa - 1
        for iw, wopt in enumerate(['opt', 'pess']):
            #for iw, wopt in enumerate([ 'opt']):
            #for it, thopt in enumerate(['opt', 'pess', 'reas']):
            for it, thopt in enumerate(['reas']):
                if rank == 0: print(aa, wopt, thopt)

                angle = np.round(mapn.wedge(zz, att=wopt, angle=True), 0)
                dpath = '/global/cscratch1/sd/chmodi/m3127/21cm_cleaning/recon/fastpm_%0.4f/wedge_kmin%0.2f_%s/' % (
                    aa, 0.03, wopt)
                dpath += 'L%04d-N%04d-R//thermal-%s-hex/ZA/opt_s999_h1massA_fourier_rsdpos/' % (
                    bs, nc, thopt)
                ofolder = '../../data/ZArecon-rsd/kmin-003_wedge-%s/thermal-%s-hex/' % (
                    wopt, thopt)
                if args.pp:
                    suff = '-up'
                else:
                    suff = ''
                recon = np.loadtxt(ofolder + 'recon-L%04d_%0.4f%s.txt' %
                                   (bs, aa, suff))
                k = recon[:, 0]
                pxr, pr, ps = recon[:, 2], recon[:, 6], recon[:, 7]
                rccr, tfr = pxr / (pr * ps)**0.5, (pr / ps)**0.5
                biasr = tfr[1:5].mean()

                pstd = np.loadtxt(ofolder + 'std-L%04d_%0.4f%s.txt' %
                                  (bs, aa, suff))[:, 1]
                pxstd = np.loadtxt(ofolder + 'xstd-L%04d_%0.4f%s.txt' %
                                   (bs, aa, suff))[:, 1]
                rccstd, tfstd = pxstd / (pstd * ps)**0.5, (pstd / ps)**0.5
                biasstd = tfstd[1:5].mean()

                #biasr, biasstd = 1, 1
                #print(biasr, biasstd)
                fid, std = [rccr, tfr, biasr,
                            pr], [rccstd, tfstd, biasstd, pstd]
                sig = []
                for rcc, tf, bias, pkr in [fid, std]:

                    p02 = np.interp(0.2, k, ps).real
                    ck = rcc * tf / bias
                    #     pmc = pkr - ck**2 * pkd
                    pmc = pkr - bias**2 * ck**2 * ps
                    #     den = (pkd * ck**2 + pmc)/p02
                    den = (ps * (bias * ck)**2 + pmc) / p02
                    num = np.exp(-2 * (k * silk)**1.4) * (bias * ck)**4

                    #integ = fac*np.array([np.trapz(k[:i]**2 * num[:i]/den[:i]**2,  k[:i]) for i in np.arange(k.size)])
                    fish = fac * np.trapz(k[1:]**2 * num[1:] / den[1:]**2,
                                          k[1:])
                    sig.append(fish**-0.5)

                #print(sig, sig[1]/sig[0])
                print(sig[1] / sig[0])
예제 #4
0
def make_1d_plot():
    """Does the work of making the real-space xi(r) and b(r) figure."""

    fig, axar = plt.subplots(3, 2, figsize=(9, 9), sharex=True)

    #fits
    linestyle = ['-', '--']
    colors = ['C0', 'C1', 'C2']
    lww = 2

    for ia, aa in enumerate([0.3333, 0.2000, 0.1429]):
        zz = 1 / aa - 1
        for iw, wopt in enumerate(['opt', 'pess']):
            lss = linestyle[iw]
            for it, thopt in enumerate(['opt', 'pess', 'reas']):
                if rank == 0: print(aa, wopt, thopt)
                cc = colors[it]
                ax = axar[ia]
                try:
                    angle = np.round(mapn.wedge(zz, att=wopt, angle=True), 0)
                    dpath = '/global/cscratch1/sd/chmodi/m3127/21cm_cleaning/recon/fastpm_%0.4f/wedge_kmin%0.2f_%s/' % (
                        aa, 0.03, wopt)
                    dpath += 'L%04d-N%04d-R//thermal-%s-hex/ZA/opt_s999_h1massA_fourier_rsdpos/' % (
                        bs, nc, thopt)
                    ofolder = '../../data/ZArecon-rsd/kmin-003_wedge-%s/thermal-%s-hex/' % (
                        wopt, thopt)
                    if args.pp: suff = '-up'
                    else: suff = ''
                    recon = np.loadtxt(ofolder + 'recon-L%04d_%0.4f%s.txt' %
                                       (bs, aa, suff))
                    k = recon[:, 0]
                    pxr = recon[:, 2]
                    pr = recon[:, 6]
                    ps = recon[:, 7]
                    pstd = np.loadtxt(ofolder + 'std-L%04d_%0.4f%s.txt' %
                                      (bs, aa, suff))[:, 1]
                    pxstd = np.loadtxt(ofolder + 'xstd-L%04d_%0.4f%s.txt' %
                                       (bs, aa, suff))[:, 1]

                    if ia == 0 and iw == 0:
                        if thopt == 'reas': thopt = 'fid'
                        lbl = 'Noise - %s' % thopt
                    elif ia == 1 and it == 0:
                        lbl = 'Wedge = %s' % wopt
                    else:
                        lbl = None
                    ax[0].plot(k,
                               pxr / (pr * ps)**0.5,
                               ls=lss,
                               lw=lww,
                               color=cc,
                               label=lbl)
                    ax[1].plot(k,
                               pxstd / (pstd * ps)**0.5,
                               ls=lss,
                               lw=lww,
                               color=cc)
                    ax[1].text(0.6,
                               0.8,
                               r'$z = %.2f$' % zz,
                               color='black',
                               ha='left',
                               va='bottom',
                               fontdict=font)
                except Exception as e:
                    if rank == 0: print(e)

    axar[0, 0].set_title('Iterative', fontdict=font)
    axar[0, 1].set_title('Standard', fontdict=font)
    for axis in axar[:, 0]:
        axis.set_ylabel('$r_{cc}$', fontdict=font)
        axis.set_ylim(-0.05, 1.1)
    for axis in axar[:, 1]:
        axis.set_ylabel(r'$T_f$', fontdict=font)
        axis.set_ylim(-0.05, 1.1)
    for axis in axar[2, :]:
        axis.set_xlabel(r'$k\quad [h\,{\rm Mpc}^{-1}]$', fontdict=font)
    for axis in axar.flatten():
        axis.axhline(1, color='k', ls=':')
        axis.set_xscale('log')
        axis.grid(which='both', lw=0.2, alpha=0.2, color='gray')
        axis.legend(prop=fontmanage, loc=4)

    # Put on some more labels.
    for axis in axar.flatten():
        for tick in axis.xaxis.get_major_ticks():
            tick.label.set_fontproperties(fontmanage)
        for tick in axis.yaxis.get_major_ticks():
            tick.label.set_fontproperties(fontmanage)
    ##and finish
    plt.tight_layout(rect=[0, 0, 1, 0.95])
    if rank == 0 and not args.pp:
        plt.savefig(figpath + '/rccstd_L%04d-hex.pdf' % (bs))
    if rank == 0 and args.pp:
        plt.savefig(figpath + '/rccstd_L%04d-hexup.pdf' % (bs))
예제 #5
0
def make_mu_plot(Nmu=8, nx=2, ny=2):
    """Does the work of making the real-space xi(r) and b(r) figure."""

    mub = np.linspace(0, 1, Nmu + 1)
    linestyle = ['-', '--']
    markers = ['o', 'x']
    colors = ['C0', 'C1', 'C2']
    fig, ax = plt.subplots(2, 3, figsize=(11, 6), sharex=True, sharey=True)
    for ia, aa in enumerate([0.3333, 0.2000, 0.1429]):
        zz = 1 / aa - 1
        for iw, wopt in enumerate(['opt', 'pess']):
            #for iw, wopt in enumerate(['opt']):
            lss = linestyle[iw]
            mm = markers[iw]
            #for it, thopt in enumerate(['opt', 'pess', 'reas']):
            for it, thopt in enumerate(['reas']):
                if rank == 0: print(aa, wopt, thopt)
                cc = colors[ia]
                try:
                    angle = np.round(mapn.wedge(zz, att=wopt, angle=True), 0)
                    dpath = '/global/cscratch1/sd/chmodi/m3127/21cm_cleaning/recon/fastpm_%0.4f/wedge_kmin%0.2f_%s/' % (
                        aa, 0.03, wopt)
                    dpath += 'L%04d-N%04d-R//thermal-%s-hex/ZA/opt_s999_h1massA_fourier_rsdpos/' % (
                        bs, nc, thopt)
                    fname = './tmpdata/mapp%d-L%04d_%0.4f_kmin%0.2f_%s-th%shex' % (
                        Nmu, bs, aa, 0.03, wopt, thopt)
                    if args.pp: fname = fname[:] + '-up'
                    try:
                        rpfit = [{
                            'k': np.loadtxt(fname + '-k.txt'),
                            'power': np.loadtxt(fname + '-p%d.txt' % i)
                        } for i in range(3)]
                    except:
                        if args.pp:
                            datapp = mapp.Observable.load(dpath + '/datap_up')
                            bpaths = [
                                dpath + 'upsample2/%d-0.00//best-fit' % nc2
                            ] + [
                                dpath + 'upsample2/%d-0.00//%04d/fit_p/' %
                                (nc2, i) for i in range(100, 50, -20)
                            ]
                        else:
                            datapp = mapp.Observable.load(dpath + '/datap')
                            bpaths = [dpath + '%d-0.00//best-fit' % nc] + [
                                dpath + '%d-0.00//%04d/fit_p/' % (nc, i)
                                for i in range(100, 50, -20)
                            ]
                        for path in bpaths:
                            if os.path.isdir(path): break
                        if rank == 0: print(path)
                        bfit = mapp.Observable.load(path)
                        rpfit = rp.evaluate2d1(bfit,
                                               datapp,
                                               Nmu=Nmu,
                                               field='mapp')
                    #
                    mus = np.linspace(0, 1, Nmu)
                    k = rpfit[0]['k'].mean(axis=1)
                    k[np.isnan(k)] = -1
                    kk = np.logspace(np.log10(0.05), 0, 6)
                    for i in range(kk.size):
                        axis = ax.flatten()[i]
                        if i == 0 and iw == 0:
                            lbl = 'z = %.1f' % (1 / aa - 1)
                        elif i == 1 and ia == 0:
                            lbl = 'Wedge = %s' % wopt
                        else:
                            lbl = None
                        ik = np.where(k > kk[i])[0][0]
                        #if rank == 0: print(k, kk[i], ik)
                        #ik = ik[0][0]
                        rcc = (rpfit[0]['power'][ik, :] /
                               (rpfit[1]['power'][ik, :] *
                                rpfit[2]['power'][ik, :])**0.5).real
                        axis.plot(mus,
                                  rcc,
                                  ls=lss,
                                  lw=2,
                                  color=cc,
                                  label=lbl,
                                  marker=mm)
                        if args.pp:
                            axis.text(0.7,
                                      0.41,
                                      r'$k = %.3f$' % (kk[i]),
                                      color='black',
                                      ha='left',
                                      va='bottom',
                                      fontdict=font)
                        else:
                            axis.text(0.75,
                                      0.15,
                                      r'$k = %.3f$' % (kk[i]),
                                      color='black',
                                      ha='left',
                                      va='bottom',
                                      fontdict=font)
                        amu = np.sin(angle * np.pi / 180.)
                        print(angle, amu)
                        axis.axvline(amu, color=cc, ls=lss, lw=1, alpha=0.5)
                except Exception as e:
                    if rank == 0: print(e)

    ##
    for axis in ax[:, 0]:
        axis.set_ylabel('$r_{cc}$', fontdict=font)
    for axis in ax[1]:
        axis.set_xlabel(r'$\mu$', fontdict=font)
    for axis in ax.flatten():
        axis.axhline(1, ls="--", color='k')
        axis.set_xlim(-0.05, 1.05)
        axis.grid(which='both', lw=0.2, alpha=0.2, color='gray')
        axis.legend(loc=3, prop=fontmanage)
        #axis.set_ylim(0.5, 1.05)
    # Put on some more labels.
    for axis in ax.flatten():
        for tick in axis.xaxis.get_major_ticks():
            tick.label.set_fontproperties(fontmanage)
        for tick in axis.yaxis.get_major_ticks():
            tick.label.set_fontproperties(fontmanage)
    ##and finish
    plt.tight_layout(rect=[0, 0, 1, 0.95])
    if rank == 0 and not args.pp:
        plt.savefig(figpath + '/rep2dmu_L%04d_mu%d.pdf' % (bs, Nmu))
    if rank == 0 and args.pp:
        plt.savefig(figpath + '/rep2dmu_L%04d_mu%d_up.pdf' % (bs, Nmu))
예제 #6
0
def make_rep_plot(Nmu=4, nx=2, ny=2):
    """Does the work of making the real-space xi(r) and b(r) figure."""

    mub = np.linspace(0, 1, Nmu + 1)
    linestyle = ['-', '--']
    colors = ['C0', 'C1', 'C2']
    fig, ax = plt.subplots(nx,
                           ny,
                           figsize=(ny * 3 + 2, nx * 3 + 0),
                           sharex=True,
                           sharey=True)
    for ia, aa in enumerate([0.3333, 0.2000, 0.1429]):
        zz = 1 / aa - 1
        for iw, wopt in enumerate(['opt', 'pess']):
            #for iw, wopt in enumerate(['opt']):
            lss = linestyle[iw]
            #for it, thopt in enumerate(['opt', 'pess', 'reas']):
            for it, thopt in enumerate(['reas']):
                if rank == 0: print(aa, wopt, thopt)
                cc = colors[ia]
                try:
                    angle = np.round(mapn.wedge(zz, att=wopt, angle=True), 0)
                    dpath = '/global/cscratch1/sd/chmodi/m3127/21cm_cleaning/recon/fastpm_%0.4f/wedge_kmin%0.2f_%s/' % (
                        aa, 0.03, wopt)
                    dpath += 'L%04d-N%04d-R//thermal-%s-hex/ZA/opt_s999_h1massA_fourier_rsdpos/' % (
                        bs, nc, thopt)
                    fname = './tmpdata/mapp%d-L%04d_%0.4f_kmin%0.2f_%s-th%shex' % (
                        Nmu, bs, aa, 0.03, wopt, thopt)
                    if args.pp: fname = fname[:] + '-up'
                    try:
                        rpfit = [{
                            'k': np.loadtxt(fname + '-k.txt'),
                            'power': np.loadtxt(fname + '-p%d.txt' % i)
                        } for i in range(3)]
                    except:
                        if args.pp:
                            datapp = mapp.Observable.load(dpath + '/datap_up')
                            bpaths = [
                                dpath + 'upsample2/%d-0.00//best-fit' % nc2
                            ] + [
                                dpath + 'upsample2/%d-0.00//%04d/fit_p/' %
                                (nc2, i) for i in range(100, 50, -20)
                            ]
                        else:
                            datapp = mapp.Observable.load(dpath + '/datap')
                            bpaths = [dpath + '%d-0.00//best-fit' % nc] + [
                                dpath + '%d-0.00//%04d/fit_p/' % (nc, i)
                                for i in range(100, 50, -20)
                            ]
                        for path in bpaths:
                            if os.path.isdir(path):
                                break
                        if rank == 0: print(path)
                        bfit = mapp.Observable.load(path)
                        rpfit = rp.evaluate2d1(bfit,
                                               datapp,
                                               Nmu=Nmu,
                                               field='mapp')
                        if rank == 0:
                            np.savetxt(fname + '-k.txt', rpfit[0]['k'])
                            for ip in range(3):
                                np.savetxt(fname + '-p%d.txt' % ip,
                                           rpfit[ip]['power'].real)

                    #
                    k = rpfit[0]['k'].mean(axis=1)
                    for i in range(Nmu):
                        axis = ax.flatten()[i]
                        if i == 0 and iw == 0:
                            lbl = 'z = %.1f' % (1 / aa - 1)
                        elif i == 1 and ia == 0:
                            lbl = 'Wedge = %s' % wopt
                        else:
                            lbl = None
                        rcc = rpfit[0]['power'][:, i] / (
                            rpfit[1]['power'][:, i] *
                            rpfit[2]['power'][:, i])**0.5
                        axis.plot(k, rcc, ls=lss, lw=2, color=cc, label=lbl)
                        if Nmu == 4:
                            axis.text(0.1,
                                      0.3,
                                      r'$\mu = %.2f-%.2f$' %
                                      (mub[i], mub[i + 1]),
                                      color='black',
                                      ha='left',
                                      va='bottom',
                                      fontdict=font)
                        #if Nmu == 8: axis.text(0.05, 0.41, r'$\mu = %.2f$'%mus[i],color='black',ha='left',va='bottom', fontdict=font)
                        if Nmu == 8:
                            axis.text(0.1,
                                      0.3,
                                      r'$\mu = %.2f-%.2f$' %
                                      (mub[i], mub[i + 1]),
                                      color='black',
                                      ha='left',
                                      va='bottom',
                                      fontdict=font)
                except Exception as e:
                    if rank == 0: print(e)

    ##
    for axis in ax[:, 0]:
        axis.set_ylabel('$r_{cc}$', fontdict=font)
    for axis in ax[1]:
        axis.set_xlabel(r'$k\quad [h\,{\rm Mpc}^{-1}]$', fontdict=font)
    for axis in ax.flatten():
        axis.set_xscale('log')
        axis.axhline(1, ls="--", color='k')
        axis.set_xlim(0.02, 1.1)
        axis.grid(which='both', lw=0.2, alpha=0.2, color='gray')
        axis.legend(loc='center left', prop=fontmanage)
        #axis.set_ylim(0.5, 1.05)
    # Put on some more labels.
    for axis in ax.flatten():
        for tick in axis.xaxis.get_major_ticks():
            tick.label.set_fontproperties(fontmanage)
        for tick in axis.yaxis.get_major_ticks():
            tick.label.set_fontproperties(fontmanage)
    ##and finish
    plt.tight_layout(rect=[0, 0, 1, 0.95])
    if rank == 0 and not args.pp:
        plt.savefig(figpath + '/rep2d_L%04d_mu%d.pdf' % (bs, Nmu))
    if rank == 0 and args.pp:
        plt.savefig(figpath + '/rep2d_L%04d_mu%d_up.pdf' % (bs, Nmu))
예제 #7
0
def make_rep_plot():
    """Does the work of making the real-space xi(r) and b(r) figure."""

    fig, axar = plt.subplots(1, 2, figsize=(9, 4), sharex=True)

    #fits
    linestyle = ['-', '--']
    colors = ['C%d' % i for i in range(7)]
    lww = 2

    wopt = 'opt'
    thopt = 'reas'
    lss = '-'
    for ia, aa in enumerate([0.2000]):
        zz = 1 / aa - 1
        for ik, kmin in enumerate([0.001, 0.01, 0.03, 0.05]):
            cc = colors[ik]
            angle = np.round(mapn.wedge(zz, att=wopt, angle=True), 0)
            #dpath = '/global/cscratch1/sd/chmodi/m3127/21cm_cleaning/recon/fastpm_%0.4f/wedge_kmin%0.2f_ang%0.1f/'%(aa, 0.03, angle)
            dpath = '/global/cscratch1/sd/chmodi/m3127/21cm_cleaning/recon/fastpm_%0.4f/wedge_kmin%0.2f_%s/' % (
                aa, kmin, wopt)
            dpath += 'L%04d-N%04d-R//thermal-%s-hex/ZA/opt_s999_h1massA_fourier_rsdpos/' % (
                bs, nc, thopt)
            datapp = mapp.Observable.load(dpath + '/datap')
            bpaths = [dpath + '%d-0.00//best-fit' % nc] + [
                dpath + '%d-0.00//%04d/fit_p/' % (nc, i)
                for i in range(100, 30, -20)
            ]
            for path in bpaths:
                if os.path.isdir(path):
                    break
            if rank == 0: print(path)
            bfit = mapp.Observable.load(path)
            rpfit = rp.evaluate1(bfit, datapp, field='mapp')[:-2]
            lbl = '$k_\parallel = %.2f$' % kmin
            axar[0].plot(rpfit[0]['k'],
                         rpfit[0]['power'] /
                         (rpfit[1]['power'] * rpfit[2]['power'])**0.5,
                         ls=lss,
                         lw=lww,
                         color=cc,
                         label=lbl)
            axar[1].plot(rpfit[0]['k'],
                         (rpfit[1]['power'] / rpfit[2]['power'])**0.5,
                         ls=lss,
                         lw=lww,
                         color=cc)

    ik += 1
    cc = colors[ik]
    dpath = '/global/cscratch1/sd/chmodi/m3127/21cm_cleaning/recon/fastpm_%0.4f/wedge_kmin%0.2f_ang%0.2f/' % (
        aa, 0, 0)
    dpath += 'L%04d-N%04d-R//thermal-%s-hex/ZA/opt_s999_h1massA_fourier_rsdpos/' % (
        bs, nc, thopt)
    datapp = mapp.Observable.load(dpath + '/datap')
    bpaths = [dpath + '%d-0.00//best-fit' % nc] + [
        dpath + '%d-0.00//%04d/fit_p/' % (nc, i) for i in range(100, 30, -20)
    ]
    for path in bpaths:
        if os.path.isdir(path):
            break
    if rank == 0: print(path)
    bfit = mapp.Observable.load(path)
    rpfit = rp.evaluate1(bfit, datapp, field='mapp')[:-2]
    lbl = 'All modes'
    axar[0].plot(rpfit[0]['k'],
                 rpfit[0]['power'] /
                 (rpfit[1]['power'] * rpfit[2]['power'])**0.5,
                 ls='--',
                 lw=lww,
                 color=cc,
                 label=lbl)
    axar[1].plot(rpfit[0]['k'], (rpfit[1]['power'] / rpfit[2]['power'])**0.5,
                 ls='--',
                 lw=lww,
                 color=cc)

    axis = axar[0]
    axis.set_ylabel('$r_{cc}$', fontdict=font)
    axis.set_ylim(-0.05, 1.1)
    #for axis in axar[:, 1]: axis.set_ylabel(r'$\sqrt{P_{\rm mod}/P_{hh}}$', fontdict=font)
    axis = axar[1]
    axis.set_ylabel(r'$T_f$', fontdict=font)
    axis.set_ylim(-0.05, 2)
    for axis in axar[:]:
        axis.set_xlabel(r'$k\quad [h\,{\rm Mpc}^{-1}]$', fontdict=font)
    for axis in axar.flatten():
        axis.axhline(1, color='k', ls=':')
        axis.set_xscale('log')
        axis.grid(which='both', lw=0.2, alpha=0.2, color='gray')
        axis.legend(prop=fontmanage)

    # Put on some more labels.
    for axis in axar.flatten():
        for tick in axis.xaxis.get_major_ticks():
            tick.label.set_fontproperties(fontmanage)
        for tick in axis.yaxis.get_major_ticks():
            tick.label.set_fontproperties(fontmanage)
    ##and finish
    plt.tight_layout(rect=[0, 0, 1, 0.95])
    if rank == 0: plt.savefig(figpath + '/kmin_L%04d-hex.pdf' % (bs))
예제 #8
0
def make_rep_plot(Nmu=4,):
    """Does the work of making the real-space xi(r) and b(r) figure."""
    

    mub = np.linspace(0, 1, Nmu+1)
    linestyle = ['-', '-.', ':', '--']
    colors = ['C0', 'C1', 'C2']
    fig, ax = plt.subplots(1, 3, figsize=(12, 4), sharex=True, sharey=True)
    for ia, aa  in enumerate([0.3333, 0.2000, 0.1429]):
        zz = 1/aa-1
        #for iw, wopt in enumerate(['opt', 'pess']):
        for iw, wopt in enumerate(['opt']):
            for it, thopt in enumerate(['opt', 'pess', 'reas']):
            #for it, thopt in enumerate([ 'reas']):
                if rank == 0: print(aa, wopt, thopt)
                cc = colors[it]
                try:
                    angle = np.round(mapn.wedge(zz, att=wopt, angle=True), 0)
                    dpath = '/global/cscratch1/sd/chmodi/m3127/21cm_cleaning/recon/fastpm_%0.4f/wedge_kmin%0.2f_%s/'%(aa, 0.03, wopt)
                    dpath += 'L%04d-N%04d-R//thermal-%s-hex/ZA/opt_s999_h1massA_fourier_rsdpos/'%(bs, nc, thopt)
                    ofolder = '../../data/ZArecon-rsd/kmin-003_wedge-%s/thermal-%s-hex/Nmu%d/'%(wopt, thopt, Nmu)
                    data = ofolder + 'dataw-L%04d_%0.4f.txt'%(bs, aa)
                    noise = ofolder + 'pnoise-L%04d_%0.4f.txt'%(bs, aa)
                    if args.pp : 
                        data = data[:-4] + '-up'
                        noise = noise[:-4] + '-up'
                    k = np.loadtxt(data+'-k.txt').T
                    dfit = np.loadtxt(data+'-pm2.txt').T
                    nfit = np.loadtxt(noise+'.txt').T
                    
                    for i in range(0, k.shape[0]):
                        lss = linestyle[i%len(linestyle)]
                        axis = ax.flatten()[ia]
                        if ia==2 and it==0:
                            lbl = r'$\mu = %.2f-%.2f$'%(mub[i], mub[i+1])                            
                        elif ia == 1 and i == 1:
                            if thopt == 'reas': thopt = 'fid'
                            lbl = 'Noise = %s'%thopt
                        else: lbl = None
                        axis.plot(k[i], dfit[i]/(dfit[i] + nfit[i]), ls=lss, lw=2, color=cc, label=lbl)
                        #axis.plot(k[i], nfit[i], ls=lss, lw=2, color=cc, label=lbl)
                        #axis.set_yscale('log')
                        #axis.set_ylim(10, 1e4)
                        #
                        axis.text(0.22, 0.0, 'z = %.1f'%(1/aa-1),color='black',ha='left',va='bottom', fontdict=font)


                except Exception as e: 
                    if rank == 0: print(e)


    ##
    ax[0].set_ylabel(r'$S/(S+N)$', fontdict=font)
    for axis in ax[:]: axis.set_xlabel(r'$k\quad [h\,{\rm Mpc}^{-1}]$', fontdict=font)
    for axis in ax.flatten():
        axis.axhline(1, ls="--", color='k')
        #axis.set_xscale('log')
        axis.set_xlim(0.008, 1.3)
        #axis.set_yscale('log')
        #axis.set_ylim(1e-3, 1.3)
        axis.grid(which='both', lw=0.2, alpha=0.2, color='gray')
        #axis.legend(loc='center left', prop=fontmanage)
        axis.legend(loc=0, prop=fontmanage)
    # Put on some more labels.
    for axis in ax.flatten():
        for tick in axis.xaxis.get_major_ticks():
            tick.label.set_fontproperties(fontmanage)
        for tick in axis.yaxis.get_major_ticks():
            tick.label.set_fontproperties(fontmanage)
    ##and finish
    plt.tight_layout(rect=[0, 0, 1, 0.95])
    if rank  == 0 and not args.pp:  plt.savefig(figpath + '/noise2d_L%04d_mu%d.pdf'%(bs, Nmu))
    if rank  == 0 and args.pp:  plt.savefig(figpath + '/noise2d_L%04d_mu%d_up.pdf'%(bs, Nmu))
    for axis in ax.flatten():
        axis.set_xscale('log')
    if rank  == 0 and not args.pp:  plt.savefig(figpath + '/noise2d_L%04d_mu%d_log.pdf'%(bs, Nmu))
    if rank  == 0 and args.pp:  plt.savefig(figpath + '/noise2d_L%04d_mu%d_up_log.pdf'%(bs, Nmu))
예제 #9
0
def save2dphoto(Nmu=4, numd=1e-2, aa=None, scatter=False):

    if numd > 1e-2:
        print('Too high number density')
        sys.exit()
    num = int(numd * bs**3)

    if aa is None: aas = [0.3333, 0.2000, 0.1429]
    else: aas = [aa]
    for ia, aa in enumerate(aas):
        zz = 1 / aa - 1
        sigz = lambda z: 120 * ((1 + z) / 5)**-0.5

        ##
        cat = BigFileCatalog(
            '/global/cscratch1/sd/chmodi/m3127/H1mass/highres/10240-9100/fastpm_%0.4f/Hcat-Numd-%04d/'
            % (aa, 1e-2 * 1e4))
        if scatter:
            pos = cat['Position'][:num].compute()
            dz = np.random.normal(0, sigz(zz), size=pos[:, -1].size)
            pos[:, -1] += dz
            layout = pm.decompose(pos)
            hmesh = pm.paint(pos, layout=layout)
        else:
            pos = cat['Position'][:num].compute()
            layout = pm.decompose(pos)
            hmesh = pm.paint(pos, layout=layout)

        def tf(k):  #Photoz smoothing
            kmesh = sum(ki**2 for ki in k)**0.5
            kmesh[kmesh == 0] = 1
            mumesh = k[2] / kmesh
            weights = np.exp(-kmesh**2 * mumesh**2 * sigz(zz)**2 / 2.)
            return weights

        hmesh /= hmesh.cmean()
        if not scatter:
            hmeshc = hmesh.r2c()
            hmeshc.apply(lambda k, v: nyquist_mask(tf(k), v) * v, out=Ellipsis)
            hmesh = hmeshc.c2r()
        ph = FFTPower(hmesh, mode='2d', Nmu=Nmu).power

        #
        for iw, wopt in enumerate(['opt', 'pess']):
            #for iw, wopt in enumerate(['opt']):
            for it, thopt in enumerate(['opt', 'pess', 'reas']):
                #for it, thopt in enumerate([ 'reas']):
                if rank == 0: print(aa, wopt, thopt)

                angle = np.round(mapn.wedge(zz, att=wopt, angle=True), 0)
                #dpath = '/global/cscratch1/sd/chmodi/m3127/21cm_cleaning/recon/fastpm_%0.4f/wedge_kmin%0.2f_ang%0.1f/'%(aa, 0.03, angle)
                dpath = '/global/cscratch1/sd/chmodi/m3127/21cm_cleaning/recon/fastpm_%0.4f/wedge_kmin%0.2f_%s/' % (
                    aa, 0.03, wopt)
                dpath += 'L%04d-N%04d-R//thermal-%s-hex/ZA/opt_s999_h1massA_fourier_rsdpos/' % (
                    bs, nc, thopt)
                if scatter:
                    ofolder = '../../data/ZArecon-rsd/kmin-003_wedge-%s/thermal-%s-hex/photog-Numd%04d-Nmu%d/' % (
                        wopt, thopt, numd * 1e4, Nmu)
                else:
                    ofolder = '../../data/ZArecon-rsd/kmin-003_wedge-%s/thermal-%s-hex/photo-Numd%04d-Nmu%d/' % (
                        wopt, thopt, numd * 1e4, Nmu)
                try:
                    os.makedirs(ofolder)
                except:
                    pass
                if rank == 0: print(ofolder)

                if args.pp:
                    datapp = BigFileMesh(dpath + '/dataw_up/', 'mapp').paint()
                    bpaths = [dpath + 'upsample2/%d-0.00//best-fit' % nc2] + [
                        dpath + 'upsample2/%d-0.00//%04d/fit_p/' % (nc2, i)
                        for i in range(100, 50, -20)
                    ]
                else:
                    datapp = BigFileMesh(dpath + '/dataw/', 'mapp').paint()
                    bpaths = [dpath + '%d-0.00//best-fit' % nc] + [
                        dpath + '%d-0.00//%04d/fit_p/' % (nc, i)
                        for i in range(100, 50, -20)
                    ]
                for path in bpaths:
                    if os.path.isdir(path):
                        break
                if rank == 0: print(path)
                bfit = BigFileMesh(path, 'mapp').paint()

                pxrh = FFTPower(hmesh, second=bfit, mode='2d', Nmu=Nmu).power
                pxwh = FFTPower(hmesh, second=datapp, mode='2d', Nmu=Nmu).power

                fname = ofolder + 'photo-L%04d_%0.4f.txt' % (bs, aa)
                if args.pp: fname = fname[:-4] + '-up.txt'
                np.savetxt(fname, ph['power'].real)

                fname = ofolder + 'xdataw-L%04d_%0.4f.txt' % (bs, aa)
                if args.pp: fname = fname[:-4] + '-up.txt'
                np.savetxt(fname, pxwh['power'].real)

                fname = ofolder + 'xrecon-L%04d_%0.4f.txt' % (bs, aa)
                if args.pp: fname = fname[:-4] + '-up.txt'
                np.savetxt(fname, pxrh['power'].real)
예제 #10
0
def make_rep_plot():
    """Does the work of making the real-space xi(r) and b(r) figure."""

    fig, axar = plt.subplots(3, 2, figsize=(9, 9), sharex=True)

    #fits
    linestyle = ['-', '--']
    colors = ['C0', 'C1', 'C2']
    lww = 2

    for ia, aa in enumerate([0.3333, 0.2000, 0.1429]):
        zz = 1 / aa - 1
        for iw, wopt in enumerate(['opt', 'pess']):
            lss = linestyle[iw]
            for it, thopt in enumerate(['opt', 'pess', 'reas']):
                if rank == 0: print(aa, wopt, thopt)
                cc = colors[it]
                ax = axar[ia]
                try:
                    angle = np.round(mapn.wedge(zz, att=wopt, angle=True), 0)
                    #dpath = '/global/cscratch1/sd/chmodi/m3127/21cm_cleaning/recon/fastpm_%0.4f/wedge_kmin%0.2f_ang%0.1f/'%(aa, 0.03, angle)
                    dpath = '/global/cscratch1/sd/chmodi/m3127/21cm_cleaning/recon/fastpm_%0.4f/wedge_kmin%0.2f_%s/' % (
                        aa, 0.03, wopt)
                    dpath += 'L%04d-N%04d-R//thermal-%s-hex/ZA/opt_s999_h1massA_fourier_rsdpos/' % (
                        bs, nc, thopt)
                    fname = './tmpdata/mapp-L%04d_%0.4f_kmin%0.2f_%s-th%shex.txt' % (
                        bs, aa, 0.03, wopt, thopt)
                    if args.pp: fname = fname[:-4] + '-up.txt'
                    try:
                        rep = np.loadtxt(fname).T
                        rpfit = [{
                            'k': rep[0],
                            'power': rep[i + 1]
                        } for i in range(3)]
                    except:
                        if args.pp:
                            datapp = mapp.Observable.load(dpath + '/datap_up')
                            bpaths = [
                                dpath + 'upsample2/%d-0.00//best-fit' % nc2
                            ] + [
                                dpath + 'upsample2/%d-0.00//%04d/fit_p/' %
                                (nc2, i) for i in range(100, 50, -20)
                            ]
                        else:
                            datapp = mapp.Observable.load(dpath + '/datap')
                            bpaths = [dpath + '%d-0.00//best-fit' % nc] + [
                                dpath + '%d-0.00//%04d/fit_p/' % (nc, i)
                                for i in range(100, 50, -20)
                            ]
                        for path in bpaths:
                            if os.path.isdir(path):
                                break
                        if rank == 0: print(path)
                        bfit = mapp.Observable.load(path)
                        #bfit = mapp.Observable.load(dpath+'ZA/opt_s999_h1massA_fourier_rsdpos/best-fit/')
                        rpfit = rp.evaluate1(bfit, datapp, field='mapp')[:-2]
                        if rank == 0:
                            np.savetxt(fname,
                                       np.stack([rpfit[0]['k']] + [
                                           rpfit[i]['power'].real
                                           for i in range(len(rpfit))
                                       ]).T,
                                       header='k, pr, pd, px')

                    if ia == 0 and iw == 0:
                        if thopt == 'reas': thopt = 'fid'
                        lbl = 'Noise - %s' % thopt
                    elif ia == 1 and it == 0:
                        lbl = 'Wedge = %s' % wopt
                    else:
                        lbl = None
                    ax[0].plot(rpfit[0]['k'],
                               rpfit[0]['power'] /
                               (rpfit[1]['power'] * rpfit[2]['power'])**0.5,
                               ls=lss,
                               lw=lww,
                               color=cc,
                               label=lbl)
                    ax[1].plot(rpfit[0]['k'],
                               (rpfit[1]['power'] / rpfit[2]['power'])**0.5,
                               ls=lss,
                               lw=lww,
                               color=cc)
                    ax[1].text(0.02,
                               2,
                               r'$z = %.2f$' % zz,
                               color='black',
                               ha='left',
                               va='bottom',
                               fontdict=font)
                except Exception as e:
                    if rank == 0: print(e)

    for axis in axar[:, 0]:
        axis.set_ylabel('$r_{cc}$', fontdict=font)
        axis.set_ylim(-0.05, 1.1)
    #for axis in axar[:, 1]: axis.set_ylabel(r'$\sqrt{P_{\rm mod}/P_{hh}}$', fontdict=font)
    for axis in axar[:, 1]:
        axis.set_ylabel(r'$T_f$', fontdict=font)
        axis.set_ylim(-0.05, 3)
    for axis in axar[2, :]:
        axis.set_xlabel(r'$k\quad [h\,{\rm Mpc}^{-1}]$', fontdict=font)
    for axis in axar.flatten():
        axis.axhline(1, color='k', ls=':')
        axis.set_xscale('log')
        axis.grid(which='both', lw=0.2, alpha=0.2, color='gray')
        axis.legend(prop=fontmanage)

    # Put on some more labels.
    for axis in axar.flatten():
        for tick in axis.xaxis.get_major_ticks():
            tick.label.set_fontproperties(fontmanage)
        for tick in axis.yaxis.get_major_ticks():
            tick.label.set_fontproperties(fontmanage)
    ##and finish
    plt.tight_layout(rect=[0, 0, 1, 0.95])
    if rank == 0 and not args.pp:
        plt.savefig(figpath + '/allcompare_L%04d-hex.pdf' % (bs))
    if rank == 0 and args.pp:
        plt.savefig(figpath + '/allcompare_L%04d-hexup.pdf' % (bs))
예제 #11
0
def make_repwd_plot():
    """Does the work of making the real-space xi(r) and b(r) figure."""

    for ia, aa in enumerate([0.3333, 0.2000, 0.1429]):
        zz = 1 / aa - 1
        for iw, wopt in enumerate(['opt', 'pess']):
            for it, thopt in enumerate(['opt', 'pess', 'reas']):
                if rank == 0: print(aa, wopt, thopt)

                angle = np.round(mapn.wedge(zz, att=wopt, angle=True), 0)
                #dpath = '/global/cscratch1/sd/chmodi/m3127/21cm_cleaning/recon/fastpm_%0.4f/wedge_kmin%0.2f_ang%0.1f/'%(aa, 0.03, angle)
                dpath = '/global/cscratch1/sd/chmodi/m3127/21cm_cleaning/recon/fastpm_%0.4f/wedge_kmin%0.2f_%s/' % (
                    aa, 0.03, wopt)
                dpath += 'L%04d-N%04d-R//thermal-%s-hex/ZA/opt_s999_h1massA_fourier_rsdpos/' % (
                    bs, nc, thopt)
                ofolder = '../../data/ZArecon-rsd/kmin-003_wedge-%s/thermal-%s-hex/' % (
                    wopt, thopt)
                try:
                    os.makedirs(ofolder)
                except:
                    pass
                fname = ofolder + 'recon-L%04d_%0.4f.txt' % (bs, aa)
                if args.pp: fname = fname[:-4] + '-up.txt'
                header = 'k, xm.power, xs.power, xd.power,  pm1.power, pm2.power, ps1.power, ps2.power, pd1.power, pd2.power'
                try:
                    rep = np.loadtxt(fname).T
                    rpfit = [{
                        'k': rep[0],
                        'power': rep[i + 1]
                    } for i in range(3)]
                except:
                    if args.pp:
                        datapp = mapp.Observable.load(dpath + '/datap_up')
                        bpaths = [
                            dpath + 'upsample2/%d-0.00//best-fit' % nc2
                        ] + [
                            dpath + 'upsample2/%d-0.00//%04d/fit_p/' % (nc2, i)
                            for i in range(100, 50, -20)
                        ]
                    else:
                        datapp = mapp.Observable.load(dpath + '/datap')
                        bpaths = [dpath + '%d-0.00//best-fit' % nc] + [
                            dpath + '%d-0.00//%04d/fit_p/' % (nc, i)
                            for i in range(100, 50, -20)
                        ]
                    for path in bpaths:
                        if os.path.isdir(path):
                            break
                    if rank == 0: print(path)
                    bfit = mapp.Observable.load(path)
                    #bfit = mapp.Observable.load(dpath+'ZA/opt_s999_h1massA_fourier_rsdpos/best-fit/')
                    rpfit = rp.evaluate(bfit, datapp)[:-2]
                    if rank == 0:
                        np.savetxt(fname,
                                   np.stack([rpfit[0]['k']] + [
                                       rpfit[i]['power'].real
                                       for i in range(len(rpfit))
                                   ]).T,
                                   header=header)

                fname = ofolder + 'dataw-L%04d_%0.4f.txt' % (bs, aa)
                if args.pp: fname = fname[:-4] + '-up.txt'
                try:
                    rep = np.loadtxt(fname).T
                    rpfit = [{
                        'k': rep[0],
                        'power': rep[i + 1]
                    } for i in range(3)]
                except:
                    if args.pp:
                        datapp = mapp.Observable.load(dpath + '/datap_up')
                        bfit = mapp.Observable.load(dpath + '/dataw_up')
                    else:
                        datapp = mapp.Observable.load(dpath + '/datap')
                        bfit = mapp.Observable.load(dpath + '/dataw')
                    #bfit = mapp.Observable.load(dpath+'ZA/opt_s999_h1massA_fourier_rsdpos/best-fit/')
                    rpfit = rp.evaluate(bfit, datapp)[:-2]
                    if rank == 0:
                        np.savetxt(fname,
                                   np.stack([rpfit[0]['k']] + [
                                       rpfit[i]['power'].real
                                       for i in range(len(rpfit))
                                   ]).T,
                                   header=header)