Skip to content

earthlib.NIRv

Methods for computing NIRv (near infrared reflectance of vegetation) from ee.Image data

ASTER(image)

Transform ASTER image data to scaled reflectance values

Source code in earthlib/NIRv.py
44
45
46
47
48
def ASTER(image: ee.Image) -> ee.Image:
    """Transform ASTER image data to scaled reflectance values"""
    sensor = "ASTER"
    red, nir = getNIRvBands(sensor)
    return NIRvWrapper(image, red, nir)

AVNIR2(image)

Transform ALOS-AVNIR2 image data to scaled reflectance values

Source code in earthlib/NIRv.py
51
52
53
54
55
def AVNIR2(image: ee.Image) -> ee.Image:
    """Transform ALOS-AVNIR2 image data to scaled reflectance values"""
    sensor = "AVNIR2"
    red, nir = getNIRvBands(sensor)
    return NIRvWrapper(image, red, nir)

DoveR(image)

Transform Planet DoveR image data to scaled reflectance values

Source code in earthlib/NIRv.py
58
59
60
61
62
def DoveR(image: ee.Image) -> ee.Image:
    """Transform Planet DoveR image data to scaled reflectance values"""
    sensor = "DoveR"
    red, nir = getNIRvBands(sensor)
    return NIRvWrapper(image, red, nir)

Landsat4(image)

Transform Landsat4 image data to scaled reflectance values

Source code in earthlib/NIRv.py
65
66
67
68
69
def Landsat4(image: ee.Image) -> ee.Image:
    """Transform Landsat4 image data to scaled reflectance values"""
    sensor = "Landsat4"
    red, nir = getNIRvBands(sensor)
    return NIRvWrapper(image, red, nir)

Landsat5(image)

Transform Landsat5 image data to scaled reflectance values

Source code in earthlib/NIRv.py
72
73
74
75
76
def Landsat5(image: ee.Image) -> ee.Image:
    """Transform Landsat5 image data to scaled reflectance values"""
    sensor = "Landsat5"
    red, nir = getNIRvBands(sensor)
    return NIRvWrapper(image, red, nir)

Landsat7(image)

Transform Landsat7 image data to scaled reflectance values

Source code in earthlib/NIRv.py
79
80
81
82
83
def Landsat7(image: ee.Image) -> ee.Image:
    """Transform Landsat7 image data to scaled reflectance values"""
    sensor = "Landsat7"
    red, nir = getNIRvBands(sensor)
    return NIRvWrapper(image, red, nir)

Landsat8(image)

Transform Landsat8 image data to scaled reflectance values

Source code in earthlib/NIRv.py
86
87
88
89
90
def Landsat8(image: ee.Image) -> ee.Image:
    """Transform Landsat8 image data to scaled reflectance values"""
    sensor = "Landsat8"
    red, nir = getNIRvBands(sensor)
    return NIRvWrapper(image, red, nir)

MODIS(image)

Transform MODIS image data to scaled reflectance values

Source code in earthlib/NIRv.py
93
94
95
96
97
def MODIS(image: ee.Image) -> ee.Image:
    """Transform MODIS image data to scaled reflectance values"""
    sensor = "MODIS"
    red, nir = getNIRvBands(sensor)
    return NIRvWrapper(image, red, nir)

NIRvWrapper(image, red_band, nir_band)

Compute NIRv for an image.

Parameters:

Name Type Description Default
image Image

the input image object.

required
red_band str

the name of the red band to use

required
nir_band str

the name of the near infrared band to use

required

Returns:

Type Description
Image

appends the input image with and "NIRv" band.

Source code in earthlib/NIRv.py
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
def NIRvWrapper(image: ee.Image, red_band: str, nir_band: str) -> ee.Image:
    """Compute NIRv for an image.

    Args:
        image: the input image object.
        red_band: the name of the red band to use
        nir_band: the name of the near infrared band to use

    Returns:
        appends the input image with and "NIRv" band.
    """
    red = image.select(red_band)
    nir = image.select(nir_band)
    ndvi = (nir.subtract(red)).divide(nir.add(red))
    ndviScaled = ndvi.subtract(0.08)
    nirv = ndviScaled.multiply(nir).rename("NIRv")
    return image.addBands(nirv)

PlanetScope(image)

Transform PlanetScope image data to scaled reflectance values

Source code in earthlib/NIRv.py
100
101
102
103
104
def PlanetScope(image: ee.Image) -> ee.Image:
    """Transform PlanetScope image data to scaled reflectance values"""
    sensor = "PlanetScope"
    red, nir = getNIRvBands(sensor)
    return NIRvWrapper(image, red, nir)

Sentinel2(image)

Transform Sentinel2 image data to scaled reflectance values

Source code in earthlib/NIRv.py
107
108
109
110
111
def Sentinel2(image: ee.Image) -> ee.Image:
    """Transform Sentinel2 image data to scaled reflectance values"""
    sensor = "Sentinel2"
    red, nir = getNIRvBands(sensor)
    return NIRvWrapper(image, red, nir)

SuperDove(image)

Transform Planet SuperDove image data to scaled reflectance values

Source code in earthlib/NIRv.py
114
115
116
117
118
def SuperDove(image: ee.Image) -> ee.Image:
    """Transform Planet SuperDove image data to scaled reflectance values"""
    sensor = "SuperDove"
    red, nir = getNIRvBands(sensor)
    return NIRvWrapper(image, red, nir)

VIIRS(image)

Transform VIIRS image data to scaled reflectance values

Source code in earthlib/NIRv.py
121
122
123
124
125
def VIIRS(image: ee.Image) -> ee.Image:
    """Transform VIIRS image data to scaled reflectance values"""
    sensor = "VIIRS"
    red, nir = getNIRvBands(sensor)
    return NIRvWrapper(image, red, nir)

bySensor(sensor)

Returns the appropriate NIRv 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 NIRv function associated with a sensor to pass to an ee .map() call

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

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

    Returns:
        the NIRv function associated with a sensor to pass to an ee .map() call
    """
    lookup = {
        "ASTER": ASTER,
        "AVNIR2": AVNIR2,
        "DoveR": DoveR,
        "Landsat4": Landsat4,
        "Landsat5": Landsat5,
        "Landsat7": Landsat7,
        "Landsat8": Landsat8,
        "MODIS": MODIS,
        "PlanetScope": PlanetScope,
        "Sentinel2": Sentinel2,
        "SuperDove": SuperDove,
        "VIIRS": VIIRS,
    }
    try:
        function = lookup[sensor]
        return function
    except KeyError:
        supported = ", ".join(lookup.keys())
        raise SensorError(
            f"NIRv calculation not supported for '{sensor}'. Supported: {supported}"
        )

getNIRvBands(sensor)

Look-up the red and near infrared bands for NIRv calculation

Source code in earthlib/NIRv.py
128
129
130
131
132
133
134
135
136
def getNIRvBands(sensor: str) -> tuple:
    """Look-up the red and near infrared bands for NIRv calculation"""
    bnames = getBands(sensor)
    descriptions = getBandDescriptions(sensor)
    idx_red = descriptions.index("red")
    idx_nir = descriptions.index("near infrared")
    red = bnames[idx_red]
    nir = bnames[idx_nir]
    return red, nir