I have a data set that I want to plot as a quiver plot. The set contains parameters of stars represented as ellipses (center, long axis length, short axis length, bearing (angle) of the long axis) that I want to draw as a vector field with quiver plot. The data (axis lengths and bearings) is noisy and I need to smooth it. While smoothing works fine for axis length I'm stuck with angle smoothing. The problem here is that any ellipse is visually (and for my purposes too) equivalent to an ellipse rotated by 180 degrees and ellipses' angles are distributed in the range from 0 to 180. Smoothing for the most part of this range works fine except for corner cases where angles are close to 0 and close to 180. While two ellipses with angles close to 0 and close to 180 looks visually similar, their "average" has an angle of 90 degrees which is clearly wrong. See an example of unsmoothed data (white stars and green arrows representing these stars) where the smoothing breaks. To be clear I don't need the direction of the arrow, and in my final plot I'm hiding arrow heads. I need only the angle/bearing of it and the average of two angles of 179.9 and 0.1 needs to be either 180 or 0 but not 90.
Any idea how to approach the problem? 
2
votes
I would triangulate the data and use a wavefront propagation to choose the "best" representation modulo 180. If you can share a dataset, I will try to post an answer.
- GBy
1 Answers
1
votes
Two options:
First, you can convert your angle to an int and expand it to the full range of that int and take advantage of overflow. For example:
np.astype((ang-180.)/360.*65536, 'uint16')
This may work if your smoothing function is simple and doesn't have comparison operators in it and is in my opinion a nasty hack.
Second, rotate your angle by some arbitrary amount, and do the smoothing multiple times, picking the best answer.
I would smooth the original, then rotate by 120, smooth that, rotate by 240, smooth that. Then un-rotate and then keep only the angles that agree. Of course this comes with a 3x+ performance hit.
Edit: Third option: Smooth the vector components.