cfmask: Mask clouds using a quality band

View source: R/water_RSfunctions.R

cfmaskR Documentation

Mask clouds using a quality band

Description

Masks clouds, cloud shadows and fill pixels of an image using its quality band. Use it after loading the image (e.g. with loadImageSR()) and before METRIC.EB(), so that cloudy pixels are not used as anchor pixels. All layers of the image are masked, including the surface temperature (Band_10).

Usage

cfmask(path = getwd(), image, cfmask, keep, buffer = 60)

Arguments

path

folder where the quality band is searched when cfmask is missing: a Collection 2 *_QA_PIXEL.TIF file or, for older products, a *_cfmask.tif or *_BQA.TIF file

image

SpatRaster to mask, e.g. from loadImageSR() or loadImage()

cfmask

SpatRaster with the quality band. If missing, it is read from path

keep

For older quality bands only: values to keep (all other pixels are masked). Use 0 for cfmask files, 2720 for Landsat 8 Collection 1 BQA files and 672 for Landsat 7 Collection 1 BQA files. If missing, a Collection 2 QA_PIXEL band is decoded by bits: pixels flagged as fill, dilated cloud, cirrus, cloud or cloud shadow (bits 0 to 4) are masked.

buffer

distance (in map units, usually meters) around clouds and cloud shadows that is also masked. Use 0 for no buffer

Value

The image (SpatRaster) with the masked pixels set to NA.

Author(s)

Guillermo Federico Olmedo

See Also

Other remote sensing support functions: calcRadiance(), calcSR(), calcTOAr(), loadImage(), loadImageSR()

Examples

scene <- system.file("extdata", "L8_C2", package = "water")
image.SR <- loadImageSR(scene)
image.SR <- cfmask(path = scene, image = image.SR)
plot(image.SR[[1]])

water documentation built on Nov. 25, 2026, 5:08 p.m.