Advertisement
dannycbowman

NARRE point extraction with rNOMADS

Feb 29th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.02 KB | None | 0 0
  1. library(rNOMADS)
  2.  
  3. #Get the latest 1 model instances
  4. urls.out <- CrawlModels(abbrev = "narre", depth = 1)[1] # , verbose = FALSE)
  5.  
  6. #Get the available predictions.
  7. model.parameters <- ParseModelPage(urls.out[1])
  8.  
  9. ## added from examples page ###RK
  10. pred.ind <- which(grepl("f03", model.parameters$pred))
  11. latest.pred <- model.parameters$pred[pred.ind[1]] #here I just use the first result
  12.  
  13. levels <- c("surface")
  14. variables <- c("APCP")
  15. domain <- c(-81, -77, 38, 34) #small area around ch hill
  16.  
  17. #Now let's get the grib file
  18. grb.info <- GribGrab(urls.out, latest.pred, levels, variables, model.domain = domain)
  19.  
  20. #Read it in
  21. grb.data <- ReadGrib(grb.info$file.name, levels, variables)
  22.  
  23. #Pull values for points we're interested in
  24.  
  25. lon <- c(-79.052104, -78.010020)
  26. lat <- c(35.907553, 36.000200)
  27.  
  28. for(k in 1:length(lon)) {
  29.    dist <- sqrt((grb.data$lon[k] - lon)^2 + (grb.data$lat[k] - lat)^2)
  30.    v.i <- which(dist == min(dist))
  31.    print(paste("LAT", lat[k], "LON", lon[k], levels[1], variables[1], ":", grb.data$value[v.i]))
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement