Simple script to calculate circular / directional mean of some angular data. Samples is assumed to be in range of <0,2PI>.

To get more information about mean of circular quantities, you can read at wikipedia and more generally about directional statistics.

1 2 3 4 5 6 7 8 9 10 |
import math def CircMean( samples ): cosSum = 0 sinSum = 0 n = len(samples) for sample in samples: cosSum += math.cos(sample) sinSum += math.sin(sample) return math.atan2(sinSum/n, cosSum/n ) |

However rather than using this consider using `scipy.stats.circmean`

http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.circmean.html#scipy.stats.circmean