rplotfilternetcdfatmosphere

Error in UseMethod("filter_"): while Accessing and Processing Quikscat Wind speed and direction with R


I was planning to plot wind speed and wind direction using Quickscat data by following the tutorial shown in this link : Access and Process Quikscat Wind speed and direction with R.

All subsections of the codes seemed to work fine. But in Wind Fields Manipulation section, especially selecting data for the area of interest by defining the geographical bounds with filter() function; execution returned with Error in UseMethod("filter_") : no applicable method for 'filter_' applied to an object of class "NULL". screenshot of the error

I am assuming they are selecting the geographical area which doesn't exist in the data. Although i am not sure. Will getting the right coordinates should solve the problem ? Any suggestions as what should I do ? Additionally, if you have alternatives codes for plotting wind data from netCDF file or any other file, I'd really appreciate if you share those with me. Thank you.


Solution

  • When I ran the code from the tutorial, they were using a depreciated function as.tibble() in tidyverse that threw errors. I changed this to as_tibble() and ran the rest of the code through the lines in your screenshot without any errors. Did you view your velocity.all dataframe before trying to filter it? If you had NULL values due to the tibble error that may have been your issue.

    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))