knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

rcodede

This package is in the earliest stages of development and should be used with caution.

The goal of rcodede is to simplify the usage of the CODE-DE satellite data repository with R and provide functions for basic processing steps with the esa SNAP Graph Processing Tool.

Installation

You can install the development version from GitHub with:

install.packages("devtools")
devtools::install_github("felixlobert/rcodede")

If the included functions for the processing of satellite data shall be used, esa SNAP has to be installed on the system and the SNAP Graph Processing tool (GPT) has to be executable from the command line. You can check this by typing "gpt" to the command line. If the console shows the GPT context menu after you press enter, you are ready to go.

Dockerized SNAP

Alternatively, you can use a dockerized version of SNAP which is less prone to errors. The image is automatically installed when you use a processing function from rcodede and all file paths to the orbit files and the DEM provided by CODE-DE are set. Just make sure docker is installed on your machine and docker = TRUE when the processing function is called.

Examples

Query available scenes

This is a basic example which shows you how to query available Sentinel-1 scenes for a given area of interest and multiple filter criteria. The function rcodede::getScenes creates an HTTP-GET request for the CODE-DE EO Finder API and processes the results for an easy usage. ?getScenes shows you, which criteria are supported at the moment.

# load simple features library
library(sf)

# Create example AOI
aoi <- c(10.441054, 52.286959) %>%
  sf::st_point() %>%
  sf::st_sfc(crs = 4326)

# load rcodede package
library(rcodede)

# Query footprints and metadata of available scenes for the AOI and given criteria
scenes <- 
  getScenes(
    aoi = aoi,
    startDate = "2019-01-01",
    endDate = "2019-01-15",
    satellite = "Sentinel1",
    productType = "SLC",
    view = T
  )

Queried Scenes

library(rcodede)

aoi <- c(10.441054, 52.286959) %>%
  sf::st_point() %>%
  sf::st_sfc(crs = 4326)

scenes <- 
  getScenes(
    aoi = aoi,
    startDate = "2019-01-01",
    endDate = "2019-01-15",
    satellite = "Sentinel1",
    productType = "SLC",
  )

This table shows the 5 top entries of the resulting sf object:

knitr::kable(scenes[1:5,])

Basic Processing

If the CODE-DE satellite data repository is mounted to the used machine, processing steps can be directly executed to the queried scenes.

Coherence Estimation

The next example shows the estimation of the interferometric coherence for two subsequent Sentinel-1 scenes. To ensure similar acquisition geometries of the scenes, only one relative orbit is selected.

# filter for scenes from same orbit to ensure same acquisition geometry
scenes.filtered <-
  scenes %>%
  dplyr::filter(relativeOrbitNumber == 117)

mapview::mapview(
  x = scenes.filtered,
  alpha.regions = .15,
  map.types = "Esri.WorldImagery",
  zcol = "relativeOrbitNumber"
) +
  mapview::mapview(
    x = aoi,
    color = "black",
    col.regions = "white",
    alpha.regions = .5,
    legend = FALSE
  )

Filtered Scenes

The function rcodede::estimateCoherence creates a command for the esa SNAP Graph Processing Tool that is executed in the background if execute = TRUE. A pre-built SNAP-Workflow delivered with the package is then applied to the selected scenes. If execute = FALSE, the command is returned as string instead. The output is written to a defined path and is returned if return = TRUE. Several processing parameters such as the spatial resolution of the output raster or the desired polarizations can be set.

# estimate the coherence for the first two scenes in the sf object
coherence <-
  estimateCoherence(
    scene1 = scenes.filtered$productPath[2],
    scene2 = scenes.filtered$productPath[1],
    fileName = "coherence.tif",
    resolution = 10,
    polarisation = "VH",
    aoi = aoi,
    aoiBuffer = 300,
    execute = TRUE,
    return = TRUE
  )

The created coherence raster or stack can then be plotted or further processed:

# plot the returned coherence raster
mapview::mapview(
  x = coherence$layer,
  layer.name = paste0("Coherence VH\n", scenes.filtered$date[2]),
  alpha = .5,
  na.color = "transparent",
  map.types = "Esri.WorldImagery"
) +
  mapview::mapview(
    x = aoi,
    color = "black",
    col.regions = "white",
    alpha.regions = .5,
    legend = FALSE
  )

Estimated Coherence



felixlobert/rcodede documentation built on July 31, 2022, 4:57 a.m.