Ejemplo n.º 1
0
def test_GTC_truthLineStyles():
    truthLineStyles = ['-', '-']
    truths = ((4, .5, None, .1), (None, None, .3, 1))
    pygtc.plotGTC(chains=[SAMPLES_1, SAMPLES_2],
                  truths=truths,
                  truthLineStyles=truthLineStyles,
                  smoothingKernel=0)
Ejemplo n.º 2
0
def test_GTC_smoothingKernel():
    if not HAS_SCIPY:
        warnings.warn("Can't test smoothing without scipy. Skipping test.", UserWarning)
        raise nose.SkipTest

    pygtc.plotGTC(chains=[SAMPLES_1,SAMPLES_2],
                    smoothingKernel = 2)
Ejemplo n.º 3
0
def test_GTC_smoothingKernel():
    if not HAS_SCIPY:
        warnings.warn("Can't test smoothing without scipy. Skipping test.",
                      UserWarning)
        raise nose.SkipTest

    pygtc.plotGTC(chains=[SAMPLES_1, SAMPLES_2], smoothingKernel=2)
Ejemplo n.º 4
0
def test_GTC_truthLabels_withTex():
    truths = ((4, .5, None, .1), (None, None, .3, 1))
    truthLabelsWithTex = ('the truth $f_0$', 'alternative truth $\\lambda$')
    pygtc.plotGTC(chains=[SAMPLES_1, SAMPLES_2],
                  truths=truths,
                  truthLabels=truthLabelsWithTex,
                  smoothingKernel=0)
Ejemplo n.º 5
0
def test_GTC_truthLabels_noTex():
    truths = ((4, .5, None, .1), (None, None, .3, 1))
    truthLabelsNoTex = ('the truth', 'alternative truth')
    pygtc.plotGTC(chains=[SAMPLES_1, SAMPLES_2],
                  truths=truths,
                  truthLabels=truthLabelsNoTex,
                  smoothingKernel=0)
Ejemplo n.º 6
0
def test_GTC_paramNames_withTex():
    namesWithTex = [
        'param name', '$B_\mathrm{\lambda}$', '$Q^a$', '$\\lambda$'
    ]
    pygtc.plotGTC(chains=[SAMPLES_1, SAMPLES_2],
                  paramNames=namesWithTex,
                  smoothingKernel=0)
Ejemplo n.º 7
0
def test_GTC_truthLineStyles():
    truthLineStyles = ['-', '-']
    truths = ((4, .5, None, .1),
                (None, None, .3, 1))
    pygtc.plotGTC(chains=[SAMPLES_1,SAMPLES_2],
                    truths = truths,
                    truthLineStyles = truthLineStyles,
                    smoothingKernel = 0)
Ejemplo n.º 8
0
def test_GTC_truthLabels_withTex():
    truths = ((4, .5, None, .1),
                (None, None, .3, 1))
    truthLabelsWithTex = ('the truth $f_0$', 'alternative truth $\\lambda$')
    pygtc.plotGTC(chains=[SAMPLES_1,SAMPLES_2],
                    truths = truths,
                    truthLabels = truthLabelsWithTex,
                    smoothingKernel = 0)
Ejemplo n.º 9
0
def test_GTC_truthLabels_noTex():
    truths = ((4, .5, None, .1),
                (None, None, .3, 1))
    truthLabelsNoTex = ('the truth', 'alternative truth')
    pygtc.plotGTC(chains=[SAMPLES_1,SAMPLES_2],
                    truths = truths,
                    truthLabels = truthLabelsNoTex,
                    smoothingKernel = 0)
Ejemplo n.º 10
0
def test_GTC_priors():
    if not HAS_SCIPY:
        warnings.warn("Can't test priors without scipy installed. Skipping test.", UserWarning)
        raise nose.SkipTest

    priors = (None, (2, 1), (.5, 2), ())
    pygtc.plotGTC(chains=[SAMPLES_1,SAMPLES_2],
                    priors = priors,
                    smoothingKernel = 0)
