def __init__(self, lst=[]): #Store the list, so we can later do interesting data work # Note that we project the data into radians! self.original_list = lst self.list = [radians(i) for i in filter_list(lst)] if len(lst): value, self.std, self.n, self.err, self.min, self.max = self.meanstdv(lst) else: self.std = float(-9e9) self.n = 9e9 self.err = 9e9 self.min = 9.e9 self.max = 9e9
def __init__(self, lst=[]): #Store the list, so we can later do interesting data work # Note that we project the data into radians! self.original_list = lst self.list = [radians(i) for i in filter_list(lst)] if len(lst): value, self.std, self.n, self.err, self.min, self.max = self.meanstdv( lst) else: self.std = float(-9e9) self.n = 9e9 self.err = 9e9 self.min = 9.e9 self.max = 9e9
def meanstdv(self, lst, bad_value=-32768): "Calculate mean and standard deviation of data in lst:" if (lst[0] < 1): pass lst = [radians(i) for i in filter_list(lst, bad_value)] if not len(lst): return tuple([bad_value for i in range(6)]) n, std = len(lst), 0 # The mean of an azimuth is no simple task. # Some sanity checking if ((max(lst) > 2 * pi) or (min(lst) < 0)): raise Exception # Convenience functions ave = lambda x: sum(x) / len(x) rotate = lambda x: x + ( 2 * pi) if x < 0 else x # bring back to positive angle values # self.list is already in radians. sa = ave([sin(i) for i in lst]) ca = ave([cos(i) for i in lst]) # Take the arctan of this, using atan2 to preserve the quadrant information mean = rotate(atan2(sa, ca)) # In a normal calculation, our standard deviation value would be # # for a in lst: # std += (a - mean)**2 # try: std = sqrt(std / float(n-1)) # except ZeroDivisionError: # if (n == 1): std = 0 # else: raise ZeroDivisionError # # However, we cannot do something so simple because angles may cross 0 (i.e. average # north could be the list of values [355, 356, 0, 4,5]. Thus, we have to keep # our mean into radians, and we'll use the list of radians as our sample population for a in lst: std += (a - mean)**2 try: std = sqrt(std / float(n - 1)) except ZeroDivisionError: if (n == 1): std = 0 # Only one sample, Standard Deviation is meaningless else: raise ZeroDivisionError err = std / sqrt(n) return mean, std, n, err, min(lst), max(lst)
def meanstdv(self, lst, bad_value=-32768): "Calculate mean and standard deviation of data in lst:" lst = filter_list(lst, bad_value) if not len(lst): return tuple([bad_value for i in range(6)]) n, mean, std = len(lst), 0, 0 for a in lst: mean += a mean = mean / float(n) for a in lst: std += (a - mean)**2 try: std = sqrt(std / float(n-1)) except ZeroDivisionError: if (n == 1): std = 0 else: raise ZeroDivisionError err = std/sqrt(n) print(lst) return mean, std, n, err, min(lst), max(lst)
def meanstdv(self, lst, bad_value=-32768): "Calculate mean and standard deviation of data in lst:" lst = filter_list(lst, bad_value) if not len(lst): return tuple([bad_value for i in range(6)]) n, mean, std = len(lst), 0, 0 for a in lst: mean += a mean = mean / float(n) for a in lst: std += (a - mean)**2 try: std = sqrt(std / float(n - 1)) except ZeroDivisionError: if (n == 1): std = 0 else: raise ZeroDivisionError err = std / sqrt(n) print(lst) return mean, std, n, err, min(lst), max(lst)
def meanstdv(self, lst, bad_value=-32768): "Calculate mean and standard deviation of data in lst:" if (lst[0]<1): pass lst = [radians(i) for i in filter_list(lst, bad_value)] if not len(lst): return tuple([bad_value for i in range(6)]) n, std = len(lst),0 # The mean of an azimuth is no simple task. # Some sanity checking if ((max(lst)>2*pi) or (min(lst)< 0)): raise Exception # Convenience functions ave = lambda x: sum(x)/len(x) rotate = lambda x: x+(2*pi) if x<0 else x # bring back to positive angle values # self.list is already in radians. sa = ave([sin(i) for i in lst]) ca = ave([cos(i) for i in lst]) # Take the arctan of this, using atan2 to preserve the quadrant information mean = rotate(atan2(sa,ca)) # In a normal calculation, our standard deviation value would be # # for a in lst: # std += (a - mean)**2 # try: std = sqrt(std / float(n-1)) # except ZeroDivisionError: # if (n == 1): std = 0 # else: raise ZeroDivisionError # # However, we cannot do something so simple because angles may cross 0 (i.e. average # north could be the list of values [355, 356, 0, 4,5]. Thus, we have to keep # our mean into radians, and we'll use the list of radians as our sample population for a in lst: std += (a - mean)**2 try: std = sqrt(std / float(n-1)) except ZeroDivisionError: if (n == 1): std = 0 # Only one sample, Standard Deviation is meaningless else: raise ZeroDivisionError err = std/sqrt(n) return mean, std, n, err, min(lst), max(lst)