Yet another narcissistic load of old cobblers that no-one will ever read.

The Sun and the Moon

For my Chacmool project, I want to display sunrise and sunset and also the moon phases.

I found some Python code to calculate the Sun times here:

I did find some code for calculating the moon phases elsewhere (e.g. but it looked pretty bloody complicated and I failed to get the Python 2 code I found to compile in my Python 3 project despite trying to modify it.  I'm not a Python expert!  It was after this minor failure that I discovered that you can make a much simpler calculation as long as your happy for it to be inaccurate by a few hours here or there.  Fine by me.  All you have to do is get the length of the average lunar cycle (see box), take the date and time of a recent new moon and see how many cycles fit in to the time span between then and now.  You then take the remainder from that and compare it to the cycle time to find out how far through the cycle you are.  Easy!

The synodic cycle (or lunar month) - which takes into account the Earth's movement relative to the Sun as well as the Moon's movement - is the time between new moons as observed by us here on our spinning Earthy platform.  This is different to the siderial month which is basically how long the Moon takes to do one orbit round the Earth without worrying about the Sun or what we see.  The siderial month is about 27.3 days whereas synodic month is about 29.5 days.

My Moon code can be found here:

I'll probably put all the code for my project up on Github or Bitbucket at some point in the near future.

You've just been mooned.

Add comment