Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/wfrog/wfrog into bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
debrunner committed Feb 24, 2018
2 parents 0788cde + 0177041 commit 5c1071a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 8 deletions.
32 changes: 32 additions & 0 deletions wfcommon/meteo.py
Expand Up @@ -441,3 +441,35 @@ def WindPredominantDirection(l):
return WindDir(avg_x, avg_y)


###########################################################################################
## 4) Radiation transformations
###########################################################################################

# Source: https://en.wikipedia.org/wiki/Lux
#
# The lux is one lumen per square metre (lm/m2), and the corresponding radiometric unit,
# which measures irradiance, is the watt per square metre (W/m2). There is no single
# conversion factor between lx and W/m2; there is a different conversion factor for
# every wavelength, and it is not possible to make a conversion unless one knows the
# spectral composition of the light.
#
# Source: http://bccp.berkeley.edu/o/Academy/workshop08/08%20PDFs/Inv_Square_Law.pdf
#
# Converting Lux to W/m2
# There is no simple conversion it depends on
# the wavelength or color of the light.
# However, for the SUN, there is an approximate
# conversion of 0.0079 W/m2 per Lux.
# Example: We read 75,000 Lux on our light
# sensor. We can convert that reading to W/m2.
# 75,000 x 0.0079 = 590 W/m2

def convert_illuminance_wm2(lux):
"Approximate conversion of illuminance in lux to solar radiation in W/m2"
# This value needs to be adjusted depending on the location.
if lux is None:
return None
return lux * 0.0075



28 changes: 20 additions & 8 deletions wfdriver/station/wh3080.py
Expand Up @@ -19,7 +19,7 @@

import time
import logging
from wfcommon import units
from wfcommon import meteo

class WH3080Station(object):

Expand All @@ -37,7 +37,9 @@ class WH3080Station(object):
def run(self, generate_event, send_event, context={}):

from pywws import WeatherStation
station = WeatherStation.weather_station()

# pywws manages a wh1080 by default. Therefore '3080' shall be passed.
station = WeatherStation.weather_station('3080')

for data, last_ptr, logged in station.live_data():
if not logged:
Expand Down Expand Up @@ -83,23 +85,33 @@ def run(self, generate_event, send_event, context={}):
e.create_child('mean')
e.mean.speed = data['wind_ave']
e.mean.dir = 22.5*(data['wind_dir'])

e.create_child('gust')
e.gust.speed = 0.0;
e.gust.dir = 0.0;
if data['wind_gust']:
e.create_child('gust')
#e.create_child('gust')
e.gust.speed = data['wind_gust']
e.gust.dir = 22.5*(data['wind_dir'])
send_event(e)

# pywws manages "uv" in the case of 3080 stations
if data['uv'] is not None:
e = generate_event('uv')
e.sensor = 1
e.value = data['uv']
send_event(e)

if data['solar_rad'] is not None:
e = generate_event('rad')
e.sensor = 1
e.value = (data['solar_rad'])
send_event(e)
# pywws manages the "illuminance" in the case of 3080 stations
if data['illuminance'] is not None:
e = generate_event('rad')
e.sensor = 1
e.value = (meteo.convert_illuminance_wm2(data['illuminance']))
send_event(e)

except Exception, e:
self.logger.error(e)


except Exception, e:
self.logger.error(e)

0 comments on commit 5c1071a

Please sign in to comment.