Esempio n. 1
0
 def makeplot(bfit, datapp, lss, lww, cc, lbl=None):
     rpfit = rp.evaluate1(bfit, datapp, field='mapp')[:-2]
     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)
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))
Esempio n. 3
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))
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))