1

我有兴趣访问历史 NOAA 模型数据,并且一直在使用 R 中的 rNOMADS 包。

这个包的大多数教程都关注当前数据,例如这个优秀的:

https://bovineaerospace.wordpress.com/2014/05/28/downloading-weather-sea-ice-and-wave-model-data-with-the-rnomads-package-in-r/

library(rNOMADS)
#A location near my house
lat <- 35.828304
lon <- -79.107467

#Find the latest Global Forecast System model run
model.urls <- GetDODSDates("gfs_0p50")
latest.model <- tail(model.urls$url, 1)
model.runs <- GetDODSModelRuns(latest.model)
latest.model.run <- tail(model.runs$model.run, 1)

#Figure out which forecasts to use
forecast.date <- as.POSIXlt(Sys.time(), tz = "UTC") 
abbrev <- "gfs_0p50"
## Not run:
forecasts <- GetClosestForecasts(abbrev = abbrev, forecast.date)

#Get nearest model nodes
lons <- seq(0, 359.5, by = 0.5)
lats <- seq(-90, 90, by = 0.5)
lon.diff <- abs(lon + 360 - lons)
lat.diff <- abs(lat - lats)
model.lon.ind <- which(lon.diff == min(lon.diff)) - 1 #NOMADS indexes at 0
model.lat.ind <- which(lat.diff == min(lat.diff)) - 1

#Subset model
time <- c(0,0) #Model status at initialization
lon.inds <- c(model.lon.ind - 2, model.lon.ind + 2)
lat.inds <- c(model.lat.ind - 2, model.lat.ind + 2)
variables <- c("ugrd10m", "vgrd10m") #E-W and N-S wind

wind.data <- DODSGrab(latest.model, latest.model.run, variables,
                      time, lon.inds, lat.inds)

profile <- BuildProfile(wind.data, lon, lat, spatial.average = TRUE, points = 4)

#Present results!
print(paste("At", profile[[1]]$forecast.date, "the East-West winds at Briar Chapel were going", sprintf("%.2f", profile[[1]]$profile.data[1, which(profile[[1]]$variables == "ugrd10m"), 1]),
            "meters per second, and the north-south winds were going", sprintf("%.2f", profile[[1]]$profile.data[1, which(profile[[1]]$variables == "vgrd10m"), 1]),
            "meters per second."))

这适用于当前模型数据。但我想要特定日期和位置的历史数据

我尝试使用函数“GetClosestForcasts”,这似乎是我需要对历史数据执行的操作。但是直接从小插图中运行此代码时出现错误:

#Figure out which forecasts to use
forecast.date <- as.POSIXlt(Sys.time(), tz = "UTC") 
abbrev <- "gfs_0p50"
## Not run:
forecasts <- GetClosestForecasts(abbrev = abbrev, forecast.date)


Error in stringr::str_match_all(url.to.use, "\\d{10}")[[1]][1, 1] : 
  subscript out of bounds

理想情况下,我想做的是给出这两个具体日期

forecast.date <- as.POSIXlt("2005-05-05", tz = "UTC")
forecast.date <- as.POSIXlt("2017-05-05", tz = "UTC")

并且能够针对这些日期和位置运行与上述相同的示例,返回地表模型数据风速、温度和降水

4

0 回答 0