Last week, I created an algorithm to generate a pseudo-rose diagram using Python and the Google Chart API. The diagram gave a decent “rough view” of azimuth data so that I could see at a glance the realism of my given azimuth average. Because I’m working in Python 3.0, I couldn’t use the host of great plotting libraries out there, so I had to roll my own. It worked, but I needed to make it better.
The original result was interesting and somewhat useful. It showed the relative number of samples at each 10° increment around the compass. I thought it was a decent view, but it turns out that it just wasn’t good enough. I showed some results to my boss and he immediately questioned the validity of mean azimuths based on the visual I’d presented.
This is a good lesson to re-learn. When you tell someone that you “generated rose diagrams,” they are going to expect rose diagrams. It doesn’t matter if you tell them that you “generated a hack that somewhat approximates a rose diagram.” They are not going to assume that what they are looking at is “incorrect but for the right reason.” They, as I, are going to assume that what they are looking at is “broken.”
So, I showed some samples to my boss and his response was, in retrospect, exactly what mine would have been: Either the rose, or the azimuth is incorrect.
What he was expecting to see, what anyone would expect to see, is something more like the image at the right. A rose diagram is a circular histogram, and is thus a bar graph. What I generated was more like a line graph, where values jumped from zero (the center) to some unknown level (the edge).
The problem is that the radar diagram is a continuous line starting at 0° and extending to whatever degrees the final value is at. If I wanted to create bars, I’d have to make a line that goes from zero, up to some value (the top of the bar), stays at that value for a bit, then goes back to zero, then goes back up to another value (the top of the next bar).
This sounded like a pain in the ass, but what the hell, right?
So, a bit of algorithmic flow control later, I came up with a Google Chart radar diagram that fully approximates a circular histogram.
The result makes me pretty darn happy. Now we have a true rose diagram, a circular histogram with 36 10° bins and magnitudes that range from zero to the maximum number of bins. Here, the largest number of samples were found in the 150° bin. All other bins are a percentage of that maximum.
The r axis shows gray lines at 50% and 100% of this maximum value and light gray lines at 25% and 75%. Thus, we know that the 0° and 10° bins, for example, are just over 75% of the maximum.
As with the previous version, the code1 is not abstracted enough to be usable for any rose diagram. For example, a 360°, azimuth-based diagram with 10° bins is assumed. Moreover, it is the maximum number of samples in a given 10° range that this version calculates, rather than, say total magnitude or some other metric.
However, it wouldn’t take much to generalize it for use with any range and bin size. Moreover, with a minor amount of tweaking, one can easily change the colors, line weights, etc. Right now, all of that would be done manually, but I may go back and make it more object oriented so that the code can be more robust (and subject to use with different data). Creating a separate bin class that smartly handles the generation of the different bins and their sizes, for instance, would allow someone to easily decide which metric they would like the rose diagram to use (magnitude, sum, average, number of samples, etc). The code is fairly well documented (and I’ll try to keep it that way) so it shouldn’t be that difficult to change that as necessary.
Overall, this has been a great exercise. My initial views on Google Chart were less than positive. “Why would I need a web API to do something that I can do using a Python library?” For years, Gri and Matplotlib have been my bread and butter, but suddenly Python 3.0 was out, I was using it, and there were no plotting libraries available yet. This problem illustrated the power and utility of a web-accessible, system agnostic approach to image generation that I will certainly keep in my toolbox.