Grid Running – Part Ia

As a post-script to last week’s post, here’s a snippet of Python code that uses the wonderful matplotlib to display a given frame of Timepix data. It takes the Comma Separated Value (CSV) file generated by the frame reader and plots a “pixel” at each (x, y) with a colour corresponding to the number of counts measured by that pixel.

iPython_screenshot

I’ve added the Python code to the github repository as display.py, but it’s also included below so you can use it however you like. I’ve been having a lot of fun with IPython and the IPython notebook (which you can find out how to install on your own system here) to do all this on a web browser (screenshot above). But here’s the source code anyway:

###############################################################################
#              CERN@school: A very simple Python frame display                #
###############################################################################
# Author: T. Whyntie - t.whyntie [at] qmul.ac.uk                              #
# Date:   April 2013                                                          #
###############################################################################
#!/bin/env python

# Import what we need from numpy and matplotlib.
from numpy import loadtxt
from matplotlib import pyplot
from matplotlib.patches import Rectangle

# Open the data file - specify the actual filename between the quotes.
datafile = open("dataout0.csv", "r")

# Get the X, Y and C values from the data file.
X, Y, C = loadtxt(datafile, delimiter=",", unpack=True)

# Set up the plot area for the frame data.
pyplot.figure().add_subplot(111, aspect='equal') # ensure equal aspect ratio.
pyplot.xlim(0,256)                               # x limits.
pyplot.ylim(0,256)                               # y limits.
pyplot.gca().patch.set_facecolor((0,0,0))        # Black background.

# Select the "hot" colour map for the pixel counts.
cmap = pyplot.cm.hot

# Loop over the pixels extracted from the data file and draw a "pixel"
# in the plot area.
for x, y, c in zip(X, Y, C):
    pyplot.gca().add_patch( \
        Rectangle( # We now define the pixel's "Rectangle"; \
            (x,y), # The location of the pixel (lower-left corner);
            facecolor=cmap(c/C.max()), # The pixel colour (from the map);
            edgecolor='none',          # Edgeless pixels;
            width=1.0, height=1.0,     # Specify the size of the pixel.
            )\
        )

# Display the frame.
pyplot.show()

If you didn’t manage to get the frame reader working/compiling, I’ve put the CSV files of the test dataset on figshare too. Enjoy!

A Little Banana Activity

It’s a question that bugs us all at some point in our lives: just how many radioactive decays happen in your average banana per second? The banana is often held up (so to speak) as an example of an everyday object that can be used to placate a panicked public in discussions about nuclear safety (whether it should be is another discussion entirely). The source of the radioactivity is the potassium in the banana — or rather, the unstable potassium-40 isotope. You can read all about potassium-40 and its decay modes on Wikipedia. I certainly did.

So to our original question: roughly how many of these decays will take place per second? I thought I’d have a go at a “back-of-the-envelope” calculation. Quite literally:

Image

References: Potassium-40 on Wikipedia, potassium in an average banana (pdf).

I’ve assumed that because the timescales we’re considering are so small compared to the mean lifetime of potassium-40, the first rearrangement pretty much holds.

Now, there are two reasons I’ve posted this. Firstly, the question itself harks back to something I heard while visiting the Simon Langton Grammar School for Boys in September. They’ve got quite an interesting project going on there: the CERN@school project uses the “Medipix” chip for various experiments/data collection activities, and they often demonstrate what it can do by holding a banana next to it as a makeshift radioactive source. 13 decays per second seems like the right order of magnitude to make this feasible.

The second reason, though, is a little more self-indulgent: as I was doing the calculation yesterday, I was operating in bit of a vacuum. The numbers and approximations seemed reasonable, but I didn’t have anyone on hand to check them. Supposing I’d done something really silly with this seemingly trivial calculation? Would people be all, “oh, that’s OK, we all make mistakes”, or would I unleash the unrelenting fury of a thousand internet trolls? It’s an interesting question which I think has relevance to the “open science” debate: sure, “everybody goofs”, but do we like being called on those goofs in public?

I know what I think — but there’s only one way to find out…

Update (1447 4/3/2012): @sirjamesgreen has pointed me to this article which quotes roughly the same number. As he says, though, they haven’t shown their working…