Welcome to AstroPython

The purpose of this web site is to act as a community knowledge base for performing astronomy research with Python. It provides lists of useful resources, a forum for general discussion, advice, or relevant news items, collecting users' code snippets or scripts, and longer tutorials on specific topics. The topics within these pages are presented in a list view with the ability to sort by date or topic. A traditional "blog" view of the most recently posted topics is visible from the site Home page.


Contributions from the community are strongly encouraged. If you are interested please contact the AstroPython team via the Contribute page. We can either post material on your behalf or give you an astropython.org user account to allow your own postings.


Blog: Book: Statistics, Data Mining, and Machine Learning in Astronomy

What can I say - the new book Statistics, Data Mining, and Machine Learning in Astronomy: A Practical Python Guide for the Analysis of Survey Data is simply amazing and deserves a spot on the desk of almost any modern astronomer.

Posted by aldcroft

Blog: Matrix multiply infix operator in Python 3.5

Good news for anyone who does a lot of matrix manipulation in their Python codes: PEP 465 was accepted for inclusion into Python 3.5!

The upshot is that an expression like:

  >>> S = (H.dot(beta) - r).T.dot(inv(H.dot(V).dot(H.T))).dot(H.dot(beta) - r)

turns into something much more reasonable and obvious:

 >>> S = (H @ beta - r).T @ inv(H @ V @ H ...

Posted by aldcroft

Blog: Contributing to Astropy for newbies

One of the big goals of Astropy is to remove the line between developers and users. 

We want to empower the astronomy community to be a part of the process.  What does that mean exactly?  It means that if you see something in Astropy that is wrong or missing, you can not only report this (which is a great first step), but you can fix it!  It's ...

Posted by aldcroft

Snippet: Stopping a script for debugging

Dylan Gregersen brings us another nice code snippet which might be especially welcome for IDL users who miss the STOP procedure:

Here's a snippet I'm using often while writing scripts, executing via run -i <file> or execfile(<file>), and I want to quickly truncate the code so that the remaining part of the script doesn't run. Then I can access the variables and do other ...

Posted by aldcroft

Snippet: Modified histogram plotting

Dylan Gregersen at the University of Utah, has contributed this nice snippet which lets you generate a modified histogram plot using only the counts and bins from the histogram instead of the original data.  For instance you might want to apply some operation to the counts (e.g. divide by a constant) and replot.  Here is the main code:

# Reverse histogram

import numpy as np
import matplotlib.pylab ...

Posted by aldcroft