--- title: "Landsat 8 and 9 data with METRIC and the water package" author: "Guillermo Federico Olmedo" date: "`r Sys.Date()`" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Landsat 8 and 9} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- The **water** package does not estimate surface reflectance for Landsat 8 and 9. Instead, it uses the products that USGS computes for every scene: [Collection 2 Level-2](https://www.usgs.gov/landsat-missions/landsat-collection-2-level-2-science-products) surface reflectance (SR) and surface temperature (ST). With them, METRIC can run without the raw digital numbers (DN). This vignette uses a small crop of a Landsat 8 Collection 2 Level-2 scene (path 232, row 83, 9 February 2016, near Mendoza, Argentina) included in **water**. Landsat 9 products have the same structure and are handled the same way. ## Getting Collection 2 Level-2 data Download the scene from USGS EarthExplorer, dataset "Landsat 8-9 OLI/TIRS C2 L2". The package repository also has two step-by-step guides to search and download the scenes for an area and a date range, from the [USGS M2M API](https://github.com/midraed/water/blob/master/vignettes/Landsat_download_USGS.qmd) or from [Microsoft Planetary Computer](https://github.com/midraed/water/blob/master/vignettes/Landsat_download_Planetarycomputer.qmd). Among other files, the scene folder contains: - `*_SR_B2.TIF` to `*_SR_B7.TIF`: surface reflectance (blue, green, red, NIR, SWIR1 and SWIR2), - `*_ST_B10.TIF`: surface temperature, - `*_QA_PIXEL.TIF`: quality band, with the cloud mask, - `*_MTL.txt`: metadata, with the acquisition date and time. A full scene is almost 1 GB, so crop an area of interest when loading it, e.g. `loadImageSR(path = scene_folder, aoi = createAoi(topleft = c(500000, -3644000), bottomright = c(526000, -3660000), EPSG = 32619))`. ## Loading the data `loadImageSR()` reads the SR bands, rescales them to reflectance (DN * 0.0000275 - 0.2) and names them B, G, R, NIR, SWIR1 and SWIR2. It also adds the surface temperature as the last layer, `Band_10`, in Kelvin (DN * 0.00341802 + 149). Pixels where any band is outside the valid range (reflectance 0 to 1) are masked in every layer: 109 pixels here, many of them dense crops with slightly negative blue reflectance. ```{r, message=FALSE, fig.width = 7} library(water) scene_folder <- system.file("extdata", "L8_C2", package = "water") image.SR <- loadImageSR(path = scene_folder) plot(image.SR) ``` Clouds and cloud shadows must be masked before running METRIC, otherwise they can be selected as cold anchor pixels. `cfmask()` reads the `QA_PIXEL` band and masks fill, dilated cloud, cirrus, cloud and cloud shadow pixels in all layers, including the surface temperature. By default it also masks a 60 m buffer around clouds and shadows: ```{r} image.SR <- cfmask(path = scene_folder, image = image.SR) ``` ## Weather station data The weather station data are in `INTA.csv`. With the MTL file, `read.WSdata()` also interpolates the weather conditions at the time of the satellite overpass. The overpass time in the MTL file is UTC and the station clock uses Argentina time, so we set `tz`: ```{r} csvfile <- system.file("extdata", "INTA.csv", package = "water") MTLfile <- list.files(scene_folder, pattern = "MTL.txt$", full.names = TRUE) WeatherStation <- read.WSdata(WSdata = csvfile, datetime.format = "%Y/%m/%d %H:%M", columns = c("date" = 1, "time" = 1, "radiation" = 5, "wind" = 6, "RH" = 3, "temp" = 2, "rain" = 4), lat = -33.00513, long = -68.86469, elev = 927, height = 2, tz = "America/Argentina/Mendoza", MTL = MTLfile) print(WeatherStation) ``` `read.WSdata()` warns that the station radiation at the overpass (587 W/m2) is 68% of the clear-sky value. The cold anchor pixels are calibrated with it, so check the pyranometer, or use `overpass.radiation = "clear-sky"` if clouds shaded only the station. Here we keep the measured value. ## Energy balance With `surf.temp`, `METRIC.EB()` uses the Level-2 surface temperature instead of estimating it from the thermal band (it would also be used by default, `LST.method = "auto"`, because `image.SR` has the layer `Band_10`). The satellite is detected from the MTL file (`sat = "auto"`) and the albedo coefficients are chosen for the satellite (`alb.coeff = "auto"`: those of Olmedo for Landsat 8 and 9, Tasumi et al. for Landsat 7). The hot and cold anchor pixels are selected from percentiles of the NDVI, the albedo and the surface temperature (`anchors.method = "percentile"`; see `?calcAnchors`), and the sensible heat flux iterates over them with the aerodynamic resistance (`?calcH`): ```{r, fig.width = 7} Energy.Balance <- METRIC.EB(image.SR = image.SR, surf.temp = image.SR$Band_10, WeatherStation = WeatherStation, MTL = MTLfile, Z.om.ws = 0.03) plot(Energy.Balance) ``` `summary()` shows the calibration (anchor pixels, temperature difference dT, wind speed used and the share of pixels with ETrF above 1.1) so that you can judge it. Read it before using the results, and see `?plotAnchors` to draw the anchors on the map: ```{r} summary(Energy.Balance) ``` Without `image.DN`, `METRIC.EB()` computes the leaf area index and selects the anchor pixels from the surface reflectance. The LAI equations of METRIC were described for top-of-atmosphere reflectance, so the results can differ from a run that also uses the Level-1 data (see the last section). ## Daily evapotranspiration Finally, `ET24h()` takes the energy balance and returns the instantaneous ET (`ETinst`, mm/h), the reference ET fraction (`ETrF`, the crop coefficient with respect to alfalfa), the daily ET (`ET24`, mm/day) and the pixels where H is larger than Rn - G (`HgtRnG`). The daily reference ET (ETr, ASCE-EWRI 2005) of the day of the image comes from the weather station: ```{r, fig.width = 7} ET.24 <- ET24h(Energy.Balance) plot(ET.24$ET24) ``` The message about the record of 24:00 is not an error: the weather station file ends at 23:00 of the day, so the last hour of the day (at night) is left out of the daily ETr, which follows the ASCE-EWRI (2005) day of hourly periods ending at 01:00 to 24:00. A day with more missing hours gives NA, and then you must provide the daily ETr (`ETr.daily`) from another source. For a season, the ETrF of several images can be interpolated and added up with `ETperiod()`, using the daily reference ET of every day from `dailyETseries()`. ## Using Level-1 digital numbers If the Level-1 product of the same scene is also available (dataset "Landsat 8-9 OLI/TIRS C2 L1" in EarthExplorer), it can be loaded with `loadImage()` and passed as `image.DN`. `METRIC.EB()` then uses the top-of-atmosphere reflectance for the leaf area index and the anchor pixels and, with `LST.method = "METRIC"`, estimates the surface temperature from the thermal band with the equations of METRIC (Eqs. 20-21) instead of using the Level-2 product. The Level-1 example files included in **water** are from the same scene, with the older (pre-Collection) file names: ```{r, fig.width = 7} image.DN <- loadImage(path = system.file("extdata", package = "water"), sat = "L8") MTL.L1 <- system.file("extdata", "LC82320832016040LGN00_MTL.txt", package = "water") Energy.Balance.DN <- METRIC.EB(image.DN = image.DN, image.SR = image.SR, WeatherStation = WeatherStation, MTL = MTL.L1, sat = "L8", LST.method = "METRIC", Z.om.ws = 0.03) plot(Energy.Balance.DN) ``` The warning about the atmosphere above is expected here: without the Level-2 product, the surface temperature from the thermal band uses general atmospheric values and can be biased by several K for Landsat 8 and 9. Prefer the Level-2 surface temperature, as in the first run.