Пример #1
0
from matplotlib.backends.backend_pdf import PdfPages
pp = PdfPages('plt_overlay.pdf')

### log-log data
data_dir = '/Users/jingjing/Work/DK_project/Data/Mine/'
dwarfplanet, exoplanet, browndwarf, star = \
np.loadtxt(data_dir+'dpl.txt'), \
np.loadtxt(data_dir+'epl.txt'), \
np.loadtxt(data_dir+'bd.txt'), \
np.loadtxt(data_dir+'st.txt')

data = [dwarfplanet, exoplanet, browndwarf, star]

### solar planets
# Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune
solarplanet = convert_data( np.loadtxt(data_dir+'spl.txt') )


### mcmc result, spatial_median and trans_1up/down

best_hyper = np.loadtxt('h4_spatial_median.txt', delimiter=',')
trans_best = best_hyper[-3:]
slope_best = best_hyper[1:5]
# find_best.py with spatial_median.txt and find trans_1up/down
trans_1up = trans_best + np.array([0.1245372 , 0.0534476 ,  0.04035559])
trans_1down = trans_best - np.array([0.14317994, 0.06079727,  0.03514506 ])


# convert trans best
mearth2mjup = 317.828
mearth2msun = 333060.4
Пример #2
0
pid = os.getpid()
np.random.seed(pid)
print 'input', input
print 'output', dir
print 'top', top
print 'random seed', pid

### fix the number of different populations
n_pop = 4

### data
#file = '/Users/jingjing/Work/DK_project/Data/Mine/PlanetGroup.txt'
file = 'PlanetGroup.txt'
dat = np.loadtxt(file)
m_exact = (dat[:,1]==0.)
dat_fixm = convert_data(dat[m_exact]) 
M0 = dat_fixm[:,0]
dat_varm = convert_data(dat[~m_exact]) 


### some static parameter 
n_fixm = np.shape(dat_fixm)[0]
n_varm = np.shape(dat_varm)[0]


### inverse sampling
def inverse_hyper(hyper_prob):
	prob_C0, prob_slope, prob_sigma, prob_trans = \
	hyper_prob[0], hyper_prob[1:1+n_pop], hyper_prob[1+n_pop:1+2*n_pop], hyper_prob[1+2*n_pop:3*n_pop]
	
	C0 = uniform.ppf(prob_C0,-1.,2.)
Пример #3
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