ps1_question4
.pdf
keyboard_arrow_up
School
University of Toronto *
*We aren’t endorsed by this school
Course
221
Subject
Astronomy
Date
Feb 20, 2024
Type
Pages
5
Uploaded by DrProton13473
ps1_question4
January 24, 2024
1
Question 4
I’m here to guide you through making your own hubble diagram!
First, lets load in some code
packages to make our lives easier:
[31]:
import
matplotlib.pyplot
as
plt
from
scipy.optimize
import
curve_fit
import
numpy
as
np
import
pandas
as
pd
Now,lets load in our data:
[32]:
cepheid_periods
=
np
.
loadtxt(
"cepheid_periods.txt"
)
cepheid_magnitudes
=
np
.
loadtxt(
'cepheid_magnitudes.txt'
)
wavelengths
=
np
.
loadtxt(
'wavelengths.txt'
)
1.1
Part a)
Now that you’ve gotten to do some analysis of cepheid variables, lets make our own hubble diagram
with some real data! We’ve provided a python notebook to help you complete this question,
1.1.1
Finding Distance
We have observed cepheid variables in 10 assorted host galaxies . In table 1, we give the periods
(T) and apparent magnitudes (m) of these cepheids. Find the distances between our observer and
each host galaxy by filling in your formula for distance.
Note: Assume cepheids have an approximate period luminosity relationship of:
𝑀 = −3(𝑙𝑜𝑔
10
(𝑃𝑒𝑟𝑖𝑜𝑑) − 1) − 4
Where period is given in units of days.
[33]:
## Define a function to calculate cepheid distance from aparent mangitude and
␣
↪
period
def
cepheid_distance_finder
(magnitude,period):
return
10 **
((magnitude
-
(
-3 *
(np
.
log10(period)))
+ 4
)
/ 5
)
Now we just run this function on our lists of periods and aparent magnitudes to get distances
1
[34]:
# plug in your data to find the cepheid distances
cepheid_distances
=
cepheid_distance_finder(magnitude
=
cepheid_magnitudes,
␣
↪
period
=
cepheid_periods)
print
(cepheid_distances)
#just to double check my function is right
[ 1767591.89944544 15002392.53348405
1559519.7631191
814398.39674279
9974491.17060978
4296137.67397539
3759161.73526182
1262249.66649162
6657474.48808416
1696805.72732787]
1.2
Part b)
21 cm emission lines are easily recognizable emission lines that have been detected from all of these
listed galaxies. When a 21cm photon would be emitted or absorbed, its wavelength would be about
0.21106114 m (hence 21cm!). In table 2, we have provided the wavelength at which this line was
observed on earth. Using this, calculate the recessional velocity of each galaxy
[35]:
## Define a function to calculate galaxy recessional velocity using the
␣
↪
observed wavelength of its 21 cm line
c
= 3E+5
def
velocity_21cm
(wavelength):
return
c
*
((wavelength
/ 0.21106114
)
- 1
)
[36]:
## Plug in your data to find recessional velocity
recessional_velocities
=
velocity_21cm(wavelengths)
print
(recessional_velocities)
[ 547.49064655 1905.59948648
321.29078806
143.98671399 1637.09908892
717.58827797
922.49572802
133.49686257
635.38934737
513.29202524]
1.3
Part c)
Now that we have distances and recessional velocities, let’s find Hubble’s Constant!
Plot your
distances and recessional velocities and fit a line whose slope will determine
𝐻
0
. Please give
𝐻
0
in
units of km Mpc
−1
s
−1
Plot your hubble diagram below:
Be mindful of your units! Please include them in your plot
[57]:
## Fill out the title and x and y axis labels for your hubble diagram
plt
.
scatter(cepheid_distances, recessional_velocities)
# scatter plot of
␣
↪
recessional velocities for hubble diagram
plt
.
xlabel(
'Distances (Parcsecs)'
)
plt
.
ylabel(
'Recessional Velocities (km/s)'
)
plt
.
title(
"Hubble's Law"
)
plt
.
xscale(
'log'
)
plt
.
yscale(
'log'
)
plt
.
xlim(
5e+5
,
5e+7
)
2
plt
.
ylim(
7e+1
,
5e+3
)
mean
=
(recessional_velocities
/
cepheid_distances)
print
( np
.
mean(mean))
0.00018998431042958653
Now, lets fit a line through our datapoints.
[58]:
## Define a function to calculate recessional velocity using the Hubble equation
Ho
= 0.00019
#average
def
velocity_hubble_equation
(distance,Ho):
return
(Ho
*
distance)
[59]:
## Fit the hubble constant. Covariance gives a measure of how ood your fit is.
␣
↪
You can check it if you like,
## but be mindful that real data is quite messy!
covariance
=
␣
↪
curve_fit(velocity_hubble_equation,cepheid_distances,recessional_velocities)
[60]:
covariance
3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help