Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Using Astropy for Astronomy With Python (Summary)

This course uses real world calculation problems from astronomy to teach you some third-party data and science libraries. In it you learned about:

  • Astronomy coordinate systems
  • Astropy
  • Using pandas to store and filter calculated data
  • Building graphs with Matplotlib

For more information on using astronomy with Python, see:

To dive deeper into some of the things you’ve learned, you might enjoy other Real Python content:

Download

Course Slides (.pdf)

11.8 MB
Download

Sample Code (.zip)

4.5 KB

00:00 In the previous lesson, I showed you how to trace the movement of bodies in the sky and graph their positions. I may also have said a few things under my breath about Matplotlib.

00:09 Alright, it wasn’t under my breath. This is the last lesson where I’ll summarize the course and point you at some other libraries you might find interesting.

00:17 Trying to find the right object in the sky can be complicated. It changes over time, and where to look is different depending on where you are on Earth.

00:26 Astropy has tools that help with this, including mechanisms for dealing with a variety of coordinate systems and to translate between them. It also has ways of looking up the positions of planets and stars and general 3D spatial math stuff, allowing you to do things like calculate the angle of separation between two bodies.

00:45 Although a little quirky to use, Matplotlib is a very powerful graphing library and pretty much the de facto one out there. It comes with many different graphing types, including histograms, line graphs, scatter charts, pie graphs, and more.

00:59 And you can even put multiple graphs in the same figure and interrelate the data between the graphs.

01:05 If you’re dealing with tabular data, instead of using lists of lists, you can use the pandas library and its DataFrame object. It has a function call, so you can read data from a CSV, manipulate the rows and columns of data, perform operations on whole rows or columns of data with a single line of code.

01:23 And because it’s built in a low-level library, it’s faster than equivalent pure Python code.

01:29 Astropy is a pretty big library, and I only touched the surface. If you want to dig in some more, there are a collection of tutorials and the docs themselves are pretty comprehensive.

01:39 There are also alternatives to Astropy out there. One of the bigger ones is PyAstronomy. It covers a lot of the same kinds of functions as Astropy. If you want to play with orbits, Orbit Romy is a library built on top of PyAstronomy that helps you visualize orbits or if you want to dig into the moon some more.

01:58 Hmm. Green Cheese FM might have what you’re looking for. If you want something a little simpler and only want to deal with how to plan your stellar viewing, Astroplan is an interesting little library that helps you schedule your ogling of the night sky.

02:13 And not a library, but a database, SIMBAD is a web-based tool you can use to look up all sorts of stellar information. In fact, I believe it’s one of the databases Astropy uses behind the scenes when it looks up an object by name.

02:26 If you haven’t got your fill of space stuff yet, you might also check out this course, which like this one focuses on writing code to play with astronomy data.

02:34 It includes velocity calculations for gravity slingshots, visualizing wavelengths output by stars, and mapping star attributes on a graph to compare them.

02:44 Like with this course along the way, you’ll learn a bit about pandas and Matplotlib. I may even have grumbled in that one as well. If you’d like to learn more about working with pandas and all the powerful things it can do, this video course and equivalent tutorial is a good place to start.

02:59 Start. It’s where I started when I first learned pandas and it’s quite well done.

03:03 And if you’ve done some pandas in the past, but you want to up your game, this content shows you some trickier things that can help solve some of your pandas problems.

03:12 My fellow writer Juliano and I hope you enjoyed this course. Happy coding.

Become a Member to join the conversation.