R/pixelsSplitByY.R

Defines functions pixelsSplitByY

Documented in pixelsSplitByY

#' RAnEnExtra::pixelsSplitByY
#'
#' RAnEnExtra::pixelsSplitByY divide pixels according
#' to cuts on along the y axis.
#'
#' cut.pixels.along.y cuts the pixels into separate
#' sets based on the cutting points specified in
#' ycuts and the y coordinates of each pixel.
#' The start counting index of pixels should
#' be specified in the argument start. Note that
#' ycuts should be counted from 1
#'
#' @param pixels a vector of indices of pixels that
#' will get divided
#' @param ycuts a vector of integers specifing the y
#' locations that will be cut. The range of the cut will
#' be defined as [ycuts[i], ycuts[i+1]).
#' @param xgrids.total total number of x.
#' @param ygrids.total total number of y.
#' @param start the counting start of pixels.
#' @param flag.sort a bool specifing whether to sort
#' the cut pixels or not
#'
#' @return a list of vectors with the separate pixels.
#'
#' @export
pixelsSplitByY <- function(
  pixels, ycuts, xgrids.total,
  ygrids.total, start = 1, flag.sort = T) {

  res <- list()

  ys.to.compute <-
    pixels.to.y.by.row(pixels, xgrids.total, start)

  for (i in 1:length(ycuts)) {
    min = ycuts[i]
    max = ycuts[i+1] - 1
    if (i == length(ycuts)) {
      max = xgrids.total*ygrids.total
    }

    flags <- ys.to.compute<=max &
      min<=ys.to.compute

    if(flag.sort) {
      res <- c(res, list(sort(pixels[flags])))
    } else {
      res <- c(res, list(pixels[flags]))
    }
  }

  return(res)
}
Weiming-Hu/RAnEnExtra documentation built on Sept. 26, 2021, 6:44 a.m.