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.
You will be working either in the Microsoft Planetary Computer (MPC) or locally in VSCode with the environment we created yesterday.
Clone your
eds-220-sectionsdirectory to your chose platform.Create a new notebook in your
eds-220-sectionsdirectory. Update the name to ‘modis-ndvi.ipynb’.Use the terminal to stage, commit, and push this file to the remote repository.
- Add comments in each one of your code cells
- Include markdown cells in between your code cells to add titles/information to each exercise
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
- Open the MPC STAC catalog.
- 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.
- How many items are in the search?
26.2 Examine Dates
Select the first item in the search as a variable
item.Run
item.properties. What kind of Python data structure is this? You can also check it usingtype.Use the
'datetime','start_datetime', and'end_datetime'keys to print the datetime information of the item.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
Check the item’s assets. What kind of Python structure is this?
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.
Identify which key in
item.assetshas the 500m NDVI asset.Open the 500m 16 days NDVI data using the href from the corresponding asset and
rioxr.open_rasterio(). Store it as a variable nameddata.
26.4 Rescaling
Plot the
dataraster. Discuss with your team the range of values in the raster and how these relate to the NDVI range.Run the following code:
item.assets["500m_16_days_NDVI"].extra_fields["raster:bands"]What kind of structure is this?
Extract the scale value (0.0001) from the
itemusing the previous code and store it in a variable namedscale.Multiply the
dataraster byscaleto get the actual NDVI values. Store the new raster as a variablendvi.Plot
ndviusing 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.