Sun Shine Hours

118 views
Skip to first unread message

Phil Owers

unread,
Jul 25, 2020, 12:39:58 PM7/25/20
to weewx-user
Hi All

Have been using the Instromet Stand Alone Sun Duration sensor which if connected to a Davis Vantage Pro2 system needs to go to a spare rain socket in the ISS.
Each 0.01 is equivalent to 36 seconds of sunshine and I have converted that to hours and minutes on my web page. 
The next stage was to produce a graph per hour using the rain field in the database  and to adjust that  reading.either with another field in the database or when the plot/graph was produced .
I did have a look in the vantage.py and came across  loop_packet['rain'] = delta. 
So im asking is this the place to do this or am I totally in the wrong place to achieve a field with with rain * 36 in.
Thanks in Advance

gjr80

unread,
Jul 25, 2020, 7:09:34 PM7/25/20
to weewx-user
Hi,

If I am understanding you correctly you have a field that is being populated in the WeeWX database. The field data is such that you display cumulative values or sums (ala rain) rather than point in time values (like temperature, pressure etc). You have been scaling that field on your web page. You would now like to plot that field but you wish to plot the scaled data rather than the data stored in the field.

The WeeWX plot engine is fairly limited in abilities and essentially any observation you want to plot needs to be stored in your archive. One approach you could take is to use the StdCalibrate service to do your scaling for you and provided the field containing the scaled value is stored in the archive you can just plot the scaled value. For example, say your data is coming from the console in field new_obs, something like:

[StdCalibrate]
   
[[Corrections]]
        new_obs
= new_obs * 36 if new_obs is not None else None

would result in your field new_obs now containing your scaled data and provided new_obs is in the db schema it will be saved to archive and able to be plotted. An alternative if you want to keep the original data in new_obs would be to place the scaled data in a new field:

[StdCalibrate]
   
[[Corrections]]
        another_obs
= new_obs * 36 if new_obs is not None else None

This will result in your original sensor data remaining in field new_obs and the scaled data being in field another_obs. Provided another_obs is in your schema it will be saved to archive and able to be plotted. This data will be in seconds and I suspect there will be some scaling issues on your plots. You could alter the scaling formula to store your scaled data in decimal hours and that may plot better, something like:

[StdCalibrate]
   
[[Corrections]]
        another_obs
= new_obs * 36/3600 if new_obs is not None else None

Rather than re-using existing database fields it is quite straightforward to add new fields to the database. You can find information on adding new fields to the database in the section Adding a new type to the database in the Customization Guide.

Hope that helps and I have not misunderstood your question.

Gary

Phil Owers

unread,
Jul 26, 2020, 1:57:38 AM7/26/20
to weewx-user
Hi Gary
Thanks for your quick response.
You have confirmed the best way is to populate a new field to get the graph Im looking for.
Im happy with adding a new field to the database
This new field would have the 0.01 * 36 but im not sure how to do that
Is that done in the vantage.py file, and if so how please, or somewhere else
Phil

gjr80

unread,
Jul 26, 2020, 2:54:02 AM7/26/20
to weewx-user
Phil,

No need to modify vantage.py, in fact modifying one of the core WeeWX files is seldom a good solution when others exist. You open yourself up to losing your changes over an upgrade or if you place your modified file in /home/weewx/bin/user (or /usr/share/weewx/user) so it is safe from upgrades, you risk missing changes to the core WeeWX files. In this case you can use StdCalibrate to create your new field. Once you create your new field, if you change you db schema to include it your new field will be automatically saved in the database. Once it is in the database you can plot it. Let's assume the name of the field that has your current sunshine data is 'sunshine_field'. As an experiment try this swapping 'sunshine_field' for the field name that presently has your sunshine data:

1. edit weewx.conf and add the highlighted lines under [StdCalibrate] [[Corrections]]:

[StdCalibrate]
   
[[Corrections]]
         
....
         
sunshine_seconds = sunshine_data * 36

2. look through weewx.conf and see if you have an [Accumulator] stanza, if so add the highlighted lines, if you don't have an [Accumulator] stanza create one and add the highlighted lines:

[Accumulator]
    [[sunshine_seconds]]
        extractor
= sum

3. save weewx.conf.

4. stop WeeWX if it is running and run WeeWX directly. You should see loop packets (lines starting with LOOP:) every few seconds and archive records (lines starting with REC:) every archive interval. You should see your 'sunshine_field' and you should see the new sunshine_seconds field. Note that sunshine_seconds is not being saved to database yet as (presumably) you have not yet added a sunshine_seconds field to your db schema, once you do it will be saved to database and you can then use the field in plots.

You can stop WeeWX with ctrl-C or ctrl-Z and restart the daemon.

I failed to mention the [Accumulator] stanza before, the [Accumulator] stanza, among other things, is used to tell WeeWX how to create an archive record field out of the accumulated loop data for that field. In this case, just like rain, we want the sum of the data over the archive interval (most obs want the default which is average, eg temperature, pressure etc)

Gary

Phil Owers

unread,
Jul 27, 2020, 7:41:48 AM7/27/20
to weewx-user
Thanks Gary
That worked ok to a temp field but then I realised that I had added a new field to the weewx.sdb.
I have 4 conf files working on the same rasp pi and the sun console has its own database.
Just wondered how thats done.
Thanks
Phil

On Saturday, July 25, 2020 at 5:39:58 PM UTC+1, Phil Owers wrote:
Reply all
Reply to author
Forward
0 new messages