Esempio n. 1
0
def lnprob_step2(theta, x, y, yerr):
    lp = lnprior_step2(theta)
    if not np.isfinite(lp):
        return -np.inf
    logprobs.append(lp + lnlike_fast_linear.lnlike(theta, x, y, yerr))
    logvals.append(theta)
    return lp + lnlike_fast_linear.lnlike(theta, x, y, yerr)
Esempio n. 2
0
def perform_emcee_single(time, flux, err_2, dMu, scale, ROW, mu, color):
    diff_time = [x - time[i - 1] for i, x in enumerate(time)][1:]
    fig = plt.figure(figsize=(10, 10))

    nll = lambda *args: -lnlike_fast_linear.lnlike(*args)  #-lnlike_old(*args)
    ndim, nwalkers = 2, 100
    # MAKE POSITION ARRAY ARRAY FOR WALKERS
    if sys.argv[4].lower() == 'normal':
        result = [np.log10(V), np.log10(Tau)]
        pos = (np.random.rand(nwalkers, ndim) - 0.5) * np.array([1, 1
                                                                 ]) + result
    elif sys.argv[4].lower() == 'optimal':
        # not sure how this will work for the multi-band situation??
        result = op.minimize(nll, [np.log10(V), np.log10(Tau)],
                             args=(time, flux, err_2))
        pos = [
            result['x'] + 1e-1 * np.random.rand(ndim) for i in range(nwalkers)
        ]
    else:
        print("What the hell do you want to do?")
        print("'optimal', or 'normal' search through MCMC?")
        exit()

    # run sampler
    sampler = emcee.EnsembleSampler(nwalkers,
                                    ndim,
                                    lnprob_step2,
                                    args=(time, flux, err_2))
    # run mcmc
    sampler.run_mcmc(pos, 200)

    samples = sampler.chain[:, 50:, :].reshape((-1, ndim))
    logprobs_samp = sampler.lnprobability[:, 50:].reshape((-1))

    # make corner plot
    max_theta = samples[np.argmax(logprobs_samp)]
    fig1 = corner.corner(samples,
                         labels=[r"log$_{10}V$", r"log$_{10}\tau$"],
                         truths=[max_theta[0], max_theta[1]])

    fig1.savefig(file_path + str(ROW) + sys.argv[4] + "_" + color + "_band_" +
                 "triangle_linear_" + str(sys.argv[5]) + "VAR.pdf")

    # PRINT MAX THETA VALUES TO THE SCREEN
    print('ROW:', ROW, 'Tau:', str(max_theta[1]), 'V:', str(max_theta[0]))

    sausageplot_step2(max_theta[0], time, flux, max_theta[1], 5, err_2, dMu,
                      scale, ROW, fig, color)
    fig.savefig(file_path + str(ROW) + sys.argv[4] + "_" + color + "_band_" +
                "sausage_step2_linear_" + str(sys.argv[5]) + "VAR.pdf")

    plt.close("all")

    # WRITE THE FOUND MAX THETA VALUES TO FILE
    fit_str = str(sys.argv[1].split("/")[-1].split("_")[0])
    filename = 'scratch_new/' + str(ROW) + "_" + fit_str + "_" + sys.argv[
        4] + "_" + color + "_band_linear_" + str(sys.argv[5]) + '.txt'
    with open(filename, 'w+') as fout:
        fout.write('Fits-Object, Tau, V \n' + fit_str + "\t" + str(ROW) +
                   '\t' + str(max_theta[1]) + '\t' + str(max_theta[0]))
Esempio n. 3
0
def lnprob_step2(theta, x, y, yerr):
    lp = lnprior_step2(theta)
    if not np.isfinite(lp):
        return -np.inf
    try:
        lp_app = lp + lnlike_fast_linear.lnlike(theta, x, y, yerr)
    except ValueError:  #Nan value case
        lp_app = -np.inf  #ignore the Nan value case
    logprobs.append(lp_app)
    logvals.append(theta)
    return lp_app