% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sen2cor.R
\name{sen2cor}
\alias{sen2cor}
\title{Correct L1C products using Sen2Cor}
\usage{
sen2cor(
  l1c_prodlist = NULL,
  l1c_dir = NULL,
  outdir = NULL,
  proc_dir = NA,
  tmpdir = NA,
  rmtmp = TRUE,
  gipp = NULL,
  use_dem = NA,
  tiles = NULL,
  parallel = FALSE,
  timeout = 0,
  kill_errored = FALSE,
  overwrite = FALSE,
  .log_message = NA,
  .log_output = NA
)
}
\arguments{
\item{l1c_prodlist}{List of L1C product names to be corrected. They can be both
product names with full/relative path or only names of SAFE products (in this case, also
l1c_dir argument must be provided). SAFE products must be unzipped.
Note that, at this stage, all products must be in the same directory (this will be fixed).}

\item{l1c_dir}{Full or relative path of input L1C products.
If NULL (default), \code{l1c_prodlist} must already be a vector of full paths.}

\item{outdir}{Directory where output L2A products will be placed.
If NULL (default), each product is left in the parent directory of \code{l1c_prodlist}.}

\item{proc_dir}{(optional) Directory where processing is applied.
If NA (default), processing is done in \code{l1c_dir} and output L2A product is
then moved to \code{outdir}, unless \code{l1c_dir} is a subdirectory of a SAMBA mountpoint under Linux:
in this case, L1C input products are copied in a temporary directory
(specified with argument \code{tmpdir}),
processing is done there and then L2A is moved to \code{outdir}.
This is required under Linux systems when \code{l1c_dir} is a subdirectory of
a unit mounted with SAMBA, otherwise Sen2Cor would produce empty L2A products.}

\item{tmpdir}{(optional) Path where processing is performed if a temporary
working directory is required (see argument \code{proc_dir}). Be sure \code{tmpdir}
not to be a SAMBA mountpoint under Linux.
Default is a temporary directory.
If \code{tmpdir} is a non-empty folder, a random subdirectory will be used.}

\item{rmtmp}{(optional) Logical: should temporary files be removed?
(Default: TRUE)}

\item{gipp}{(optional) Ground Image Processing Parameters (GIPP)
to be passed to Sen2Cor.
It is possible to specify both the path of an existing XML file
or a list of parameters in the form \code{parameter_name = "value"}, where
\code{parameter_name} is the name of the parameter as specified in the
XML file (case insensitive), and \code{"value"} is the character value
which the user wants to set
(notice that, in the case the user wants to specify the value \code{NONE},
both \code{"NONE"} and \code{NA} can be used, but not \code{NULL}, which has the effect
to maintain the value specified in the XML file).

For details about the GIPP parameters, refer to the Sen2Cor documentation
(v. \href{https://step.esa.int/main/snap-supported-plugins/sen2cor/sen2cor_v2-5-5/}{2.5.5}
or \href{https://step.esa.int/main/snap-supported-plugins/sen2cor/sen2cor_v2-8/}{2.8.0}:
see the "Schemas of the GIPP file" at the end of each page).
\emph{Note}: this argument takes effect only in the current execution of
\code{sen2cor()} function.}

\item{use_dem}{(optional) Logical:
if TRUE, Sen2Cor is set to use a Digital Elevation Model for topographic
correction (reflecting what is done for Level-2A SAFE images provided by ESA Hub);
if FALSE, it is set not to perform topographic correction (reflecting the
current default Sen2Cor behaviour);
if NA (default), the option set in the XML GIPP configuration file
used by sen2r (stored in the default sen2r settings directory) is respected;
in case the user never edited it,
the current default setting is not to perform topographic correction.

\emph{Notes}:
\enumerate{
\item if TRUE, the path used to read or store DEM files
and the online source used to download missing DEM tiles
are respectively the \code{DEM_Directory} and \code{DEM_Reference} parameters
set in the default sen2r GIPP XML file (the user can read them
with the function \code{read_gipp(c("DEM_Directory", "DEM_Reference"))}).
In case one or both these parameters were set to \code{"NONE"},
a subdirectory \code{"srtm90"} of the default sen2r directory is used as
DEM directory, and/or the
\href{https://csidotinfo.wordpress.com/category/data/}{CGIAR SRTM 90m}
is set as online source.
To set another directory or reference, use argument \code{gipp} in the form
\code{gipp = list(DEM_Directory = tempdir(), DEM_Reference ="another_reference", ...)}
(replacing \code{tempdir()} with the desired path and specifying the online resource).
\item Currently the default value is NA in order to grant backward
compatibility. In a future release of sen2r, the default value will be
set to TRUE, so to grant homogeneity between Level-2A products downloaded
from ESA Hub and generated using Sen2Cor.
}}

\item{tiles}{Vector of Sentinel-2 Tile strings (5-length character) to be
processed (default: process all the tiles found in the input L1C products).}

\item{parallel}{(optional) Logical: if TRUE, Sen2Cor instances are launched
in parallel using multiple cores; if FALSE (default), they are launched in
series on a single core.
The number of cores is automatically determined; specifying it is also
possible (e.g. \code{parallel = 4}).}

\item{timeout}{Integer value: number of minutes after which killing Sen2Cor
if it is still running (default, 0, means that this is never done).
This can be useful in case Sen2Cor produced an error without exiting
from Python (leaving a standing process running).}

\item{kill_errored}{Logical: experimental feature allowing killing dead Sen2Cor
processes, so leaving \code{sen2cor()} continuing processing on the remaining
products. Set to TRUE to activate it (default is FALSE).
This experimental feature is available only on Unix systems,
and requires package "tools" to be installed.
This option is not compatible with \code{timeout} (in case both are set,
\code{kill_errored} will be ignored).}

\item{overwrite}{Logical value: should existing output L2A products be overwritten?
(default: FALSE)}

\item{.log_message}{(optional) Internal parameter
(it is used when the function is called by \code{sen2r()}).}

\item{.log_output}{(optional) Internal parameter
(it is used when the function is called by \code{sen2r()}).}
}
\value{
Vector character with the list ot the output products
(being corrected or already existing).
}
\description{
The function uses Sen2Cor to manually correct L1C products.
Standalone version of
\href{https://step.esa.int/main/snap-supported-plugins/sen2cor/}{sen2cor}
(version 2.8.0 or 2.5.5) is used.
}
\note{
License: GPL 3.0
}
\examples{
\dontrun{
# Download an L1C SAFE product
example_s2_list <- s2_list(
  spatial_extent = st_sfc(st_point(c(12.0, 44.8)), crs=st_crs(4326)), 
  tile = "32TQQ", 
  time_interval = as.Date(c("2017-05-01","2017-07-30"))
)
s2_download(example_s2_list, outdir = tempdir())

# Correct it applying a topographic correction
sen2cor(
  names(example_s2_list)[1], 
  l1c_dir = tempdir(), 
  outdir = tempdir(),
  use_dem = TRUE
)
}
}
\references{
L. Ranghetti, M. Boschetti, F. Nutini, L. Busetto (2020).
"sen2r": An R toolbox for automatically downloading and preprocessing
Sentinel-2 satellite data. \emph{Computers & Geosciences}, 139, 104473.
\doi{10.1016/j.cageo.2020.104473}, URL: \url{https://sen2r.ranghetti.info/}.
}
\author{
Luigi Ranghetti, phD (2019)
}
