%matplotlib inline
import warnings
warnings.filterwarnings('ignore')
from IPython.display import Image
from IPython.display import HTML
Only has Numpy as a required dependency (easy to install)
Well tested, documented, and stable code
Works on Linux, MacOS X, and Windows
Python 2 and 3 compatible
Latest stable release v0.4.2 on Sept 23
Core data structures and transformationsModels and Fitting |
Connecting up: Files and I/O |
Astronomy computations and utilities |
from astropy import constants as c
c.G
M = c.M_earth
M
from astropy import units as u
r = c.R_earth
v_esc = (2 * c.G * M / r)**0.5
v_esc.to(u.km/u.s)
v_esc = ((2 * c.G * M / (r+559*u.km))**0.5)
v_esc.to(u.km/u.s)
v_esc = ((2 * c.G * 3 * u.m / (r+559*u.km))**0.5)
v_esc.to(u.km/u.s)
--------------------------------------------------------------------------- UnitsError Traceback (most recent call last) <ipython-input-9-871ca449b6fa> in <module>() 1 v_esc = ((2 * c.G * 3 * u.m / (r+559*u.km))**0.5) ----> 2 v_esc.to(u.km/u.s) /Users/crawford/programs/astropy/astropy/units/quantity.pyc in to(self, unit, equivalencies) 586 unit = Unit(unit) 587 new_val = np.asarray( --> 588 self.unit.to(unit, self.value, equivalencies=equivalencies)) 589 return self._new_view(new_val, unit) 590 /Users/crawford/programs/astropy/astropy/units/core.pyc in to(self, other, value, equivalencies) 924 If units are inconsistent 925 """ --> 926 return self.get_converter(other, equivalencies=equivalencies)(value) 927 928 def in_units(self, other, value=1.0, equivalencies=[]): /Users/crawford/programs/astropy/astropy/units/core.pyc in get_converter(self, other, equivalencies) 860 except UnitsError: 861 return self._apply_equivalences( --> 862 self, other, self._normalize_equivalencies(equivalencies)) 863 return lambda val: scale * _condition_arg(val) 864 /Users/crawford/programs/astropy/astropy/units/core.pyc in _apply_equivalences(self, unit, other, equivalencies) 823 raise UnitsError( 824 "{0} and {1} are not convertible".format( --> 825 unit_str, other_str)) 826 827 def get_converter(self, other, equivalencies=[]): UnitsError: 'm(3/2) / (kg(1/2) s)' and 'km / s' (speed) are not convertible
from astropy import units as u
from astropy.coordinates import SkyCoord
c1 = SkyCoord('00h42m00s', '+41d12m00s', 'icrs')
print("{0} {1}".format( c1.ra,c1.dec))
print c1.to_string('hmsdms')
c2 = SkyCoord(ra=11*u.degree, dec=10*u.degree, distance=11.5*u.pc, frame='icrs')
c1.separation(c2)
Also available are coordinate transformation between different systems (e.g. ICRS, FK5, galactic) and matching catalags of coordinates.
Astropy also has a modelling fitting package. Let's see how it works. Let's create a Gaussian shape and add some noise to it.
import numpy as np
x = np.linspace(-5., 5., 200)
y = 3 * np.exp(-0.5 * (x - 1.3)**2 / 0.8**2)
y += np.random.normal(0., 0.2, x.shape)
Now let's fit the model using the astropy modeling class
from astropy.modeling import models, fitting
g_init = models.Gaussian1D(amplitude=1., mean=0, stddev=1.)
fit_g = fitting.LevMarLSQFitter()
g = fit_g(g_init, x, y)
print(g)
import pylab as plt
plt.figure(figsize=(8,5))
plt.plot(x, y, 'ko')
plt.plot(x, g(x), 'r-', lw=2, label='Gaussian')
plt.xlabel('Position')
plt.ylabel('Flux')
plt.legend(loc=2)
plt.show()
A range of different models already exist for 1-D and 2-D fitting. The API for the modeling class is still being refined but it should be stable in the next major release.
Tools for accessing the virtual observatory
from astropy.vo.client import conesearch
Tools for reading/writing FITS files (formerly pyfits)
from astropy.io import fits
Tools for reading in ascii tables including CDS, IPAC, HTML, Latex, Sextractor
from astropy.io import ascii
table = ascii.read("ftp://cdsarc.u-strasbg.fr/pub/cats/VII/253/snrs.dat",
readme="ftp://cdsarc.u-strasbg.fr/pub/cats/VII/253/ReadMe")
print table
from astropy.cosmology import WMAP9 as cosmo
cosmo.H(0)
cosmo
A number of cosmological models are already available and the user can define their own cosmological models including dark energy and neutrino properties
from astropy.cosmology import WMAP7
from astropy.cosmology import WMAP9 as cosmo
from astropy.cosmology import Planck13
z = np.linspace(0,10,200)
plt.figure(figsize=(8,5))
plt.plot(z, WMAP7.luminosity_distance(z)-cosmo.luminosity_distance(z), 'b-', label='WMAP7')
plt.plot(z, cosmo.luminosity_distance(z)-cosmo.luminosity_distance(z), '-', color='black', label='WMAP9')
plt.plot(z, Planck13.luminosity_distance(z)-cosmo.luminosity_distance(z), 'g-', label='Planck13')
plt.xlabel('z')
plt.ylabel('$\Delta D_L [%s]$' % cosmo.luminosity_distance(0).unit)
plt.legend(loc=2)
plt.show()
from astropy import stats
for x in stats.funcs.__all__: print x
Development of testing, documentation, and installation infrastructre to make it easier to build and deploy your own code
These packages are at different stages of development and there are a number of other packages in early development which are not mentioned here. Some of the packages will be integrated into the core astropy package.
import aplpy
gc = aplpy.FITSFigure('2MASS_k.fits')
gc.show_rgb('2MASS_arcsinh_color.png')
from astroquery.simbad import Simbad
result_table = Simbad.query_object("m1")
result_table.pprint(show_unit=True)
Services available to query include Vizier, Simbad, NED, SDSS, GAMA, archives, catalogs, and many more online resources
import ccdproc
ccd = ccdproc.CCDData.read('a8280418.fits', unit=u.adu)
ccd.header
ccd = ccdproc.subtract_overscan(ccd, fits_section=ccd.header['biassec'],
median=True, model=models.Polynomial1D(5))
ccd = ccdproc.trim_image(ccd, fits_section=ccd.header['trimsec'])
ccd = ccdproc.create_deviation(ccd, readnoise=ccd.header['rdnoise']*u.electron,
gain=ccd.header['gain']*u.electron/u.adu)
ccd.write('out.fits', clobber=True)
from astropy import log
log.setLevel('ERROR')
fc = aplpy.FITSFigure(ccd.data)
fc.show_grayscale()
Download and install astropy
Join astropy@scipy.org
Provide feedback (submit issues, ask questions)
Use the astropy template and astropy classes for your packages
Look for 'easy' issues and submit a pull request
Contribute code either to astropy or an affiliated package
Websites
Homepage: http://www.astropy.org/
Documentation: http://docs.astropy.org/
Tutorials: http://www.astropy.org/astropy-tutorials/
Github
https://github.com/astropy
Contacts
Twitter: @astropy
General Mailing List: astropy@scipy.org
Mailing list for developers: astropy-dev@googlegroups.com
Acknowledgement
This talk made use of Astropy, a community-developed core Python package for Astronomy (Astropy Collaboration, 2013).
Special thank you to Thomas Robitaille, Adrian Price-Whelan, Mathew Craig, and the Astropy Community for material for this talk.