From 1ec6cf287d62ca799d726f963e2e1e5c671177ed Mon Sep 17 00:00:00 2001 From: Michele Maris <michele.maris@inaf.it> Date: Thu, 13 Jul 2023 19:52:07 +0200 Subject: [PATCH] a periodic_stats --- src/yapsut/__init__.py | 2 +- src/yapsut/periodic_stats.py | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/yapsut/__init__.py b/src/yapsut/__init__.py index 8c11f93..bc7d5e9 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 6f29725..2459acb 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) -- GitLab