R code used to create wind rose plots (fig. 7 & figs. 9-12)

Load the relevant packages and set working directory

library('openair')
## Warning: package 'openair' was built under R version 3.4.4
library('ncdf4')
library('dplyr')
## Warning: package 'dplyr' was built under R version 3.4.3
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
setwd("G:/Thesis data")
getwd()
## [1] "G:/Thesis data"
path <- file.path(getwd());

Open the u and v wind files in working directory

nc_u <-nc_open(file.path(path,'uwnd.sig995.mon.mean.nc'))
nc_v <-nc_open(file.path(path,'vwnd.sig995.mon.mean.nc'))

get the data, uwnd = monthly mean eastward wind

uwind <- ncvar_get(nc_u, 'uwnd')

get the data, vwnd = monthly mean northward wind

vwind <- ncvar_get(nc_v, 'vwnd')

Replace missing values with NA

uwind[uwind==-9.99999] <- NA
vwind[vwind==-9.99999] <- NA

Extracting remaining variables; lat and lon and time

lat<-ncvar_get(nc_u, 'lat') #### latitude, 90 -90
lon<-ncvar_get(nc_v, 'lon') #### logitude, 0 358

lon_split = which(lon==180) #### find the date line 
lon = c(lon[(lon_split+1):length(lon)]-360,lon[1:lon_split]) #### rearrange the longitudes
uwind = uwind[c((lon_split+1):length(lon),1:lon_split),,] #### and the data
vwind = vwind[c((lon_split+1):length(lon),1:lon_split),,]

Load time

time<-ncvar_get(nc_u, 'time') #### time

get units

tunits<-ncatt_get(nc_u,"time",attname="units")
tustr<-strsplit(tunits$value, " ")
date_all<-as.character(as.Date(time/24,origin=unlist(tustr)[3]))

Getting mean wind direction from u and v wind components

First, get u and v winds on correct time base (AMO pos and AMO neg) and centre over Ireland

uwind_pos <- uwind[83:87,18:21,889:1380] 
vwind_pos <- vwind[83:87,18:21,889:1380]
uwind_neg <- uwind[83:87,18:21,1381:1740]
vwind_neg <- vwind[83:87,18:21,1381:1740]

Calculate the average wind vectors

mean_uwind_pos <- mean(uwind_pos, na.rm = TRUE)
mean_vwind_pos <- mean(vwind_pos, na.rm = TRUE)
mean_uwind_neg <- mean(uwind_neg, na.rm = TRUE)
mean_vwind_neg <- mean(vwind_neg, na.rm = TRUE)

Calculate the resultant vector average wind direction with atan2

wd_average_pos <- (atan2(mean_uwind_pos, mean_vwind_pos) * 360/2/pi) + 180

wd_average_neg <- (atan2(mean_uwind_neg, mean_vwind_neg) * 360/2/pi) + 180

Calculate the vector average wind speed

ws_average_pos <- ((mean_uwind_pos^2 + mean_vwind_pos^2)^0.5)

ws_average_neg <- ((mean_uwind_neg^2 + mean_vwind_neg^2)^0.5)

Creating two datasets for plotting with windRose: 1. Monthly means of AMO positive phase (1925-1965) 2. Monthly means of AMO negative phase (1965-1995)

AMO positive

Average windspeed for positive phase

Windspeed_pos <- sqrt(uwind_pos^2 + vwind_pos^2)

Average wind direction for positive phase

Winddirection_pos <- atan2(uwind_pos/Windspeed_pos, vwind_pos/Windspeed_pos)*180/pi+180

Individual months 1925-1965

date_pos <- date_all[889:1380]

Extract ws and wd values

Windspeed_pos_values <- Windspeed_pos[1:492] ####Windspeed values
Winddirection_pos_values <- Winddirection_pos[1:492] ####Wind direction values]

Create data frame

IRE_monmeans_pos <- data.frame(date_pos, Windspeed_pos_values, Winddirection_pos_values)

