Removing clouds#

Let’s use EOReader with optical data, in order to remove clouds from brightness temperature measurements

Imports#

import os
from eoreader.reader import Reader
from eoreader.bands import TIR_1, CLOUDS

Open the product#

First, open a Landsat-8 OLI-TIRS collection 2 product.

path = os.path.join("/home", "prods", "LANDSATS_COL2", "LC08_L1TP_200030_20201220_20210310_02_T1.tar")
reader = Reader()
prod = reader.open(path)
prod
eoreader.LandsatProduct 'LC08_L1TP_200030_20201220_20210310_02_T1'
Attributes:
	condensed_name: 20201220T104856_L8_200030_OLI_TIRS
	path: /home/prods/LANDSATS_COL2/LC08_L1TP_200030_20201220_20210310_02_T1.tar
	constellation: Landsat-8
	sensor type: Optical
	product type: L1
	default pixel size: 30.0
	default resolution: 30.0
	acquisition datetime: 2020-12-20T10:48:56
	band mapping:
		COASTAL_AEROSOL: 1
		BLUE: 2
		GREEN: 3
		RED: 4
		NIR: 5
		NARROW_NIR: 5
		SWIR_CIRRUS: 9
		SWIR_1: 6
		SWIR_2: 7
		THERMAL_IR_1: 10
		THERMAL_IR_2: 11
		PANCHROMATIC: 8
	needs extraction: False
	cloud cover: 16.36
	tile name: 200030

Load clouds and TIR band#

# Load those bands as a xarray.Dataset
bands = prod.load([TIR_1, CLOUDS])
bands[TIR_1][:, ::5, ::5].plot(robust=True, cmap="mako")
/opt/conda/lib/python3.11/site-packages/rasterio/warp.py:387: NotGeoreferencedWarning: Dataset has no geotransform, gcps, or rpcs. The identity matrix will be returned.
  dest = _reproject(
<matplotlib.collections.QuadMesh at 0x7f66191e8390>
../_images/aa2d1d3740031fd842e0c3c694a5fac7a5d3f7cbc5620301c72783bc64cd5aa8.png
bands[CLOUDS][:, ::5, ::5].plot(robust=True, cmap="mako")
<matplotlib.collections.QuadMesh at 0x7f66105fd850>
../_images/52ac9acac70a75effb9333e77671a215dd9f80b1ade4f488f81edb2d20f30740.png

Remove clouds from TIR band#

EOReader cloud masks have 1 where the clouds are, 0 elsewhere.

cloud_free = bands[TIR_1].where(bands[CLOUDS] == 0)
cloud_free[:, ::5, ::5].plot(robust=True, cmap="mako")
<matplotlib.collections.QuadMesh at 0x7f66199cd550>
../_images/a05e4fd35f473eb158bea84f6a33a885a05dbbd0336468530c4f9264cb70fa28.png