Calculating Sun Energy from Radiation Reading

133 views
Skip to first unread message

Karen K

unread,
Mar 10, 2021, 2:39:50 PM3/10/21
to weewx-user
The radiation observation type provides the actual sun power received at the time of measurement. The value depends on cloud coverage and the time of day.

Besides that it is interesting to know which amount of energy was received from the sun during the day or any other period of time.

To get that value some calculation has to be done. Unlike with rain that cannot be done by simply summarizing the observation readings. Energy is no cumulative value. Instead, it is necessary to integrate (in the mathematical meaning of that word) the radiation readings over the aggregation interval.

I extended GTS extension to do that.

For example you can display the amount of sun energy received the day before by using the tag $yesterday.radiation.energy_integral. Plots are also possible.

For examples showing these values see:


hesf...@gmail.com

unread,
Mar 11, 2021, 3:23:39 AM3/11/21
to weewx-user
in line 546
def calc_radiation_integral(self, timespan, db_manager):
        """calculate radiation integral over time

        radiation: actual radiation in Watt per square meter
        interval:  registration interval as per database record in minutes

        """

        try:
            _result = db_manager.getSql(
                    "SELECT SUM(radiation*interval)/60.0, "
                    "MIN(usUnits), MAX(usUnits) FROM %s "
                    "WHERE dateTime >? AND dateTime<=?"
                    % db_manager.table_name, timespan)

is there a sql error

Mar 11 09:20:26 hesba weewx[16349] ERROR weewx.reportengine:         ****    File "/home/weewx/bin/user/GTS.py", line 559, in calc_radiation_integral
Mar 11 09:20:26 hesba weewx[16349] ERROR weewx.reportengine:         ****      % db_manager.table_name, timespan)
Mar 11 09:20:26 hesba weewx[16349] ERROR weewx.reportengine:         ****    File "/home/weewx/bin/weewx/manager.py", line 430, in getSql
Mar 11 09:20:26 hesba weewx[16349] ERROR weewx.reportengine:         ****      _cursor.execute(sql, sqlargs)
Mar 11 09:20:26 hesba weewx[16349] ERROR weewx.reportengine:         ****    File "/home/weewx/bin/weedb/mysql.py", line 61, in guarded_fn
Mar 11 09:20:26 hesba weewx[16349] ERROR weewx.reportengine:         ****      raise klass(e)
Mar 11 09:20:26 hesba weewx[16349] ERROR weewx.reportengine:         ****  weedb.DatabaseError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')/60.0, MIN(usUnits),MAX(usUnits) FROM archive WHERE dateTime>1612825200 AND ...' at line 1")
Mar 11 09:20:26 hesba weewx[16349] ERROR weewx.reportengine:         ****  Generator terminated

Karen K

unread,
Mar 11, 2021, 3:54:12 AM3/11/21
to weewx-user
You are using MySQL or MariaDB? I use Sqlite. There this statemant works. 

I am not really at home with MySQL, but could you change the statement like that:

          _result = db_manager.getSql(
                    "SELECT SUM(radiation*interval/60.0), "

                    "MIN(usUnits), MAX(usUnits) FROM %s "
                    "WHERE dateTime >? AND dateTime<=?"
                    % db_manager.table_name, timespan)


If that does not help I would move the division by 60 from the SQL statement to the Python code. But first I ask you to check if that change works.

gjr80

unread,
Mar 11, 2021, 4:07:01 AM3/11/21
to weewx-user
I think you will find the issue is that interval is a reserved word in MySQL. The solution is to enclose interval in backticks, eg: 'interval'

Gary

hesf...@gmail.com

unread,
Mar 11, 2021, 4:19:02 AM3/11/21
to weewx-user
yes interval set to 'interval'

and the value dayET is in Vantage Pro2 by loop2 a value
in the calculation I changed it to day_ET

der Wert dayET wird bei Vantage Pro2 unter loop2 ermittelt
in der Berechnung habe ich es auf day_ET geändert

Hartmut

Karen K

unread,
Mar 11, 2021, 4:19:54 AM3/11/21
to weewx-user
gjr80 schrieb am Donnerstag, 11. März 2021 um 10:07:01 UTC+1:
I think you will find the issue is that interval is a reserved word in MySQL. The solution is to enclose interval in backticks, eg: 'interval'

Thank you, Gary, for your tip. Unfortunately, that in turn does not work for Sqlite. There, it only works with quotes, "interval"
 

Karen K

