Created
June 26, 2012 04:35
-
-
Save ptweir/2993307 to your computer and use it in GitHub Desktop.
Two functions for working with circular data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| def circmean(alpha,axis=None): | |
| mean_angle = np.arctan2(np.mean(np.sin(alpha),axis),np.mean(np.cos(alpha),axis)) | |
| return mean_angle | |
| def circvar(alpha,axis=None): | |
| if np.ma.isMaskedArray(alpha) and alpha.mask.shape!=(): | |
| N = np.sum(~alpha.mask,axis) | |
| else: | |
| if axis is None: | |
| N = alpha.size | |
| else: | |
| N = alpha.shape[axis] | |
| R = np.sqrt(np.sum(np.sin(alpha),axis)**2 + np.sum(np.cos(alpha),axis)**2)/N | |
| V = 1-R | |
| return V |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
really just a test of gists and how easy it is to embed them in blogger.