26  *Lab: STAC access

The goal of this lab is to practice retrieving data from a STAC catalog and extracting information from STAC item’s assets.

Notebook Setup
  1. You will be working either in the Microsoft Planetary Computer (MPC) or locally in VSCode with the environment we created yesterday.

  2. Clone your eds-220-sections directory to your chose platform.

  3. Create a new notebook in your eds-220-sections directory. Update the name to ‘modis-ndvi.ipynb’.

  4. Use the terminal to stage, commit, and push this file to the remote repository.

General directions
  • Add comments in each one of your code cells
  • Include markdown cells in between your code cells to add titles/information to each exercise
About the data

I this task we will use data from the Moderate Resolution Imaging Spectroradiometer (MODIS) Vegetation Indices 16-Day Version. This dataset has NDVI calculations at 500m spatial resolution globally and is part of the MPC STAC catalog.

Read the catalog’s overview before starting the exercise.

26.1 Data access

  1. Open the MPC STAC catalog.
  2. Create a search for data in the MODIS Vegetation Indices dataset (id = 'modis-13A1-061') from 2023 that intersects the box bounds:

[-119.28376473993174, 35.561681976121605, -117.15965333370627, 36.65291223580975]

This list of coordinates is in the form [minx, miny, maxx, maxy] with epsg:4326 and describes a rectangular region around Sequoia National Park.

HINT: You can use the list of coordinates directly in the catalog search without converting it to a JSON format.

  1. How many items are in the search?

26.2 Examine Dates

  1. Select the first item in the search as a variable item.

  2. Run item.properties. What kind of Python data structure is this? You can also check it using type.

  3. Use the 'datetime', 'start_datetime', and 'end_datetime' keys to print the datetime information of the item.

  4. The 'datetime' value usually refers to the date of collection. Discuss with your team: why does this item does not have a datetime, but instead has start and end times? HINT: read the datset’s overview.

26.3 Assets

  1. Check the item’s assets. What kind of Python structure is this?

  2. Run the following code in a cell

for key, asset in item.assets.items():
    print(key, '-', asset.title)

Here, item.assets.items() returns the key-value pairs of the item.assets dictionary as tuples we can iterate over simultaneously.

  1. Identify which key in item.assets has the 500m NDVI asset.

  2. Open the 500m 16 days NDVI data using the href from the corresponding asset and rioxr.open_rasterio(). Store it as a variable named data.

26.4 Rescaling

  1. Plot the data raster. Discuss with your team the range of values in the raster and how these relate to the NDVI range.

  2. Run the following code:

item.assets["500m_16_days_NDVI"].extra_fields["raster:bands"]

What kind of structure is this?

  1. Extract the scale value (0.0001) from the item using the previous code and store it in a variable named scale.

  2. Multiply the data raster by scale to get the actual NDVI values. Store the new raster as a variable ndvi.

  3. Plot ndvi using the colormap PiYG. HINT: cmap="PiYG". This is a nice area to look at NDVI since we can see the transition in NDVI between the Sierra Nevada and Death Valley.