Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple points extraction (wish) #106

Open
stineb opened this issue Jun 15, 2020 · 3 comments
Open

Multiple points extraction (wish) #106

stineb opened this issue Jun 15, 2020 · 3 comments

Comments

@stineb
Copy link

stineb commented Jun 15, 2020

It would be great to be able to extract data from multiple points at once. That is, it would be nice if the following code would work for extracting from two points A (lona, lata), and B (lonb, latb) at once:

df <- tidync(filnam) %>% 
    hyper_filter(lon = near(lon, c(lona, lonb)), lat = near(lat, c(lata, latb))) %>% 
    hyper_tibble(select_var(varnam))
@mdsumner
Copy link
Collaborator

I don't think near() works that way, you can use between() though, i.e.

hyper_filter(lon = between(lon, lona, lonb))

You can't easily find individually arbitrary points with tidync, it certainly would be possible but I'm uncomfortable about when a point belongs in a cell or is near to a cell reference point. If it's points in cells and the grid is a raster, it's vastly simpler to use raster::extract(). I'd be more comfortable with a strong cell-abstraction in tidync (like raster has) to allow the distinction to be clear.

Is your raster not regular in longlat? (this is a loaded question ... I'm not just trolling), if it is then

b <- raster::brick(filnam)
raster::extract(b, cbind(lona, lata))  ## or multiple lon,lat values

is way better than tidync. That said we have toyed with extraction ideas for points (and lines and polygons) in tidync, but I always go back to more base-ways of working for that stuff and so far that has worked for me. I'm always interested to explore though, I might try a "nearest-neighbour" cell lookup for your use case (...)

@stineb
Copy link
Author

stineb commented Jun 15, 2020

Thanks for your answer and efforts! I have been using raster::extract for such cases before but was looking for a faster alternative. But of course, if things can't be sped up with tidync for this use case, then I should just resort to raster::extract.

Anyways, a nearest-neighbour cell lookup has great practical potential. I use it all the time.

@mdsumner
Copy link
Collaborator

Fwiw the best speed up for extract is to calculate the cell number for repeated lookups - though, it doesn't help if you can do it all on one brick, and also not for weightings or interpolation). It's very hard to beat raster for NetCDF (for regular grids)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants