Searching for and Compiling a List of Granule IDs for Batch Processing

While using the MAAP ADE, you may wish to create a list of granule IDs to be used for batch processing, granules being the individual files from a sensor that are used for processing. For this example, we will imagine a scenario that we wish to produce a biomass estimate for a single Landsat tile, and then expand that estimate over a larger area. In order to produce this expanded estimate, we will create a list of the Landsat files which fall within a certain area.

We start by importing the MAAP and pprint packages and creating a new MAAP class.

# import the MAAP package
from maap.maap import MAAP

# import printing package to help display outputs
from pprint import pprint

# create MAAP class
maap = MAAP()

We can use the searchGranule function to search for Landsat 8 granules. Click here for more information about searching for granules with the searchGranule function. Since the default limit on results from the MAAP API is 20, we specify a variable to use in our search query.

# get at max 1000 results from CMR

To filter our search to Landsat 8 data, we create a variable with the collection ID of the Landsat 8 OLI Surface Reflectance Analysis Ready Data collection. You can find this collection ID as well as the collection IDs for all of the collections in MAAP in the following table within the documentation: Using the Collection Concept ID is the preferred method to filter by a collection, as it is a unique identifier which avoids ambiguity.

COLLECTIONID = 'C1200110769-NASA_MAAP' # specifying the collection ID for the Landsat 8 dataset

Next, we search for granules using the collection ID and a spatial filter. We can use a bounding box as our spatial filter. The bounding box is a sequence of four latitude and longitude values in the order of [W,S,E,N]. For this example, let’s search for granules from the Landsat 8 data using a bounding box for the country Peru.

collectionDomain = '-81.4109425524,-18.3479753557,-68.6650797187,-0.0572054988649' # specify bounding box to search by

# getting results from granule search using the bounding box, collection ID, and results limit
results = maap.searchGranule(bounding_box=collectionDomain,concept_id=COLLECTIONID,limit=MAXRESULTS)
pprint(f'Got {len(results)} results') # print the number of results
'Got 805 results'

We were able to get 805 results. Each element in the list results contains the metadata for one of the granules returned by the search. Within this metadata is the key concept-id, which is the unique identifier for each granule. To create a list of granule IDs, we create a new list and use a for loop to add the concept-id from each element of results into the new list.

granuleID_list = [] # create list for granule IDs

for result in results: # loop through each element (granule) in the list `results`
    granuleID_list.append(result['concept-id']) # add the concept id for each granule to `granuleID_list`
    # Tip: you can use `print(granuleID_list)` to see the result

Now we have a list of all the granule IDs for granules in the Landsat 8 collection that fall within the bounding box for the country Peru within granuleID_list.