Loading video player…

Exploring Astrophysics in Python With pandas and Matplotlib (Overview)

This course uses three problems often covered in introductory astro-physics courses to play in Python. Along the way you’ll learn some astronomy, and how to use a variety of datascience libraries like NumPy, Matplotlib, pandas, and pint.

In this video course you’ll learn about:

  • Introductory astrophysics topics
  • Working with dataframes in pandas
  • Writing code that uses scientific units
  • Visualizing information with Matplotlib
Download

Course Slides (.pdf)

6.6 MB
Download

Sample Code (.zip)

33.4 KB

00:00 Welcome to Exploring Astrophysics in Python using pandas and Matplotlib. My name is Christopher and I will be your guide. This course was built in conjunction with an astrophysics student named Juliano, so although you’ll only hear my voice, the material was a joint effort.

00:19 When you’re learning to code, the examples you play with are often based on classic computer science problems. It would be an easy mistake to make if you concluded that software was all about million-line programs and web or app dev.

00:32 But modern science is very dependent on coding to do its number crunching, and most scientists are now programmers and often data scientists to boot. This course explores one corner of that idea by delving into three problems encountered in introductory astronomy courses.

00:48 That makes this course a bit of a mishmash rather than a specific learn Python or learn pandas. It’s more of a collection of examples where you can see some of those things in practice, and along the way you might learn something about astronomy and astrophysics as well.

01:03 I’ll be using several different libraries along the way, including pandas, the Pint library for dealing with units and Matplotlib to visualize your results.

01:13 I’ll be making no assumptions about your knowledge of any of these topics. Nothing will be deep dive, but as long as you’re comfortable with Python, the language, everything else will be covered as I go along.

01:24 Code in this course was tested using Python 3.12, Matplotlib 3.9, NumPy 1.26.4, pandas 2.2.2, and Pint 0.24.1. Lots of libraries to check out this time.

01:40 By pure lines of code, the vast majority of software out there is for business applications, and that tends to mean web and app development. Coding for science is subtly different.

01:51 First off, there’s more of a focus on the end result. Of course, results are important in business as well, but here you’re often writing software that you might not reuse.

02:00 Once you’ve crunched the numbers. Once you’ve caught the result you’re looking for, you might not do it again. And not always, but frequently, the software is written by you and for you.

02:10 You’re writing a script to solve a problem, not writing software to solve a problem for a large set of users.

02:16 This course is about doing some astrophysics with Python. Astrophysics and astronomy tend to be a data-heavy science. For example, you might be using large catalogs of stars and their attributes to do computations or visualization.

02:30 Python is a great language for doing this kind of work as it’s fairly quick to put something together and when combined with libraries like NumPy and pandas, it can be performant as well.

02:41 This course uses Python to look at three different problems. The first is to calculate a spacecraft’s velocity when using a gravity assist. The second crunches Planck’s law and graphs the results to see what radiation a star of a certain temperature emits.

02:55 And the third takes a data file and visualizes star properties in something called a Hertzsprung-Russell diagram: a chart that helps astronomers visualize the lifecycles and evolution of stars.

03:07 Let’s get started by doing a flyby of Jupiter and borrowing some of its speed using a gravity assist maneuver.

Become a Member to join the conversation.