## Are you more likely to give birth on a full moon?

I have been attending ante-natal classes recently and, although I greatly appreciated our teacher, I found myself skeptical about some of her claims.  For example, our instructor was adamant that it is more likely to give birth during a full moon than on other days. She even told us that maternity wards are over-run during full moon nights!

In order to investigate this claim, I decided to look at some birth records. The centre for disease control in the US keeps very thorough records of births. These can be freely downloaded from: http://www.cdc.gov/nchs/data_access/Vitalstatsonline.htm . It is also possible to download the date for full moons from this website .

Having obtained data for dates of birth and dates of full moon, I  wrote a program to extract the probability of giving birth as a function of phase in the moon. The following graph shows the results for births in the US in 1969.

The x axis shows the number of days between the birth and the full moon and the y axis shows the probability of birth. If there was a correlation between full moon and likelihood of giving birth, there should be a peak in the distribution about x=0. However, clearly, the distribution is flat. Therefore there is no correlation between these two quantities. I guess it is still possible that only british women feel the influence of the moon. I somehow doubt that!

Here is the code I used to analyse the data:


import bisect
#birth data from CDC: http://www.cdc.gov/nchs/data_access/Vitalstatsonline.htm
#Phases of the moon from http://moonphases.info/past_full_moon_dates_calendar.html#1970

codeToYear={'9':1969, '0':1970, '1':1971}

FullMoon1969 = [ [03,01,1969], [02,02,1969], [04,03,1969], [02,04,1969], [02,05,1969], [31,05,1969], [29,06,1969], \
[29,07,1969], [27, 8,1969], [25, 9,1969], [25,10,1969], [23,11,1969], [23,12,1969] ]

#here i build the cumulative number of days from the beginning of a year to a certain month, in order to convert a date
#into an integer describing the # of the day of the year
length_of_month = [ 31, 28, 31, 30, 31,30,31,31,30,31, 30,31]
cum_day_by_month = dict()
cum = 0;
for i in range(1, 13):
cum_day_by_month[i] = cum
cum += length_of_month[i-1]

def get_birth_day(s):
year = codeToYear[s[0]]
month = int(s[83:85])
day   = int(s[85:87])
return [ day, month, year]

def hash_date(date):
[d,m,y] = date
# when the day is not recored, the field is entered with a 99
if d != 99 :
return cum_day_by_month[m] + d
else :
return - 1

def get_hash_birth_day(s):
return hash_date(get_birth_day(s))

# this list contains the day of the year when a full moon occured
full_moon_hashed = map(lambda x : hash_date(x) , FullMoon1969)

def d_from_full_moon(h):
# bisect_left ensures that h <= full_moon[i]
i = bisect.bisect_left(full_moon_hashed, h)
if i != len(full_moon_hashed) :
d1 = h-full_moon_hashed[i]
d2 = h-full_moon_hashed[i-1]
if abs(d1) < abs(d2) :
return d1
else:
return d2
else:
return h-full_moon_hashed[i-1]

distribution_full_moon_d = list()
for i in range(36):
distribution_full_moon_d.append(0)

f = open("NATL1969.PUB", 'r')
count = 0
for line in f:
hd = get_hash_birth_day(line)
#ignore the births where the date is non-reported
if hd != -1 :
d = d_from_full_moon(hd)
distribution_full_moon_d[d+18] += 1
count += 1

print "#number of records counted: " , count
print "#days from/to full moon, probability"
for d in range(36):
print d-18, float(distribution_full_moon_d[d])/count


Advertisements
Posted in Uncategorized | 5 Comments

## Which way round do the pedals go?

Since my last post was cycle related, I thought I would share the most fiendish problem regarding bikes that I have come across so far, courtesy of one my colleagues from Southampton (GR!).  It has resurfaced with a colleague at Imperial (PB) and I fear I may in the spur of the moment given the wrong solution. Here is my attempt to right my wrongs.

Imagine you have a bike with its pedals in the vertical position. The bike is assumed to be magically balancing and not falling sidewise, whilst still being free to move backwards and forwards. You grab the bottom pedal and push it backwards. Will the bike move forwards or backwards?

Consider the diagram below:

The two important points on this diagram are: 1), the bottom of the rear wheel and 2) the bottom pedal.What the problem boils down to is the position of the bike as a function of the position of 2.  The other quantities shown on the diagram are the angles φ and θ describing the positions of 1 and 2 relative to the bike itself, the radius of the back wheel ‘r’ and the length of the pedal cranks ‘k’.

Assuming that the bike travels in a straight line, the centre of the cranks (the bottom bracket) is at a point with coordinates (d,0), where d is the distance that the bike has travelled. I will define d such that it is positive if the bike is moving forward and that it has a value of 0 when the pedal and the bottom of the wheel are in the positions shown in the diagram. It is very straightforward to relate d to the angle φ:

