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)  

20 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

  2. hi¡¡

    I have problems wiht the rwind package. when i use the command wind.dl i have and ERROR message.

    data2014<-wind.dl(2014,1,1,21,-10,3,44,36,type = "read-data")

    ERROR: database not found. Please, check server connection, date or geographical ranges

    I have been investigating about the problem but I can't solve it.

    Thank you very much


  3. Hi Óscar!

    the last two values should been in this order: southern latitude, northern latitude. You are placing first the northern value.

    Try this!

    data2014<-wind.dl(2014,1,1,21,-10,3,36,44,type = "read-data")


  4. Hi! Do you know why I could get this meessage?
    Error in : could not find function ""


    1. Hi! There is a new version of rWind package and function is now included in wind.dl or wind.dl_2. Please, check help(wind.dl) for more information.

  5. Este comentario ha sido eliminado por el autor.

  6. Javier, this package is super useful! thanks for all the efforts!!

    Instead of using I could get the same results using:

    wind_data<-wind_data[c("lat", "lon", "dir", "speed")]

    The rest of the code will work just fine. Except the wind series. The loop does not give a rWind_series anymore:

    wind.mean(wind_serie) : x needs to be of class rWind_series

    Don't know how to solve it yet.

    1. Hi Alexander! Thanks for your feedback!
      Yes, you are right. In this post I was using the first version or rWind, and it worked a little bit different. Now wind.dl includes, so function doesen't exist anymore. wind.mean also works different. Now you can use wind.dl_2 to download series of wind data, and then use wind.mean. Recently we published a paper introducing rWind package, and you can find in the support material full examples using wind.mean and wind.dl_2. Please, check:

      Supp. material:

      If you have more questions, please, send me an e-mail:

    2. Check also this post about the new wind.dl_2

  7. Salut,
    comment faire pour trouver les données d'un pays spécifique? c'est à dire si je veux trouver les données du Maroc.

  8. Hi!
    To find winds for Maroc, you have to provide the geographic coordinates for the entire region as:

    wind.dl(yyyy, mm, dd, tt, lon1, lon2, lat1, lat2)


    yyyy Selected year.
    mm Selected month.
    dd Selected day.
    tt Selected time. There are currently several options at the GFS database: 00:00 - 03:00 - 06:00 - 09:00 - 12:00 - 15:00 - 18:00 - 21:00 (UTC).
    lon1 Western longitude
    lon2 Eastern longitude
    lat1 Southern latitude
    lat2 Northern latitude

    Here would be an example:


  9. Hi Javi,

    Do you know if it is possible to extract historical forecasts for a selected region ?
    Thanks a lot :)

    1. Hi Edouard!

      rWind is based in a database that covers wind data since May 2011... What do you mean with " historical forecasts"...?
      Anyway, there are some people that is using rWind to explain old patterns of ships movements, for instance:


  10. Hi Javi, thanks for your prompt reply! By forecasts, i mean that I am not interested in the actual historical wind but interested in the evolution of the forecasts of wind made by GFS. They publish every 6 hours a forecast of wind and I'd like to access it but I am not able to find it anywhere...

    Have a good day,

  11. Bonjour :
    Comment faire pour tracer les lignes,
    Par exemple:
    w <- wind.dl(2015, 2, 12, 12, -5.55, -1.55, 35.20, 40.20)
    dt <- wind2raster(w)
    mais comment faire pour tracer les lignes ?
    newmap <- getMap(resolution = "low")


    plot(r_dir, main="direction")
    lines(newmap, lwd=4)

    plot(r_speed, main="speed")
    lines(newmap, lwd=4), Comment ça marche ?????

  12. Howdy,

    You need to split the r_data into direction and speed first.

    Do the following before the last set of plot.

    r_data <- wind2raster(wind_data)
    r_dir <- r_data$wind.direction
    r_speed <- r_data$wind.speed

  13. Hi Javi,

    rWind currently downloads GFS with 0.5 degree resolution.

    From the NCEP archive, I've seen GFS data with resolution of 0.25. However, there are only 10 data entries at a time. Is it possible to download them with rWind as well?

    Many thanks,