Ejemplo n.º 11
0
def test_GTC_priors():
    if not HAS_SCIPY:
        warnings.warn(
            "Can't test priors without scipy installed. Skipping test.",
            UserWarning)
        raise nose.SkipTest

    priors = (None, (2, 1), (.5, 2), ())
    pygtc.plotGTC(chains=[SAMPLES_1, SAMPLES_2],
                  priors=priors,
                  smoothingKernel=0)
Ejemplo n.º 12
0
def test_GTC_pandas():
    namesNoTex = ['param name', 'B_labmda', 'C', 'lambda']

    if HAS_PANDAS:
        samples1_pd = pd.DataFrame(SAMPLES_1, columns=namesNoTex)
        samples2_pd = pd.DataFrame(SAMPLES_2, columns=namesNoTex)

    else:
        warnings.warn("Can't test pandas auto-name without pandas. Skipping test.", UserWarning)
        raise nose.SkipTest

    pygtc.plotGTC(chains=[samples1_pd,samples2_pd],
                    smoothingKernel = 0)
Ejemplo n.º 13
0
def test_GTC_pandas():
    namesNoTex = ['param name', 'B_labmda', 'C', 'lambda']

    if HAS_PANDAS:
        samples1_pd = pd.DataFrame(SAMPLES_1, columns=namesNoTex)
        samples2_pd = pd.DataFrame(SAMPLES_2, columns=namesNoTex)

    else:
        warnings.warn(
            "Can't test pandas auto-name without pandas. Skipping test.",
            UserWarning)
        raise nose.SkipTest

    pygtc.plotGTC(chains=[samples1_pd, samples2_pd], smoothingKernel=0)
Ejemplo n.º 14
0
def SamplePosterior(filebasename, showplots):
    #print(np.exp(gp.kernel.vector))
    #obsll= lambda *args: -lnlike(*args)
    #results=op.minimize(obsll,[fixx1v,fixx2v,fixx3v,fixx4v])
    #print(results.x)
    #exit()
    sampler = emcee.EnsembleSampler(nwalkers, ndim, obslnprob)
    #p0 = [results.x + 1e-4 * np.random.randn(ndim)
    #      for i in range(nwalkers)]
    p0 = [[fixx1v, fixx2v, fixx3v, fixx4v] + 1e-4 * np.random.randn(ndim)
          for i in range(nwalkers)]
    #print p0,obslnprob(p0[0],y)
    print("Running burn-in")
    p0, _, _ = sampler.run_mcmc(p0, nburnin)
    print("Running production chain")
    sampler.run_mcmc(p0, nproduction)
    samples = sampler.flatchain
    g4.create_dataset('posterior samples', data=samples)
    labels = [r"$x_1$", r"$x_2$", r"$x_3$", r"$x_4$"]
    #fig = triangle.corner(samples[:, 2:], labels=labels)
    #print np.array(samples)
    #fig = triangle.corner(np.array(samples), bins=100, labels=labels)
    nburn = nburnin * nwalkers
    fig = pygtc.plotGTC(chains=[samples[nburn:, :]])
    fig.savefig("%s_Triangle.png" % (filebasename), dpi=150)
    if showplots:
        fig.show()
Ejemplo n.º 15
0
def test_GTC_priors():
    if not HAS_SCIPY:
        pytest.skip("Can't test priors without scipy installed.")

    priors = (None, (2, 1), (.5, 2), ())
    return pygtc.plotGTC(chains=[SAMPLES_1, SAMPLES_2],
                         priors=priors,
                         smoothingKernel=0)
Ejemplo n.º 16
0
def test_GTC_mathTextFontSet():
    namesWithTex = [
        'param name', '$B_\\mathrm{\\lambda}$', '$Q^a$', '$\\lambda$'
    ]
    return pygtc.plotGTC(chains=[SAMPLES_1, SAMPLES_2],
                         paramNames=namesWithTex,
                         mathTextFontSet=None,
                         smoothingKernel=0)
