A blog of Python-related topics and code.

Searching for pi-mnemonic strings in a text

Piphilology comprises the creation and use of mnemonic techniques to remember a span of digits of the mathematical constant $\pi$. One famous technique, attributed to the physicist James Jeans uses the number of letters in each word of the sentence:

Quadtrees #1: Background

The quadtree data structure is a convenient way to store the location of arbitrarily-distributed points in two-dimensional space. Quadtrees are often used in image processing and collision detection.

Processing UK Ordnance Survey terrain data

The UK's Ordnance Survey mapping agency now makes its 50 m resolution elevation data freely-available through its online OpenData download service. This article uses Python, NumPy and Matplotlib to process and visualize these data without using a specialized GIS library.

Visualizing uncertainties in plotted data

The equation for the temperature-dependence of the diffusion of hydrogen in tungsten may be written in Arrhenius form: $$ k = A\exp\left(-\frac{E}{T}\right) \quad \Rightarrow \; \ln k = \ln A - \frac{E}{T}, $$ where the temperature, $T$, and activation energy, $E$, are expressed in eV and the pre-exponential Arrhenius parameter, $A$, and rate constant, $k$, take units of $\mathrm{m^2\,s^{-1}}$. From the study of Frauenfelder [1] the parameters $A$ and $E$ may be associated with uncertainties as follows: $$ \begin{align*} A & = (4.1 \pm 0.5) \times 10^{-7}\;\mathrm{m^2\,s^{-1}}, \\ E &= 0.39 \pm 0.08 \;\mathrm{eV}. \end{align*} $$ These uncertainties can be propagated to the expression for $\ln k$: $$ \sigma_{\ln k} \approx \sqrt{ \left( \frac{\sigma_A}{A} \right)^2 + \left( \frac{\sigma_E}{T} \right)^2 }. $$ If we assume the uncertainty remains normally-distributed, Matplotlib's imshow function can be used to illustrate the Arrhenius equation for this data.

Turning an image into a sticker chart

To produce a children's sticker chart from a provided image, the following code divides it into squares (which can be cut out) and produces further images with matching labels for the reverse side of the printed image and a piece of card onto which the squares can be stuck (you need to provide your own glue).