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 HLS tile, and then expand that estimate over a larger area. In order to produce this expanded estimate, we will create a list of the HLS files which fall within a certain area.

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

[1]:
# 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 “HLS Landsat Operational Land Imager Surface Reflectance and TOA Brightness Daily Global 30m v2.0” 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.

[2]:
# get at max 1000 results from CMR
MAX_RESULTS = 1000

To filter our search to HLS data, we create a variable with the collection ID of the HLS collection. Using the collection concept ID is the preferred method to filter by a collection, as it is a unique identifier which avoids ambiguity.

[3]:
COLLECTION_ID = 'C2021957657-LPCLOUD' # specifying the collection ID for the HLS 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 HLS data using a bounding box for the country Peru.

[4]:
collection_bbox = '-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(
    cmr_host='cmr.earthdata.nasa.gov',
    bounding_box=collection_bbox,
    concept_id=COLLECTION_ID,
    limit=MAX_RESULTS
)
pprint(f'Got {len(results)} results') # print the number of results
'Got 1000 results'

We were able to get 1000 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.

[5]:
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`

# You can uncomment the line below to see the result
# print(granuleID_list)

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.