Esempio n. 1
0
def plt_linear(infile, outfile, datadir=""):

    pp = PdfPages(outfile)

    ### data
    hyper = np.loadtxt(infile + "hyper.out")
    loglike = np.loadtxt(infile + "loglike.out")
    repeat = np.loadtxt(infile + "repeat.out")

    ### split data
    c0 = hyper[:, 0]
    slope = hyper[:, 1:5]
    sigma = hyper[:, 5:9]
    trans = hyper[:, 9:12]

    ### plot
    plt.clf()

    row = 2
    col = 4

    f, ((a00, a01, a02, a03), (a10, a11, a12, a13)) = plt.subplots(row, col, figsize=(col * 5, row * 5))
    ax = ((a00, a01, a02, a03), (a10, a11, a12, a13))

    # repeat
    ax[0][0].plot(repeat)
    ax[0][0].set_yscale("log")
    ax[0][0].set_xlabel("repeat")

    # loglike
    ax[0][1].plot(loglike)
    ax[0][1].set_xlabel("L")

    # loglike
    ax[0][2].plot(range(len(loglike) / 2, len(loglike)), loglike[len(loglike) / 2 :])
    ax[0][1].set_xlabel("L")

    # over plot
    dat = convert_data(np.loadtxt(datadir + "PlanetGroup.txt"))
    ax[0][3].errorbar(dat[:, 0], dat[:, 2], xerr=dat[:, 1], yerr=dat[:, 3], fmt=".")

    best_ind = np.argmax(loglike)
    hyper_best = hyper[best_ind, :]
    trans_best = hyper_best[-3:]
    print 10.0 ** trans_best
    m_sample = np.linspace(np.min(dat[:, 0]), np.max(dat[:, 0]), 1000)
    r_sample = piece_linear(hyper_best, m_sample, prob_R=0.5 * np.ones_like(m_sample))
    # r_upper = piece_linear(hyper_best, m_sample, prob_R = 0.84 * np.ones_like(m_sample))
    # r_lower = piece_linear(hyper_best, m_sample, prob_R = 0.16 * np.ones_like(m_sample))
    r_upper = piece_linear_complex(hyper_best, m_sample, prob_R=0.84 * np.ones_like(m_sample))
    r_lower = piece_linear_complex(hyper_best, m_sample, prob_R=0.16 * np.ones_like(m_sample))

    ax[0][3].plot(m_sample, r_sample, "r-")
    ax[0][3].fill_between(m_sample, r_lower, r_upper, color="grey", alpha=0.2)

    r_trans = piece_linear(hyper_best, trans_best, prob_R=0.5 * np.ones_like(trans_best))
    ax[0][3].plot(trans_best, r_trans, "rx")

    ax[0][3].set_xlabel(r"log10(M [M$_\oplus$])")
    ax[0][3].set_ylabel(r"log10(R [R$_\oplus$])")

    # C
    ax[1][0].plot(c0)
    ax[1][0].set_xlabel("c0")
    ax[1][0].set_ylim([-1, 1])

    # slope
    for i in range(4):
        ax[1][1].plot(slope[:, i])
    ax[1][1].set_xlabel("slope")

    # sigma
    for i in range(4):
        ax[1][2].plot(sigma[:, i])
    ax[1][2].set_yscale("log")
    ax[1][2].set_xlabel("sigma")
    ax[1][2].set_ylim([1e-3, 1e0])

    # transition
    for i in range(3):
        ax[1][3].plot(trans[:, i])
    ax[1][3].set_xlabel("transition")
    ax[1][3].set_ylim([-4, 6])

    pp.savefig()
    pp.close()

    return None
Esempio n. 2
0
r2m_r2 = np.log10(Mpost2R(10.**r2m_m))

### mass histogram
nbin=10
ax1.hist(m2r_m2, fc='r', ec='r', alpha=0.3, bins=nbin)
ax1.hist(m2r_m,fc='b', bins=nbin, label=['M -> R -> M'])
ax1.hist(r2m_m,fc='g', bins=nbin, label=['R -> M'])
ax1.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)

### model
from func import piece_linear, piece_linear_complex
best_hyper = np.loadtxt('spatial_median.txt', delimiter=',')

m_sample = np.linspace( -3.9, 5.5, 1000 )
r_sample = piece_linear(best_hyper, m_sample, prob_R = 0.5*np.ones_like(m_sample))
r_upper = piece_linear_complex(best_hyper, m_sample, prob_R = 0.84 * np.ones_like(m_sample))
r_lower = piece_linear_complex(best_hyper, m_sample, prob_R = 0.16 * np.ones_like(m_sample))
r_2upper = piece_linear_complex(best_hyper, m_sample, prob_R = 0.975 * np.ones_like(m_sample))
r_2lower = piece_linear_complex(best_hyper, m_sample, prob_R = 0.025 * np.ones_like(m_sample))

ax2.plot(m_sample, r_sample, 'r-')
ax2.fill_between(m_sample, r_lower, r_upper, color='grey', alpha=0.6)
ax2.fill_between(m_sample, r_2lower, r_2upper, color='grey', alpha=0.4)

ax2.set_xlabel(r'$\rm log_{10}\ M/M_\oplus$')
ax2.set_ylabel(r'$\rm log_{10}\ R/R_\oplus$')

### radius histogram
ax3.hist(m2r_r,fc='b', orientation='horizontal', bins=nbin)
ax3.hist(r2m_r,fc='g', orientation='horizontal', bins=nbin)
#ax3.hist(r2m_r2, fc='r', ec='r', alpha=0.3, bins=nbin)