Unit Conversion - Solutions

Level 1

What is 1 barn megaparsecs in teaspoons?

In [1]:
from astropy import units as u
from astropy.units import imperial
In [2]:
(1. * u.barn * u.Mpc).to(imperial.tsp) 
Out[2]:
$0.626035 \; \mathrm{tsp}$

Level 2

What is \(3 \mathrm{nm}^2 \mathrm{Mpc} / \mathrm{m}^3\) in dimensionless units?

In [3]:
(3. * u.nm**2 * u.Mpc / u.m**3).decompose()
Out[3]:
$92570.3 \; \mathrm{}$

or to just get the numerical value:

In [4]:
(3. * u.nm**2 * u.Mpc / u.m**3).decompose().value
Out[4]:
92570.32744401575

Level 3

Try and use equivalencies to find the doppler shifted wavelength of a line at \(454.4\mathrm{nm}\) if the object is moving at a velocity of \(510\mathrm{km}/\mathrm{s}\) away from the observer.

In [5]:
(510. * u.km / u.s).to(u.nm, equivalencies=u.doppler_optical(454.4 * u.nm))
Out[5]:
$455.173 \; \mathrm{nm}$