POTM Sept. 2016 - Wind Roses!

More
10 months 1 week ago - 10 months 1 week ago #104 by Kim_Cressman
Kim_Cressman created the topic: POTM Sept. 2016 - Wind Roses!
As anyone who's tried to QC weather data can attest, wind direction isn't something you can just look at with a line graph. Because 360 is the same as 0, it's just messy and you need a better option: a wind rose! Wind roses give you information on speed as well as direction. (I was torn on whether to post this under 'single variable exploration' or 'multiple variable exploration' because technically it's 2, but most of us just think of 'WIND' - so here it is in single.)

Spokes come out of the center to represent the direction wind was coming from during the selected time period; the longer a spoke is, the more often wind blew from that direction. The color bands within the spokes tell you how often certain wind speeds were logged. Wind roses show us frequency. Here's an example of aaaallll the wind data from my weather station since 2008:





You can see that most of our wind comes out of the north and is <6 m/s. To check for seasonality, you can break it out by month (or for other reasons, year, day, or whatever):





Fortunately, R makes this relatively easy. Specifically, a package called 'openair'. You'll need to install it:
install.packages('openair')

I'm using SWMPr here because it lets me work with a lot of data, but you could easily do this on a single file by just using the read.csv() command. You'd also need to turn the datetimestamp into a POSIXct format using as.POSIXct() - something that SWMPr automatically does for us.

Step 1: Open up the packages you need, read in and QC the data, and make a column called 'date' (openair needs that specifically, as a POSIXct column). In this example, I'm only working with my 2015 data.
library(SWMPr)
library(openair)
library(lattice) #gets installed automatically with openair and should open automatically with it; but I've had better results calling it manually
setwd('C:/Users/kimberly.cressman/MET graphing')  # where files will be saved
path <- 'C:/Users/kimberly.cressman/Data-latest'  # where SWMPr will pull files from
# import and QC met data
met.data <- import_local(path, 'gndcrmet2015', trace=TRUE)
met.data <- subset(qaqc(met.data, qaqc_keep = c(0,1,4,5)), rem_cols = T)
# openair needs a POSIXct column named 'date' to facet correctly. datetimestamp is already POSIXct because of SWMPr, so just make a new column, same as that one, with the right name
met.data$date <- met.data$datetimestamp 


Step 2: Check the names of your columns. You need to know the names for wind speed and wind direction.
names(met.data)


Step 3: Make your overall wind rose. Openair has several defaults. All you really have to do is define your dataset and the variable names that correspond to speed and direction, and you will get a rose. Here's the default:
windRose(met.data, ws='wspd', wd='wdir')




I've played around with various settings and done my best to document that within my script, so the roses look the way I want them. Play around with things yourself to see what works best for your data.
windRose(met.data, ws='wspd', wd='wdir', 
         angle=45, #splits the wind into 8 directions (default is 30 degrees/12 directions)
         width=1.5, 
         breaks=5, #number of categories the wind speeds are broken up into
         paddle=FALSE, #shape of the spokes 
         grid.line=10, #lines around the center every 10% 
         max.freq=30, #which %ile aligns with the very top of the panel (found by trial and error) 
         cols='GnBu', #color scheme from RColorBrewer
         annotate=FALSE, #gets rid of the mean, calm, and legend label
         main='GNDCRMET wind, 2015')





Step 4: Split it out by month. Caveat: openair uses the lattice package in the background for its graphics. To change the formatting - like creating space between the different panels, or making the labels bold - you have to use commands for lattice. I'm more familiar with ggplot2, so this was really tough for me to learn, because it's a different vocabulary. You can start by following this example and then just playing with the different options to get what you like.
# facet by month
windRose(met.data, ws='wspd', wd='wdir', 
         angle=45, 
         width=1.5, 
         breaks=5, 
         paddle=FALSE,  
         grid.line=15, 
         max.freq=45, #which %ile aligns with the very top of the panel (found by trial and error) 
         cols='GnBu', #color scheme from RColorBrewer
         annotate=FALSE,
         main='GNDCRMET wind by month, 2015',
         type='month', #everything from this line on is related to faceting and formatting the panels
         between = list(x = 1, y = 1),
         par.settings = list(axis.line = list(col = 'darkgray'),
                             par.main.text = list(cex=1.1),
                             strip.border = list(col = 'darkgray'),
                             layout.widths = list(right.padding = 3),
                             layout.heights = list(top.padding = 3)),
         strip=strip.custom(par.strip.text=list(cex=0.8, fontface='bold'))) #facet labels in bold
# axis.line is the border around each individual plot
# strip.border is the border around the individual plot labels
# layout.widths and .heights padding leaves some room around the individual plots

That results in the second plot I posted above.





Exploring wind data this way has been really fun for me, and should be really useful for future analyses. I hope it helps you all too!
Attachments:
Last Edit: 10 months 1 week ago by Kim_Cressman.

Please Log in to join the conversation.

More
10 months 1 week ago #105 by Marcus Beck
Marcus Beck replied the topic: POTM Sept. 2016 - Wind Roses!
Nice looking graphs, thanks for the great post Kim! I'm wondering if this would be useful to include in SWMPr or if it's better to leave as standalone. What do you think?

Please Log in to join the conversation.

More
10 months 1 week ago - 10 months 1 week ago #106 by Kim_Cressman
Kim_Cressman replied the topic: POTM Sept. 2016 - Wind Roses!
I think it would be awesome as part of SWMPr. I use them together all the time. What would including it in SWMPr entail?
Last Edit: 10 months 1 week ago by Kim_Cressman.

Please Log in to join the conversation.

More
10 months 1 week ago #107 by Marcus Beck
Marcus Beck replied the topic: POTM Sept. 2016 - Wind Roses!
Not much, just wrapping your code in a function. I'm always kind of conflicted about plotting functions that work perfectly fine by themselves. Putting them in a SWMPr-specific function can limit their use for some of the fine-tuning but it also makes it easier to use out of the box.

Please Log in to join the conversation.

More
10 months 1 week ago #108 by Kim_Cressman
Kim_Cressman replied the topic: POTM Sept. 2016 - Wind Roses!
That's a good point - we don't want to make it any harder to fine-tune this than it already is. Maybe just leaving it here and in the cookbook (when we update that) would be good enough then. And keep it as well-documented as possible.

Please Log in to join the conversation.

More
10 months 1 week ago #109 by Dave Eslinger
Dave Eslinger replied the topic: POTM Sept. 2016 - Wind Roses!
Kim,

I agree with Marcus, these are great plots and a helpful post. Well done!

As for putting it into a SAWMPr function, that seems to make sense. Then it would be relatively easy for users to begin using it with default options. As needed, they can come here to see how to set their own options and run the commands outside of SWMPr.

Just my $0.02 worth,
Dave

Please Log in to join the conversation.

Time to create page: 0.237 seconds
Powered by Kunena Forum