colab Open in SageMaker Studio Lab Open in Planetary Computer

Complete Preprocessing (Clouds Masking, Shadows Masking, Scaling and Offsetting) With Just One Method

Tutorial created by **David Montero Loaiza**: GitHub | Twitter

Let’s start!

If required, please uncomment:

[1]:
#!pip install eemont
#!pip install geemap

Import the required packages.

[2]:
import ee, eemont, geemap
import geemap.colormaps as cm

Authenticate and Initialize Earth Engine and geemap.

[3]:
Map = geemap.Map()

Let’s define a point of interest:

[4]:
poi = ee.Geometry.BBoxFromQuery("Puerto Rico",user_agent = "eemont-tutorial-017")

Let’s take the L8 product as example:

[5]:
L8 = (ee.ImageCollection("LANDSAT/LC08/C01/T1_SR")
      .filterBounds(poi)
      .filterDate("2020-01-01","2021-01-01"))

Complete Preprocessing

Do you want to do almost everything with just one method? Here is it: preprocess.

[6]:
L8pre = L8.preprocess()

The preprocess method automatically masks clouds and shadows and scales and offsets the image or image collection.

NOTE: You can apply the preprocess method to any ee.Image or ee.ImageCollection from the GEE STAC.

If you want to change some argument for cloud masking, just use the same arguments that are used for the maskClouds method. If not, the default parameters of maskClouds are used in preprocess:

[7]:
L8pre = L8.preprocess(maskShadows = False)

After preprocessing, you can process your ee.Image or ee.ImageCollection as you want!

[8]:
L8full = L8pre.spectralIndices(["SAVI","GNDVI"],L = 0.5).median()

Visualization parameters:

[9]:
vis = {
    "min": 0,
    "max": 1,
    "palette": cm.palettes.ndvi
}

Visualize everything with geemap:

[10]:
Map.addLayer(L8full.select("SAVI"),vis,"SAVI")
Map.addLayer(L8full.select("GNDVI"),vis,"GNDVI")
Map.centerObject(poi.centroid(1),8)
Map