Ejemplo n.º 17
0
def test_GTC_doOnly1dPlot():
    input_chains = [
        np.array([SAMPLES_1[:, 0]]).T,
        np.array([SAMPLES_2[:, 0]]).T
    ]
    return pygtc.plotGTC(chains=input_chains,
                         doOnly1dPlot=True,
                         smoothingKernel=0)
Ejemplo n.º 18
0
    def plot_gtc(self, resObj, chains):
        #Plot the triangle plot, and overlay the best fit values with dashed black lines (default)
        #You can see that the least-squares fitter did a very nice job of getting the values right

        #You can also see that there is some strange non-gaussian parameter space that the MCMC
        #analysis maps out! This is kind of wierd, but not too worrisome. It is probably suggestive
        #that more care is needed in choosing good options for the MCMC engine.

        figGTC = pygtc.plotGTC(chains, truths=[resObj.lmfit_vals])
        plt.show()
Ejemplo n.º 19
0
def test_GTC_pandas():
    namesNoTex = ['param name', 'B_labmda', 'C', 'lambda']

    if HAS_PANDAS:
        samples1_pd = pd.DataFrame(SAMPLES_1, columns=namesNoTex)
        samples2_pd = pd.DataFrame(SAMPLES_2, columns=namesNoTex)
    else:
        pytest.skip("Can't test pandas auto-name without pandas.")

    return pygtc.plotGTC(chains=[samples1_pd, samples2_pd], smoothingKernel=0)
Ejemplo n.º 20
0
def test_GTC_figureSize():
    pygtc.plotGTC(chains=[SAMPLES_1,SAMPLES_2],
                    figureSize = 'APJ_page',
                    smoothingKernel = 0)
Ejemplo n.º 21
0
def test_GTC_do1dPlots():
    return pygtc.plotGTC(chains=[SAMPLES_1, SAMPLES_2],
                         do1dPlots=False,
                         smoothingKernel=0)
Ejemplo n.º 22
0
def test_GTC_tickShifts():
    return pygtc.plotGTC(chains=[SAMPLES_1, SAMPLES_2],
                         tickShifts=(0.2, 0.2),
                         smoothingKernel=0)
Ejemplo n.º 23
0
def test_GTC_panelSpacing():
    return pygtc.plotGTC(chains=[SAMPLES_1, SAMPLES_2],
                         panelSpacing='loose',
                         smoothingKernel=0)
Ejemplo n.º 24
0
def test_GTC_plotDensity():
    return pygtc.plotGTC(chains=[SAMPLES_1, SAMPLES_2],
                         plotDensity=True,
                         smoothingKernel=0)
Ejemplo n.º 25
0
def test_GTC_nBins():
    return pygtc.plotGTC(chains=[SAMPLES_1, SAMPLES_2],
                         nBins=20,
                         smoothingKernel=0)
Ejemplo n.º 26
0
def test_GTC_nContourLevels():
    return pygtc.plotGTC(chains=[SAMPLES_1, SAMPLES_2],
                         nContourLevels=3,
                         smoothingKernel=0)
Ejemplo n.º 27
0
def test_GTC_sigmaContourLevels():
    pygtc.plotGTC(chains=[SAMPLES_1,SAMPLES_2],
                    sigmaContourLevels = True,
                    smoothingKernel = 0)
Ejemplo n.º 28
0
def test_GTC_colorsOrder():
    pygtc.plotGTC(chains=[SAMPLES_1,SAMPLES_2],
                    colorsOrder = ['purples', 'yellows'],
                    smoothingKernel = 0)
Ejemplo n.º 29
0
def test_GTC_nBins():
    pygtc.plotGTC(chains=[SAMPLES_1,SAMPLES_2],
                    nBins = 20,
                    smoothingKernel = 0)
Ejemplo n.º 30
0
def test_GTC_tickShifts():
    pygtc.plotGTC(chains=[SAMPLES_1,SAMPLES_2],
                    tickShifts = (0.2, 0.2),
                    smoothingKernel = 0)
