R/prepare_samples.R

Defines functions select_bands get_timeSeries

#Autor: Gilberto : sits_select
select_bands <- function(data.tb, ...) {

  # store the dots in a list
  dots <- match.call(expand.dots = TRUE)

  # remove the bands argument from the list (this will be processed later)
  bands <- dots$bands
  if (!purrr::is_null(bands))
    dots$bands <- NULL

  # apply the dplyr filter to select a subset of the tibble
  # this works for arguments like "label", "start_date", "end_date"
  if (length(dots) > 2)
    for (i in 3:length(dots))
      data.tb <- dplyr::filter_(data.tb, toString(dots[i]))

  #retrieve only the chosen bands (if the bands argument is used)
  if (!purrr::is_null(bands)) {
    b1 <- as.character(bands)
    data.tb <- sits_select_bands(data.tb, b1[-1])
  }

  return(data.tb)
}


#Autor: gilberto Camera (Altera saida)
get_timeSeries <- function(data.tb, bands=NULL) {

  if (purrr::is_null(bands))
    bands <- sits_bands(data.tb)

  values.lst <- bands %>% purrr::map(function (band) {
    data.tb$time_series %>%
      purrr::map(function (ts) {
        dplyr::select(ts, dplyr::one_of(band))
      }) %>%
      data.frame() %>%
      tibble::as_tibble() %>%
      as.matrix() %>% t()
  })
  names(values.lst) <- bands

  data.tb<- list(data.tb, values.lst)

  return (data.tb)

  #return (values.lst)
}
lorenalves/SITSSA documentation built on May 20, 2019, 11:59 a.m.