This is an illustrative R Notebook for the Percepcion Remota 2020 1S course at UNAL.
A Quality Assessment (QA) band is included in selected Landsat Level-1 data products. Each pixel in the QA band contains a decimal value that represents bit-packed combinations of surface, atmosphere, and sensor conditions that can affect the overall usefulness of a given pixel.
All Landsat 8 Operational Land Imager (OLI) Pre-Collection data products include a QA band, as do Landsat 4-5 Thematic Mapper (TM), Landsat 7 Enhanced Thematic Mapper Plus (ETM+), and Landsat 8 OLI Collection 1 products.
The bit-packed information in a QA band is a decimal translation of binary strings. For example, the decimal value 1 translates to the binary value 0001. The binary value 0001 has 4 bits (0, 1, 2, and 3), written right to left as bits 0 (1), 1 (0), 2 (0), and 3 (0).
In case of doubt regarding binary numbers, there are several online decimal-binary converters like this one which may be helpful.
Each of the bits 0-3 represents a condition that can affect the calculation of a physical value. Bit 0 may be used to identify fill values, bit 1 may be used to identify a cloud, bit 2 may be used to indicate water, and bit 3 may be used identify snow. If the condition is true, the bit is set to 1 and 0 if false.
In the example, 0001 means the pixel contains a fill value, and should likely be ignored. - Bit 0 = 1 = fill - Bit 1 = 0 = no cloud - Bit 2 = 0 = land - Bit 3 = 0 = no snow
Rigorous science applications seeking to optimize the value of pixels used in a study will find QA bits useful as a first level indicator of certain conditions. Otherwise, users are advised that this file contains information that can be easily misinterpreted and it is not recommended for general use. More generalized quality band information is available in the LandsatLook Quality Image.
NASA has published the LANDSAT QUALITY ASSESSMENT (QA) TOOLS - LANDSAT QA BAND SUPPORT User Guide. It can be found at https://landsat.usgs.gov/sites/default/files/documents/landsat_QA_tools_userguide.pdf
RStoolbox is a R package providing a wide range of tools for your every-day remote sensing processing needs. The available toolset covers many aspects from data import, pre-processing, data analysis, image classification and graphical display. RStoolbox builds upon the raster package, which makes it suitable for processing large data-sets even on smaller workstations. Moreover in most parts decent support for parallel processing is implemented. The package is published under GPL3.
#install.packages("RStoolbox")
The RStoolbox library provides a function to understand the QA band.
library(RStoolbox)
library(raster)
## Loading required package: sp
qa <- raster(ncol = 100, nrow=100, val = sample(1:2^14, 10000))
# crop extension of image for visualizing its contents
qa2 <- crop(qa, extent(qa, 15, 25, 15, 25))
qa2
## class : RasterLayer
## dimensions : 11, 11, 121 (nrow, ncol, ncell)
## resolution : 3.6, 1.8 (x, y)
## extent : -129.6, -90, 45, 64.8 (xmin, xmax, ymin, ymax)
## crs : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
## source : memory
## names : layer
## values : 5, 16354 (min, max)
plot(qa2)
text(qa2/1000)
The function classifyQA extracts five classes from QA band: background, cloud, cirrus, snow and water.
library(knitr)
#library(kableExtra)
clase <- c('background', 'cloud', 'cirrus', 'snow', 'water')
valor <- c(1,2,3,4,5)
tabla <- data.frame(clase,valor)
kable(tabla)
| clase | valor |
|---|---|
| background | 1 |
| cloud | 2 |
| cirrus | 3 |
| snow | 4 |
| water | 5 |
Values outside of these classes are returned as NA. If confLayers = TRUE then a RasterStack with one layer per condition (except ‘background’) is returned, whereby each layer contains the confidence level of the condition.
confidence <- c('low', 'medium', 'high')
value <- c(1,2,3)
tabla2 <- data.frame(confidence,value)
kable(tabla2)
| confidence | value |
|---|---|
| low | 1 |
| medium | 2 |
| high | 3 |
Let’s try the function with our toy image:
## QA classes
qacs <- classifyQA(img = qa2)
## Confidence levels
qacs_conf <- classifyQA(img = qa2, confLayers = TRUE)
plot(qacs)
text(qacs)
plot(qacs_conf)
text(qacs_conf)
In case you are interested in going deeper with this topic, you may give a try to the Landsat Level-1 Quality Assessment Tools available at https://www.usgs.gov/land-resources/nli/landsat/landsat-level-1-quality-assessment-tools.