Ejemplo n.º 31
0
def test_GTC_labelRotation():
    pygtc.plotGTC(chains=[SAMPLES_1,SAMPLES_2],
                    labelRotation = (False, False),
                    smoothingKernel = 0)
Ejemplo n.º 32
0
def test_GTC_panelSpacing():
    pygtc.plotGTC(chains=[SAMPLES_1,SAMPLES_2],
                    panelSpacing = 'loose',
                    smoothingKernel = 0)
Ejemplo n.º 33
0
def test_GTC_chainLabels_withTex():
    chainLabelsWithTex = ['data1 $\\lambda$', 'data 2']
    return pygtc.plotGTC(chains=[SAMPLES_1, SAMPLES_2],
                         chainLabels=chainLabelsWithTex,
                         smoothingKernel=0)
Ejemplo n.º 34
0
def test_GTC_nContourLevels():
    pygtc.plotGTC(chains=[SAMPLES_1,SAMPLES_2],
                    nContourLevels = 3,
                    smoothingKernel = 0)
Ejemplo n.º 35
0
def test_GTC_chainLabels_noTex():
    chainLabelsNoTex = ['data1', 'data 2']
    pygtc.plotGTC(chains=[SAMPLES_1,SAMPLES_2],
                    chainLabels = chainLabelsNoTex,
                    smoothingKernel = 0)
Ejemplo n.º 36
0
def test_GTC_paramNames_noTex():
    namesNoTex = ['param name', 'B_labmda', 'C', 'lambda']
    pygtc.plotGTC(chains=[SAMPLES_1,SAMPLES_2],
                    paramNames = namesNoTex,
                    smoothingKernel = 0)
Ejemplo n.º 37
0
def test_GTC_sigmaContourLevels():
    return pygtc.plotGTC(chains=[SAMPLES_1, SAMPLES_2],
                         sigmaContourLevels=True,
                         smoothingKernel=0)
Ejemplo n.º 38
0
def test_GTC_paramNames_withTex():
    namesWithTex = ['param name', '$B_\mathrm{\lambda}$', '$Q^a$', '$\\lambda$']
    pygtc.plotGTC(chains=[SAMPLES_1,SAMPLES_2],
                    paramNames = namesWithTex,
                    smoothingKernel = 0)
Ejemplo n.º 39
0
def test_GTC_smoothingKernel():
    if not HAS_SCIPY:
        pytest.skip("Can't test smoothing without scipy.")

    return pygtc.plotGTC(chains=[SAMPLES_1, SAMPLES_2], smoothingKernel=2)
Ejemplo n.º 40
0
def test_GTC_chainLabels_withTex():
    chainLabelsWithTex = ['data1 $\lambda$', 'data 2']
    pygtc.plotGTC(chains=[SAMPLES_1,SAMPLES_2],
                    chainLabels = chainLabelsWithTex,
                    smoothingKernel = 0)
Ejemplo n.º 41
0
def test_GTC_figureSize():
    return pygtc.plotGTC(chains=[SAMPLES_1, SAMPLES_2],
                         figureSize='APJ_page',
                         smoothingKernel=0)
Ejemplo n.º 42
0

####### CORNER PLOT ESTIMATES #######################################


import corner

fig = corner.corner(samples_plot, labels=[param1[0], param2[0]],
                      truths=[param1[1], param2[1]])
fig.savefig('corner_'+fileOut+'.png')



import pygtc
fig = pygtc.plotGTC(samples_plot, paramNames=[param1[0], param2[0]], truths=[ param1[1],
                                                                             param2[1]] ,
                    figureSize='MNRAS_page' )
fig.savefig('pygtc_'+fileOut+'.png')



####### FINAL PARAMETER ESTIMATES #######################################
#
# plt.figure(1432)
#
# xl = np.array([0, 10])
# for m, b, lnf in samples[np.random.randint(len(samples), size=100)]:
#     plt.plot(xl, m*xl+b, color="k", alpha=0.1)
# plt.plot(xl, m_true*xl+b_true, color="r", lw=2, alpha=0.8)
# plt.errorbar(x, y, yerr=yerr, fmt=".k", alpha=0.1)
Ejemplo n.º 43
0
def test_GTC_labelRotation():
    return pygtc.plotGTC(chains=[SAMPLES_1, SAMPLES_2],
                         labelRotation=(False, False),
                         smoothingKernel=0)
