knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

library(magrittr)
library(dplyr)
library(ggplot2)
library(sits.prodes)
library(sits.starfm)

stopifnot(file.exists(system.file("extdata/accuracy_ls.Rdata", 
                                  package = "sits.prodes")))

Interpolated samples.

A dataset containing a tibble with time series sampled on the brazilian Amazon. The time series come from Landsat 8 Collection images. The clouds in the images are filled in using billinear resampled MODIS images (MOD13Q1 and MYD13Q1) of the closest in terms of place and date.

data(prodes_samples_interpolated)
p_samples <- prodes_samples_interpolated

# Helper function for getting the extent from a path to a shapefile.
get_extent <- function(x){
  x %>% 
    sf::st_read(quiet = TRUE) %>%
    sf::st_bbox() %>%
    sf::st_as_sfc() %>%
    return()
}

# Helper function for binding rows of sf objects.
rbind_sf <- function(x){
  do.call(rbind, x)
}

l8_extent_tb <- "/home/alber/Documents/data/experiments/prodes_reproduction/data/vector/prodes/tiled" %>% 
  list.files(pattern = "*[.]shp", full.names = TRUE) %>% 
  tibble::enframe(name = NULL) %>% 
  dplyr::rename(file_path = value) %>% 
  dplyr::mutate(file_name = tools::file_path_sans_ext(basename(file_path))) %>% 
  tidyr::separate(col = file_name, into = c(NA, NA, NA, "path", "row"), sep = '_') %>% 
  dplyr::mutate(g = purrr::map(file_path, get_extent))
extent_sf <- l8_extent_tb %>% 
  dplyr::pull(g) %>% 
  purrr::map(sf::st_as_sf) %>% 
  rbind_sf() %>%
  dplyr::bind_cols(l8_extent_tb) %>% 
  dplyr::select(path, row) %>% 
  sf::st_transform(4326)
rm(l8_extent_tb) 


suppressWarnings(
  p_samples %>% 
    sf::st_as_sf(coords = c("longitude", "latitude")) %>% 
    sf::st_set_crs(4326) %>% 
    sf::st_join(extent_sf) %>% 
    sf::st_set_geometry(NULL) %>% 
    dplyr::mutate(path_row = paste0(path, row),
                  pyear = lubridate::year(end_date)) %>% 
    dplyr::select(Scene = path_row, Prodes_year = pyear, Label = label) %>% 
    dplyr::group_by(Scene, Prodes_year, Label) %>% 
    dplyr::summarize(Frequency = n()) %>% 
    tidyr::pivot_wider(names_from = Label, values_from = Frequency) %>% 
    #table() %>% 
    knitr::kable(digits = 0, row.names = TRUE, full_width = TRUE, 
                 caption = "Number of samples per PRODES year.") %>% 
    kableExtra::kable_styling()
)
p_samples %>% 
  dplyr::sample_frac(0.05) %>% 
  sits::sits_select_bands(ndvi) %>% 
  sits::sits_plot()

Interpolated samples (few clouds).

A dataset containing a tibble with time series sampled on the brazilian Amazon. The time series come from Landsat 8 Collection images with the fewest cluods on each PRODES year. The clouds in the images are filled in using billinear resampled MODIS images (MOD13Q1 and MYD13Q1) of the closest in terms of place and date.

data(prodes_samples_interpolated_few_clouds)

p_samples <- prodes_samples_interpolated_few_clouds
suppressWarnings(
  p_samples %>% 
    dplyr::mutate(pyear = lubridate::year(end_date)) %>% 
    dplyr::select(pyear, label) %>% 
    table() %>% 
    knitr::kable(digits = 0, row.names = TRUE, full_width = TRUE, 
                 caption = "Number of samples per PRODES year.") %>% 
    kableExtra::kable_styling()
)
p_samples %>% 
  dplyr::sample_frac(0.05) %>% 
  sits::sits_select_bands(ndvi) %>% 
  sits::sits_plot()

Cloud-masked samples.

A dataset containing a tibble with time series sampled on the brazilian Amazon. The time series come from Landsat 8 Collection images in which the clouds have been replaced with a no-data value (-9999).

data(prodes_samples_mask_cloud)

p_samples <- prodes_samples_mask_cloud
suppressWarnings(
  p_samples %>% 
    dplyr::mutate(pyear = lubridate::year(end_date)) %>% 
    dplyr::select(pyear, label) %>% 
    table() %>% 
    knitr::kable(digits = 0, row.names = TRUE, full_width = TRUE, 
                 caption = "Number of samples per PRODES year.") %>% 
    kableExtra::kable_styling()
)
p_samples %>% 
  dplyr::sample_frac(0.05) %>% 
  sits::sits_select_bands(ndvi) %>% 
  sits::sits_plot()

RAW samples

A dataset containing a tibble with time series sampled on the brazilian Amazon. The time series come from Landsat 8 Collection images.

data(prodes_samples_raw)

suppressWarnings(
  prodes_samples_raw %>% 
    dplyr::mutate(pyear = lubridate::year(end_date)) %>% 
    dplyr::select(pyear, label) %>% 
    table() %>% 
    knitr::kable(digits = 0, row.names = TRUE, full_width = TRUE, 
                 caption = "Number of raw samples per PRODES year.") %>% 
    kableExtra::kable_styling()
)

