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

focal index #2

Open
mdsumner opened this issue Jul 20, 2022 · 2 comments
Open

focal index #2

mdsumner opened this issue Jul 20, 2022 · 2 comments

Comments

@mdsumner
Copy link
Member

for focal, we need something like

cell_kernel <- function(dimension, cell, size = 1) {
  ## offset is
  row <- row_from_cell(dimension, cell)
  col <- col_from_cell(dimension, cell)
  offset <- c(col + c(-1, 1) * size, row + c(-1, 1) * size)
  offset[c(1, 3)] <- pmax(offset[c(1, 3)], 0)  ## 0-based for vapour_read_raster
  offset[c(2, 4)] <- pmin(offset[c(2, 4)], dimension-1)
  
  outdim <- diff(offset)[c(1, 3)] + 1
  c(offset[c(1, 3)], outdim)
}
cell_kernel(c(100, 50), 3)

which, is called for each 1:prod(dimension) to provide offset and dimension for a given cell (size = 1 is 3x3)

the output is the input to vapour_read_raster(window = ) - 0-based index

@mdsumner
Copy link
Member Author

then probably, need to convert these to R-order in big chunks and read big swathes of raster - with masks for the different kernels, and a group by to do the calcs

@mdsumner
Copy link
Member Author

mdsumner commented Jul 20, 2022

see here, it's actually pretty simple because we only have a matrix for the kernel to apply to - read a chunk that aligns to the kernel size, and zap out the dangle on the left and top by index out of bounds, you don't care what the extent is just use local cell logic as the data is a flat vector, we expand out by kernel group ID

https://github.com/hypertidy/vaster/blob/10ef32a3ff98ec3c27073c933e9603b8eeebfcec/R/kernel.R

  • allow weighted kernel of different types, essentially the weights mask the kernel appropriately
  • provide helpers for size of chunk determine
  • dplyr or whatever group apply engine
  • consider relationship of this to adjacent() and can it be combined simply

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