simple python question, while adopting current.inc

80 views
Skip to first unread message

Vetti52

unread,
Dec 3, 2020, 11:48:56 AM12/3/20
to weewx-user
After upgrading to Weewx version 4.2.0 I want to replace the deprecated type Beaufort by the new unit  $current.windSpeed.beaufort.
First, I replaced the previous evaluation in my accomodated current.inc, where I want to express the beaufort value by a literal description:
#if $varExists('day.windSpeed') and $current.windSpeed.raw is not None
  #if $current.windSpeed.beaufort == '0'
    #set $word_current_beaufort = 'Calm'
  #elif $current.windSpeed.beaufort == '1'
    #set $word_current_beaufort = 'Light Air
'
...
  #else
    #set $word_current_beaufort = 'N/A'
  #end if
 
This construct does not result in errors, but always ends up displaying "N/A".

As gust seems not to be covered by the new unit $current.windSpeed.beaufort, I evaluate gust into beaufort still the old way, which is an adoption from another contribution in this forum. This works well:

  #if $unit.unit_type.windSpeed == 'mile_per_hour'
    #set $current_gust_kts = $current.windGust.raw * 0.8689762
  #elif $unit.unit_type.windSpeed == 'km_per_hour'
    #set $current_gust_kts = $current.windGust.raw * 0.539956
  #elif $unit.unit_type.windSpeed == 'meter_per_second'
    #set $current_gust_kts = $current.windGust.raw * 1.943844
  #elif $unit.unit_type.windSpeed == 'knot'
    #set $current_gust_kts = $current.windGust.raw
  #else
    #set $current_gust_kts = 0
  #end if
  #if $current_gust_kts < 1
    #set $current_gust_beaufort = 0
  #elif $current_gust_kts < 4
    #set $current_gust_beaufort = 1
 ...
  #else
    #set $current_gust_beaufort = 12
  #end if
#else
  #set $current_gust_beaufort = 'N/A'
#end if

As I am pretty naive with python, I do not understand, what is wrong with my solution. Python experts may lough about it. But, please, explain, how to solve my problem.

Thanks!

Tom Keffer

unread,
Dec 3, 2020, 11:59:37 AM12/3/20
to weewx-user
Your main problem is that $current.windSpeed.beaufort returns a number, not a string. So, you want

#if $varExists('day.windSpeed') and $current.windSpeed.raw is not None
  #if $current.windSpeed.beaufort == 0
    #set $word_current_beaufort = 'Calm'
  #elif $current.windSpeed.beaufort == 1
    #set $word_current_beaufort = 'Light Air
'
...
  #else
    #set $word_current_beaufort = 'N/A'
  #end if

You should be able to do $current.windGust.beaufort as well. However, oceanographically, Beaufort's observations are related to the steady wind speed, not gusts, so the results cannot be related to sea state through his table.

-tk


--
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/d84a6194-945c-4754-8ee9-a04421821429n%40googlegroups.com.

Vetti52

unread,
Dec 3, 2020, 12:35:33 PM12/3/20
to weewx-user
I tried the integer version already, with the same result. So, I assumed, that Beaufort is a string. Still no success.
At least current.windGust.beaufort works fine!
Thanks for the hint.
Showing wind gust is just to compare the values to the red line in the windspeed/gust graph. When sailing, I am accustomed to trust on the waves, not on the wind meter.

Tom Keffer

unread,
Dec 3, 2020, 12:47:33 PM12/3/20
to weewx-user
Silly me. You need a .raw suffix:

#if $varExists('day.windSpeed') and $current.windSpeed.raw is not None
  #if $current.windSpeed.beaufort.raw == 0
    #set $word_current_beaufort = 'Calm'
  #elif $current.windSpeed.beaufort.raw == 1

    #set $word_current_beaufort = 'Light Air
'
...
  #else
    #set $word_current_beaufort = 'N/A'
  #end if

Vetti52

unread,
Dec 3, 2020, 2:33:40 PM12/3/20
to weewx-user
Right! That works nicely.

Well, I could have realized it. But perfect, that there is somone, that understands, what I have written.
Thanks a lot!
Reply all
Reply to author
Forward
0 new messages