#### Welcome to the Dark Energy worksheet. 

The worksheet is organized as a series of tasks. You can edit this notebook directly by adding code (and comment) cells to perform these tasks. You will need to import packages, even if this is not explicitly requested.

One function from a package that we haven't mentioned so far but you might need is scipy.integrate (numerical integration).

#### Task 1: import the data from the file sn_data.txt

This data set contains three columns. 

The first one is the redshift of the supernovae. Redshift is a measure of the velocity at which supernovae are moving away from us. Redshift = 0 means no motion, increasing values represent increasing velocity. Redshift has no units.

The second column is the distance of the supernovae, expressed in the units of Mpc (megaparsec). Mega = 1 Million; 1 parsec (pc) = 3.26 light years.

The third column contains the error on the distance (let's call it sigma(d)), again expressed in Mpc.

#### Task 2: Make an errorbar plot of this data set.

Place redshift (z) on the x axis, distance on the y axis, and sigma(d) as the error on the distance. Add labels to the axes and don't forget the units.

#### A few words on our model

The plot that you just made just shows the data. Now what we want to do is to build different models for the distance of these supernovae, and then choose the model that works best.

Our model for the distance (called "Luminosity Distance" by physicists) is a function of different parameters: 

- z (the redshift) is the independent variable; in other words, our model for the distance will return a distance for any redshift value.

- Omegam is the percentage of matter in the Universe, and it's a number between 0 and 1;

- OmegaDE is the percentage of Dark Energy in the Universe; we can assume that Omegam + OmegaDE = 1 (so the Universe only contains matter and dark energy), which simplifies our model a little bit, because we can write OmegaDE = 1 - Omegam;

- H0 is the Hubble constant, which gives the current rate of expansion of the Universe; we will fix it in the beginning to be = 70 km/s/Mpc;

- c is the speed of light in km/s; c = 2.99 x 10**5. This is a constant of nature so we won't need to change it.

Here comes our model:


\begin{align}
D_L(z,\Omega_m, H_0, c) = \,(1+z) \frac{c}{H_0}\int_0^z \frac{dx}{\sqrt{\Omega_m(1+x)^3 + \Omega_{DE}}} 
\end{align}

#### Task 3: Complete this function definition.

Notes: 

1. Omega_DE is not a parameter of the function, so make sure you write your function as a function of Omega_m only.

2. It might be easier to first define a function for the integrand
       
3. You might find useful to invoke the scipy.integrate.quad function of the scipy package and to look at the examples here
       
https://docs.scipy.org/doc/scipy-0.18.1/reference/tutorial/integrate.html

       
def LumDist(z, Omegam = 0.7, H0 = 70, ckms = 2.9979 $\times 10^5$) :

    ###write the function here


#### Task 4

1. Answer the questions: What are the arguments of the LumDist function? Which ones have default values?

2. Check that LumDist(1) ~ 5512 and LumDist(0.5) ~ 2522

#### Task 5

Vectorize the function so we can give it a 1D array of redshifts as input. Check that it works by 
defining a numpy array as the first column of your supernova data and feeding it to your function.

#### Task 6

Plot the data with error bars as before, and then the luminosity distance values for the supernovae predicted by these three models:
    
Model 1: Omega_m = 0 
    
Model 2: Omega_m = 0.3
    
Model 3: Omega_m = 1

Make sure you add labels for all the models.
    


#### Task 7

Answer the following questions:

1) What are the Omega_DE values for the above models? Which model contains no Dark Energy at all?

2) Just judging by eye, which model seems to be the best fit to the data and why?

#### Task 8

It is now time to define a proper function to judge whether these models are good fit to the data. This is done through the $\chi^2$ function that we mentioned in the "Fit a line" worksheet.

Complete the following function:

def chi2(x,x_err,y): 

    Write a function that computes the chi2 between a vector containing measurements (x) and their experimental errors (x_err), with respect to a vector of model predictions y 

   

#### Task 9

Calculate the $\chi^2$ of the model with Omega_m = 0.3. 
    
(Hint: your "y" vector is the vector of luminosity distances for all the supernovae)

#### Task 10

And now the magic begins!

1. Calculate and save the $\chi^2$ values for different models with values of Omega_m between 0 and 1, spaced every 0.05.

2. Create a scatter plot that has the values of Omega_m on the x axis, and the value of the $\chi^2$ on the y axis.

#### Task 11

Find the model with the lowest $\chi^2$ and answer the questions:

1. Which value of Omega_m corresponds to this model? 

2. Which value of Omega_DE corresponds to this model?

3. Based on your answers, is a non-zero value of Dark Energy supported by the data?

#### Task 12 (optional, for Extra Credit)

Repeat the $\chi^2$ analysis for a two parameter model, with Omega_m varying between 0 and 1 in 0.05 intervals 
and H_0, the Hubble constant, varying between 50 and 80 km/s/Mpc in intervals of 5 km/s/Mpc.

What are the values of Omega_m and H_0 that correspond to the lowest $\chi^2$? How do your conclusions change in this case?



d4adf740b612dfd6cb249bdbd5d2985939b02be6
ipynb
Jupyter Notebook
Worksheets/WS2_DarkEnergy.ipynb
vacquaviva/PHYS3600ID_ML
747038261f8a0ee2424325bc1821e91418a111d4
MIT
Worksheets/WS2_DarkEnergy.ipynb
vacquaviva/PHYS3600ID_ML
747038261f8a0ee2424325bc1821e91418a111d4
MIT
Worksheets/WS2_DarkEnergy.ipynb
vacquaviva/PHYS3600ID_ML
747038261f8a0ee2424325bc1821e91418a111d4
MIT
2019-07-01T01:34:20.000Z
2019-07-04T17:33:50.000Z
Qwen/Qwen-72B
1. YES
2. YES