SharedDark Energy Assignment Meyers.ipynbOpen in CoCalc
Dark Energy Experiment in Python
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

redshift = np.genfromtxt('sn_data.txt',skip_header= True, usecols=(0))
distance = np.genfromtxt('sn_data.txt',skip_header= True, usecols=(1))
sigma = np.genfromtxt('sn_data.txt',skip_header= True, usecols=(2))

plt.errorbar(redshift,distance, yerr = sigma, marker= '.', c = 'green', ls = 'None')
plt.xlabel('Redshift')
plt.ylabel('Distance')
plt.title('Distance versus Redshift');

Assumptions

  • z is redshift
  • omegalight is the percentage of matter in the universe [0,1]
  • omegadark is the percent dark energy
  • Hubble_constant = 70 km/s/Mpc
  • c=2.99105km/sc = 2.99*10^5 km/s

hubble = 70
c = 2.99*10**5
import scipy.integrate as integrate

def lum_dist(z,omegalight = .7,hubble=70,c=2.9979*10**5):
    omegadark = 1-omegalight
    #function = (((omegalight*(1.0+x)**3.0+omegadark)**(1/2))**-1.0)
    result = integrate.quad(lambda x: (((omegalight*(1.0+x)**3.0+omegadark)**(1/2))**-1.0),0,z)[0]
    return (1+z)*(c/hubble)* result


lum_dist_vec = np.vectorize(lum_dist)


lum_dist_vec(redshift,.7);
model1 = lum_dist_vec(redshift,0)
model2 = lum_dist_vec(redshift,.3)
model3 = lum_dist_vec(redshift,1)

plt.errorbar(redshift,distance, yerr = sigma, marker= '.', c = 'green', ls = 'None')
plt.xlabel('Redshift')
plt.ylabel('Distance')
plt.title('Distance versus Redshift');
plt.plot(redshift, model1, c='red',label='Model 1')
plt.plot(redshift, model2, c='yellow',label='Model 2')
plt.plot(redshift, model3, c='blue',label='Model 3')
plt.legend();

Task 7

Model 1 has a value of 1 for ΩDE\Omega_{DE}. Model 2 has an ΩDE\Omega_{DE} = .7. Model 3 predicts a zero value for ΩDE\Omega_{DE}. It is clear from these models that ΩDE\Omega_{DE} fits our data the best. However, we can do better than a couples guesses.

def chi_square(x,x_error, y):
    return np.sum(((x-y)**2)/((x_error)**2))
chi_square(distance,sigma,model1)
447.81951103787316
chi_square(distance,sigma,model2)
308.1221776880534
chi_square(distance,sigma,model3)
1142.2432142471703
test = np.linspace(0,1,21)
values = []
results = []
for thing in test:
    values.append (lum_dist_vec(redshift,thing))
for value in values:
    results.append (chi_square(distance,sigma,value))
show(results)
[447.819511038,312.941094516,254.30626851,237.209595942,245.736554157,271.144003779,308.122177688,353.229126587,404.128432924,459.178811649,517.196501092,577.309862239,638.866425379,701.37131864,764.445265898,827.795214954,891.193358242,954.4618712,1017.46163137,1080.08376209,1142.24321425]\left[447.819511038, 312.941094516, 254.30626851, 237.209595942, 245.736554157, 271.144003779, 308.122177688, 353.229126587, 404.128432924, 459.178811649, 517.196501092, 577.309862239, 638.866425379, 701.37131864, 764.445265898, 827.795214954, 891.193358242, 954.4618712, 1017.46163137, 1080.08376209, 1142.24321425\right]
test[results.index(min(results))]
0.15000000000000002
plt.scatter(test,results);
plt.xlabel('$Omega_m$');
plt.ylabel( '$\chi^2$');
plt.title('$Omega_m$ versus  $\chi^2$');
An omega_m of .15 fits this model the best
An omega_dark of .85 fits this model best
This model suggests a non-zero value of dark energy.