prodes_samples_raw %>% 
  dplyr::sample_frac(0.01) %>% 
  sits::sits_select_bands(ndvi) %>% 
  sits::sits_plot()

cloud <- n_clouds <- NULL
prodes_samples_raw %>% 
    dplyr::sample_frac(0.1) %>% 
    dplyr::mutate(n_clouds = purrr::map_int(.$time_series, function(x){
        x %>% 
            dplyr::select(cloud) %>% 
            sum() %>% 
            as.integer() %>% 
            return()
    })) %>% 
    ggplot2::ggplot(ggplot2::aes(n_clouds)) + 
    ggplot2::geom_histogram(breaks = 0:23) + 
    ggplot2::labs(title = "Clouded samples (prodes_samples_raw)") +
    ggplot2::xlab("Number of clouded pixels") +
    ggplot2::ylab("Count")

print(sprintf("Number of samples %s", nrow(prodes_samples_raw)))

Simple samples

A dataset containing a tibble with time series sampled on the brazilian Amazon. The time series come from Landsat 8 Collection images.

data(prodes_samples_simple)

p_samples <- prodes_samples_simple
suppressWarnings(
  p_samples %>% 
    dplyr::mutate(pyear = lubridate::year(end_date)) %>% 
    dplyr::select(pyear, label) %>% 
    table() %>% 
    knitr::kable(digits = 0, row.names = TRUE, full_width = TRUE, 
                 caption = "Number of samples per PRODES year.") %>% 
    kableExtra::kable_styling()
)
p_samples %>% 
  dplyr::sample_frac(0.05) %>% 
  sits::sits_select_bands(ndvi) %>% 
  sits::sits_plot()

StarFM samples

A dataset containing a tibble with time series sampled on the brazilian Amazon. The time series come from Landsat 8 Collection images. The clouds in the images are filled in using the StarFM image fusion model. StarFM builds a statistical model between MODIS and LANDSAT images at time t1 which is later applied to MODIS images at time t0. The result is a prediction of a Landsat 8 image at t0.

data(prodes_samples_starfm)

p_samples <- prodes_samples_starfm
suppressWarnings(
  p_samples %>% 
    dplyr::mutate(pyear = lubridate::year(end_date)) %>% 
    dplyr::select(pyear, label) %>% 
    table() %>% 
    knitr::kable(digits = 0, row.names = TRUE, full_width = TRUE, 
                 caption = "Number of samples per PRODES year.") %>% 
    kableExtra::kable_styling()
)
p_samples %>% 
  dplyr::sample_frac(0.05) %>% 
  sits::sits_select_bands(ndvi) %>% 
  sits::sits_plot()

StarFM samples(few clouds)

A dataset containing a tibble with time series sampled on the brazilian Amazon. The time series come from Landsat 8 Collection images. The clouds in the images are filled in using the StarFM image fusion model. StarFM builds a statistical model between MODIS and LANDSAT images at time t1 which is later applied to MODIS images at time t0. The result is a prediction of a Landsat 8 image at t0. These time series are the best four time steps of the samples in prodes_samples_starfm.

data(prodes_samples_starfm_few_clouds)

p_samples <- prodes_samples_starfm_few_clouds
suppressWarnings(
  p_samples %>% 
    dplyr::mutate(pyear = lubridate::year(end_date)) %>% 
    dplyr::select(pyear, label) %>% 
    table() %>% 
    knitr::kable(digits = 0, row.names = TRUE, full_width = TRUE, 
                 caption = "Number of samples per PRODES year.") %>% 
    kableExtra::kable_styling()
)
p_samples %>% 
  dplyr::sample_frac(0.05) %>% 
  sits::sits_select_bands(ndvi) %>% 
  sits::sits_plot()
#?sits.prodes::prodes_samples_interpolated
#?sits.prodes::prodes_samples_interpolated_few_clouds
#?sits.prodes::prodes_samples_mask_cloud
#?sits.prodes::prodes_samples_raw
#?sits.prodes::prodes_samples_simple
#?sits.prodes::prodes_samples_starfm
#?sits.prodes::prodes_samples_starfm_few_clouds
sample_description <- tibble::tribble(
    ~Sample_type, ~Obs_year, ~Description,
    #--------------------|----------|--------------------|
    "interpolated",       23,        "The samples were taken from the bricks of Landsat 8 where the clouds were filled up by interpolation of MXD13 data. The vegetation indexes were recalculated from the bricks of the corresponding bands.",
    "starfm",             23,        "The samples were taken from the bricks of Landsat 8 where the clouds were filled up by the StarFM mixture model (Landsat 8 - MOD13Q1 mixture model).",
    "simple",             4,         "The samples were taken from the bricks of the best 4 Landsat 8 images of a year.",
    "mask_clouds",        4,         "The samples were taken from the bricks of the best 4 Landsat 8 images of a year and the clouds were masked as 'no_data'."
)

suppressWarnings(
    sample_description %>% 
        knitr::kable(digits = 2, row.names = TRUE, full_width = FALSE) %>% 
        kableExtra::kable_styling()
)

TODO



albhasan/sits.prodes documentation built on Sept. 3, 2020, 2:03 p.m.