Install
The installation requires git.
remotes::install_git(
"https://gitlab.com/floriandeboissieu/sen2proc",
ref="dev-v1")
remotes::install_git("https://forge.inrae.fr/florian.deboissieu/s2brdf")Usage
To be able to download data Copernicus Dataspace, create an account on the plateform and add your credentials to your ~/.Rprofile or ~/.Renviron:
usethis::edit_r_profile()and add the following
# sen2proc CDSE credentials
Sys.setenv(
SEN2PROC_CDSE_USERNAME = "xxxxx",
SEN2PROC_CDSE_PASSWORD = "xxxxx"
)Download a Sentinel-2 L2A scene from Copernicus Dataspace:
download_dir <- "./data/download"
if (!dir.exists(download_dir)) {
dir.create(download_dir, recursive = TRUE)
}
# search for a some L2A scene
stac_items <- sen2proc::s2_search(
start = "2015-12-26",
level = "L2A",
tile = "32NRJ")
# download files
files <- sen2proc::cdse_download(stac_items, outdir = download_dir)
# check sen2proc documentation for authentication configurationCompute Nadir BRDF Adjusted Reflectance:
library(s2brdf)
bands <- c("B02", "B05")
output_dir <- "./data/outputs"
if (!dir.exists(output_dir)) {
dir.create(output_dir)
}
model <- get_brdf_model()
# get a data.frame of available scenes
s2_db <- sen2proc::s2_build_database(download_dir)
# let's process the first scene
scene <- s2_db$path[1]
scene_output_dir <- file.path(output_dir, s2_db$title[1])
if (!dir.exists(scene_output_dir)) {
dir.create(scene_output_dir, recursive = TRUE)
}
# check all needed files are here
mtd_tl_file <- sen2proc::find_mtd_tl_file(scene)
mtd_msi_file <- sen2proc::find_mtd_msi_file(scene)
detector_files <- sen2proc::s2_detector_files(scene)
band_stack <- sen2proc::s2_band_stack(scene, bands)
# compute Nadir BRDF Adjusted Reflectance
nbar_files <- apply_brdf_correction(
band_stack, model, mtd_tl_file, mtd_msi_file,
output_dir = scene_output_dir,
write_prods = c("angles", "kernels", "cf")
)