Important
This page is intended for use by people with no Python experience, as such it aims to be readable by non-programmers. It is not clean Python by any stretch of the imagination and doesn't aim to be. If you're not used to Python, and still find it unreadable drop me a mail and I'll try to clear up any problems.
I don't really consider myself to be a keen amateur astronomer, but I always try to catch the unusual events. I'll stay up until four in the morning for a partial lunar eclipse or get up at five for the most partial of solar eclipse, and I have vague recollections of borrowing an uncle's binoculars when I was at primary school to view Halley's comet. So this January I've had to add viewing Robert McNaught's recent discovery to my to-do list.
The question on my mind now is which unearthly hours, and on what days, will I need to be awake to view this celestial wonder. The average person no doubt hunts around on Google to find a website with times and date for their location, or possibly watches the BBC's The Sky At Night in the hope of some information. I'm not the average person though, I'm a geek and as a geek I want a tool that can tell me this and more.
It turns out there aren't any tools available to do exactly what I want, or at least none that I can find. I want something scriptable, that way I can seed my calendar and forget about the dates. I want something that displays actual data, I don't care simply for pretty pictures. And finally, perhaps most importantly, I'd like to learn something new along the way.
After playing with the excellent stellarium and Xephem I came to the conclusion that I needed something a little more low-level so I could accomplish my calendar syncing. A final search with eix resulted in PyEphem, a set of Python bindings for Xephem's backend library libastro.
Important
The licensing situation of PyEphem isn't exactly clear. The libastro code is entirely non-Free as is the rest of the Xephem project it comes from, resembling the strictest of closed source proprietary software in its usage terms. However, the PyEphem author has released his code under the GPL with a copy of the libastro source with the permission of its author that can only be used for building the Python module. The wording of the copyright notices appear to make it impossible to even distribute binary builds of the PyEphem module. Read the licenses for yourself, and see if they're acceptable to you.
PyEphem appears to fulfil all of my requirements and gives me a reason to dust off the Python cobwebs a little. I'm going to limit myself to talking about basic output from PyEphem, but if you're interested in the other ways I've been using it drop me a mail and I'll clean up those scripts for posting.
The first thing I wrote was a small script to output the rise and set times of Comet McNaught so that I can plan a time to look for it, it is called mcnaught_ephemeris.py. Living in the UK one gets used to having to make numerous attempts at viewing anything, and that is especially true when winter weather needs to be taken in to account, therefore the first job was to display daily rise and set times for the comet. It generates simple text output, such as the snippet below for the days around its perihelion:
2007-01-11 > McNaught rises @ 07:22:46 > Sun rises @ 08:08:01 > Duration 45 minutes < Sun sets @ 16:10:18 < McNaught sets @ 17:17:05 < Duration 66 minutes 2007-01-12 > McNaught rises @ 07:41:05 > Sun rises @ 08:07:19 > Duration 26 minutes < Sun sets @ 16:11:47 < McNaught sets @ 17:05:58 < Duration 54 minutes 2007-01-13 > McNaught rises @ 08:03:48 > Sun rises @ 08:06:35 > Duration 2 minutes < Sun sets @ 16:13:18 < McNaught sets @ 16:50:08 < Duration 36 minutes
Note that the layout is totally non-standard, but it provides all the information I need and is narrow enough to display easily on my phone. That in itself is a good thing because it allows me to have the "complete" information displayed in calendar entries on my phone.
I'm going to explain a few parts of the script and simple improvements, so maybe it can be useful to you too.
# McNaught Xephem entry from
# http://cfa-www.harvard.edu/iau/Ephemerides/Comets/Soft03Cmt.txt
McNaught = ephem.readdb("C/2006 P1 (McNaught),h,01/12.7961/2007,77.8349,267.4144,155.9771,1.000019,0.170742,2000,6.0,4.0")
PyEphem allows you to enter new objects it knows nothing about in the format supported by the underlying library, namely Xephem format. There are many, many resources on the 'net that supply data using this format or if you can't find the object you're looking for you can create your own.
Note
I've received a few mails concerning inputting your own non-Xephem formatted data, and instead of answering each individually I've described the process on a companion page.
# Location for my house :) Approximately, 50 kilometres south west of
# Cambridge, UK. For all intents and purposes elevation is entirely
# redundant for these calculations, and can be ignored. The
# accuracy expressed in the latitude and longitude values are also
# neither required, nor particularly useful outside of being a good
# example of false precision. I just happen to have the information
# to hand in this format from my FOAF file.
home = ephem.Observer()
home.lat, home.long, home.elev = '52.015', '-0.221', 60.0
The section above sets the location of the observer, you, and you'll notice that the latitude and longitude are given as strings not as floats as you might imagine. PyEphem assumes that floats for latitude and longitude are in radians and not degrees as you may expect.
The other alternative would be to use Python's excellent math module to do conversion for you. For example:
import math
home.lat, home.long = math.radians(52.015), math.radians(-0.221)
but I'm sure you'll agree just using strings is much easier in this case.
home.date = ephem.date('2007/1/5')
It is important to remember here that PyEphem expects all times to be UTC relative. The above date sets the observer's date and time as 2007-01-05T00:00z. If for example you live in Hawaii and set the date as above you'll be calculating positions for a local time of 14:00 on the January the 4th. This can easily cause you to calculate the locations for the previous or next day by mistake if you're not careful, for more information read the dates section in the manual the comes with PyEphem.
Note
There are some accompanying notes on the calculation of the sunrise and sunset times that address calculation against darkness times instead.
You could add other data to the output too such as print McNaught.rise_az to display the location on the horizon that the comet will be located as it rises. I've ignored it in this case, because I already knew it would be around the 100° point at sunrise.
You could also use plotutils or gnuplot to generate transit maps simply by stepping from the object.rise_time to object.set_time and storing the azimuth and altitude at each point. In fact I'm going to suggest this produces cleaner and more useful images than the packages with actual GUIs I mentioned at the top because it displays only the required information. Given a computer controlled telescope, which I don't have unfortunately, the same basic procedure could be employed to make a simple sky tracking system.
If you have any questions you can drop me a mail, and I'll do my best to answer them.
Downloads
- mcnaught_ephemeris.txt (sha1 digest = aa2ba8cd03e909332a5848348d4d7f137ebb10a7)