WeeWX now also with wind rose.

1,704 views
Skip to first unread message

FlyingBirdy

unread,
Jan 9, 2013, 4:01:40 AM1/9/13
to weewx...@googlegroups.com

I wrote a python script to convert the degrees numbers to a wind rose direction as seen in the "current conditions" part.
The wind rose is divided in 16 parts, so you got N, NNE, NE, ENE, E ............
16 Wind rose pictures are generated with the help of a program at http://www.642weather.com/weather/scripts-wind-graphics.php
The icons are placed in /home/weewx/skins/Standard and the script in /home/weewx
There is only one thing to edit, add a line (between line 73 and 74) at the "index.html.tmpl" file.

              <tr>
                <td class="stats_label">Wind</td>
                <td class='stats_data'>$current.windSpeed from $current.windDir</td>
ADD this line   <td> <img src="WindDirection.png"/> </td>
              </tr>

And put this line in crontab "*/5 * * * * python2.7 /home/weewx/WindDirection.py"

That's all.
It's not the best way to do but its works.............(just started with learning python)
Also when weewx get a update, nothing as to be changed for the wind rose script.
Look at my webpage www.pa3aod.nl/index.html for the result.


The script:

import re
import shutil

file = open('/var/www/index.html', "r")

for line in file:
   s = re.search(r"<td class='stats_data'>\d{1,3} km/h from (?P<number>[0-9]{1,3})&#176;</td>",line)
   if s:
      print s.group('number')
      Direction = int(s.group('number'))

if (Direction >= 0) and (Direction <= 11):
   print "N"
   shutil.copy2('/home/weewx/skins/Standard/N.png', '/var/www/WindDirection.png')
elif (Direction > 11) and (Direction < 34):
   print "NNE"
   shutil.copy2('/home/weewx/skins/Standard/NNE.png', '/var/www/WindDirection.png')
elif (Direction >= 34) and (Direction <= 56):
   print "NE"
   shutil.copy2('/home/weewx/skins/Standard/NE.png', '/var/www/WindDirection.png')
elif (Direction > 57) and (Direction < 79):
   print "ENE"
   shutil.copy2('/home/weewx/skins/Standard/ENE.png', '/var/www/WindDirection.png')
elif (Direction >= 79) and (Direction <= 101):
   print "E"
   shutil.copy2('/home/weewx/skins/Standard/E.png', '/var/www/WindDirection.png')
elif (Direction >= 102) and (Direction < 124):
   print "ESE"
   shutil.copy2('/home/weewx/skins/Standard/ESE.png', '/var/www/WindDirection.png')
elif (Direction >= 124) and (Direction <= 146):
   print "SE"
   shutil.copy2('/home/weewx/skins/Standard/SE.png', '/var/www/WindDirection.png')
elif (Direction > 147) and (Direction < 169):
   print "SSE"
   shutil.copy2('/home/weewx/skins/Standard/SSE.png', '/var/www/WindDirection.png')
elif (Direction >= 169) and (Direction <= 191):
   print "S"
   shutil.copy2('/home/weewx/skins/Standard/S.png', '/var/www/WindDirection.png')
elif (Direction > 191) and (Direction < 214):
   print "SSW"
   shutil.copy2('/home/weewx/skins/Standard/SSW.png', '/var/www/WindDirection.png')
elif (Direction >= 214) and (Direction < 236):
   print "SW"
   shutil.copy2('/home/weewx/skins/Standard/SW.png', '/var/www/WindDirection.png')
elif (Direction >=236) and (Direction < 259):
   print "WSW"
   shutil.copy2('/home/weewx/skins/Standard/WSW.png', '/var/www/WindDirection.png')
elif (Direction >= 259) and (Direction < 281):
   print "W"
   shutil.copy2('/home/weewx/skins/Standard/W.png', '/var/www/WindDirection.png')
elif (Direction >= 281) and (Direction < 304):
   print "WNW"
   shutil.copy2('/home/weewx/skins/Standard/WNW.png', '/var/www/WindDirection.png')
elif (Direction >= 304) and (Direction < 326):
   print "NW"
   shutil.copy2('/home/weewx/skins/Standard/NW.png', '/var/www/WindDirection.png')
elif (Direction >= 326) and (Direction <= 349):
   print "NNW"
   shutil.copy2('/home/weewx/skins/Standard/NNW.png', '/var/www/WindDirection.png')
elif (Direction > 349) and (Direction <= 360):
   print "N"
   shutil.copy2('/home/weewx/skins/Standard/N.png', '/var/www/WindDirection.png')

Thomas Keffer

unread,
Jan 9, 2013, 10:56:02 AM1/9/13
to weewx...@googlegroups.com
LOL! Well, that's one way of doing it!

Here's another that does not require a cron script.

Put this near the top of your template index.html.tmpl

#def rose_file($winddir)
#set $bigdir=$winddir+360.0-22.5
#set $octant=int($bigdir/45.0)
#if $octant >= 8
#set $octant-=8
#end if
$("rose"+str($octant)+".png")
#end def

