Skip to content

Instantly share code, notes, and snippets.

@ptweir
Created June 26, 2012 04:35
Show Gist options
  • Select an option

  • Save ptweir/2993307 to your computer and use it in GitHub Desktop.

Select an option

Save ptweir/2993307 to your computer and use it in GitHub Desktop.
Two functions for working with circular data
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
@ptweir
Copy link
Author

ptweir commented Jun 26, 2012

really just a test of gists and how easy it is to embed them in blogger.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment