UseMethod("filter_")错误:使用 R 访问和处理 Quikscat 风速和风向时
Error in UseMethod("filter_"): while Accessing and Processing Quikscat Wind speed and direction with R
我计划按照 link 中显示的教程使用 Quickscat 数据绘制风速和风向:Access and Process Quikscat Wind speed and direction with R。
代码的所有小节似乎都可以正常工作。但在 风场操纵 部分,特别是通过使用 filter()
函数定义地理边界来为感兴趣的区域选择数据;执行返回 Error in UseMethod("filter_") : no applicable method for 'filter_' applied to an object of class "NULL"
。
screenshot of the error
我假设他们正在选择数据中不存在的地理区域。虽然我不确定。获得正确的坐标是否可以解决问题?有什么建议我该怎么办?此外,如果您有从 netCDF 文件或任何其他文件绘制风数据的替代代码,如果您与我分享这些代码,我将不胜感激。谢谢。
当我 运行 教程中的代码时,他们在 tidyverse 中使用了折旧函数 as.tibble() 并抛出了错误。我通过屏幕截图中的行将其更改为 as_tibble() 和 运行 其余代码,没有任何错误。在尝试过滤之前,您是否查看了 velocity.all 数据框?如果由于 tibble 错误而导致 NULL 值可能是您的问题。
require(xtractomatic)
require(tidyverse)
require(oce)
require(lubridate)
require(gganimate)
require(sf)
getInfo("qsux101day")
getInfo("qsuy101day")
# set spatial extent
lon = c(25,65)
lat = c(-35,10)
## set temporal extent
time = c("2006-01-01", "2006-12-31")
wind_x = xtracto_3D(dtype = "qsux101day",
xpos = lon,
ypos = lat,
tpos = time)
wind_y = xtracto_3D(dtype = "qsuy101day",
xpos = lon,
ypos = lat,
tpos = time)
## extract location and time bounds as vector
longitude = wind_x$longitude
latitude = wind_x$latitude
time = wind_x$time%>%as.Date()
## extract u and v as array
# eastward velocity (zonal)
u = wind_x$data
# northward velocity (meridional)
v = wind_y$data
# calculate wind velocity
velocity = sqrt(u^2 + v^2)
n.lon = length(longitude)
n.lat = length(latitude)+1
velocity.all = NULL
for (i in 1:length(time)){
velocity.df = data.frame(longitude, velocity[,,i] %>% as.data.frame()) %>%
gather(key = "key" , value = "velocity", 2:n.lat) %>%
mutate(latitude = rep(latitude, each = n.lon), date = time[i]) %>%
select(date,longitude, latitude, velocity)%>%
as_tibble()
velocity.all = velocity.all %>% bind_rows(velocity.df)
}
velocity.month = velocity.all %>%
filter(between(longitude,38,55)) %>%
filter(between(latitude,-15,-7)) %>%
mutate(day = yday(date) %>% as.integer(), week = week(date)%>% as.integer(),
month = month(date)%>% as.integer())%>%
group_by(longitude, latitude, month) %>%
summarise(velocity = mean(velocity, na.rm = TRUE))
我计划按照 link 中显示的教程使用 Quickscat 数据绘制风速和风向:Access and Process Quikscat Wind speed and direction with R。
代码的所有小节似乎都可以正常工作。但在 风场操纵 部分,特别是通过使用 filter()
函数定义地理边界来为感兴趣的区域选择数据;执行返回 Error in UseMethod("filter_") : no applicable method for 'filter_' applied to an object of class "NULL"
。
screenshot of the error
我假设他们正在选择数据中不存在的地理区域。虽然我不确定。获得正确的坐标是否可以解决问题?有什么建议我该怎么办?此外,如果您有从 netCDF 文件或任何其他文件绘制风数据的替代代码,如果您与我分享这些代码,我将不胜感激。谢谢。
当我 运行 教程中的代码时,他们在 tidyverse 中使用了折旧函数 as.tibble() 并抛出了错误。我通过屏幕截图中的行将其更改为 as_tibble() 和 运行 其余代码,没有任何错误。在尝试过滤之前,您是否查看了 velocity.all 数据框?如果由于 tibble 错误而导致 NULL 值可能是您的问题。
require(xtractomatic)
require(tidyverse)
require(oce)
require(lubridate)
require(gganimate)
require(sf)
getInfo("qsux101day")
getInfo("qsuy101day")
# set spatial extent
lon = c(25,65)
lat = c(-35,10)
## set temporal extent
time = c("2006-01-01", "2006-12-31")
wind_x = xtracto_3D(dtype = "qsux101day",
xpos = lon,
ypos = lat,
tpos = time)
wind_y = xtracto_3D(dtype = "qsuy101day",
xpos = lon,
ypos = lat,
tpos = time)
## extract location and time bounds as vector
longitude = wind_x$longitude
latitude = wind_x$latitude
time = wind_x$time%>%as.Date()
## extract u and v as array
# eastward velocity (zonal)
u = wind_x$data
# northward velocity (meridional)
v = wind_y$data
# calculate wind velocity
velocity = sqrt(u^2 + v^2)
n.lon = length(longitude)
n.lat = length(latitude)+1
velocity.all = NULL
for (i in 1:length(time)){
velocity.df = data.frame(longitude, velocity[,,i] %>% as.data.frame()) %>%
gather(key = "key" , value = "velocity", 2:n.lat) %>%
mutate(latitude = rep(latitude, each = n.lon), date = time[i]) %>%
select(date,longitude, latitude, velocity)%>%
as_tibble()
velocity.all = velocity.all %>% bind_rows(velocity.df)
}
velocity.month = velocity.all %>%
filter(between(longitude,38,55)) %>%
filter(between(latitude,-15,-7)) %>%
mutate(day = yday(date) %>% as.integer(), week = week(date)%>% as.integer(),
month = month(date)%>% as.integer())%>%
group_by(longitude, latitude, month) %>%
summarise(velocity = mean(velocity, na.rm = TRUE))