This defines a function that, given a wind direction, returns the name of a file with the rose in it. The file names should be rose0.png, rose1.png, ..., rose7.png. They should be in your public_html directory.

Where you want to include the rose, put the following:

<img src="$rose_file($current.windDir.raw)"/>

A similar strategy can be done using JavaScript instead of Cheetah.

-tk

--
 
 



--
Tom Keffer
kef...@threefools.org
+1 541-386-8891 (h)
+1 541-490-9507 (c)
Skype: tkeffer

Tim Hewison

unread,
Jan 27, 2014, 4:18:52 PM1/27/14
to weewx...@googlegroups.com
I'd love to build wind roses into my webpages (http://www.zymurgy.org/tim/weather/) and have tried following Tom's instructions here.
But it doesn't generate any plots.

I even tried repeating the ./bin/wee_reports weewx.conf.

Any ideas?

Cheers,

Tim
Message has been deleted

gonk smith

unread,
Feb 2, 2014, 6:20:41 AM2/2/14
to weewx...@googlegroups.com
Hi 

I am only new myself but I will try and help.

First... Did you make 8 new png files and place them into the folder public_html ?   eg rose0.png, rose1.png....etc This script will not make png files, it will just looks for them in the folder public_html.
Second ... I had to edit the code as it had a minus sign in there (#set $octant-=8) that did not make any sense, also I guess it also depends on the weather station you have as to what directional data it will receive, (I have a WH1081)., because the maths #set $bigdir=$winddir+360.0-22.5 does not work for me.   So far I have done this in the file  index.html.tmpl.. I have highlighted the added code in yellow.  This places the compass rose (one of the 8 png files you have made) at the bottom of the web page just for testing.  You may have to edit #set $bigdir=$winddir+22.5 to suit your station. I made the changes and waited 10 minutes for the web page to update, as I am still trying to work out how to force it to rebuild with a command.  I hope this gives you some more clues on your problem.



#errorCatcher Echo

#def rose_file($winddir)
#set $bigdir=$winddir+22.5
#set $octant=int($bigdir/45.0)
#if $octant >= 7
#set $octant = 7
#end if
$("rose"+str($octant)+".png")
#end def

##    $Revision: 1669 $
.
.
.further down in the file index.html.tmpl
.
  <img src="daywindvec.png"   alt="Wind Vector" />
  <img src="$rose_file($current.windDir.raw)"/>
   #if $day.radiation.has_data

Tim Hewison

unread,
Feb 2, 2014, 4:54:58 PM2/2/14
to weewx...@googlegroups.com
Hi gonk,

Thanks for your advice. 

I just tried creating the files /weewx/public_html/rose0.png, rose1.png, ... using sudo touch. 
But these weren't updated when using Tom's code in my index.html.tmpl.

When I tried your suggestion of the following, but that made no difference:
#if $octant >= 7
#set $octant = 7

I don't understand why this should depend on the type of weather station that generates the data, once they are in the database, though...

Cheers,

Tim

On Wednesday, 9 January 2013 10:01:40 UTC+1, FlyingBirdy wrote:

gonk smith

unread,
Feb 2, 2014, 6:10:32 PM2/2/14
to weewx...@googlegroups.com
Don't know why it should matter but the formula "#set $bigdir=$winddir+360.0-22.5", would always give me a result of 8. Hence why I removed the 360 and lowered the maximum number to 7. I guess some weather stations give a positive and negative result, i.e. west = -90.

Does the code at least make a new index.html ? Or does it make a index.html file of zero bytes?

Message has been deleted

gonk smith

unread,
Feb 3, 2014, 6:47:38 AM2/3/14
to weewx...@googlegroups.com

I made the pictures on my pc and ftp's them to the correct folder on the pi.  Look at your index.html file and see if the code for the rose is being added.eg<img src="rose0.png"/>

gonk smith

unread,
Feb 3, 2014, 7:55:11 AM2/3/14
to weewx...@googlegroups.com

When the wind has dropped to Zero, I get a direction of "N/A".  This stops the index.html from building. 

gonk smith

unread,
Feb 3, 2014, 9:18:12 AM2/3/14
to weewx...@googlegroups.com

ok, I got it work for low wind speed, eg < 1. ( I have a Fine Offset USB Weather station)

1. I created 9 rose.png files on my pc, with rose0.png = north pointing compass picture, rose1.png = north/east pointing compass picture, etc.  With the exception of rose8.png, it is pointer-less picture of the compass as it represents no wind.
2. I uploaded all 9 rose.png files to the folder "public_html"
3. I placed this code (below) near the top of the file "index.html.tmpl" in the folder  /skins/Standard..eg the bold is code that was already present, just to show exactly where I placed it. I worked out what the minus in front of the equals does... eg  #set $octant-= 8.  This is correct. I still had to change "#set $bigdir=$winddir+360.0-22.5" to "#set $bigdir=$winddir+22.5"


#errorCatcher Echo

#def rose_file($winddir)
#set $bigdir=$winddir+22.5
#set $octant=int($bigdir/45.0)
#if $octant >= 8
#set $octant-= 8
#end if
$("rose"+str($octant)+".png")
#end def

##    $Revision: 1669 $
.
.
.further down in the file index.html.tmpl
.

4. I Added this code into index.html.tmpl to check for low wind with stops the N/A problem, I placed it near the bottom of the tables for now..

 <img src="daywindvec.png"   alt="Wind Vector" />

 #if $current.windSpeed.raw  < 1
 <img src="rose8.png"   alt="NA" />
  #else 
  <img src="$rose_file($current.windDir.raw)" />
  #end if

  #if $day.radiation.has_data



I hope this helps... and thanks a heap Tom K...it is a very nice tool.

Tim Hewison

unread,
Feb 3, 2014, 1:45:33 PM2/3/14
to weewx...@googlegroups.com
Aha! Now the penny drops! I think we've been talking at cross purposes.

The wind rose I have been talking about is a plot commonly used by meteorologists to show the distribution of wind directions (and sometimes strengths) observed at a particular site. Not just the direction the wind happens to be blowing from at one time, which I suspect is what you were looking for. That would explain why I couldn't understand the code (not that I'm familiar with perl/cheetah). Now that sounds like a good excuse to learn it...


