Commit 1ec6cf28 authored by Michele Maris's avatar Michele Maris
Browse files

a periodic_stats

parent 9351e861
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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
+19 −1
Original line number Diff line number Diff line
@@ -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)