diff --git a/src/yapsut/__init__.py b/src/yapsut/__init__.py index 8c11f936e953bb0dbc751cd3eee780dc1512660a..bc7d5e9cd22c746be058ffe5c8977ea0d9207e7a 100644 --- a/src/yapsut/__init__.py +++ b/src/yapsut/__init__.py @@ -13,7 +13,7 @@ from .DummyCLI import DummyCLI from .nearly_even_split import nearly_even_split from .geometry import ElipsoidTriangulation from .template_subs import discoverKeys, templateFiller -from .periodic_stats import periodic_stats +from .periodic_stats import periodic_stats, periodic_centroid #from import .grep #import .intervalls diff --git a/src/yapsut/periodic_stats.py b/src/yapsut/periodic_stats.py index 6f2972524a0cadf2741668cbe6ca0ee6f19fec4e..2459acb56f58a23ce2eee5f205666109bbb4cbb5 100644 --- a/src/yapsut/periodic_stats.py +++ b/src/yapsut/periodic_stats.py @@ -2,7 +2,7 @@ import numpy as np -def periodic_stats(alpha,deg=False) : +def periodic_stats(alpha) : """ 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 @@ -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 +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__' : print("Test1") alpha=np.arange(350,371)