Blog
A blog of Python-related topics and code.
-
Higher Orders of Rainbow
Posted by christian on 01 October 2025
The different orders of rainbow caused by different number of internal reflections of light in a rain droplet are simulated and a derivation of their angular size given. The provided code simulates the rainbow orders that would be observed away from and towards the sun, assuming they were bright enough (in practice, only the primary and secondary bows are commonly observed).
-
Modelling a Phase Change with Kawasaki Dynamics
Posted by christian on 15 September 2025
-
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 $$