Interactive Tutorials

Tutorial | Intermediate

Linear Regression: Fitting a line to data

MUCH has been said on this topic; in fact, it can get (surprisingly) mind-bogglingly advanced. But for now, let's focus on the basics: How does one fit a line (or any polynomial) to some data in Python? And how do we know if our "fit" is any good? You'll need this dataset.

Tutorial | Intermediate

Markov Chain Monte Carlo: An Introduction using Ice Core Data

MCMC is a powerful tool for many aspects of astronomy. In this tutorial, we'll cover when one might want to use an MCMC, and then setup and run one on some historical ice core data to fit the Earth's Milankovich Cycles! Here's the Ice Core Data File.

Tutorial | Intermediate - Advanced

Building an RK4 Orbit Integrator
Part 1 of 2

In this tutorial, I cover the classic N-body orbit integration problem in detail, showing you how to use classes and a 4th order integrator.

Tutorial | Intermediate - Advanced

Building an RK4 Orbit Integrator
Part 2 of 2

In Part 2, we adjust our RK4 orbital N-body integrator from last tutorial to integrate particles in potentials as well.

Tutorial | Intermediate

Writing a Metropolis-Hastings Sampler

In this tutorial we learn some of the statistics underlying MCMC and then write our own sampler using classes!

Python Guides


Intermediate matplotlib: Towards Publication-Ready Plots

The easiest way to start plotting things in Python (plt.plot) is just not good enough to make real research grade plots. Here, I'll talk about the first steps you'll want to take in controlling every detail of your figures.


Object Oriented Python: Building a Pipeline

Python is inherently an "object-oriented" language -- often, we don't have to write our codes that way, but it can actually make things better sometimes! Here, I'll attempt to explain why classes are useful, via the example of a data reduction pipeline.

License and Usage

Creative Commons License
Python for Astronomers: An Introduction to Scientific Computing by Imad Pasha & Christopher Agostino is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License

What does all that mean?

Personal Use

You are always free to download, keep, and reference any of the materials posted here for your own personal use.


You are free to modify and/or use any aspect of these materials in your own teaching, as long as you cite this website as a source -- I even have a DOI to make it handy (see below)! You are not allowed to use re-mixed or re-purposed versions of these materials for any commerical purpose. If you make modified versions of these materials available for free, you must do so under the this license.

Sharing and Dissemination

Feel free to share the textbook / materials with anyone who'd find them useful! I recommend sharing links rather than downloaded versions, as I update things regularly. You are not allowed to sell or otherwise use these materials for any commercial purpose, even with attribution.

Citing Usage

If you use or modify and use materials from this site, please just cite us using our DOI: DOI