New Timespan $daylight for the time while sun is up

390 views
Skip to first unread message

Karen K

unread,
Oct 17, 2021, 3:50:53 PM10/17/21
to weewx-user
I added a new tag in weewx-GTS.

$daylight is the timespan from sunrise to sunset. The option days_ago is also available.

Examples: 
$daylight.outTemp.avg is the average temperature while the sun is up today.
$daylight(days_ago=1).outTemp.avg is the same for yesterday.

$LMTmonth.daylights and $LMTyear.daylights create a series of daylight timespans 

Example:
<table>
  <tr>
    <th>day</th>
    <th>sunrise</th>
    <th>sunset</th>
    <th>avg. temperature while sun is up</th> 
</tr> 
#for $span in $LMTmonth.daylights 
<tr> 
    <td>$span.dateTime.format("%d")</td> 
    <td>$span.start</td>
    <td>$span.end</td>
    <td>$span.outTemp.avg</td> 
</tr> 
#end for 
</table>

This creates a table of the month showing day of month, sunrise, sunset and average temperature for the time in between for each day of that month.

energy_integral can now be used for group_power, too, to calculate the energy from power readings.


Karen K

unread,
Oct 20, 2021, 2:54:06 AM10/20/21
to weewx-user
daylight-timespan.png

Karen K

unread,
Oct 25, 2021, 4:15:07 AM10/25/21
to weewx-user
I updated the german readme file.
Ich habe die deutsche Beschreibung aktualisiert.

Karen K

unread,
Nov 5, 2022, 9:00:05 AM11/5/22
to weewx-user
I updated the $daylight tag. The whole tag is

$daylight(timestamp=None, data_binding=None, days_ago=0, horizon=None, use_center=False).observation.aggregation

Using the option timestamp the $daylight timespan can be used for every day, not only the actual day.This makes it possible to do things like that:

#for $dd in month.days
<p>
$dd.dateTime
day average: $dd.outTemp.avg,
average during light day: $daylight(timestamp=$dd).outTemp.avg
</p>
#end for

While `$almanac.sunrise` and `$almanac.sunset` calculate sunrise and sunset using the actual temperature and barometer of the calculation time, `$daylight` now observes temperature and barometer of the time, the daylight timespan is calculated for if there are database records available. It first calculates approximate sunrise and sunset times for the ICAO standard atmosphere at 15°C and 1013.25 mbar. Then it looks up the real temperature and barometer for both those times. After that it calculates sunrise and sunset again, using the respective temperature and barometer.

That's why `$daylight(timestamp=$X).start` provides a slightly more accurate time for sunrise than `$almanac(timestamp=$X).sunrise` if `$X` is a timestamp somewhere in the past and database records are available for that time. The same applies to `$daylight(timestamp=$X).end` instead of `$almanac(almanac_time=$X).sunset` for sunset and  `$daylight(timestamp=$X).length` instead of `$almanac(almanac_time=$X).sun.visible` for the daylight duration.

But please note that the real purpose of the $daylight tag is not sunrise and sunset but aggregation. 

https://github.com/roe-dl/weewx-GTS


Rory Gillies

unread,
Jan 25, 2023, 8:22:27 AM1/25/23
to weewx-user
Hi,

I originally sent this to the author but posting here as well. I am trying to use the $daylight tag to display the daylight average of UV and Radiation values. It works fine in the current day and yesterday templates, but generates an error when I try to use accumulator code for the week, month and year templates, and the month and year report templates. I am using the NeowWX-Material skin with WeeWX 4.8 on a RPi 4B 4GB running Bullseye.

