Skip to content

earthlib.BrightMask

Functions for brightness masking earth engine images.

Landsat457(img, threshold=0.4)

Apply bright pixel masking to a Landsat ⅘/7 image.

Parameters:

Name Type Description Default
img Image

the ee.Image to shade mask.

required
threshold float

the brightness/reflectance value to exclude. pixels above this value are flagged as bright.

0.4

Returns:

Type Description
Image

the same input image with an updated mask.

Source code in earthlib/BrightMask.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def Landsat457(img: ee.Image, threshold: float = 0.4) -> ee.Image:
    """Apply bright pixel masking to a Landsat 4/5/7 image.

    Args:
        img: the ee.Image to shade mask.
        threshold: the brightness/reflectance value to exclude.
            pixels above this value are flagged as bright.

    Returns:
        the same input image with an updated mask.
    """
    subset = img.select(getBands("Landsat7"))
    shade = brightMask(subset, threshold)
    return img.updateMask(shade)

Landsat8(img, threshold=0.4)

Apply bright pixel masking to a Landsat 8 image.

Parameters:

Name Type Description Default
img Image

the ee.Image to shade mask.

required
threshold float

the brightness/reflectance value to exclude. pixels above this value are flagged as bright.

0.4

Returns:

Type Description
Image

the same input image with an updated mask.

Source code in earthlib/BrightMask.py
68
69
70
71
72
73
74
75
76
77
78
79
80
81
def Landsat8(img: ee.Image, threshold: float = 0.4) -> ee.Image:
    """Apply bright pixel masking to a Landsat 8 image.

    Args:
        img: the ee.Image to shade mask.
        threshold: the brightness/reflectance value to exclude.
            pixels above this value are flagged as bright.

    Returns:
        the same input image with an updated mask.
    """
    subset = img.select(getBands("Landsat8"))
    shade = brightMask(subset, threshold)
    return img.updateMask(shade)

brightMask(img, threshold)

Use brightness normalization to identify and remove bright pixels.

Parameters:

Name Type Description Default
img Image

the ee.Image to shade mask.

required
threshold float

the brightness/reflectance value to exclude. pixels above this value are flagged as bright.

required

Returns:

Type Description
Image

a pixel byte map with 0 for shade pixels, 1 for bright pixels.

Source code in earthlib/BrightMask.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def brightMask(img: ee.Image, threshold: float) -> ee.Image:
    """Use brightness normalization to identify and remove bright pixels.

    Args:
        img: the ee.Image to shade mask.
        threshold: the brightness/reflectance value to exclude.
            pixels above this value are flagged as bright.

    Returns:
        a pixel byte map with 0 for shade pixels, 1 for bright pixels.
    """
    brightness = img.reduce(ee.Reducer.mean())
    mask = brightness.lt(threshold)
    return mask

bySensor(sensor)

Returns the appropriate shade mask function to use by sensor type.

Parameters:

Name Type Description Default
sensor str

string with the sensor name to return (e.g. "Landsat8", "Sentinel2").

required

Returns:

Type Description
Callable

the mask function associated with a sensor to pass to an ee .map() call

Source code in earthlib/BrightMask.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def bySensor(sensor: str) -> Callable:
    """Returns the appropriate shade mask function to use by sensor type.

    Args:
        sensor: string with the sensor name to return (e.g. "Landsat8", "Sentinel2").

    Returns:
        the mask function associated with a sensor to pass to an ee .map() call
    """
    lookup = {
        "Landsat4": Landsat457,
        "Landsat5": Landsat457,
        "Landsat7": Landsat457,
        "Landsat8": Landsat8,
    }
    try:
        function = lookup[sensor]
        return function
    except KeyError:
        supported = ", ".join(lookup.keys())
        raise SensorError(
            f"Shade masking not supported for '{sensor}'. Supported: {supported}"
        )