Blog
A blog of Python-related topics and code.
-
Converting between an OS grid reference and longitude/latitude
Posted by christian on 02 June 2025
-
Highlighting a country on a Cartopy map
Posted on 26 February 2025
Cartopy is a Python package for geospatial data processing, map production and other geospatial data analyses. This short script plots a map of the world using an orthographic projection and highlights a specified country.
-
Making a map out of dots
Posted on 12 April 2024
-
Two's complement and Python indexing
Posted on 07 April 2024
This blog post explains how computers represent signed integers using two's complement, where negative numbers are stored by inverting all bits of the positive number and adding 1 (e.g. -13 becomes 11110011). This system simplifies arithmetic operations and avoids dual representations of zero.
This can be exploited to index Python sequences as though they are one-based instead of zero-based.
-
The Kapitza pendulum
Posted on 04 March 2024
The Kapitza pendulum is an inverted pendulum that can balance stably when driven by an oscillating vertical displacement. Its behaviour can be described using Lagrangian mechanics and modelled in Python, using the NumPy, SciPy and Matplotlib libraries.
-
How wet was Cambridge in February?
Posted on 01 March 2024
Just a quick (20 min) analysis of the rainfall in Cambridge in February since 1996 to see how wet it has been compared with previous years. Data are taken from the amateur-maintained weather station on the roof of the Cambridge University Computer Laboratory.
-
The Kelvin wake pattern
Posted on 20 February 2024
An object (ship, duck, etc.) travelling across the surface of water at a constant velocity $\boldsymbol{u}$ produces a characteristic wake pattern of waves first described by Lord Kelvin. In his model of the effect, he assumed deep, still water, neglected surface tension, and restricted the magnitude of the pressure causing the wave to be small enough that the relevant equations of motion could be treated as linear.
-
The two-dimensional wave equation
Posted on 17 February 2024
The wave equation is a second-order linear partial differential equation describing the behaviour of mechanical waves; its two (spatial) dimensional form can be used to describe waves on a surface of water: $$ \frac{\partial^2 u}{\partial t^2} - c^2\left( \frac{\partial^2 u}{\partial x^2} + \frac{\partial^2 u}{\partial y^2} \right) = 0 $$
-
Analysing flight punctuality data for UK airports: I. Basic statistics for 2022
Posted on 09 February 2024
The UK Civil Aviation Authority (CAA) publishes regular statistics on the punctuality of flights arriving at and departing UK airports. These data can be retrieved with the script available on the GitHub repository accompanying this blog article: `get_data.py`.
-
The equation of the circle through three points
Posted on 14 October 2023