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

continuous time spent #15

Open
mdsumner opened this issue Sep 12, 2016 · 1 comment
Open

continuous time spent #15

mdsumner opened this issue Sep 12, 2016 · 1 comment

Comments

@mdsumner
Copy link
Member

cut.trip does most of the work, but it seems to add in a stray day with the walrus data.

library(trip)
data(walrus818)
prj <- "+proj=laea +lon_0=-165 +lat_0=90 +ellps=WGS84"
walrus <- spTransform(walrus818, prj)

grid <- rasterize(walrus)

#grid <- rasterize(tr[[1]], method = "density")
tr <- cut(walrus, "1 day")
library(raster)
library(tibble)
library(dplyr)
tib1 <- function(x) {
  bind_cols(as_tibble(as.data.frame(x)), tibble(cell = seq(ncell(x)))) %>% filter(z > 0)
}
st <- bind_rows(lapply(tr, function(x) tib1(rasterize(x, grid = grid))), .id = "interval")
sum(st$z)
[1] 45500400
> cellStats(gg, sum)
[1] 44640000

Somewhere here is integration with splat/SGAT and tabularaster.

@mdsumner
Copy link
Member Author

mdsumner commented Apr 17, 2019

this works, but a bit slow still

library(trip)
library(dplyr)
library(furrr)
x <- trip(readr::read_csv("inst/extdata/MI_albatross_sub10.csv") %>% dplyr::select(lon, lat, gmt, tag_ID))
x <- spTransform(x, "+proj=laea +lat_0=-90")


r <- raster(x, res = 50000)
spx <- explode(x)
plan(multiprocess)
l <- furrr::future_map_dfr(split(spx, 1:nrow(spx)), function(a) tibble(cell = unlist(cellFromLine(r, a) )), .id = "segment")

l$dur <- spx$timedur[as.integer(l$segment)]
dd <- l %>% group_by(segment) %>% mutate(dur = dur/n()) %>% ungroup() %>% group_by(cell) %>%  summarize(dur = sum(dur))
r[] <- 0
r[dd$cell] <- dd$dur
plot(r)
cellStats(r, sum)
[1] 1286139971
> sum(spx$timedur)
[1] 1286139971

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

1 participant