s2_mask | R Documentation |
s2_mask Applies a cloud mask to a Sentinel-2 product. Since raster functions are used to perform computations, output files are physical rasters (no output VRT is allowed).
s2_perc_masked computes the percentage of cloud-masked surface. The function is similar to s2_mask, but it returns percentages instead of masked rasters.
s2_mask(
infiles,
maskfiles,
mask_type,
smooth = 0,
buffer = 0,
max_mask = 100,
outdir = "./masked",
tmpdir = NA,
rmtmp = TRUE,
save_binary_mask = FALSE,
format = NA,
subdirs = NA,
compress = "DEFLATE",
bigtiff = FALSE,
parallel = FALSE,
overwrite = FALSE,
.log_message = NA,
.log_output = NA
)
s2_perc_masked(
infiles,
maskfiles,
mask_type = "cloud_medium_proba",
tmpdir = NA,
rmtmp = TRUE,
parallel = FALSE
)
infiles |
A vector of input filenames. Input files are paths of products already converted from SAFE format to a format managed by GDAL (use s2_translate to do it); their names must be in the sen2r naming convention (safe_shortname). |
maskfiles |
A vector of filenames from which to take the
information about cloud coverage (for now, only SCL products
have been implemented). It is not necessary that |
mask_type |
Character vector which determines the type of mask to be applied. Accepted values are:
|
smooth |
(optional) Numerical (positive): the size (in the unit of
|
buffer |
(optional) Numerical (positive or negative): the size of the
buffer (in the unit of |
max_mask |
(optional) Numeric value (range 0 to 100), which represents
the maximum percentage of allowed masked surface (by clouds or any other
type of mask chosen with argument |
outdir |
(optional) Full name of the output directory where
the files should be created (default: |
tmpdir |
(optional) Path where intermediate files (VRT) will be created.
Default is a temporary directory.
If |
rmtmp |
(optional) Logical: should temporary files be removed? (Default: TRUE). This parameter takes effect only if the output files are not VRT (in this case temporary files cannot be deleted, because rasters of source bands are included within them). |
save_binary_mask |
(optional) Logical: should binary masks be exported?
Binary mask are intermediate rasters used to apply the cloud mask:
pixel values can be 1 (no cloud mask), 0 (cloud mask) or NA (original NA
value, i.e. because input rasters had been clipped on the extent polygons).
If FALSE (default) they are not exported; if TRUE, they are exported
as |
format |
(optional) Format of the output file (in a
format recognised by GDAL). Default is the same format of input images
(or |
subdirs |
(optional) Logical: if TRUE, different indices are
placed in separated |
compress |
(optional) In the case a |
bigtiff |
(optional) Logical: if TRUE, the creation of a BigTIFF is forced (default is FALSE). This option is used only in the case a GTiff format was chosen. |
parallel |
(optional) Logical: if TRUE, masking is conducted using parallel
processing, to speed-up the computation for large rasters.
The number of cores is automatically determined; specifying it is also
possible (e.g. |
overwrite |
(optional) Logical value: should existing output files be overwritten? (default: FALSE) |
.log_message |
(optional) Internal parameter
(it is used when the function is called by |
.log_output |
(optional) Internal parameter
(it is used when the function is called by |
s2_mask returns a vector with the names of the created products.
An attribute "toomasked"
contains the paths of the outputs which were not
created cause to the high percentage of cloud coverage.
s2_perc_masked returns a names vector with the percentages of masked surfaces.
License: GPL 3.0
Luigi Ranghetti, phD (2019)
L. Ranghetti, M. Boschetti, F. Nutini, L. Busetto (2020). "sen2r": An R toolbox for automatically downloading and preprocessing Sentinel-2 satellite data. Computers & Geosciences, 139, 104473. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1016/j.cageo.2020.104473")}, URL: https://sen2r.ranghetti.info/.
# Define file names
ex_in <- system.file(
"extdata/out/S2A2A_20190723_022_Barbellino_RGB432B_10.tif",
package = "sen2r"
)
ex_mask <- system.file(
"extdata/out/S2A2A_20190723_022_Barbellino_SCL_10.tif",
package = "sen2r"
)
# Run function
ex_out <- s2_mask(
infiles = ex_in,
maskfiles = ex_mask,
mask_type = "land",
outdir = tempdir()
)
ex_out
# Show output
oldpar <- par(mfrow = c(1,3))
par(mar = rep(0,4))
image(stars::read_stars(ex_in), rgb = 1:3, useRaster = TRUE)
par(mar = rep(2/3,4))
image(stars::read_stars(ex_mask), useRaster = TRUE)
par(mar = rep(0,4))
image(stars::read_stars(ex_out), rgb = 1:3, useRaster = TRUE)
par(oldpar)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.