Code:
#from weewx.units import ValueTuple, ValueHelper
#for $dd in $week.days
#set $light=$daylight(timestamp=$dd)
#set $dayradiation=$dd.$light.radiation.sum.raw <-- this is where it fails
#set $dayradiationacc=$dayradiationacc.raw+$dayradiation.raw
#end for
#set $dayradiationavg=$dayradiationacc.raw/$week.days
#set $dayradiation_vh=ValueHelper(ValueTuple($dayradiationavg,$unit.unit_type.radiation,'group_radiation'),formatter=$station.formatter)
...
<div class="row">
  <div class="col-3 text-muted font-small">
  $dayradiation_vh <br>
  $Extras.Translations[$Extras.language].avg
  </div>
  <div class="col-6">
    <h4 class='h2-responsive '>$week.radiation.energy_integral.kilowatt_hour_per_meter_squared</h4>
  </div>
  <div class="col-3 text-muted font-small hi-text">
    $week.radiation.max <br>
    ($week.radiation.maxtime.format($Extras.Formatting.datetime))
  </div>
</div>


Error:
Jan 25 12:45:28 weather weewx[625144] ERROR weewx.cheetahgenerator: Evaluation of template /etc/weewx/skins/neowx-material/week.html.tmpl failed with exception '<class 'TypeError'>'
Jan 25 12:45:28 weather weewx[625144] ERROR weewx.cheetahgenerator: **** Ignoring template /etc/weewx/skins/neowx-material/week.html.tmpl
Jan 25 12:45:28 weather weewx[625144] ERROR weewx.cheetahgenerator: **** Reason: 'ObservationBinder' object is not callable
Jan 25 12:45:28 weather weewx[625144] ERROR weewx.cheetahgenerator: ****  Traceback (most recent call last):
Jan 25 12:45:28 weather weewx[625144] ERROR weewx.cheetahgenerator: ****    File "/usr/share/weewx/weewx/cheetahgenerator.py", line 348, in generate
Jan 25 12:45:28 weather weewx[625144] ERROR weewx.cheetahgenerator: ****      unicode_string = compiled_template.respond()
Jan 25 12:45:28 weather weewx[625144] ERROR weewx.cheetahgenerator: ****    File "cheetah__etc_weewx_skins_neowx_material_week_html_tmpl_1674650728_0954206_64383.py", line 574, in respond
Jan 25 12:45:28 weather weewx[625144] ERROR weewx.cheetahgenerator: ****  TypeError: 'ObservationBinder' object is not callable


Any help, pointers or neater code would be appreciated!

Karen K

unread,
Jan 26, 2023, 7:59:43 AM1/26/23
to weewx-user
rory.g...@googlemail.com schrieb am Mittwoch, 25. Januar 2023 um 14:22:27 UTC+1:
#set $dayradiation=$dd.$light.radiation.sum.raw <-- this is where it fails

Try $light.radiation.sum.raw

$dd and $light in one statement is too much.

 

Rory Gillies

unread,
Jan 26, 2023, 12:08:23 PM1/26/23
to weewx...@googlegroups.com
Thanks! That’s moved the error down a line so I’m moving in the right direction. I can’t seem to iterate through the for loop to add each day’s average radiation.

--
You received this message because you are subscribed to a topic in the Google Groups "weewx-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/weewx-user/7CPWHA8azqY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/dab05ce0-7f02-4cfe-bd31-1e3e31c9632cn%40googlegroups.com.

Karen K

unread,
Jan 26, 2023, 1:46:02 PM1/26/23
to weewx-user
There are 3 problems in the next line:
  • $dayradiation is already raw, so another raw is too much.
  • $dayradiationacc is not initialized for the first loop
  • $dayradiationacc is already raw, so another raw is too much for the following loops

Rory Gillies

unread,
Jan 26, 2023, 2:35:07 PM1/26/23
to weewx...@googlegroups.com
Thanks again. I have removed the .raw, but as you say $dayradiationacc is not initialised:

Jan 26 19:30:32 weather weewx[625144] ERROR weewx.cheetahgenerator: Evaluation of template /etc/weewx/skins/neowx-material/week.html.tmpl failed.

Jan 26 19:30:32 weather weewx[625144] ERROR weewx.cheetahgenerator: **** Ignoring template /etc/weewx/skins/neowx-material/week.html.tmpl

Jan 26 19:30:32 weather weewx[625144] ERROR weewx.cheetahgenerator: **** Reason: cannot find 'dayradiationacc'


