Skip to content

Commit

Permalink
Compute average wind speed if direction missing
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Easterbrook <jim@jim-easterbrook.me.uk>
  • Loading branch information
jim-easterbrook committed Jan 20, 2018
1 parent 76e7853 commit f57c3ce
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
18 changes: 12 additions & 6 deletions src/pywws/Process.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# pywws - Python software for USB Wireless Weather Stations
# http://github.com/jim-easterbrook/pywws
# Copyright (C) 2008-16 pywws contributors
# Copyright (C) 2008-18 pywws contributors

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -181,17 +181,16 @@ class WindFilter(object):
"""
def __init__(self, decay=1.0):
self.decay = decay
self.Ve = 0.0
self.Ve = None
self.Vn = 0.0
self.total = 0.0
self.weight = 1.0
self.total_weight = 0.0
self.last_idx = None

def add(self, data):
direction = data['wind_dir']
speed = data['wind_ave']
if direction is None or speed is None:
if speed is None:
return
if self.last_idx and self.decay != 1.0:
interval = data['idx'] - self.last_idx
Expand All @@ -203,19 +202,26 @@ def add(self, data):
self.weight = self.weight / decay
self.last_idx = data['idx']
speed = speed * self.weight
self.total += speed
self.total_weight += self.weight
direction = data['wind_dir']
if direction is None:
return
if self.Ve is None:
self.Ve = 0.0
if isinstance(direction, int):
self.Ve -= speed * sin_LUT[direction]
self.Vn -= speed * cos_LUT[direction]
else:
direction = math.radians(float(direction) * 22.5)
self.Ve -= speed * math.sin(direction)
self.Vn -= speed * math.cos(direction)
self.total += speed
self.total_weight += self.weight

def result(self):
if self.total_weight == 0.0:
return (None, None)
if self.Ve is None:
return (self.total / self.total_weight, None)
return (self.total / self.total_weight,
(math.degrees(math.atan2(self.Ve, self.Vn)) + 180.0) / 22.5)

Expand Down
4 changes: 2 additions & 2 deletions src/pywws/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '18.01.0'
_release = '1382'
_commit = '6d14d0c'
_release = '1383'
_commit = '76e7853'

0 comments on commit f57c3ce

Please sign in to comment.