Plan: Weekly 15-30 minute python tutorials, code demonstrations, and discussions Mondays at 11 AM in the library.
Organizers: Adam Ginsburg and Bernd Husemann
If you want to get this notebook, you can find it on a public repository: https://github.com/ESO-python/ESOPythonTutorials
It can be viewed directly at http://nbviewer.ipython.org/github/ESO-python/ESOPythonTutorials/master/notebooks/ESOPythonDemoDay1.ipynb (or http://goo.gl/UNnpLF for short)
Astropy has very good and detailed documentation: http://www.astropy.org/ and a tutorial series (work in progress): http://www.astropy.org/astropy-tutorials/
Astropy is a community-led effort to provide basic astronomy-related tools and libraries in python. It is meant to provide all of the functionality astrolib once provided for IDL, but much more.
Community-developed means you can (and should) contribute. All you need is a free github account.
The core functionality of astropy includes: * Units and Quantities (astropy.units) and Constants (astropy.constants) * Data Tables (astropy.table) * Astronomical Coordinate Systems (astropy.coordinates) * World Coordinate System (astropy.wcs) * FITS File handling (astropy.io.fits)
This demonstration is written in an IPython notebook.
ipython is the best way to work with python for interactive data analysis. Notebooks are particularly useful for lectures, demonstrations, and day-to-day exploratory work.
Astropy has a complete set of unit manipulation tools.
from astropy import units as u
from astropy import constants
Any quantity can be assigned a unit by multiplying by the appropriate unit
x = 6563*u.AA
x
Units can be converted to any equivalent unit (i.e., length->length, speed->speed, etc.)
x.to(u.m)
x.to(u.pc)
They cannot be converted to non-equivalent units...
...unless the appropriate equivalencies are specified
x.to(u.THz, u.spectral())
More complicated equivalencies, such as doppler shift (redshift) are possible. They are tied to particular reference values, though:
x = 6582*u.AA
ha_rest = 6562.8*u.AA
x.to(u.km/u.s, u.doppler_optical(ha_rest))
Arrays can also be given units
frequencies = np.linspace(1,2,50)*u.GHz
fluxes = np.random.randn(50)*u.Jy
import pylab as pl
pl.plot(frequencies, fluxes, drawstyle='steps-mid')
pl.xlabel("{0} ({1})".format(frequencies.unit.physical_type, frequencies.unit.to_string()))
pl.ylabel("{0} ({1})".format(fluxes.unit.physical_type, fluxes.unit.to_string()))
Conversion between fk5 and Galactic coordinates (and any other system) is straightforward with astropy.
from astropy import coordinates
# Query the SESAME service to get the coordinates
m31_fk5 = coordinates.FK5.from_name('M31')
m31_fk5
m31_fk5.galactic
m31_fk5.fk4
Coordinates also work with arrays
ra = [17.5,17.6,17.7,17.8] * u.hour
dec = [-29.2,-29.3,-29.4,-29.5] * u.deg
c = coordinates.FK5(ra,dec)
c, c.galactic
lmc = coordinates.FK5.from_name('LMC')
smc = coordinates.FK5.from_name('SMC')
m33 = coordinates.FK5.from_name('M33')
fig = pl.figure(figsize=(8,6))
ax = fig.add_subplot(111, projection="mollweide")
ax.scatter(c.galactic.l.radian-2*np.pi, c.galactic.b.radian, color='k')
ax.scatter(m31_fk5.galactic.l.radian, m31_fk5.galactic.b.radian, color='orange')
ax.scatter(m33.galactic.l.radian, m33.galactic.b.radian, color='r')
ax.scatter(lmc.galactic.l.radian-2*np.pi, lmc.galactic.b.radian, color='b')
ax.scatter(smc.galactic.l.radian-2*np.pi, smc.galactic.b.radian, color='m')
Questions and requests?