load_s2paths: Load raster paths or data cube from a sen2r archive

View source: R/load_s2paths.R

load_s2pathsR Documentation

Load raster paths or data cube from a sen2r archive

Description

Load the paths of rasters included in a Sentinel-2 archive generated with {sen2r}, filtering relevant files and ordering them. Output can also be returned in format stars or stars_proxy (see argument out_format).

Usage

load_s2paths(
  inpath,
  out_format = "path",
  prod_type,
  time_window,
  s2_orbits,
  s2_sensors,
  file_ext,
  bbox,
  .use_vrt = FALSE
)

Arguments

inpath

Path of the directory in which {sen2r} files are stored.

out_format

(optional) Output format, being one among "path" (default), "stars" and "stars_proxy").

prod_type

(optional) sen2r product type to import (used for filtering among inpath content).

time_window

(optional) time window to import (used for filtering among inpath content).

s2_orbits

(optional) Sentinel-2 orbits to import (used for filtering among inpath content).

s2_sensors

(optional) Sentinel-2 sensor to import ("2A", "2B" or both) (used for filtering among inpath content).

file_ext

(optional) input file extension (used for filtering among inpath content).

bbox

(optional) object of class sf, sfc or bbox used to import a subset of the original raster extent.

.use_vrt

(optional) pass through a temporary VRT before creating stars?

Value

The output raster cube in the selected format.

Author(s)

Luigi Ranghetti, PhD (2020) luigi@ranghetti.info

Examples

# Path of a sample archive created with sen2r (see ?sample_paths)
archive_dir <- system.file("extdata/sen2r/sampleroi", package = "sen2rts")

# Default function behaviour
sen2r_ndvi_paths <- load_s2paths(file.path(archive_dir, "NDVI"))
gsub(archive_dir, "", head(sen2r_ndvi_paths))

# Specifying argument prod_type, the parent directory can also be provided:
sen2r_scl_paths <- load_s2paths(archive_dir, prod_type = "SCL")
gsub(archive_dir, "", head(sen2r_scl_paths))

# Filter on dates and return a stars raster cube
sen2r_ndvi_cube <- load_s2paths(
  archive_dir, prod_type = "NDVI", 
  time_window = c("2020-05-20", "2020-06-05"), 
  out_format = "stars"
)
plot(sen2r_ndvi_cube)

ranghetti/sen2rts documentation built on March 31, 2024, 1:18 a.m.