Changing class of date column in data frame

IRE_monmeans_pos$date_pos <- as.POSIXct(IRE_monmeans_pos$date_pos, format = "%Y%m%d", 
                                        tz = "")

Rename the columns

IRE_monmeans_pos <- rename(IRE_monmeans_pos, date = date_pos, ws = Windspeed_pos_values,
                           wd = Winddirection_pos_values)

Plotting

windRose(IRE_monmeans_pos, key.header = "Monthly mean ws/wd Ireland 1925-1965", 
         key.position = "top", ws.int = 3, max.freq = 30) 
## Warning: package 'bindrcpp' was built under R version 3.4.3

  1. AMO negative

Average windspeed for negative phase

Windspeed_neg <- sqrt(uwind_neg^2 + vwind_neg^2)

Average wind direction for negative phase

Winddirection_neg <- atan2(uwind_neg/Windspeed_neg, vwind_neg/Windspeed_neg)*180/pi+180

Individual months 1966-1995

date_neg <- date_all[1381:1740]

Extract ws and wd values

Windspeed_neg_values <- Windspeed_neg[1:360] ####Windspeed values
Winddirection_neg_values <- Winddirection_neg[1:360] ####Wind direction values]

Create data frame

IRE_monmeans_neg <- data.frame(date_neg, Windspeed_neg_values, Winddirection_neg_values)

Changing class of date column in data frame

IRE_monmeans_neg$date_neg <- as.POSIXct(IRE_monmeans_neg$date_neg, format = "%Y%m%d", 
                                        tz = "")

Rename the columns

IRE_monmeans_neg <- rename(IRE_monmeans_neg, date = date_neg, ws = Windspeed_neg_values,
                           wd = Winddirection_neg_values)

Plotting

windRose(IRE_monmeans_neg, key.header = "Monthly mean ws/wd Ireland 1966-1995", 
         key.position = "top", ws.int = 3, max.freq = 30) 

#################################################################################################

Investigate influence of NAO variability within AMO phases

i.e. Choose NAO positive and negative phase within AMO positive phase (1925-1965) Choose NAO positive and negative phase within AMO negative phase (1966-1995)

  1. AMO positive (1925-1965)

1.1 Nested NAO negative (1938-1943)

Individual months 1938-1943

date_NAO3843 <- date_all[1045:1116]

Windspeed and wind direction values for 1938-1943

Windspeed_NAO3843 <- Windspeed_pos_values[157:228]

Winddirection_NAO3843 <- Winddirection_pos_values[157:228]

Create a data frame

NAO_1938_1943 <- data.frame(date_NAO3843, Windspeed_NAO3843, Winddirection_NAO3843)

Change class of date column

NAO_1938_1943$date_NAO3843 <- as.POSIXct(NAO_1938_1943$date_NAO3843, format = "%Y%m%d", tz = "") 

Rename the columns

NAO_1938_1943 <- rename(NAO_1938_1943, date = date_NAO3843, ws = Windspeed_NAO3843,
                           wd = Winddirection_NAO3843)

Plotting

windRose(NAO_1938_1943, key.header = "Monthly mean ws/wd Ireland 1938-1943", 
         key.position = "top", ws.int = 2, max.freq = 40) 

1.2 Nested NAO positive (1946-1951)

Individual months 1946-1951

date_NAO4651 <- date_all[1141:1212]

Windspeed and wind direction values for 1946-1951

Windspeed_NAO4651 <- Windspeed_pos_values[253:324]

Winddirection_NAO4651 <- Winddirection_pos_values[253:324]

Create a data frame

NAO_1946_1951 <- data.frame(date_NAO4651, Windspeed_NAO4651, Winddirection_NAO4651)

Change class of date column

NAO_1946_1951$date_NAO4651 <- as.POSIXct(NAO_1946_1951$date_NAO4651, format = "%Y%m%d", tz = "") 

Rename the columns

