Astrophysics with a PC

2014/02/07 Tags: astronomy development

The newest addition to my personal library: "Astrophysics with a PC" by Paul Hellings. Published in 1994 I feared it might prove a bit dated. (Mostly because science and computing have moved at a great pace. For example, exoplanets were complete speculation, and computers were big slow and expensive things - albeit increasingly common.)

Still, astronomy and programming in one book - how could I possibly resist?

A glance through the book quickly put my mind at ease. The text focuses on the equations (without dwelling on their proofs, leaving them rightly for other texts) and then ends each chapter with the source code listing of a simple implementation. The source code is amusingly (from 2014) in QuickBasic though.

Familiar to those of us of a certain age, QuickBasic was included with MS-DOS and was thus readily available to PC owners of that era. It would have seemed a very accessible choice.

Fortunately as the book focuses on the how, the source code only serves to be a concrete starting point. In fact, judging from the comet tails chapter, the program is an old fashioned terminal interactive (no command line arguments, you enter the starting values into the program as it runs) and only outputs numbers.

I certainly could have typed the QuickBasic code verbatim and run it using a QuickBasic interpreter such as QB64. However, knowing I would want to build on the samples and being supremely disinclined to work in QuickBasic I opted for Python.

(Rationale: Java, C# are fine for work but this is play, and while I briefly considered others, I felt Python would allow me to get a result quicker. I plan on revisiting these samples later with Clojure.)

I intended from the start to create graphics, so off to Google to see what the internet recommended for Python GUI programming. Typically closed StackOverflow topics still proved helpful, and I chose QT via the PyQT wrapper.

To install on OS X, Homebrew made it easy:

brew install qt
brew install sip
brew install pyqt

I found the PyQt4 ZetCode tutorial a great place to start. The PyQt API is comprehensive.

With the tools ready, I turned to Chapter 2: Comet Tails.

Update

Samples converted to Python: https://github.com/cdacos/astrophysics_with_a_pc