예제 #1
0
파일: zscore.py 프로젝트: jbirky/trappist
## for Palatino and other serif fonts use:
mpl.rc('font', **{'family': 'serif'})
mpl.rc('text', usetex=True)

# Define labels
labels = [r"$m_{\star}$", r"$f_{sat}$", r"$t_{sat}$", r"age", r"$\beta_{XUV}$"]

# Containers
nIters = 7
zscores = np.zeros((nIters - 1, 5))

for ii in range(1, nIters):
    # Load ii-1th approxposterior output
    approxFilenamePrev = "../../Data/apRun%d.h5" % (ii - 1)
    approxChainPrev = extractMCMCResults(approxFilenamePrev,
                                         blobsExist=False,
                                         burn=500,
                                         verbose=False)

    # Load iith approxposterior output
    approxFilename = "../../Data/apRun%d.h5" % ii
    approxChain = extractMCMCResults(approxFilename,
                                     blobsExist=False,
                                     burn=500,
                                     verbose=False)
    # Loop over variables
    for jj in range(len(labels)):

        # Compute relative difference between marginal distribution medians
        zscores[ii - 1, jj] = np.fabs(
            (np.mean(approxChain[:, jj]) -
             np.mean(approxChainPrev[:, jj]))) / np.std(approxChainPrev[:, jj])
예제 #2
0
#Typical plot parameters that make for pretty plots
mpl.rcParams['font.size'] = 12.0

## for Palatino and other serif fonts use:
mpl.rc('font', **{'family': 'serif'})
mpl.rc('text', usetex=True)

# CGS constants
MSUN = 1.988435e33  # mass of Sun in grams
RSUN = 6.957e10  # radius of Sun incm
RHOSUN = MSUN / (4. / 3. * np.pi * RSUN**3)  # density of sun in g/cm^3

# Read in evolutionary tracks
chains = mcmcUtils.extractMCMCResults("../../Data/trappist1Fiducial.h5",
                                      verbose=False,
                                      applyBurnin=True,
                                      thinChains=True,
                                      blobsExist=False)

# Draw num samples
num = int(1.0e5)  # Number of samples

# Draw mass samples with replacement in grams
masses = np.random.choice(chains[:, 0], size=(num, ), replace=True) * MSUN

# Draw density samples in g/cm^3 by approximating constraint as wide gaussian
rhos = norm.rvs(loc=51.1, scale=2.4, size=(num, )) * RHOSUN

# Compute radius via density equation: rho = M/V = M/(4/3 * pi * r^3)
# -> (rho/m * (4/3) * pi)^(1/3) = r, but convert to Rsun
rads = np.power(masses / (rhos * (4. / 3.) * np.pi), 1. / 3.) / RSUN
예제 #3
0
# Get the input files, save them as strings
with open(os.path.join(PATH, "star.in"), 'r') as f:
    star_in = f.read()
    kwargs["STARIN"] = star_in
with open(os.path.join(PATH, "vpl.in"), 'r') as f:
    vpl_in = f.read()
    kwargs["VPLIN"] = vpl_in

# Check for output dir, make it if it doesn't already exist
if not os.path.exists(os.path.join(PATH, "output")):
    os.makedirs(os.path.join(PATH, "output"))

# Draw nsmaples from the posterior distributions
samples = mcmcUtils.extractMCMCResults(dataDir,
                                       blobsExist=False,
                                       burn=500,
                                       removeRogueChains=True)

# Get random initial conditions from posterior
sampleInds = np.random.choice(np.arange(len(samples)),
                              size=nsamples,
                              replace=True)

# Containers
lum = []
lumXUV = []
radius = []
temp = []
time = []

ii = 0
예제 #4
0
#Typical plot parameters that make for pretty plots
mpl.rcParams['figure.figsize'] = (9, 8)
mpl.rcParams['font.size'] = 22.0

## for Palatino and other serif fonts use:
mpl.rc('font', **{'family': 'serif'})
mpl.rc('text', usetex=True)

# Read in evolutionary tracks
data = np.load("../../Data/trappist1StarEvol.npz")
nsamples = len(data["Luminosity"])

chains, blobs = mcmcUtils.extractMCMCResults("../../Data/trappist1Fiducial.h5",
                                             verbose=True,
                                             burn=500,
                                             thinChains=True,
                                             blobsExist=True)

### Plot Lum, LumXUV, radius evolution and compare to observations ###

fig, axes = plt.subplots(ncols=3, figsize=(21, 6))

for ii in range(nsamples):

    # Left: lum
    axes[0].plot(data["time"][ii],
                 data["Luminosity"][ii],
                 alpha=0.1,
                 color="k",
                 lw=2,
#Typical plot parameters that make for pretty plots
mpl.rcParams['font.size'] = 17

## for Palatino and other serif fonts use:
mpl.rc('font',**{'family':'serif'})
mpl.rc('text', usetex=True)

# Plot points selected by approxposterior?
plotAPPoints = False

# Path to data
filename = "../../Data/convergedAP.h5"

# Extract data
samples = extractMCMCResults(filename, blobsExist=False, burn=500,
                             thinChains=True, removeRogueChains=False)

labels = [r"$m_{\star}$ [M$_{\odot}$]", r"$f_{sat}$",
          r"$t_{sat}$ [Gyr]", r"Age [Gyr]", r"$\beta_{XUV}$"]

# Output constraints
for ii in range(samples.shape[-1]):
    med = np.median(samples[:,ii])
    plus = np.percentile(samples[:,ii], 84) - med
    minus = med - np.percentile(samples[:,ii], 16)
    print("%s = %e + %e - %e" % (labels[ii], med, plus, minus))
    print()

# Scale Mass for readability
samples[:,0] = samples[:,0] * 1.0e2
예제 #6
0
#Typical plot parameters that make for pretty plots
mpl.rcParams['font.size'] = 17.5

## for Palatino and other serif fonts use:
mpl.rc('font',**{'family':'serif'})
mpl.rc('text', usetex=True)

# Path to data
filename = "../../Data/trappist1FiducialRatio.h5"
approxFilename = "../../Data/convergedAP.h5"

# Whether or not to plot blobs

# Extract true MCMC results
print("Loading true MCMC chain...")
trueChain = extractMCMCResults(filename, blobsExist=False, burn=500,
                               verbose=False, thinChains=False)

# Extract approxposterior MCMC results
print("Loading approxposterior MCMC chain...")
approxChain = extractMCMCResults(approxFilename, blobsExist=False, burn=500,
                                 verbose=False, thinChains=False)

# Define labels
labels = [r"$m_{\star}$ [M$_{\odot}$]", r"$f_{sat}$",
          r"$t_{sat}$ [Gyr]", r"Age [Gyr]", r"$\beta_{XUV}$"]

# Scale Mass for readability
trueChain[:,0] = trueChain[:,0] * 1.0e2
approxChain[:,0] = approxChain[:,0] * 1.0e2

# Estimate probability that TRAPPIST-1 is still saturated at the age of the
예제 #7
0
mpl.rcParams['font.size'] = 17

## for Palatino and other serif fonts use:
mpl.rc('font', **{'family': 'serif'})
mpl.rc('text', usetex=True)

# Path to data
filename = "../../Data/trappist1FiducialRatio.h5"

# Whether or not to plot blobs
plotBlobs = False

# Extract results
if plotBlobs:
    chain, blobs = extractMCMCResults(filename,
                                      blobsExist=plotBlobs,
                                      burn=500,
                                      removeRogueChains=False)
else:
    chain = extractMCMCResults(filename,
                               blobsExist=plotBlobs,
                               burn=500,
                               removeRogueChains=False)

if plotBlobs:
    samples = np.hstack([chain, blobs])

    # Define Axis Labels
    labels = [
        "Mass", "SatXUVFrac", "SatXUVTime", "Age", "XUVBeta", "Lum",
        "logLumXUV", "Radius"
    ]