NAO_1946_1951 <- rename(NAO_1946_1951, date = date_NAO4651, ws = Windspeed_NAO4651,
                        wd = Winddirection_NAO4651)

Plotting

windRose(NAO_1946_1951, key.header = "Monthly mean ws/wd Ireland 1946-1951", 
         key.position = "top", ws.int = 2, max.freq = 40) 

  1. AMO negative (1966-1995)

2.1 Nested NAO negative (1968-1973)

Individual months 1968-1973

date_NAO6873 <- date_all[1405:1476]

Windspeed and wind direction values for 1968-1973

Windspeed_NAO6873 <- Windspeed_neg_values[25:96]

Winddirection_NAO6873 <- Winddirection_neg_values[25:96]

Create a data frame

NAO_1968_1973 <- data.frame(date_NAO6873, Windspeed_NAO6873, Winddirection_NAO6873)

Change class of date column

NAO_1968_1973$date_NAO6873 <- as.POSIXct(NAO_1968_1973$date_NAO6873, format = "%Y%m%d", tz = "") 

Rename the columns

NAO_1968_1973 <- rename(NAO_1968_1973, date = date_NAO6873, ws = Windspeed_NAO6873,
                        wd = Winddirection_NAO6873)

Plotting

windRose(NAO_1968_1973, key.header = "Monthly mean ws/wd Ireland 1968-1973", 
         key.position = "top", ws.int = 2, max.freq = 40) 

2.2 Nested NAO positive (1988-1993)

Individual months 1988-1993

date_NAO8893 <- date_all[1645:1716]

Windspeed and wind direction values for 1988-1993

Windspeed_NAO8893 <- Windspeed_neg_values[277:348]

Winddirection_NAO8893 <- Winddirection_neg_values[277:348]

Create a data frame

NAO_1988_1993 <- data.frame(date_NAO8893, Windspeed_NAO8893, Winddirection_NAO8893)

Change class of date column

NAO_1988_1993$date_NAO8893 <- as.POSIXct(NAO_1988_1993$date_NAO8893, format = "%Y%m%d", tz = "") 

Rename the columns

NAO_1988_1993 <- rename(NAO_1988_1993, date = date_NAO8893, ws = Windspeed_NAO8893,
                        wd = Winddirection_NAO8893)

Plotting

windRose(NAO_1988_1993, key.header = "Monthly mean ws/wd Ireland 1988-1993", 
         key.position = "top", ws.int = 2, max.freq = 40) 

Seasonal analysis

Create a dataframe with columns; Month Year Windspeed Winddirection

Years

year <- format(as.Date(date_all, format="%Y-%m-%d"),"%Y")

year_pos <- year[889:1380]
year_neg <- year[1381:1740]

Months

Month <- format(as.Date(date_all, format="%Y-%m-%d"),"%m")

month_pos <- Month[889:1380]
month_neg <- Month[1381:1740]

Combine into a dataframe

Data_pos <- data.frame(month_pos, year_pos, Windspeed_pos_values, Winddirection_pos_values )
Data_neg <- data.frame(month_neg, year_neg, Windspeed_neg_values, Winddirection_neg_values)

Create two new empty columns

Data_pos <- cbind(Data_pos, NA, NA)
Data_neg <- cbind(Data_neg, NA, NA)

Rename columns

colnames(Data_pos) <- c("Month", "Year", "WS", "WD", "Season", "Season.Year")
colnames(Data_neg) <- c("Month", "Year", "WS", "WD", "Season", "Season.Year")

Create Season, adds w, sp, su, a to the data for identifying seasons

Seasons = DJF, MAM, JJA, SON

Data_pos[ ,5][Data_pos[ ,1]=="12"|Data_pos[ ,1]=="01"|Data_pos[ ,1]=="02"] <- "W"
Data_pos[ ,5][Data_pos[ ,1]=="03"|Data_pos[ ,1]=="04"|Data_pos[ ,1]=="05"] <- "SP"
Data_pos[ ,5][Data_pos[ ,1]=="06"|Data_pos[ ,1]=="07"|Data_pos[ ,1]=="08"] <- "SU"
Data_pos[ ,5][Data_pos[ ,1]=="09"|Data_pos[ ,1]=="10"|Data_pos[ ,1]=="11"] <- "A"