$d=r \phi$,

this is simply because the wheel is not allowed to slip, therefore for each inch that the bike moves forward the wheel must rotate anti-clockwise. Notice that φ is implicitly defined to be positive when the wheel is rotating anti-clockwise.

Next we want to relate φ to θ. In order to do this, we need to know the gearing g of the bike. I define this as the number of turns the wheel makes for every turn the pedals make. So a high gearing is the one you use when speeding downhill and a low gearing when struggling to get up a steep mountain.  With this definition in mind, it is clear that the two angles can be related by:

$\phi=g\theta$

Now we know φ, all that is left to do is to write down the position of the pedal in cartesian coordinates. Since the position of the centre of the cranks is (d,0) and since the pedals are turning in a circle of radius k and defining φ as 0 when in the position shown in the diagram above we conclude that the position of the cranks can be written as:

$p=\left( d-k~sin(\phi),-k~cos(\phi)\right)$

we can use our other formulae to eliminate d for φ:

$p=\left( \phi~rg-k~sin(\phi),-k~cos(\phi)\right)$

When we push the pedal backwards, we are making the x position of the pedal small and negative. The question boils down to whether this corresponds to φ being positive or negative. It is evident from the formula above that the answer must be “it depends” on the values of g,r and k. Let’s do a little bit more analysis to show exactly how. If the x position is small, then we can assume that φ is also small and that the sin can be approximated linearly. If we then measure distance in units of k and divide the whole problem through by k we find:

