Hi all
Well after researching the various alternative software packages I decided on weewx to go with my newly purchased Davis Vantage Pro 2 and have been trying hard over the last two weeks to make my way along a very steep learning curve. Linux, Python and the Raspberry Pi, I decided to run the software on, are all new to me. My only programming experience was writing some programs in BASIC around 30 years ago and since then dabbling with spreadsheets. However I have so far managed to get Debian Wheezy up and running on the Pi, installed weewx and config all the basics to get an experimental web site working at http://thecorner.me.uk/weewx (the wind speeds are slightly low until I can get a taller pole for the annometer).
Now that I can understand a little more about the capabilities of the software and the weather station I have three customisations I would like to make to suit my needs:
Add data for sunshine hours (my weather station includes a solar radiation monitor) for use in the templates and to produce plots
Calculate heating-degrees using the UKCPO9 formula so as to be compatible with UK sourced data
Make the THSW index shown on my console available for the plots
So far, having read the documentation and poked around in the various files, my thoughts on tackling these customisations are that:
- sunshine hours would be best tackled by adding an extra value to the derived values section in Vantage Pro.py using a formula along the lines of (radiation > min_limit_Wm2) * archive_interval where min_limit_Wm2 is a value stored in the weewx.conf file
- heating-degrees needs the formula in wxformulas.py changing and the calls to that formula from stats.py changing to pass the required variables
- the THSW index is available in LOOP2 packet available from the console if the LPS command is used instead of LOOP so a change will be needed to the command issued to the console. the definitions of the vp2loop changing together with the format used to parse the data in VantagePro.py and that some how the value captured in the archive database
- both the databases would need new types adding to store the new dataas
However what I have not been able to work out so far is how best to make these changes without editing the files directly. I have not been able to get my head around custom services and generators which if I understand are they key if I want to preserve as many of my changes as possible across future upgrades. Is this correct?
Would any of you care to comment on my thoughts at this conceptual level and provide some pointers the best way to tackle the customisations I would like to make to my installation?
Any help would be much appreciated. Thank you.
Alan Major
Birdham, UK--
Thanks for your guidance and code. I will develop this further and implement once the holiday period is over.
Alan Major
Birdham, UK
import syslog
import ephem
from math import sin
from datetime import datetime
import weewx
from weewx.wxengine import StdService
class sunHoursClass(StdService):
def __init__(self, engine, config_dict):
super(sunHoursClass, self).__init__(engine, config_dict)
self.bind(weewx.NEW_ARCHIVE_RECORD, self.newArchiveRecord)
def newArchiveRecord(self, event):
"""Gets called on a new archive record event."""
# Step 1 - Calculate Sun Elevation Angle as gS in radians
loc = ephem.Observer()
loc.lon = '-0.835'
loc.lat = '50.795'
loc.pressure = 0
loc.date = datetime.fromtimestamp(event.record.get('dateTime'))
s = ephem.Sun()
s.compute(loc)
gS = s.alt
# Step 2 - Calculate predicted solar radiation level as pR and record
pR = 1373 * sin(gS) * 0.4
if pR > 0:
event.record['predRadiation'] = pR
else:
event.record['predRadiation'] = 0.0
# Step - 3 Calculate if any sunshine hours and record
radiation = event.record.get('radiation')
if radiation is not None and gS > 0.104719755 and radiation > pR:
event.record['sunshineHours'] = event.record['interval'] / 60.0
else:
event.record['sunshineHours'] = 0.0
--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
For what it is worth date/time fields in weewx are stored in Unix time ie a lapsed seconds since 00:00:00 UTC 1 January 1970. How they are displayed depends on how you format them. Unless you are doing something from left field dateTimes/time stamps should really look after themselves. What exactly is your problem? It would be helpful if you posted the code concerned as well as the symptoms you are seeing.
Gary
import syslog
import ephem
from math import sin
from datetime import datetime
import weewx
from weewx.wxengine import StdService
class sunHoursClass(StdService):
def __init__(self, engine, config_dict):
super(sunHoursClass, self).__init__(engine, config_dict)
self.bind(weewx.NEW_ARCHIVE_RECORD, self.newArchiveRecord)
def newArchiveRecord(self, event):
"""Gets called on a new archive record event."""
# Step 1 - Calculate Sun Elevation Angle as gS in radians
loc = ephem.Observer()
loc.lon = '-0.835'
loc.lat = '50.795'
loc.pressure = 0
loc.date = datetime.fromtimestamp(event.record.get('dateTime'))
s = ephem.Sun()
s.compute(loc)
gS = s.alt
# Step 2 - Calculate predicted solar radiation level as pR and record
pR = 1373 * sin(gS) * 0.4
if pR > 0:
event.record['predRadiation'] = pR
else:
event.record['predRadiation'] = 0.0
# Step - 3 Calculate if any sunshine hours and record
radiation = event.record.get('radiation')
if radiation is not None and gS > 0.104719755 and radiation > pR:
event.record['sunshineHours'] = event.record['interval'] / 60.0
else:
event.record['sunshineHours'] = 0.0
Code was originally posted by Alan Major. It uses the time to calculate the sun angle and then uses sin to do a rough maximum radiation value for that time of day. Compare this to current radiation and voilà you can see if the sun is shinning.
--
...