I’m not sure where this should be initialised so it can increase in value through the for loop?

Karen K

unread,
Jan 26, 2023, 2:43:57 PM1/26/23
to weewx-user
Just before the loop.

#set $dayradiationacc=0

Rory Gillies

unread,
Jan 28, 2023, 8:24:41 AM1/28/23
to weewx-user
I'm still struggling with this. Here's the updated code:

#errorCatcher Echo


#from weewx.units import ValueTuple, ValueHelper

#set $dayradiationacc=0


#for $dd in $week.days
#set $light=$daylight(timestamp=$dd)

#set $dayradiation=$light.radiation.sum.raw
#set $dayradiationacc=$dayradiationacc+$dayradiation
#end for
#set $dayradiationavg=$dayradiationacc/$week.days
#set $dayradiation_vh=ValueHelper(ValueTuple($dayradiationavg,$unit.unit_type.radiation,'group_radiation'),formatter=$station.formatter)

And the error:

Jan 28 13:20:28 weather weewx[625144] ERROR weewx.cheetahgenerator: Evaluation of template /etc/weewx/skins/neowx-material/week.html.tmpl failed with exception '<class 'TypeError'>'
Jan 28 13:20:28 weather weewx[625144] ERROR weewx.cheetahgenerator: **** Ignoring template /etc/weewx/skins/neowx-material/week.html.tmpl
Jan 28 13:20:28 weather weewx[625144] ERROR weewx.cheetahgenerator: **** Reason: unsupported operand type(s) for +: 'float' and 'NoneType'
Jan 28 13:20:28 weather weewx[625144] ERROR weewx.cheetahgenerator: ****  Traceback (most recent call last):
Jan 28 13:20:28 weather weewx[625144] ERROR weewx.cheetahgenerator: ****    File "/usr/share/weewx/weewx/cheetahgenerator.py", line 348, in generate
Jan 28 13:20:28 weather weewx[625144] ERROR weewx.cheetahgenerator: ****      unicode_string = compiled_template.respond()
Jan 28 13:20:28 weather weewx[625144] ERROR weewx.cheetahgenerator: ****    File "cheetah__etc_weewx_skins_neowx_material_week_html_tmpl_1674912028_8195086_18355.py", line 930, in respond
Jan 28 13:20:28 weather weewx[625144] ERROR weewx.cheetahgenerator: ****  TypeError: unsupported operand type(s) for +: 'float' and 'NoneType'

I'm sure there must be an easy way to do this, I need to calculate the average UV index and solar radiation based on daylight hours only.

Thanks in advance!

Rory

Karen K

unread,
Jan 28, 2023, 2:45:20 PM1/28/23
to weewx-user

#from weewx.units import ValueTuple, ValueHelper
#set $dayradiationacc=0
#set $n=0

#for $dd in $week.days
#set $light=$daylight(timestamp=$dd)
#set $dayradiation=$light.radiation.sum.raw
#if $dayradiation is not None
#set $dayradiationacc=$dayradiationacc+$dayradiation
#set $n=$n+1
# end if
#end for
#set $dayradiationavg=$dayradiationacc/$n
#set $dayradiation_vh=ValueHelper(ValueTuple($dayradiationavg,$unit.unit_type.radiation,'group_radiation'),formatter=$station.formatter)

Rory Gillies

unread,
Jan 30, 2023, 7:45:53 AM1/30/23
to weewx...@googlegroups.com
Thanks Again Karen K! It needed a little bit of tweaking but now it’s working great. Here’s the working code extract from week.html.tmpl:

       <div class="col-3 text-muted font-small">
          #from weewx.units import ValueTuple, ValueHelper
          #attr $dayradiationacc=0
          #attr $n=0
          #for $dd in $year.days
          #set $light=$daylight(timestamp=$dd)
          #set $dayradiation=$light.radiation.avg.raw

          #if $dayradiation is not None
          #set $dayradiationacc=$dayradiationacc+$dayradiation
          #set $n=$n+1
          #end if
          #end for
          #if $n is not None

          #set $dayradiationavg=$dayradiationacc/$n
          #set $dayradiation_vh=ValueHelper(ValueTuple($dayradiationavg,$unit.unit_type.radiation,'group_radiation'),formatter=$station.formatter)
          #else
          #set $dayradiation_vh=0
          #end if

          $dayradiation_vh <br>
          $Extras.Translations[$Extras.language].avg
       </div>

