<jupyter_start><jupyter_text>Accessing MODIS vegetation data with the Planetary Computer STAC APIThe planetary computer hosts several vegetation-related MODIS 6.1 products:- Vegetation Indices- Leaf Area Index/FPAR- Gross Primary Productivity- Net EvapotranspirationFor more information about the products themselves, check out the User Guides at the [bottom of this document](user-guides).  Environment setupThis notebook works with or without an API key, but you will be given more permissive access to the data with an API key.The Planetary Computer Hub is pre-configured to use your API key.<jupyter_code>import odc.stac
import planetary_computer
from pystac.extensions.raster import RasterExtension
from pystac_client import Client
import rich.table<jupyter_output><empty_output><jupyter_text>Query for available dataMODIS is a global dataset with a variety of products available within each larger category (vegetation, snow, fire, temperature, and reflectance).For example, there are two different collections for Vegetation Indices, one available at 500m resolution and the other at 250m resolution.The [MODIS group](https://planetarycomputer.microsoft.com/dataset/group/modis) contains a complete listing of available collections.Each collection's id is in the format `modis-{product}-061`, where `product` is the MODIS product id.For example, the 500m Vegetation Indices collection is `modis-13A1-061`, and the 250m collection is `modis-13Q1-061`.The `-061` suffix indicates that all of the MODIS collections are part of the [MODIS 6.1 update](https://atmosphere-imager.gsfc.nasa.gov/documentation/collection-61).Let's find some Vegetation Indices data over the central valley of California in 2021.We'll get four images, aiming for "representative" months: January, April, July, and October.<jupyter_code># Sacramento, CA
latitude = 38.6
longitude = -121.5
buffer = 1
bbox = [longitude - buffer, latitude - buffer, longitude + buffer, latitude + buffer]
year = "2021"
months = {
    "January": "01",
    "April": "04",
    "July": "07",
    "October": "10",
}
items = dict()

catalog = Client.open("https://planetarycomputer-staging.microsoft.com/api/stac/v1")
for name, number in months.items():
    datetime = f"{year}-{number}"
    search = catalog.search(
        collections=["modis-13A1-061"],
        bbox=bbox,
        datetime=datetime,
    )
    item = search.get_all_items()[0]
    items[name] = planetary_computer.sign(item)

print(items)<jupyter_output>{'January': <Item id=MYD13A1.A2021025.h08v05.061.2021042011101>, 'April': <Item id=MOD13A1.A2021113.h08v05.061.2021133131642>, 'July': <Item id=MOD13A1.A2021209.h08v05.061.2021226035904>, 'October': <Item id=MYD13A1.A2021297.h08v05.061.2021314025325>}<jupyter_text>Available assetsEach item has several available assets, including the original HDF file and a Cloud-optimized GeoTIFF of each subdataset.<jupyter_code>item = items["January"]

t = rich.table.Table("Key", "Title")
for key, asset in items["January"].assets.items():
    t.add_row(key, asset.title)
t<jupyter_output><empty_output><jupyter_text>Loading the NDVI dataFor this example, we'll visualize and compare the [Normalized Difference Vegetation Index (NDVI)](https://en.wikipedia.org/wiki/Normalized_difference_vegetation_index). Let's grab each NDVI COG and load them into an xarray using [odc-stac](https://github.com/opendatacube/odc-stac). We'll also apply the scaling as defined by the `raster:bands` extension. The MODIS coordinate reference system is a [sinusoidal grid](https://modis-land.gsfc.nasa.gov/MODLAND_grid.html), which means that views in a naïve XY raster look skewed. For visualization purposes, we reproject to a [spherical Mercator projection](https://wiki.openstreetmap.org/wiki/EPSG:3857) for intuitive, north-up visualization.<jupyter_code>data = odc.stac.load(
    items.values(),
    crs="EPSG:3857",
    bands="500m_16_days_NDVI",
    resolution=500,
    bbox=bbox,
)
raster = RasterExtension.ext(items["January"].assets["500m_16_days_NDVI"])
data = data["500m_16_days_NDVI"] * raster.bands[0].scale
data<jupyter_output><empty_output><jupyter_text>Displaying the dataLet's sanity-check ourselves by simply displaying the NDVI for each month.<jupyter_code>data.plot.imshow(cmap="viridis", col="time");<jupyter_output><empty_output><jupyter_text>Change detectionNow let's see how the NDVI changes from season to season.<jupyter_code>change = data.diff(dim="time").assign_coords(time=["Winter", "Spring", "Summer"])
change.plot.imshow(cmap="BrBG", col="time");<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10838086880210619, 'fraction_numerical': 0.04716981132075472, 'mean_word_length': 5.754074074074074, 'pattern_counts': {'":': 4, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 7, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '317637', 'license': 'MIT', 'n_tokens_mistral': 1604, 'n_tokens_neox': 1401, 'n_words': 418, 'path': 'datasets/modis/modis-vegetation-example.ipynb', 'repo_name': 'RadiantMLHub/PlanetaryComputerExamples', 'size': '4558'}