unread,
Mar 11, 2021, 4:24:38 AM3/11/21
to weewx-user
hesf...@gmail.com schrieb am Donnerstag, 11. März 2021 um 10:19:02 UTC+1:
yes interval set to 'interval'

Does it work with "interval", too? 

(As 'interval' does not work with Sqlite.)
 
and the value dayET is in Vantage Pro2 by loop2 a value
in the calculation I changed it to day_ET

You could change the entry "dayET = software,archive" in weewx.conf to "dayET = prefer_hardware,archive". Then, the value will only be calculated by the software, if the weather station / driver does not provide it.

gjr80

unread,
Mar 11, 2021, 4:37:49 AM3/11/21
to weewx-user
Are you sure you are using backticks, there are a number of similar looking symbols. Actually, looking at my reply I said backticks but I suspect I did not actually use them, you want this one:
Backticks will work in SQLite, if you look through the WeeWX code you will find wherever interval is used in a SQL statement it is enclosed in backticks. I believe double quotes can be used in MySQL in certain modes only, but backticks can be used in all modes.

Gary

Karen K

unread,
Mar 11, 2021, 4:41:08 AM3/11/21
to weewx-user
Yes, you are right. I did use ' instead of `.

hesf...@gmail.com

unread,
Mar 11, 2021, 4:51:38 AM3/11/21
to weewx-user
Hallo,

I have a small request, the values for day.radiation.energy_integral and week...  month... and year.radiation.energy_integral not displayed

as proof, have a look at


Hartmut

Karen K

unread,
Mar 11, 2021, 4:56:17 AM3/11/21
to weewx-user
Could you send your skin.conf  and index.html.tmpl here?

hesf...@gmail.com

unread,
Mar 11, 2021, 5:04:56 AM3/11/21
to weewx-user
in Seasons/current.inc

#if $day.radiation.has_data
      <tr>
        <td class="label">$obs.label.radiation</td>
        <td class="data">$current.radiation</td>
      </tr>
      <tr>
        <td class="label">Sonnenenergie Tag</td>
        <td class="data">$day.radiation.energy_integral</td>
      </tr>
      <tr>
        <td class="label">Sonnenenergie Vortag</td>
        <td class="data">$yesterday.radiation.energy_integral.kilowatt_hour_per_meter_squared</td>
      </tr>
      <tr>
        <td class="label">Sonnenenergie Woche</td>
        <td class="data">$week.radiation.energy_integral.kilowatt_hour_per_meter_squared</td>
      </tr>
      <tr>
        <td class="label">Sonnenenergie Monat</td>
        <td class="data">$month.radiation.energy_integral.kilowatt_hour_per_meter_squared</td>
      </tr>
      <tr>
        <td class="label">Sonnenenergie Jahr</td>
        <td class="data">$year.radiation.energy_integral.kilowatt_hour_per_meter_squared</td>
      </tr>
#end if

and skin.conf which section

the installation runs under install   (wee_extension --install weewx-GTS.zip)

in configuration in weewx.conf

an 3 Installation instructions: was also implemented
GTS works
Hartmut

Karen K

unread,
Mar 11, 2021, 5:06:13 AM3/11/21
to weewx-user

Karen K

unread,
Mar 11, 2021, 5:11:06 AM3/11/21
to weewx-user
hesf...@gmail.com schrieb am Donnerstag, 11. März 2021 um 11:04:56 UTC+1:
in Seasons/current.inc 

It seems ok to me. I will try it today in the evening myself and see.

In the meantime, could you put a second # before #if and #end if in the snippet you posted? (for debugging purposes only)
 

Karen K

unread,
Mar 11, 2021, 5:14:32 AM3/11/21
to weewx-user
I added that in hilo.inc:

#if $day.radiation.has_data
<tr>
<td class="label">Sonnenenergie</td>
#for $archive in $archive_data
<td class="data new_row hilo_$archive[0]">
$archive[1].radiation.energy_integral.format(add_label=False)
</td>
#end for
<td class="units">Wh/m²</td>
</tr>
#end if

hesf...@gmail.com

unread,
Mar 11, 2021, 5:34:04 AM3/11/21
to weewx-user
fault with me
after reinstalling version 0.4.1
everything's o.k

Thank you for your work and your patience with me
Hartmut

Karen K

unread,
Mar 11, 2021, 5:38:43 AM3/11/21
to weewx-user
I could not really wait due to curiosity. So I included your configuration snippet into my configuration in current.inc. See the attached screenshot for the result. 

