A blog of Python-related topics and code.

Visualizing the Temperature in Cambridge, UK

The Digital Technology Group (DTG) at Cambridge University has been recording the weather from the roof of their building since 1995. The complete data are available to download in CSV format from the DTG website as the file weather-raw.csv.

A "universal" formula for egg shape

A recent article, Narushin et al., "Egg and math: introducing a universal formula for egg shape", Ann. N.Y. Acad. Sci. 1505, 169 (2021) introduces a "universal" formula for the shape of eggs, including "pyriform" (pear-shaped) eggs such as those of the guillemot – supposedly, such eggs roll in a circle when disturbed so that they do not fall off the cliffs where these birds nest.

Visualizing Kaczmarz's Algorithm

Kaczmarz's algorithm is an iterative algorithm for solving a system of linear equations. In its simplest form, the equations are written in matrix form, $\boldsymbol{A}\boldsymbol{x} = \boldsymbol{b}$ and, starting with the initial guess for the solution, $\boldsymbol{x}_1 = \boldsymbol{0}$, the zero vector, successive approximations are generated by projecting $\boldsymbol{x}_k$ onto the hyperplanes defined by the rows of $\boldsymbol{A}$: $\boldsymbol{a}_1, \boldsymbol{a}_2, \ldots$. $$ \boldsymbol{x}_{k+1} = \boldsymbol{x}_{k} + \frac{b_{i} - \boldsymbol{a}_i.\boldsymbol{x}_k}{|\boldsymbol{a}_i|^2} \boldsymbol{a}_i $$


This is just a simple script that takes an image and renders it as a grid of ASCII characters in the console. The character chosen depends on the brightness of each pixel in the image: the following sequence (from densest (brightest) to least dense) is used:

Raincloud plots comparing rainfall in Wales and East Anglia

As a companion script to this one on UK monthly temperatures the Met Office's data on rainfall can be compared in a similar way. The script below produces "raincloud" plots of the monthly rainfall since 1891 for two regions of the UK: East Anglia (relatively dry) and Wales (notoriously wet). The "cloud" for each month is a kernel density estimate of the distribution of the number of days on which at least 1mm of rain falls; the "rain" is a histogram of the same data.