I had to change the initial values for $dayradiationacc and $n to #attr= rather than #set=, and I put in a test for $n is not None to avoid a divide by zero error at the start of a new week / month / year before the $daylight tag returns a value > 1

You can see it in action here: https://www.360shetland.co.uk/weather/week.html

Using the standard $week.radiation.avg tag returns a very low value (around 4w/sqm prior to getting this working) as it is averaging each day over 24 hours.

Cheers!

Rory

--
You received this message because you are subscribed to a topic in the Google Groups "weewx-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/weewx-user/7CPWHA8azqY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to weewx-user+...@googlegroups.com.
Message has been deleted

Karen K

unread,
Sep 29, 2023, 2:13:23 PM9/29/23
to weewx-user
Mks Mk schrieb am Freitag, 29. September 2023 um 19:09:10 UTC+2:
We want to add below code or similar to its action to the NOAA monthly report file "NOAA-%Y-%m.txt.tmpl" but we do not know if it is possible to do so because of the span tags?


Why not trying it?

If you are not sure about the $span tag, you can replace it by something else like $ii
 
Message has been deleted

Karen K

unread,
Sep 30, 2023, 2:18:19 AM9/30/23
to weewx-user
Yes.

Mks Mk schrieb am Samstag, 30. September 2023 um 03:08:55 UTC+2:
when it comes to coding the best we can do is copy and paste,  all we wanna know is if this tag ($daylight) actually does work within NOAA template file.
thank you for your help

Message has been deleted

Meteo Oberwallis

unread,
Oct 14, 2023, 6:03:33 AM10/14/23
to weewx-user
Hallo.
Bei mir wird unter Belchertown bei der Absoluten Luftfeuchtugkeit ein zu grosser Wert angezeigt. Wie kann ich das anpassen?
2023_10_14_12_01_34_Clipboard.png
Grüsse

Karen K

unread,
Oct 14, 2023, 8:47:29 AM10/14/23
to weewx-user

    [[humidity]]

        title = "Luftfeuchtigkeit"

        [[[outHumidity]]]

            name = "relativ"

        [[[outHumAbs]]]

            name = "absolut"

            yAxis = 1

            unit = gram_per_meter_cubed

            [[[[numberFormat]]]]

                decimals = 1

Meteo Oberwallis

unread,
Oct 15, 2023, 3:40:04 AM10/15/23
to weewx-user
Hallo Karen.

Genau so habe ich es. Trotzdem habe ich diese dezimalstellenfehler.

Gruss

Karen K

unread,
Oct 15, 2023, 5:24:49 AM10/15/23
to weewx-user
Welche Belchertown-Version ist es denn? Die Option unit ist, glaube ich, erst irgendwann eingeführt worden.

Funktioniert das mit der Einheit bei anderen Größen? Einfach mal ausprobieren, ob nur die absolute Luftfeuchtigkeit betroffen ist oder auch anderes. Zum Beispiel könnte man in einem Temperaturdiagramm mal testweise nach demselben Prinzip in graphs.conf die Werte in Grad Fahrenheit anzeigen lassen.

Meteo Oberwallis

unread,
Oct 15, 2023, 6:46:46 AM10/15/23
to weewx-user
Hallo.

Ich habe die:

  • Programm version: 4.10.2
  • Skin Version: 1.2

Gruss

Karen K

unread,
Oct 15, 2023, 8:54:44 AM10/15/23
to weewx-user
Dann bitte Version 1.3 benutzen.
Reply all
Reply to author
Forward
0 new messages