Friday, February 8, 2008

The Weather here...

OK, part of the problem here is that I have so much stuff and it is difficult to get started. The weather is always a good subject to get a conversation going and it is quite t(r)opical at the moment.

I live in Central Queensland, and we are in the middle of the wet season. (Also the hurricane/cyclone season, but they are fortunately pretty rare in these parts, and even when they happen, well Cyclone Larry a couple of years ago was about a thousand km north of here, and I had to explain to American friends who called concerned about my wellbeing that this was the equivalent of a Florida hurricane if you lived in Virginia)

On the other hand we get severe thunderstorms and associated hail so it is useful to keep a watch out for what is going on so that you can move your car inside. (One of our friends who is a car dealer lost seventy vehicles in a hailstorm once...)

Anyway, there is a local weather radar on the Bureau of Meteorology weather site, which displays an updated weather picture every ten minutes. You can leave your browser open and keep an eye on things. However to really get a feel for which way the weather is coming, it is better to watch a loop, and they provide this too, but only four recent images. I wanted to watch the longer term development of storm systems, so here is the answer:


import time, urllib
rfile = "IDR233_%03d.gif"
dataFile = "http://mirror.bom.gov.au/radar/IDR233.gif"
i=1
while 1:
urllib.urlretrieve(dataFile, rfile % i)
i+=1
time.sleep(600)




The image I want to download is the same each time, but I want to save it to a series of images that I can replay, so I generate a unique new filename each time, hence the counter. Apart from that, there isn't much to see here, its just eight lines of code that took a couple of minutes to write. Here is the result, a few frames put into an animated gif showing a major thunderstorm approaching Gladstone:



Now my original intention with this blog was to talk about a whole lot of interesting scientific and engineering applications for Python, so why am I starting off with what is a very trivial web application? Because Python (batteries included) has this stuff as standard libraries and easy to use. And since it is there, I learned how to use it. I may not use it much, but it has given me insight into other areas of computing (this internet web series of pipes thingy that everyone seems to be on about
these days.

So Python is keeping me learning and that is insanely great.

Incidentally, I learned how to use the urllib stuff from working through the Python Challenge website. Its a very useful collection of little problems that introduced me to the more web-centric use of the language: a different erspective on the language to the engineering issues I generally deal with.

No comments: