Paul Strickland

Paul Strickland

A Simple Airspeed Converter Part 1

The screenshot below shows the end result of my first “complete” programming project. It is a simple calculator that converts airspeeds between some commonly used units. I wrote all the code from scratch, and the module that contains the conversion code is the first I’ve written to be fully covered by unit tests. The module exists as the first code in my new toolkit, but I also managed to build the converter as a standalone application using cx_Freeze and Inno Setup, allowing it to be installed as a Windows application. The basic GUI is the first that I built with a decent understanding of how everything works, gained largely from reading Rapid GUI Programming with Python and Qt. 1

Airspeed Converter GUI
A simple GUI to convert airspeeds

In this article, I describe my reasons for the converter and how I set about writing the module. In part two I’ll outline the process I used to build an application that can be installed on Windows without having to separately install the dependencies.

The WIAT package

Following a few experiments using Python to help with my day job, such as the trajectory calculator I wrote last year, I began to consider the idea of building a toolkit containing a few useful tools and utilities.

A toolkit needs a name, and in the absence of anything more imaginative I came up with the name of WIAT — Weapons Integration Assessment Toolkit.

Since I hacked together the trajectory calculator in a horribly messy way, I couldn’t start my toolkit with code like that. I therefore decided to choose something a bit more simple that I could produce relatively quickly, and also in a more complete state than anything I’ve written so far. In addition, a tool with a simple GUI would help me to continue learning PyQt4. Finally, I wanted to be able to package my code so that I could simply install it on a Windows computer without having to separately install Python and third party packages. This would also make it easier to share with other people where I work.

An airspeed converter

The speed of an aircraft can be represented in several different forms. For fast jet aircraft, speed can be measured as true airspeed, calibrated airspeed and as a Mach number among others.

Each measurement is useful for different reasons, and there is often a need to convert between them. Such conversions are non-linear, however, and additional parameters such as temperature and altitude may need to be considered.

The first tool in my toolkit, therefore, would be an airspeed converter. I would be able to develop a simple GUI that I could use to quickly perform standard conversions, and I would also have a Python module that I could use in future projects.

Writing the module

For the purposes of this project, I wrote my own module to perform the required calculations. However, a much more comprehensive package exists called AeroCalc. Whilst I could have used that, I wanted to write everything myself this time.

Atmosphere Model

A key feature of airspeed calculations is the atmosphere model. The model represents the changes in temperature, pressure, density and so on at different altitudes. Several models exist, but I chose to use the US Standard Atmosphere, 1976 2. Produced by NASA, it is available in the public domain.

The model consists of a number of equations that determine the change in temperature with altitude, and from that several other parameters are derived.

I wrote this module by first writing the unit tests that I required my code to pass. Correct values for each test were obtained from the look-up tables within the atmosphere model.

To test my conversions between true and calibrated airspeed I used another NASA document, Measurement of Aircraft Speed and Altitude 3


One problem I encountered when writing unit tests was the changing level of accuracy. Using look-up tables for reference values provides a limited level of precision, typically 4 or 5 significant figures. Whilst this works for units such as temperature, for others, such as dynamic pressure, there can be varying levels of rounding errors to handle.

Fortunately the built-in unittest framework includes the assertAlmostEqual method. This allows the test to be specified to an acceptable level of accuracy.


  1. Summerfield, M., Rapid GUI Programming with Python and Qt, Prentice Hall, 2008. 

  2. NASA, U.S. Standard Atmosphere, 1976, available at [accessed 09 March 2013]. 

  3. NASA, Measurement of Aircraft Speed and Altitude, available at…/pdf/88377main_H-2044.pdf‎ [accessed 17 March 2013]. 

comments powered by Disqus