domingo, 4 de diciembre de 2016

rWind R package released!

Hi there! 

 Let me introduce you rWind, an R package with several tools for downloading, editing and converting wind data from Global Forecast System ( in other formats as raster for GIS! Wind data is a powerful source of information that could be used for many purposes in biology and other sciences: from the design of air pathways for airplanes to the study of the dispersion routes of plants or bird migrations. Making more accessible this kind of data to scientist and other users is the objective of ERDDAP (, a web service to dive into a lot of weather and oceanographic data-bases and download it easily. 

 I was using specifically one of the ERDDAP data-bases to get wind direction and speed from satellite data, the NOAA/NCEP Global Forecast System (GFS) Atmospheric Model ( At first, I was following this wonderful post from Conor Delaney ( to download and fix the data to be used as a GIS layer. However, I needed soon to download and modify a lot of wind data, so I started to write some R functions to automate the different tasks. Finally, I decided to put all together into an R package and upload it to CRAN repository to make it available for other users that could be interested in this kind of data. Here I give you a reference manual and an R code with a brief tutorial to get familiar with the utilities of the rWind package!

If you have any doubt or you want to report a bug or make any suggestion, please, comment the post or write me: or 

 Enjoy it!

Javier Fernández-López (2016). rWind: Download, Edit and Transform Wind Data from GFS. R package version 0.1.3.

 # Download and install "rWind" package from CRAN:  
 # You should install also "raster" package if you do not have it   
 # "rWind" is a package with several tools for downloading, editing and transforming wind data from Global Forecast   
 # System (GFS, see <>) of the USA's  
 # National Weather Service (NWS, see <>).  
 # > Javier Fernández-López (2016). rWind: Download, Edit and Transform Wind Data from GFS. R package version 0.1.3.  
 # >  
 # First, we can download a wind dataset of a specified date from GFS using wind.dl function  
 # help(wind.dl)  
 # Download wind for Spain region at 2015, February 12, 00:00  
 # help(wind.dl)  
 # By default, this function generates an R object with downloaded data. You can store it...  
 # or download a CVS file into your work directory with the data using type="csv" argument:  
 wind.dl(2015,2,12,0,-10,5,35,45, type="csv")  
 # If you inspect inside wind_data object, you can see that data are organized in a weird way, with  
 # to rows as headers, a column with date and time, longitude data expressed in 0/360 notation and wind  
 # data defined by the two vector components U and V. You can transform these data in a much more nice format
 # using "" function:  
 # Now, data are organized by latitude, with -180/180 and U and V vector components are transformed  
 # into direction and speed. You can export the data.frame as an CVS file to be used with a GIS software  
 write.csv(wind_data, "wind_data.csv")  
 # Once you have data organized by latitude and you have direction and speed information fields,  
 # you can use it to create a raster layer with wind2raster function to be used by GIS software or to be plotted   
 # in R, for example.  
 # As raster layer can only store one information field, you should choose between direction (type="dir")  
 # or speed (type="speed").  
 r_dir <- wind2raster(wind_data, type="dir")  
 r_speed <- wind2raster(wind_data, type="speed")   
 # Now, you can use rworldmap package to plot countries contours with your direction and speed data!  
 newmap <- getMap(resolution = "low")  
 plot(r_dir, main="direction")  
 lines(newmap, lwd=4)  
 plot(r_speed, main="speed")  
 lines(newmap, lwd=4)  
 # Additionally, you can use arrowDir and Arrowhead (from "shape" package) functions to plot wind direction  
 # over a raster graph:  
 alpha<- arrowDir(wind_data)  
 plot(r_speed, main="wind direction (arrows) and speed (colours)")  
 lines(newmap, lwd=4)  
 Arrowhead(wind_data$lon, wind_data$lat, angle=alpha, arr.length = 0.12, arr.type="curved")  
 # If you want a time series of wind data, you can download it by using a for-in loop:  
 # First, you should create an empty list where you will store all the data  
 wind_serie<- list()  
 # Then, you can use a wind.dl inside a for-in loop to download and store wind data of   
 # the first 5 days of February 2015 at 00:00 in Europe region. It could take a while...  
 for (d in 1:5){  
 # Finally, you can use wind.mean function to calculate wind average   
 r_average_dir<-wind2raster(wind_average, type="dir")  
 r_average_speed<-wind2raster(wind_average, type="speed")  
 plot(r_average_dir, main="direction average")  
 lines(newmap, lwd=1)  
 plot(r_average_speed, main="speed average")  
 lines(newmap, lwd=1)  

3 comentarios:

  1. Hi.
    Very Interesting!
    So Can I aplicate this for México????
    I´ve never work with GFS data
    But i interesting in aplicate some about wind to one investigation

    1. Hi Susana!

      Yes, as Conor says, the model is global, you should only select your area of interest as longitude-latitude