Skip to content
Snippets Groups Projects
Commit 1ec6cf28 authored by Michele Maris's avatar Michele Maris
Browse files

a periodic_stats

parent 9351e861
No related branches found
No related tags found
No related merge requests found
...@@ -13,7 +13,7 @@ from .DummyCLI import DummyCLI ...@@ -13,7 +13,7 @@ from .DummyCLI import DummyCLI
from .nearly_even_split import nearly_even_split from .nearly_even_split import nearly_even_split
from .geometry import ElipsoidTriangulation from .geometry import ElipsoidTriangulation
from .template_subs import discoverKeys, templateFiller from .template_subs import discoverKeys, templateFiller
from .periodic_stats import periodic_stats from .periodic_stats import periodic_stats, periodic_centroid
#from import .grep #from import .grep
#import .intervalls #import .intervalls
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import numpy as np import numpy as np
def periodic_stats(alpha,deg=False) : def periodic_stats(alpha) :
""" statistics of a periodic alpha (radiants) """ statistics of a periodic alpha (radiants)
If alpha is a vector of angles (radiants) find the average number and the std deviation avoiding the problem of the switch between -180,180 or 360 and 0 If alpha is a vector of angles (radiants) find the average number and the std deviation avoiding the problem of the switch between -180,180 or 360 and 0
...@@ -23,6 +23,24 @@ def periodic_stats(alpha,deg=False) : ...@@ -23,6 +23,24 @@ def periodic_stats(alpha,deg=False) :
# #
return np.arctan2(rr[1],rr[0]), np.nanvar(np.arctan2(vp,up))**0.5 return np.arctan2(rr[1],rr[0]), np.nanvar(np.arctan2(vp,up))**0.5
def periodic_centroid(alpha) :
""" centroid of a periodic alpha (radiants)
If alpha is a vector of angles (radiants) find the average number and the std deviation avoiding the problem of the switch between -180,180 or 360 and 0
example: alpha=np.array([-180,180])
"""
u=np.cos(alpha)
v=np.sin(alpha)
#
rr=np.array([np.nanmean(u),np.nanmean(v)])
rr=rr/rr.dot(rr)**0.5
#
up=rr[0]*u+rr[1]*v ;
vp=-rr[1]*u+rr[0]*v
return np.array([up,vp]).T
if __name__=='__main__' : if __name__=='__main__' :
print("Test1") print("Test1")
alpha=np.arange(350,371) alpha=np.arange(350,371)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment