In [1]:
import os
In [2]:
import numpy as np
In [3]:
%matplotlib inline
import matplotlib.pyplot as plt
In [4]:
from astropy.cosmology import Planck15 as cosmo
In [5]:
import isotropy
In [6]:
mockDataFile = os.path.join(isotropy.example_data_dir, 'snFits.p.gz')
In [7]:
sampleData, totalSN = isotropy.read_mockDataPickle(mockDataFile)
In [8]:
sampleData.head()
Out[8]:
In [9]:
# Total number of SN in the simulation (before we threw away bad points)
totalSN
Out[9]:
In [10]:
sampleData['mu_err'] = sampleData.mu_var.apply(np.sqrt)
In [11]:
sampleData.head()
Out[11]:
In [12]:
# mu_err > 5.0 is pretty useless, throw them
In [12]:
sampleData = sampleData.query('mu_err < 5.0')
In [13]:
df = isotropy.binnedDescStat(sampleData)
In [14]:
# removes the nans
In [15]:
df = df.dropna()
In [16]:
df
Out[16]:
In [17]:
# Now create samples of size numSN = 50000
In [18]:
numSN = 50000
dfmu = isotropy.drawSamples(df, numSN, totalSN, np.random.RandomState(0))
In [19]:
dfmu.head()
Out[19]:
In [20]:
fig, ax = plt.subplots(1,3)
_ = ax[0].hist(dfmu.z, bins=np.arange(0., 1.4, 0.1), histtype='step')
_ = ax[1].hist(dfmu.mu_err, bins=20, histtype='step')
_ = ax[2].errorbar(dfmu.z, dfmu.mu, yerr=dfmu.mu_err.values, fmt='o')
_ = ax[2].plot(dfmu.z, cosmo.distmod(dfmu.z), 'k-', lw=2.)
ax[0].set_xlabel('x')
ax[0].set_ylabel('Num')
ax[1].set_xlabel('mu_err')
ax[2].set_xlabel('z')
ax[2].set_ylabel('mu')
Out[20]:
These show:
- z histogram in the first panel
- mu_err histogram in the second plot
- hubble diagram in the 3rd plot, with the line showing the true cosmology values
The distribution of mu_err in the 2nd panel is a problem because it is going below 0. Surely not a good repesentation!
In [22]:
from utils import plotutils as pl
In [33]:
fig, ax0, ax1 = pl.settwopanel(setdifflimits=None)
ax0.errorbar(dfmu.z, dfmu.mu, yerr=dfmu.mu_err.values, fmt='.')
ax0.plot(dfmu.z, cosmo.distmod(dfmu.z), 'k-', lw=2.)
ax0.set_xscale('log')
ax1.errorbar(dfmu.z, dfmu.mu - cosmo.distmod(dfmu.z).value, yerr=dfmu.mu_err.values, fmt='o')
ax1.set_xscale('log')
ax0.set_xlim(0., 1.5)
ax1.set_xlim(0., 1.5)
Out[33]: