Example #1
0
def main():
    eventname = sys.argv[1]
    cfile     = sys.argv[2]
    
    # Load the POET event object (up through p5)
    event_chk = me.loadevent(eventname + "_p5c")
    event_pht = me.loadevent(eventname + "_pht")
    event_ctr = me.loadevent(eventname + "_ctr", load=['data', 'uncd'])

    data  = event_ctr.data
    uncd  = event_ctr.uncd
    phase = event_chk.phase[0]

    phot    = event_pht.fp.aplev[0]
    photerr = event_pht.fp.aperr[0]
    
    # Default to 3x3 box of pixels
    avgcentx = np.floor(np.average(event_pht.fp.x) + 0.5)
    avgcenty = np.floor(np.average(event_pht.fp.y) + 0.5)
    avgcent  = [avgcenty, avgcentx]
    pixels = []
	   
    for i in range(3):
        for j in range(3):
            pixels.append([avgcenty - 1 + i, avgcentx - 1 + j])
		  
    phat, dP = zf.zen_init(data, pixels)

    npix  = len(pixels)
    necl  = 6 #number of eclipse parameters

    #photerr = photerr/np.sqrt(np.mean(phot))
    #phot    = phot/np.mean(phot)
    
    # FINDME: This is the general structure we need for MC3, but names/numbers
    # are subject to change
    allp, bp = mc3.mcmc(phot, photerr, func=zf.zen,
                        indparams=[phase, phat, npix], cfile=cfile)

    return
Example #2
0
# Alternatively, edit the paths from this script to adjust to your
# working directory.


# demo01.py:

import sys
import numpy as np
import matplotlib.pyplot as plt
sys.path.append("../MCcubed/src/")
import mccubed as mc3

# Get function to model (and sample):
sys.path.append("../MCcubed/examples/models/")
from quadratic import quad

# Create a synthetic dataset:
x = np.linspace(0, 10, 100)          # Independent model variable
p0 = 3, -2.4, 0.5                    # True-underlying model parameters
y = quad(p0, x)                      # Noiseless model
uncert = np.sqrt(np.abs(y))          # Data points uncertainty
error = np.random.normal(0, uncert)  # Noise for the data
data = y + error                     # Noisy data set

# Fit the quad polynomial coefficients:
params = np.array([ 20.0, -2.0, 0.1])  # Initial guess of fitting params.

# Run the MCMC:
allp, bp = mc3.mcmc(data, uncert, func=quad, indparams=[x],
                    params=params, numit=3e4, burnin=100)
Example #3
0
walk = 'demc'
grtest = True
burnin = 100
plots = True
savefile = 'output_ex1.npy'
savemodel = 'output_model.npy'

# Run the MCMC:
allp, bp = mc3.mcmc(data,
                    uncert,
                    func,
                    indparams,
                    params,
                    pmin,
                    pmax,
                    stepsize,
                    numit=numit,
                    nchains=nchains,
                    walk=walk,
                    grtest=grtest,
                    burnin=burnin,
                    plots=plots,
                    savefile=savefile,
                    savemodel=savemodel)

# Evaluate and plot:
y0 = quad(params, x)  # Initial guess values
y1 = quad(bp, x)  # MCMC best fitting values

plt.figure(10)
plt.clf()
plt.plot(x, y, "-k", label='true')
Example #4
0
# If func does not require additional arguments define indparams as:
# indparams=[], or simple leave it undefined in the mcmc call.

# MCMC setup:
numit   = 3e4
nchains = 10
walk    = 'demc'
grtest  = True
burnin  = 100
plots   = True
savefile  = 'output_ex1.npy'
savemodel = 'output_model.npy'

# Run the MCMC:
allp, bp = mc3.mcmc(data, uncert, func, indparams,
            params, pmin, pmax, stepsize,
            numit=numit, nchains=nchains, walk=walk, grtest=grtest,
            burnin=burnin, plots=plots, savefile=savefile, savemodel=savemodel)


# Evaluate and plot:
y0 = quad(params, x)  # Initial guess values
y1 = quad(bp,     x)  # MCMC best fitting values

plt.figure(10)
plt.clf()
plt.plot(x, y, "-k",   label='true')
plt.errorbar(x, data, yerr=uncert, fmt=".b", label='data')
plt.plot(x, y0, "-g",  label='Initial guess')
plt.plot(x, y1, "-r",  label='MCMC best fit')
plt.legend(loc="best")
plt.xlabel("X")
Example #5
0
# Optimization:
leastsq    = True   # Least-squares minimization prior to the MCMC
chisqscale = False  # Scale the data uncertainties such red.chisq = 1

# Convergence:
grtest  = True   # Calculate the GR convergence test
grexit  = False  # Stop the MCMC after two successful GR

# File outputs:
logfile   = 'MCMC.log'         # Save the MCMC screen outputs to file
savefile  = 'MCMC_sample.npy'  # Save the MCMC parameters sample to file
savemodel = 'MCMC_models.npy'  # Save the MCMC evaluated models to file
plots     = True               # Generate best-fit, trace, and posterior plots

# Correlated-noise assessment:
wlike = False   # Use Carter & Winn's Wavelet-likelihood method
rms   = False   # Compute the time-averaging test and plot


# Run the MCMC:
#  posterior is the parameters' posterior distribution
#  bestp is the array of best fitting parameters
posterior, besttp = mc3.mcmc(data=data, uncert=uncert,
            func=func, indparams=indparams,
            params=params, pmin=pmin, pmax=pmax, stepsize=stepsize,
            prior=prior, priorlow=priorlow, priorup=priorup,
            leastsq=leastsq, chisqscale=chisqscale, mpi=mpi,
            numit=numit, nchains=nchains, walk=walk, burnin=burnin,
            grtest=grtest, grexit=grexit, wlike=wlike, logfile=logfile,
            plots=plots, savefile=savefile, savemodel=savemodel, rms=rms)
Example #6
0
nchains  = 10    # Number of parallel chains
burnin   = 100   # Number of burned-in samples per chain
thinning =   1   # Thinning factor for outputs

# Optimization:
leastsq    = True   # Least-squares minimization prior to the MCMC
chisqscale = False  # Scale the data uncertainties such red.chisq = 1

# Convergence:
grtest  = True   # Calculate the GR convergence test
grexit  = False  # Stop the MCMC after two successful GR

logfile   = 'MCMC.log'         # Save the MCMC screen outputs to file
savefile  = 'MCMC_sample.npy'  # Save the MCMC parameters sample to file
savemodel = 'MCMC_models.npy'  # Save the MCMC evaluated models to file
plots     = True               # Generate best-fit, trace, and posterior plots

# Correlated-noise assessment:
wlike = False  # Use Carter & Winn's Wavelet-likelihood method.
rms   = False  # Compute the time-averaging test and plot


# Run the MCMC:
posterior, bestp = mc3.mcmc(data=data, func=func, indparams=indparams,
            params=params,
            leastsq=leastsq, chisqscale=chisqscale, mpi=mpi,
            numit=numit, nchains=nchains, walk=walk, burnin=burnin,
            grtest=grtest, grexit=grexit, wlike=wlike, logfile=logfile,
            plots=plots, savefile=savefile, savemodel=savemodel, rms=rms)