So I think, there is still an issue with the SQL statement. Are you sure you used backticks ` and not ', as I too did in the first place? 

You could download the extension again, as I uploaded the change for the SQL statement some minutes before.
Sonnenenergy-Seasons-Current.png

Karen K

unread,
Mar 11, 2021, 5:40:00 AM3/11/21
to weewx-user
hesf...@gmail.com schrieb am Donnerstag, 11. März 2021 um 11:34:04 UTC+1:
fault with me
after reinstalling version 0.4.1
everything's o.k

Thank you, too.
 

didier belin

unread,
Mar 11, 2021, 9:23:10 AM3/11/21
to weewx...@googlegroups.com
Hello,
I try to integrate in the month section of "graph.conf" of belchertown skin the following information
but it doesn't work, can someone tell me where there is an error?

 [[chart4]]
        title = Barometer
        aggregate_type = avg
        [[[barometer]]]
            color = "#BECC00"
            
    [[monthRadiationEnergy]]
        line_gap_fraction = 0.04
         #y_label = "Wh/m²"
        [[[radiation]]]
            label = "Sonnenenergie (täglich gesamt)"
            data_type = radiation
            aggregate_type = energy_integral
            aggregate_interval = 86400 


--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/3472537f-4fcb-4e4d-bfa7-d9adbe7da4d4n%40googlegroups.com.

Karen K

unread,
Mar 11, 2021, 9:58:42 AM3/11/21
to weewx-user
graphs.conf for Belchertown skin uses another syntax:

[[Sonnenenergie]]
    title = "Sonnenenergie (täglich gesamt)"
    aggregate_type = energy_integral
    aggregate_interval = 86400
    yAxis_label = Energie
    yAxis_label_unit = "Wh/m&sup2;"
    [[[radiation]]]

didier belin

unread,
Mar 11, 2021, 11:12:58 AM3/11/21
to weewx...@googlegroups.com
Thanks for your answer, but when I copy the info I get these errors:

ar 11 17:00:27 Meteo3 weewx[30301] INFO weewx.cheetahgenerator: Generated 11 files for report Belchertown in 3.60 seconds
Mar 11 17:00:27 Meteo3 weewx[30301] INFO weewx.reportengine: Copied 2 files to /var/www/html
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine: Caught unrecoverable exception in generator 'user.belchertown.HighchartsJsonGenerator'
ghchartsJsonGenerator'
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine:         ****  Error trying to use database binding wx_binding to graph observation radiation. Error was: energy_integral('radiation').
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine:         ****  Traceback (most recent call last):
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine:         ****    File "/usr/share/weewx/user/belchertown.py", line 2423, in get_observation_data
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine:         ****      (time_start_vt, time_stop_vt, obs_vt) = archive.getSqlVectors(TimeSpan(start_ts, end_ts), obs_lookup, aggregate_type, aggregate_interval)
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine:         ****    File "/usr/share/weewx/weewx/manager.py", line 456, in getSqlVectors
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine:         ****      aggregate_type, aggregate_interval)
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine:         ****    File "/usr/share/weewx/weewx/xtypes.py", line 86, in get_series
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine:         ****      aggregate_interval)
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine:         ****    File "/usr/share/weewx/weewx/xtypes.py", line 140, in get_series
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine:         ****      agg_vt = get_aggregate(obs_type, stamp, do_aggregate, db_manager)
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine:         ****    File "/usr/share/weewx/weewx/xtypes.py", line 105, in get_aggregate
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine:         ****      raise weewx.UnknownAggregation("%s('%s')" % (aggregate_type, obs_type))
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine:         ****  weewx.UnknownAggregation: energy_integral('radiation')
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine:         ****  
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine:         ****  During handling of the above exception, another exception occurred:
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine:         ****  
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine:         ****  Traceback (most recent call last):
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine:         ****    File "/usr/share/weewx/weewx/reportengine.py", line 196, in run
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine:         ****      obj.start()
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine:         ****    File "/usr/share/weewx/weewx/reportengine.py", line 281, in start
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine:         ****      self.run()
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine:         ****    File "/usr/share/weewx/user/belchertown.py", line 1917, in run
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine:         ****      series_data = self.get_observation_data(binding, archive, observation_type, minstamp, maxstamp, aggregate_type, aggregate_interval, time_length, xAxis_groupby, xAxis_categories, mirrored_value, weatherRange_obs_lookup, wind_rose_color)
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine:         ****    File "/usr/share/weewx/user/belchertown.py", line 2425, in get_observation_data
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine:         ****      raise Warning( "Error trying to use database binding %s to graph observation %s. Error was: %s." % (binding, obs_lookup, e) )
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine:         ****  Warning: Error trying to use database binding wx_binding to graph observation radiation. Error was: energy_integral('radiation').
Mar 11 17:00:28 Meteo3 weewx[30301] ERROR weewx.reportengine:         ****  Generator terminated


and no graphics produced


Karen K

unread,
Mar 11, 2021, 12:14:10 PM3/11/21
to weewx-user
That seems to me that the GTS extension is not really activated. Could you send the sections [StdWXCalculate] and [Engine] from weewx.conf? Additionally send all messages in syslog regarding GTS during the start of WeeWX.

didier belin

unread,
Mar 11, 2021, 1:15:33 PM3/11/21
to weewx...@googlegroups.com
        prep_services = weewx.engine.StdTimeSynch
        data_services = ,
        process_services = weewx.engine.StdConvert, weewx.engine.StdCalibrate, weewx.engine.StdQC, weewx.wxservices.StdWXCalculate
        xtype_services = weewx.wxxtypes.StdWXXTypes, weewx.wxxtypes.StdPressureCooker, weewx.wxxtypes.StdRainRater, weewx.wxxtypes.StdDelta, user.GTS.GTSService, user.phenologyservice.PhenologyService
        archive_services = weewx.engine.Std.Archive
        restful_services = weewx.restx.StdStationRegistry, weewx.restx.StdWunderground, weewx.restx.StdPWSweather, weewx.restx.StdCWOP, weewx.restx.StdWOW, weewx.restx.StdAWEKAS, user.mqtt.MQTT
        report_services = weewx.engine.StdPrint, weewx.engine.StdReport



[Calculations]]
        # How to calculate derived quantities.  Possible values are:
        #  hardware        - use the value provided by hardware
        #  software        - use the value calculated by weewx
        #  prefer_hardware - use value provide by hardware if available,
        #                      otherwise use value calculated by weewx

        

        pressure = prefer_hardware
        altimeter = prefer_hardware
        appTemp = prefer_hardware
        barometer = prefer_hardware
        cloudbase = prefer_hardware
        dewpoint = prefer_hardware
        ET = prefer_hardware
        heatindex = prefer_hardware
        humidex = prefer_hardware
        inDewpoint = prefer_hardware
        maxSolarRad = prefer_hardware
        rainRate = prefer_hardware
        windchill = prefer_hardware
        windrun = prefer_hardware
        GTS = "software,archive"
        GTSdate = "software,archive"
        utcoffsetLMT = "software,archive"
        dayET = "software,archive"
        ET24 = "software,archive"


       11 19:07:11 Meteo3 weewx[4992] INFO weewx.engine: StdConvert target unit is 0x10
Mar 11 19:07:11 Meteo3 weewx[4992] INFO user.GTS: Version 0.3
Mar 11 19:07:11 Meteo3 weewx[4992] INFO user.GTS: Local mean time (LMT) UTC offset 0:21:00
Mar 11 19:07:12 Meteo3 weewx[4992] INFO weewx.engine: Archive will use data binding wx_binding
Mar 11 19:07:12 Meteo3 weewx[4992] INFO weewx.engine: Record generation will be attempted in 'hardware'
Mar 11 19:07:12 Meteo3 weewx[4992] INFO weewx.engine: Using archive interval of 300 seconds (specified in weewx configuration)
Mar 11 19:07:12 Meteo3 weewx[4992] INFO weewx.restx: StationRegistry: Registration not requested.

       11 19:10:29 Meteo3 weewx[4992] INFO user.GTS: GTS initialized 2021-01-01 00:39:00 
Mar 11 19:10:29 Meteo3 weewx[4992] INFO user.GTS: GTS 235.42205669182695, 69 loops



Karen K

unread,
Mar 11, 2021, 1:20:15 PM3/11/21
to weewx-user
You have version 0.3 installed. In order to calculate solar power you need version 0.4.1. Please install the latest version and try again. 

didier belin

unread,
Mar 12, 2021, 4:05:52 AM3/12/21
to weewx...@googlegroups.com
Thanks for your help, it works

Karen K

unread,
Mar 12, 2021, 5:03:52 AM3/12/21
to weewx-user
Thanks for your patience.
Reply all
Reply to author
Forward
0 new messages