Learn R Programming

RStoolbox (version 0.3.0)

cloudMask: Simple Cloud Detection

Description

Developed for use with Landsat data cloudMask relies on the distinctive difference between the blue (or any other short-wave band) and thermal band for semi-automated creation of a cloud mask. Since it relies on thermal information it doesn't work well for sensors without thermal bands.

Usage

cloudMask(
  x,
  threshold = 0.8,
  blue = "B1_sre",
  tir = "B6_sre",
  buffer = NULL,
  plot = FALSE,
  verbose
)

Arguments

x

RasterBrick or RasterStack with reflectance and brightness temperature OR the mask of a previous run of cloudMask with returnDiffLayer=TRUE.

threshold

Numeric. cloud detection threshold. If not provided it will be guessed. Everything *below* this threshold will be considered a cloud pixel (unless it is removed by filtering afterwards).

blue

Character or integer. Bandname or number for the blue band

tir

Character or integer. Bandname or number for the thermal band

buffer

Integer. Number of pixels to use as a buffer that will be added to the identified cloud centers.

plot

Logical. Plots of the cloud mask for all sub-steps (sanitizing etc.) Helpful to find proper parametrization.

verbose

Logical. Print messages or suppress.

Value

Returns a RasterStack with two layers: CMASK contains the binary cloud mask (1 = cloud, NA = not-cloud) and NDTCI contains the cloud index.

See Also

cloudShadowMask

Examples

Run this code
# NOT RUN {
  
library(raster)
library(ggplot2)
## Import Landsat example subset
data(lsat) 
## We have two tiny clouds in the east
# }
# NOT RUN {
ggRGB(lsat, stretch = "lin")
# }
# NOT RUN {
## Calculate cloud index
cldmsk    <- cloudMask(lsat, blue = 1, tir = 6)
# }
# NOT RUN {
ggR(cldmsk, 2, geom_raster = TRUE) 
# }
# NOT RUN {
## Define threshold (re-use the previously calculated index)
## Everything above the threshold is masked
## In addition we apply a region-growing around the core cloud pixels
cldmsk_final <- cloudMask(cldmsk, threshold = 0.1, buffer = 5) 

## Plot cloudmask 
# }
# NOT RUN {
ggRGB(lsat, stretch = "lin") +
   ggR(cldmsk_final[[1]], ggLayer = TRUE, forceCat = TRUE, geom_raster = TRUE) +
   scale_fill_manual(values = c("red"), na.value = NA)
# }
# NOT RUN {
#' ## Estimate cloud shadow displacement
## Interactively (click on cloud pixels and the corresponding shadow pixels)
# }
# NOT RUN {
 shadow <- cloudShadowMask(lsat, cldmsk_final, nc = 2) 
# }
# NOT RUN {
## Non-interactively. Pre-defined shadow displacement estimate (shiftEstimate)
# }
# NOT RUN {
shadow <- cloudShadowMask(lsat, cldmsk_final, shiftEstimate = c(-16,-6))
# }
# NOT RUN {
## Plot
# }
# NOT RUN {
csmask <- raster::merge(cldmsk_final[[1]], shadow)
ggRGB(lsat, stretch = "lin") +
        ggR(csmask, ggLayer = TRUE, forceCat = TRUE, geom_raster = TRUE) +
        scale_fill_manual(values = c("blue", "yellow"), 
        labels = c("shadow", "cloud"), na.value = NA)
# }

Run the code above in your browser using DataLab