1

tl;dr

First of all, all necessary code to reproduce the problem is available below. I'm experiencing some challenges with the grib part, but also with the more basic things with download.file()

Problem

There's a nice article on using GFS weather data in R here. It would be a great starting point for further analysis, but I'm having several problems. The article contains all R code required to reproduce it, but here are the first few lines which also is the most important part to get things going:

#STEP 1 (doesn't work either way because of bad link)
loc=file.path("ftp://ftp.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/gfs.2009121700/gfs.t00z.sfluxgrbf03.grib2")

My first problem was that the link didn't work, but here's the url to a file of the same format from the same source, so this should work:

#PART 1 with working link (at least in google chrome):
loc=file.path("ftp://ftp.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/gfs.2015081112/gfs.t12z.sfluxgrbf00.grib2")
download.file(loc,"temp.grb",mode="wb")

#PART 2
shell("wgrib2 -s temp03.grb | grep :LAND: | wgrib2 -i temp00.grb -netcdf LAND.nc",intern=T)

#PART3
library(ncdf)
landFrac <-open.ncdf("LAND.nc")
land <- get.var.ncdf(landFrac,"LAND_surface")
x <- get.var.ncdf(landFrac,"longitude")
y <- get.var.ncdf(landFrac,"latitude")

#PART4
rgb.palette <- colorRampPalette(c("snow1","snow2","snow3","seagreen","orange","firebrick"), space = "rgb")#colors

image.plot(x,y,t2m.mean,col=rgb.palette(200),axes=F,main=as.expression(paste("GFS 24hr Average 2M Temperature",day,"00 UTC",sep="")),axes=F,legend.lab="o C")

contour(x,y,land,add=TRUE,lwd=1,levels=0.99,drawlabels=FALSE,col="grey30")

My system

Windows 7, 64 bit Rstudio 0.99.467

Question 1 - download.file()

I'm having problems with download.file(), even with a link (or ftp path) that works fine in Chrome. Here's a part of the error message:

In download.file(url = loc, destfile = "temp.grb", mode = "wb") :
InternetOpenUrl failed:

Anyone know what causes this?

Question: 2 - wgrib2

I've downloaded a sample file manually to get things going, but get stuck again in Part 2. How would the following r command look like directly in a command window?

shell("wgrib2 -s temp03.grb | grep :LAND: | wgrib2 -i temp00.grb -netcdf LAND.nc",intern=T)

I've installed the necessary dlls available under the links below, and I've also got wgrib 2 up and running (apparently). Information on wgrib2 is provided in the article, and available here. Source for Windows 7.

I hope some of you find this interesting!

3
  • 2
    As for Question / Part 2, I doubt your Windows 7 install has grep. You should be getting an error message from the shell command indicating what program(s) is missing. If not, try running the contents of that string in a regular command shell (i.e., cmd).
    – hoffmanc
    Aug 25, 2015 at 12:53
  • 1
    Part 1 is likely your windows box, I just tried on Ubuntu and it's fine with your link and code. Perhaps you need to set method=? Aug 25, 2015 at 14:00
  • 1
    There have been improvements in Windoze file downloading in the most recent version of R. You should update , read the NEWS files, and see whether that solves any problems.
    – IRTFM
    Aug 25, 2015 at 18:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.