Scale NDVIΒΆ

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

https://cdn.descarteslabs.com/docs/public/_images/sphx_glr_plot_scale_ndvi_001.png

Out:

/root/.cache/bazel/_bazel_drone-agent-b0bb/3517bd091dde6188868082e15543f179/sandbox/linux-sandbox/17/execroot/__main__/bazel-out/k8-opt/bin/docs/build_tools/public/descarteslabs/client/auth/auth.py:129: UserWarning: unable to read token_info from /root/.descarteslabs/token_info.json with error [Errno 2] No such file or directory: '/root/.descarteslabs/token_info.json'.
  self.token_info_path, str(e)
/root/.cache/bazel/_bazel_drone-agent-b0bb/3517bd091dde6188868082e15543f179/sandbox/linux-sandbox/17/execroot/__main__/bazel-out/k8-opt/bin/docs/build_tools/public/descarteslabs/client/auth/auth.py:397: UserWarning: unable to read token_info from /root/.descarteslabs/token_info.json with error [Errno 2] No such file or directory: '/root/.descarteslabs/token_info.json'.
  self.token_info_path, str(e)

import descarteslabs as dl
import numpy as np
import matplotlib.pyplot as plt


raster_client = dl.Raster()

# 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 = dl.scenes.search(
    aoi,
    products=["modis:09:CREFL"],
    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, bands_axis=2)

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.622 seconds)

Gallery generated by Sphinx-Gallery