Saturday 15 December 2012

You Don't Have to Be a Scientist...

2012-12-14


A recurring hobby in my life has been amateur meteorology.  I was recording daily temperatures and precipitation back in elementary school, preparing colour-coded charts and trying (largely in vain) to issue forecasts of my own.  I picked up on the hobby again shortly after my bout with cancer, eleven years ago.  First it was a simple recording thermometer, from which I dutifully took daily readings and reset the little magnetic floats; then a wireless digital model which I could read from indoors (a boon during the winter); more recently a full-blown, computerized amateur station (that died); and, finally, with the current wacky setup, which has been running for about eight months.

Those who know me well know that I have a passion for improvising and squeezing performance out of obsolescence.  I hate throwing out a computer unless it's simply too old to do anything useful.  My home weather station involves an ancient thin client with just enough horsepower to snap images of my weather station's LCD display and OCR it for the current readings; and a decade-old laptop running Linux in text mode, as the server.  And it works!

I wish I could have a better weather setup.  The reality is, my location is hemmed in with trees and other buildings, and wind and precipitation data wouldn't be accurate enough to be useful.  Be that as it may, I'm always looking to add new functionality.

Recently, I've been teaching my webcam to interpret the sky and report on it.  It captures a sky image every five minutes and archives one image per hour, for possible future use.  This week, I found that use.

My initial inspiration was to generate a poster, showing a running representation of the weather through the year.  I took each image, averaged all of the pixels together for one representative value, then generated a block pixel in the poster.  The days run in vertical stripes, top-to-bottom, left-to-right.  The result was interesting--and you'll be surprised how much information can be gleaned from it.

Here's how it looks (January at left; Midnight at top)










One of the first things you'll notice is the varying length of the day, giving the lens-shaped daylight map.  Neat, eh?  It's reminiscent of one of those composite images of the galactic centre.

You can also see the effects of the spring and fall time changes, as daylight abruptly shifts one row up or down.  (The graph was prepared using civil time; i.e. EST in winter, DST in summer.)

Notice, too, how much darker the images are from mid-year through early November.  This one puzzled me for a couple of minutes, until I realized it was foliage.  Leaves.  Lots of trees at my location, which makes the Centretown Observatory an ironic joke.

There's more.  Note how, especially in the summer months, it appears to be clear much more consistently in the morning, and much less often in the afternoon and early evening.  This could be meteorological, or it could be environmental, as in backlit trees further darkening the afternoon images.

On cloudy nights during the winter months, especially with bright snow on the ground, the night sky lights up much more.

Looking at that, I thought, I wonder if I could just use the parts of the image which are least obscured by the trees, to get a truer representation of the sky itself.  It didn't take much to produce that.  Here's a comparison of that sweet spot versus the whole frame:











Okay--that's a definite improvement; it's much easier to discern a clear sky during the summer months.

I further took the sweet spot and broke it into its red-green-blue components:











These plots just serve to confirm that the best way to read the state of the sky is to examine the ratio of Red+Green over Blue.  As you can see, there's about as much blue light on a cloudy day as on a clear one.  This rule-of-thumb also works at night:  if there's light in the sky, and it's reddish, then it's cloudy; else it's likely twilight.

Taking all this together, I put together a simple set of rules and wrote the code.  To test and calibrate it, I had it colour-code its interpretation of each image into a test poster.











Not bad at all.  It's about 90% right in recognizing Cloudy (white = day, grey = night), Clear (dark blue(), and Twilight (pale blue).  Compare with the first image.

With a bit more calibration, and factoring in sunrise/sunset times ("sunny" vs "clear") and recent history (last several images), I should be able to boost the daytime accuracy to about 95%.  At some point, I'll also add zone comparisons (i.e. some blue and some white = "scattered clouds").  For nighttime, I don't know.  I'll have to analyze the numbers in greater detail, to see if I can pull sufficient intel from a very dark camera frame.  I notice, too, that the images are generally dark in the afternoons, when the trees are backlit; I could colour-correct for that.

And so, as of today, my weather system is reporting local sky conditions.  And, for now, it's good enough.


No comments:

Post a Comment