# Astropy: 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.62603503 \; \mathrm{tsp}$

## Level 2¶

What is 3 nm^2 Mpc / m^3 in dimensionless units?

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

Out[3]:
$92570.327 \; \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.4nm if the object is moving at a velocity of 510km/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.17301 \; \mathrm{nm}$