Ejemplo n.º 44
0
plt.tight_layout()

if bayesian_model == 'multinest':
    plt.savefig('multinest_best_fit_{}.png'.format(time_stamp))
if bayesian_model == 'emcee':
    plt.savefig('emcee_best_fit_{}walkers_{}steps_{}.png'.format(nwalkers, nsteps, time_stamp))

res_flatchain_df = DataFrame(result.samples, columns=fit_info.fit_param_names)

if 'Rs' in fit_info.fit_param_names: res_flatchain_df['Rs'] = res_flatchain_df['Rs'] / R_sun
if 'Rp' in fit_info.fit_param_names: res_flatchain_df['Rp'] = res_flatchain_df['Rp'] / R_jup
if 'Mp' in fit_info.fit_param_names: res_flatchain_df['Mp'] = res_flatchain_df['Mp'] / M_jup

plt.rcParams['figure.dpi'] = 150
plt.rcParams['figure.figsize'] = (10,10)

fit_param_names = ['Rs [Rsun]', 'Mp [Mjup]', 'Rp [Rjup]', 'T [K]', 'log(haze)', 'logZ [FeH]', 'log(P_c) [mbar]', 'err_mod']

pygtc_out = plotGTC(res_flatchain_df.values, 
                    weights=result.weights,
                    nContourLevels=3, 
                    paramNames=fit_param_names,
                    # range=[0.99] * result.flatchain.shape[1],
                    # chainLabels=['Not Cheap', 'Cheap'],
                    customLabelFont={'size':10},
                    customTickFont={'size':7},
                    # customLegendFont={'size':30},
                    figureSize=12);

plt.savefig('multinest_gtc_{}.png'.format(time_stamp))
Ejemplo n.º 45
0
def test_GTC_colorsOrder():
    return pygtc.plotGTC(chains=[SAMPLES_1, SAMPLES_2],
                         colorsOrder=['purples', 'yellows'],
                         smoothingKernel=0)
Ejemplo n.º 46
0
def test_GTC_chainLabels_noTex():
    chainLabelsNoTex = ['data1', 'data 2']
    return pygtc.plotGTC(chains=[SAMPLES_1, SAMPLES_2],
                         chainLabels=chainLabelsNoTex,
                         smoothingKernel=0)
Ejemplo n.º 47
0
def test_GTC_do1dPlots():
    pygtc.plotGTC(chains=[SAMPLES_1,SAMPLES_2],
                    do1dPlots = False,
                    smoothingKernel = 0)
Ejemplo n.º 48
0
def test_GTC_plotDensity():
    pygtc.plotGTC(chains=[SAMPLES_1,SAMPLES_2],
                    plotDensity = True,
                    smoothingKernel = 0)
Ejemplo n.º 49
0
def test_GTC_bare():
    return pygtc.plotGTC(chains=[SAMPLES_1, SAMPLES_2], smoothingKernel=0)
Ejemplo n.º 50
0
def test_GTC_doOnly1dPlot():
    input_chains = [np.array([SAMPLES_1[:,0]]).T, np.array([SAMPLES_2[:,0]]).T]
    pygtc.plotGTC(chains=input_chains,
                    doOnly1dPlot = True,
                    smoothingKernel = 0)
Ejemplo n.º 51
0
def test_GTC_paramNames_noTex():
    namesNoTex = ['param name', 'B_labmda', 'C', 'lambda']
    return pygtc.plotGTC(chains=[SAMPLES_1, SAMPLES_2],
                         paramNames=namesNoTex,
                         smoothingKernel=0)
Ejemplo n.º 52
0
def test_GTC_bare():
    pygtc.plotGTC(chains=[SAMPLES_1,SAMPLES_2],
                    smoothingKernel = 0)