$x=\phi\left(g'-1\right)$

where g’ has been defined as $g'=\frac{g r}{k}$. So there are two cases. If g’ is greater than 1, then a negative x corresponds to a negative φ. This means that moving the pedal backwards corresponds to the cranks and the wheel rotating clockwise and hence to the bike moving backwards. On the other hand, if g’ is smaller than 1, then a negative x corresponds to a positive φ. In this case, moving the pedal backward makes the wheel turn anti-clockwise and hence the bike moves forward. Since most normal bikes have a gearing g greater than 1, and since it would be hard to design a bike with cranks longer than the radius of the wheel, g’ is almost always greater than 1 therefore for a normal bike, if you push the pedals back, the bike moves back!

Posted in Uncategorized | 4 Comments

## Times cycle campaign

I invite you guys to subscribe to the Times’ cycle campaign to make British roads safer for cyclist.

Posted in Uncategorized | Leave a comment

## Making a “hovering box” in Tkinter

I have found myself programming GUIs recently using python and Tkinter. I was particularly interested in the providing users with help by creating hover boxes that display a certain message when the mouse is hovering over a certain widget.

I would like to post the code I used to develop this, hopefully someone will find it useful!

from Tkinter import *
import re

class HoverInfo(Menu):
def __init__(self, parent, text, command=None):
self._com = command
Menu.__init__(self,parent, tearoff=0)
if not isinstance(text, str):
raise TypeError('Trying to initialise a Hover Menu with a non string type: ' + text.__class__.__name__)
toktext=re.split('\n', text)
for t in toktext:
self.add_command(label = t)
self._displayed=False
self.master.bind("<Enter>",self.Display )
self.master.bind("<Leave>",self.Remove )

def __del__(self):
self.master.unbind("<Enter>")
self.master.unbind("<Leave>")

def Display(self,event):
if not self._displayed:
self._displayed=True
self.post(event.x_root, event.y_root)
if self._com != None:
self.master.unbind_all("<Return>")
self.master.bind_all("<Return>", self.Click)

def Remove(self, event):
if self._displayed:
self._displayed=False
self.unpost()
if self._com != None:
self.unbind_all("<Return>")

def Click(self, event):
self._com()


I decided to use Menu widgets because of the post method that allows you to place the floating menu where you like, but I was also interested in allowing for having messages on multiple lines. This works, but is kind of hacky – I am interested in superior solutions!

I also include a simple App that uses this hover box:

from Tkinter import *
from HoverInfo import HoverInfo
class MyApp(Frame):
def __init__(self, parent=None):
Frame.__init__(self, parent)
self.grid()
self.lbl = Label(self, text='testing')
self.lbl.grid()

self.hover = HoverInfo(self, 'while hovering press return \n for an exciting msg', self.HelloWorld)

def HelloWorld(self):
print 'Hello World'

app = MyApp()
app.master.title('test')
app.mainloop()


Posted in Uncategorized | 1 Comment

## Poor Mr Boole

Numerical integration is awfully useful. Most of us will remember the trapezoid rule that we learn at school, where the function we are integrating is substituted by a straight line and the integral as estimated as the are under the curve:

$I_2~=~\frac{1}{2}h\left(f_1-f_0\right)$

where h is the interval that we split the curve into and $f_1$ and $f_0$ are the values of the function on either side of the function.

One way to obtain better methods is to interpolate higher order polynomials, and the integrate those. It is possible to, for example, use three points and interpolate with a parabola, four points and interpolate with a cubic or five points and interpolate with a quartic. This latter method is often called Bode’s rule. But here comes the shocking news: it wasn’t Bode who came up with, but the English mathematician Boole. It became known as Bode’s rule because of a misprint in a maths textbook from the 70s. I guess the consolation prize is that Boole got a whole branch of logic named after him.

So does Boole’s rule make a better approximation than the just applying the trapezoidal rule? In this picture I will show sin(x) with x between 0 and $\pi/2$ fitted with 5 straight lines (green curve) and with the polynomial used in Boole’s rule (red curve):

The red (corresponding to Boole’s rule) is pretty much right on the sin curve. If we actually take the difference between the fits and the sine curve we obtain the error:

where blue is the error using trapezoidal rule and green sticking with Boole.

The moral of the story is that you can get the name wrong, so long as you get the Maths rights!

Posted in Uncategorized | 3 Comments

## Antiparticles and Solar Cells: what’s the connection?

The answer is: the Dirac sea. Paul Dirac developed a quantum mechanical theory of the electron which is compatible with special relativity. In order to satisfy special relativity, the energy of the electron must satisfy the following equation:

$E^2 = m^2 + p^2$

where E is the energy, m is the rest mass of the electron and p is it’s momentum. (this is the correct version of $E=mc^2$ by the way). Dirac realized that there was something funny about this equation, when you take the square root to determine the energy of an electron it allows for both positive and negative roots. I am sure most of us would have just brushed these uncomfortable negative solutions under the carpet, but Dirac postulated that the negative solutions do in fact exist – except they are always occupied. The vacuum, in Dirac’s interpretation,  is teeming with these negative energy electrons. Dirac realised that if one of these negative energy electrons was excited to a positive energy state this would leave behind an empty state. This empty state would behave like a positive charged particle with inverse characteristics to a normal electron: the idea of positrons was born. In particular if a positron met an electron, the electron would simply return to its negative energy state liberating some energy, a process known as annihilation.

So what does this have to do with solar cells? The idea of the Dirac sea has now been abandoned in particle physics, but a close analogue is very important in the theory of solar cells. The figure below shows the energy levels in a semiconductor. There are a whole load

occupied (valence) states all full of electrons. Then there is a large sway of energy with no states (a band gap) and a whole load of empty (conduction) states. When a photon with energy greater than the band gap is absorbed, an electron is promoted to the empty states, leaving behind an empty space. Solid state physicists call this a “hole” rather than a positron, but the concept is exactly the same as Dirac’s. To a solid state physicist a hole is every bit as real as an electron, carrying current, holding a potential just as if it was an anti-electron.

It’s weird to think about “nothing” as something. Solar panels make half their current through absences of electrons. A beautiful  application of Dirac’s  seemingly abstruse idea!

Posted in Uncategorized | Leave a comment

## What is the most efficient way to boil water?

Today, an experimental post. I was wondering what is the most efficient way to boil water, using a kettle or boiling on the gas hob? In order to determine this, I decided to knuckle down and experiment (for those of you who know me, you will realise this is somewhat out of character).

In order to determine how much energy it takes to boil half a liter of water, I turned the heating off and took a gas reading, including the little wheel reading that measures how many cubic feet of gas I have been using. I put the water in a non stick pot (lid on) and put it on the medium hob at max power. It took 5.25 cubic feet of natural gas to boil half a liter. Converting cubic feet of natural gas to Joules is not straight forward. In principle I would need to density of the gas, which might depend on atmospheric pressure and temperature etc. and also I would need to know the exact type of gas, it might in fact not be 100% methane. Luckily I found a website that does it for me. So to 1 significant figure, it takes 6 MJ to boil half a liter of water.

To work out how much electricity it takes to boil half a liter, I simply timed the kettle. It took 103 seconds. The kettle claims it is rated at 2000/2400 W.  This implies that (to one significant figure) it takes just 0.2 MJ using the kettle. This is actually a very small amount of energy. In fact, it is possible to determine the minimum possible amount energy required to raise half a liter of water from room temperature (20 degrees) to boiling (100 degrees). The specific heat of water is 4.2 J/g, so I deduce that the minimum amount of energy it takes to boil half a liter is 0.17 MJ. The kettle is approximately 85% efficient!

Comments on the validity of this approach. I wish I had a thermometer to determine the exact temperature of the water, rather than relying on when I think the water is boiling in the pot. I also wished I had a high voltage ammetre to measure the actual power usage of kettle.

The conclusion of all this is that the kettle is massively more efficient (almost 20 times more efficient) than the gas on the hob. I believe that even if we allow for the fact that electricity production is not 100% efficient the kettle wins. So long as you only boil as much as you need!

Posted in Uncategorized | 8 Comments