[Rnomads-user] ModelGrid function with Dods data
Bowman, Daniel
haksaeng at live.unc.edu
Thu Jan 8 04:07:47 CET 2015
I think I have something that will work.
Basically you have to subset the output of DODSGrab before sending it to ModelGrid, because ModelGrid can't handle multiple forecasts.
FYI, I'm not sure if tmax2m and tmin2m have data...try tmp2m for 2 meter temperature.
library("rNOMADS")
GFS.list <- GetDODSDates(abbrev="gfs_hd", archive=F, request.sleep=1) #returns list of available dates with GFS data in a numerical list
current.GFS.url <- tail(GFS.list$url, 1)
GFS.model.runs <- GetDODSModelRuns(current.GFS.url)
GFS.0z <- (head(GFS.model.runs$model.run,1))
#run when needed
#GFS.info.variables <- GetDODSModelRunInfo(current.GFS.url, GFS.0z)
lon <- c(480, 620) # USA Longitude
lat <- c(240, 280) # USA Latitude
variables <- c("tmax2m","tmin2m", "weasdsfc", "ugrdmwl", "vgrdmwl")
GFS.Model.Data <- DODSGrab(current.GFS.url, GFS.0z, variables, time = c(0,36), lon, lat)
#So we've gotten 37 forecasts. ModelGrid can only take 1 forecast at a time so we have to loop through them.
pred <- 0
for(fcst in unique(GFS.Model.Data$forecast.date)) {
fcst.ind <- which(GFS.Model.Data$forecast.date == fcst)
GFS.Model.Data.sub <- list(
model.run.date = GFS.Model.Data$model.run.date[fcst.ind],
forecast.date = GFS.Model.Data$forecast.date[fcst.ind],
variables = GFS.Model.Data$variables[fcst.ind],
levels = GFS.Model.Data$levels[fcst.ind],
lon = GFS.Model.Data$lon[fcst.ind],
lat = GFS.Model.Data$lat[fcst.ind],
value = GFS.Model.Data$value[fcst.ind])
GFS.modelgrid <- ModelGrid(GFS.Model.Data.sub, resolution = c(0.5, 0.5))
#Save each forecast
save(GFS.modelgrid, file = paste0(sprintf("%03i", pred), ".RData"))
pred <- pred + 3 #I think this is right...
}
Daniel C. Bowman
Doctoral Candidate in Geophysics
Mitchell 315
Department of Geological Sciences
The University of North Carolina at Chapel Hill
phone: 575-418-8555
email: daniel.bowman at unc.edu
web:http://geosci.unc.edu/page/daniel-c-bowman
________________________________
From: rnomads-user-bounces at lists.r-forge.r-project.org <rnomads-user-bounces at lists.r-forge.r-project.org> on behalf of Adam Simkowski <akssimkowski at sbcglobal.net>
Sent: Wednesday, January 7, 2015 4:12 PM
To: rnomads-user at lists.r-forge.r-project.org
Subject: [Rnomads-user] ModelGrid function with Dods data
Hi all,
I am attempting to build an array of GFS model data, but I am running into some trouble when it comes to defining my Cartesian nodes in the ModelGrib function.
I'll walk you through my code before that point... I pull the current day 0z GFS_hd run and then specify a given lat lon area along with certain variables to reduce the size of the data that I am reading in. From there, I run the DODSGrab function to pull in 36 hours worth of forecast data (gfs_hd) which works fine.
>From there, my troubles begin with the ModelGrid function. I believe I have all the arguments correct other than Cartesian.nodes, but I am skeptical on the resolution... not completely sure if I did that correctly. When it comes to the Cartesian.nodes function, I'm not exactly sure what to put in the argument. I understand that it has to be a list with an x and y element, but I can't find any literature on the gfs_hd grid in kilometers. Any thoughts on how to move forward here?
Thank you.
Code is listed below. I am running on a windows 7 machine so pulling Grib data is not an option for me, unfortunately.
#############################################3
library("rNOMADS")
library("RCurl")
GFS.list <- GetDODSDates(abbrev="gfs_hd", archive=F, request.sleep=1) #returns list of available dates with GFS data in a numerical list
current.GFS.url <- tail(GFS.list$url, 1)
GFS.model.runs <- GetDODSModelRuns(current.GFS.url)
GFS.0z <- (head(GFS.model.runs$model.run,1))
#run when needed
#GFS.info.variables <- GetDODSModelRunInfo(current.GFS.url, GFS.0z)
lon <- c(480, 620) # USA Longitude
lat <- c(240, 280) # USA Latitude
variables <- c("tmax2m","tmin2m", "weasdsfc", "ugrdmwl", "vgrdmwl")
GFS.Model.Data <- DODSGrab(current.GFS.url, GFS.0z, variables, time = c(0,36), lon, lat)
GFS.modelgrid <- ModelGrid(model.data = GFS.Model.Data, grid.type = "cartesian", resolution = c(-140,40),levels = c("surface","2_m_above_ground"), variables, model.domain = NULL, cartesian.nodes = (list(x=0.5,y=0.5)))
########################################################################
Adam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rnomads-user/attachments/20150108/85abefdf/attachment.html>
More information about the Rnomads-user
mailing list