Okay all.  Here is a working solution to the problem I encountered trying to
exploit Area Forecast Matrices for generating a forecast_table in WeeWX.

Background.  If you live in an area served by a moderately sized or larger
airport, the NWS most likely generates a Point Forecast Matrix (PFM) that
fairly accurately predicts your future weather up to 7 days out.  If, on
the other hand, you live in a rural/agri-business area like I do, where the
PFMs are only published for airports more than an hours drive away you
probably want to make use of an Area Forecast Matrix (AFM) for your 
immediate
area.  The actual data content of the PFM and AFM are identical with the
exception of a few lines of header information.  In the PFM, this is lines
two and three of the report which provide the Description (airport name) and
Location information (lat/lon/elev).  In the AFM, line two provides a zone 
or
county name and line three(/four/five?) lists cities or towns within the
zone/county that are covered by the report.

A problem existed with finding the DTG in some (not all) of the AFMs.  Here
I'll present a solution to this issue that is rather trivial.  I won't bore
you with the logic of the solution.  I assume you already have installed the
forecast extension.  You will need v3.4.0b10 if you are running WeeWX v4.
Make sure it is producing a forecast panel in WeeWX using any valid PFM/FOID
combination.  Before proceeding, you will want to download the AFM dataset
from your local NWS forecast office and make a note of the location ID (LID)
for your immediate area.

The code for this extension is installed in /usr/share/weewx/user/.  The
filename is forecast.py.  You need to edit this file using your favorite
editor (mine happens to be nedit):

    shell prompt> cd /usr/share/weewx/user/
    shell prompt> sudo cp -p forecast.py forecast.py-dist
    shell prompt> sudo nedit forecast.py

Somewhere around line 1900 is a function named 'date2ts'.  You will need to
replace or modify that function so that it looks like this when you are 
done:
 
    def date2ts(tstr):
        """Convert NWS date string to timestamp in seconds.
        sample format: 418 PM EDT SAT MAY 11 2013
        """

        parts = tstr.split(' ')
        s = '%s %s %s %s %s' % (parts[0], parts[1], parts[4], parts[5], 
parts[6])
        try:
            time_struct = time.strptime(s, "%I%M %p %b %d %Y")
        except ValueError, err:
            logerr('%s: %s is not a valid DTG' % (NWS_KEY, s))
            return None
        ts = time.mktime(time_struct)
        return int(ts)


With the above changes made save your file.  Next you need to modify your
existing options for the forecast extension in /etc/weewx/weewx.conf.


    [Forecast]
       ⁞ 
    [[NWS]]
        lid = 'Your location ID'
        foid = 'Forecast Office ID'
        url = 
http://forecast.weather.gov/product.php?site=NWS&product=AFM&format=txt&issuedby='Forecast
 
Office ID'
        interval = 3600

Note that I opt to capture an update every hour vice the default of 3 hour 
so
don't include the interval parameter if you're happy with the default.  Save
your file when the changes are complete.  Now simply run the following 
commands:


    shell prompt> sudo /etc/init.d/weewx stop
    shell prompt> sudo rm /var/lib/weewx/forecast.sdb
    shell prompt> sudo /etc/init.d/weewx start
    shell prompt> sudo tail -n 100 -f /var/log/syslog

Check the output from syslog to see that it picked up your changes and that
the forecast thread is running (no python error messages).  At this point,
you will need to wait for the next report cycle to see that the AFM dataset
is downloaded and that forecast records are written to the database. This
typically happens 2 to 3 minutes after the beginning of the report cycle on
my RPi4.  The forecast panel in WeeWX will not propagate until the following
report cycle completes (about 5 minutes after the forecast records are
written).

That's all there is to it.  With this change you can exploit either PFM or 
AFM
products from the NWS.

Mike/AJ9X

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/8152f127-0c97-4602-b1ca-213ca36543d2n%40googlegroups.com.

Reply via email to