Scale NDVIΒΆ

This example shows how to request MODIS NDVI data and scale the returned values.

https://cdn.descarteslabs.com/docs/1.11.0/public/_images/sphx_glr_plot_scale_ndvi_001.png
from descarteslabs.scenes import search
import numpy as np
import matplotlib.pyplot as plt

# A bounding box geometry
aoi = {
    "type": "Polygon",
    "coordinates": [
        [
            [-105.86975097656249, 36.94550173495345],
            [-104.930419921875, 36.94550173495345],
            [-104.930419921875, 37.70120736474139],
            [-105.86975097656249, 37.70120736474139],
            [-105.86975097656249, 36.94550173495345],
        ]
    ],
}

# fetch scene from the MODIS product
scenes, ctx = search(
    aoi,
    products=["modis:09:v2"],
    start_datetime="2017-05-01",
    end_datetime="2017-05-15",
    limit=1,
)
low_res = ctx.assign(resolution=480)
# speed up by requesting a lower resolution ndarray
masked_array = scenes[0].ndarray("ndvi alpha", low_res)

masked = np.where(masked_array.mask[-1, :, :], 0, masked_array.data[0, :, :])

# plot the results on a histogram
plt.hist(masked)

Total running time of the script: ( 0 minutes 2.113 seconds)

Gallery generated by Sphinx-Gallery