senCloudMask: Create cloud masks for Sentinel-2 images

Description Usage Arguments Details Value Examples

View source: R/senCloudMask.R

Description

senCloudMask creates cloud masks derived from the cloud probability band (CLDPRB) band from the "S2MSI2A" product.

Usage

1
2
3
4
5
6
7
8
9
senCloudMask(
  src,
  AppRoot,
  out.name,
  resbands,
  sensitivity = 50,
  overwrite = FALSE,
  ...
)

Arguments

src

the path to the folder with the "S2MSI2A" images.

AppRoot

the directory where the cloud masks are saved.

out.name

the name of the folder that stores the outputs. If the arguemnt is not defined the folder will be named as "CloudMask".

resbands

a character vector argument. Defines the band resolution used to create the cloud mask. Ex "20m" or "60m".

sensitivity

a numeric argument. Defines the sensitivity of the cloud detection method.

overwrite

logical argument. If TRUE, overwrites the existing images with the same name.

...

arguments for nested functions.

  • dates a vector with the capturing dates being considered for mosaicking. If not supplied, all dates are mosaicked.

Details

The valid threshold range for sensitivity is 0-100. By default, the argument is set to 50.

Value

this function does not return anything. It saves the cloud masks (CLD) as GTiff files in the AppRoot directory.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
## Not run: 
# load a spatial polygon object of Navarre
data(ex.navarre)
# Download S2MSI1C products sensed by Sentinel-2 
# between the julian days 210 and 218, 2018
wdir <- file.path(tempdir(),"Path_for_downloading_folder")
print(wdir)
senDownSearch(startDate = as.Date("2018210", "%Y%j"),
              endDate = as.Date("2018218", "%Y%j"),
              platform = "Sentinel-2",
              extent = ex.navarre,
              product = "S2MSI2A",
              pathrow = c("R094"),
              username = "username",
              password = "password",
              AppRoot = wdir)
# define the paths to the Sentinle-2 images and the
# folder with the unzipped images
wdir.sen <- file.path(wdir, "Sentinel-2")
wdir.sen.unzip <- file.path(wdir.sen, "unzip")
# mosaic the Sentinel-2 images
senMosaic(wdir.sen.unzip,
          AppRoot = wdir.sen,
          gutils = TRUE,
          out.name = "Navarre")
          
# calculate the cloud mask
wdir.sen.navarre <- file.path(wdir.sen, "Navarre")
senCloudMask(src = wdir.sen.navarre,
             resbands = "60m",
             overwrite = TRUE,
             sensitivity = 98,
             AppRoot = wdir.sen)
             
# define the path for the Sentinel-2 cloud mask
wdir.sen.cloud <- file.path(wdir.sen, "CloudMask")

# select B02 images of 60 meters
tiles.sen.navarre <- list.files(wdir.sen.navarre,
                            full.names = TRUE,
                            recursive = TRUE,
                           pattern = "\\.tif$")
tiles.sen.navarre.b2 <- tiles.sen.navarre[grepl("B02",tiles.sen.navarre)]
tiles.sen.navarre.b2 <- tiles.sen.navarre.b2[grepl("60m",tiles.sen.navarre.b2)]

# generate a 60-meter resolution cloud mask 
tiles.sen.cloud <- list.files(wdir.sen.cloud,
                              full.names = TRUE,
                              pattern = "\\.tif$")
tiles.sen.cloud.60 <- tiles.sen.cloud[grepl("60m",tiles.sen.cloud)]

# remove the cloud mask from b02 tiles
img.sen.navarre.b2 <- stack(tiles.sen.navarre.b2)
img.sen.cloud.60 <- stack(tiles.sen.cloud.60)
img.sen.navarre.b2.cloud.free <- img.sen.navarre.b2*img.sen.cloud.60
# plot b2 cloud free layers
spplot(img.sen.navarre.b2.cloud.free)

## End(Not run)

RGISTools documentation built on July 2, 2020, 3:58 a.m.