Thanks for your help, anyway - and of course to Tom K for this excellent project.

Cheers,

Tim





--
You received this message because you are subscribed to a topic in the Google Groups "Weewx user's group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/weewx-user/vwX11T8pBlM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to weewx-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Tim Hewison

unread,
Feb 3, 2014, 3:26:01 PM2/3/14
to weewx...@googlegroups.com
I just spotted the following topic on the development forum: 

I look forward to this development coming to fruitition.

Cheers,

Tim

David Gardner

unread,
Feb 4, 2014, 3:50:15 PM2/4/14
to weewx...@googlegroups.com
On Mon, Feb 03, 2014 at 07:45:33PM +0100, Tim Hewison wrote:
> Aha! Now the penny drops! I think we've been talking at cross purposes.
>
> The wind rose I have been talking about is a plot commonly used by
> meteorologists to show the distribution of wind directions (and sometimes
> strengths) observed at a particular site. Not just the direction the wind
> happens to be blowing from at one time, which I suspect is what you were
> looking for. That would explain why I couldn't understand the code (not that
> I'm familiar with perl/cheetah). Now that sounds like a good excuse to learn
> it...
>

It looks like it's been done before... and in python too...
See: http://code.google.com/p/pywws/issues/detail?id=8

So, does anyone who's familiar with the code know how easy it would be to
pull that code into weewx?

David

Oz Greg

unread,
Feb 4, 2014, 4:17:03 PM2/4/14
to weewx...@googlegroups.com
Not that hard at all, Gary has the code in the weewx-wd codebase to generate rose image if you want to copy it go ahead..


We also have a class to generate a windrose for Steel Gauges

Panos Vatikiotis

unread,
Jun 24, 2016, 11:56:03 AM6/24/16
to weewx-user
Well it worked for me too and thank you all! I could not find any roses so i made some by photoshop so here
they are: http://www.milosbeach.gr/weatherstation/

RobbH

unread,
Mar 31, 2018, 8:11:55 PM3/31/18
to weewx-user
This a very old thread, but it still turns up in searches. Here's a simple way to do a crude version of what the original poster was doing. That is, a display of the most recent wind direction on the background of a compass rose, not a wind rose, showing history. May not work in all browsers, but hasn't failed me yet.

Add the following code to index.html.tmpl. I created a table with one row of two cells at the top of the page, put the masthead text in the left cell and this in the right cell:

<svg version="1.1" baseProfile="full" width="200" height="200" xmlns="http://www.w3.org/2000/svg">
 <circle cx="90" cy="85" r="75" stroke="black" stroke-width="5" stroke-dasharray="1,12.08" fill="transparent" />
 <circle cx="90" cy="85" r="80" stroke="lightgray" stroke-width="10" fill="transparent" />
 <polygon points="90 35, 100 75, 140 85, 100 95, 90 135, 80 95, 40 85, 80 75" fill="lightsalmon" transform="rotate(45 90 85)" />
 <polygon points="90 25, 100 75, 150 85, 100 95, 90 145, 80 95, 30 85, 80 75" fill="salmon" />
 <text x="90" y="22" font-size="16" text-anchor="middle" fill="gray">N</text>
 <text x="90" y="159" font-size="16" text-anchor="middle" fill="gray">S</text>
 <text x="22" y="91" font-size="16" text-anchor="middle" fill="gray">W</text>
 <text x="158" y="91" font-size="16" text-anchor="middle" fill="gray">E</text>
 <circle cx="90" cy="85" r="20" stroke="black" fill="white" />
 <text x="90" y="90" font-size="16" text-anchor="middle" fill="black">$current.windSpeed.formatted</text>
 #if $current.windDir.formatted != "   N/A"
 <polygon points="90 20, 95 65, 85 65" fill="black" transform="rotate($current.windDir.formatted 90 85)" />
 #end if
</svg>

I hope someone finds this helpful, and that someone will improve on it.
Reply all
Reply to author
Forward
0 new messages