Extracting North American Mesoscale (NAM) Model Data with rNOMADS using DODS

[This article was first published on Bovine Aerospace » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The (relatively) recent upgrade of rNOMADS to version 2.0.0 allows cross platform support for downloading atmospheric and oceanic operational model data into R via the GrADS-DODS system.  However, users have been experiencing difficulty using DODS to get North American Mesoscale (NAM) real time data.  The script below shows an example of getting the NAM 12z model for North America using DODS.  Below the script and the figure, I’ll talk about why getting NAM data via DODS is different than, say, GFS.

#Get data for NAM subsets using DODS
library(rNOMADS)
library(rgl)
#Individual NAM models are listed separately in GRIB but all together in DODS.
#So we get the dates of the NAM runs first, then we have to sort out which "type" of NAM we want.

all.nam.dates <- GetDODSDates("nam", request.sleep = 1)

#Here, we pull the model runs.  This is when we can get individual models out.
#Get the most recent one:
all.nam.mr <- GetDODSModelRuns(tail(all.nam.dates$url, 1))

#For example, let's get North America "nam_na" model, 12z model run.
namna.model.runs <- all.nam.mr$model.run[grepl("nam_na_12z", all.nam.mr$model.run)]

#We can get info on what that model contains by inspecting the output from this:
info <- GetDODSModelRunInfo(tail(all.nam.dates$url, 1), tail(namna.model.runs, 1))

#Get data on surface solar flux across North America
sf.data <- DODSGrab(tail(all.nam.dates$url, 1), tail(namna.model.runs, 1), "csdsfsfc", 0, c(0,707), c(0, 286))

#Now we can plot it with rgl (do NOT use ModelGrid, it has the wrong projection)
#First, set the "missing data" values to -1 (or whatever)

#Credit to Dr. David Forrest for this display code:
valScrubbed<-as.numeric(sf.data$value)
valScrubbed[valScrubbed==9.999e+20]<- -1
with(sf.data,plot3d(lon,lat,valScrubbed,col=heat.colors(100)[cut(valScrubbed,breaks=100)],asp=c(1/cos(35*pi/180),1,.2)))

Solar radiation flux over North America from the NAM NA model.

Solar radiation flux over North America from the NAM NA model.


The reason we can’t just get a specific NAM subset model using (for example)

GetDODSDates("nam_na", request.sleep = 1)

is because the DODS server is set up differently than the GRIB server for NAM. It turns out that all the NAM models are stored together in one directory (in GRIB, each one has its own directory), and so we actually have to sort out individual models at the model run level, not the date level. So the way the above script deals with this is:
1. Figure out all dates when NAM was run.
2. Figure out the model runs for a specific date.
3. Pull out the specific NAM model subset you want (e.g. nam_na, nam_ak, whatever).
4. Get the model data.

If you have questions, don’t hesitate to contact me:


To leave a comment for the author, please follow the link and comment on their blog: Bovine Aerospace » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)