Data_neg[ ,5][Data_neg[ ,1]=="12"|Data_neg[ ,1]=="01"|Data_neg[ ,1]=="02"] <- "W"
Data_neg[ ,5][Data_neg[ ,1]=="03"|Data_neg[ ,1]=="04"|Data_neg[ ,1]=="05"] <- "SP"
Data_neg[ ,5][Data_neg[ ,1]=="06"|Data_neg[ ,1]=="07"|Data_neg[ ,1]=="08"] <- "SU"
Data_neg[ ,5][Data_neg[ ,1]=="09"|Data_neg[ ,1]=="10"|Data_neg[ ,1]=="11"] <- "A"

Create Season.Year

Data_pos[ ,6] <- ifelse(Data_pos[ ,1] == 12, Data_pos[ ,2], Data_pos[ ,2])
Data_neg[ ,6] <- ifelse(Data_neg[ ,1] == 12, Data_neg[ ,2], Data_neg[ ,2])

Extract each season

Winter_pos <- subset(Data_pos, Season == 'W', select = c("Year","WS","WD"))
Spring_pos <- subset(Data_pos, Season == 'SP', select = c("Year","WS","WD"))
Summer_pos <- subset(Data_pos, Season == 'SU', select = c("Year","WS","WD"))
Autumn_pos <- subset(Data_pos, Season == 'A', select = c("Year","WS","WD"))

Winter_neg <- subset(Data_neg, Season == 'W', select = c("Year","WS","WD"))
Spring_neg <- subset(Data_neg, Season == 'SP', select = c("Year","WS","WD"))
Summer_neg <- subset(Data_neg, Season == 'SU', select = c("Year","WS","WD"))
Autumn_neg <- subset(Data_neg, Season == 'A', select = c("Year","WS","WD"))

Plotting seasons with windRose

AMO positive seasons first (1925-1965)

  1. Winter

Change class of date column

Winter_pos$Year <- as.POSIXct(Winter_pos$Year, format = "%Y%m%d", tz = "") 

Rename the columns

Winter_pos <- rename(Winter_pos, date = Year, ws = WS, wd = WD)

Plotting

windRose(Winter_pos, key.header = "Mean Winter ws/wd Ireland 1925-1965", 
         key.position = "top", ws.int = 3, max.freq = 35) 

  1. Summer

Change class of date column

Summer_pos$Year <- as.POSIXct(Summer_pos$Year, format = "%Y%m%d", tz = "") 

Rename the columns

Summer_pos <- rename(Summer_pos, date = Year, ws = WS, wd = WD)

Plotting

windRose(Summer_pos, key.header = "Mean Summer ws/wd Ireland 1925-1965", 
         key.position = "top", ws.int = 3, max.freq = 35) 

AMO negative seasons (1966-1995)

  1. Winter

Change class of date column

Winter_neg$Year <- as.POSIXct(Winter_neg$Year, format = "%Y%m%d", tz = "") 

Rename the columns

Winter_neg <- rename(Winter_neg, date = Year, ws = WS, wd = WD)

Plotting

windRose(Winter_neg, key.header = "Mean Winter ws/wd Ireland 1966-1995", 
         key.position = "top", ws.int = 3, max.freq = 35) 

  1. Summer

Change class of date column

Summer_neg$Year <- as.POSIXct(Summer_neg$Year, format = "%Y%m%d", tz = "") 

Rename the columns

Summer_neg <- rename(Summer_neg, date = Year, ws = WS, wd = WD)

Plotting

windRose(Summer_neg, key.header = "Mean Summer ws/wd Ireland 1966-1995", 
         key.position = "top", ws.int = 3, max.freq = 35)