Getting Started with the AρρEEARS API: Submitting and Downloading an Area Request

This tutorial demonstrates how to use Python to connect to the AρρEEARS API

The Application for Extracting and Exploring Analysis Ready Samples (AρρEEARS) offers a simple and efficient way to access and transform geospatial data from a variety of federal data archives in an easy-to-use web application interface. AρρEEARS enables users to subset geospatial data spatially, temporally, and by band/layer for point and area samples. AρρEEARS returns not only the requested data, but also the associated quality values, and offers interactive visualizations with summary statistics in the web interface. The AρρEEARS API offers users programmatic access to all features available in AρρEEARS, with the exception of visualizations. The API features are demonstrated in this notebook.


Example: Submit an area request using a U.S. National Park boundary as the region of interest for extracting elevation, vegetation and land surface temperature data

Connect to the AρρEEARS API, query the list of available products, submit an area sample request, download the request, become familiar with the AρρEEARS Quality API, and import the results into Python for visualization. AρρEEARS area sample requests allow users to subset their desired data by spatial area via vector polygons (shapefiles or GeoJSONs). Users can also reproject and reformat the output data. AρρEEARS returns the valid data from the parameters defined within the sample request.

Data Used in the Example:

  • Data layers:
    • NASA MEaSUREs Shuttle Radar Topography Mission (SRTM) Version 3 Digital Elevation Model
    • Combined MODIS Leaf Area Index (LAI)
    • Terra MODIS Land Surface Temperature
      • MOD11A2.006, 1000m, 8 day: 'LST_Day_1km', 'LST_Night_1km'

Topics Covered:

  1. Getting Started
    1a. Set Up the Working Environment
    1b. Login [Login]
  2. Query Available Products [Product API]
    2a. Search and Explore Available Products [List Products]
    2b. Search and Explore Available Layers [List Layers]
  3. Submit an Area Request [Tasks]
    3a. Import a Shapefile
    3b. Search and Explore Available Projections [Spatial API]
    3c. Compile a JSON [Task Object]
    3d. Submit a Task Request [Submit Task]
    3e. Retrieve Task Status [Retrieve Task]
  4. Download a Request [Bundle API]
    4a. Explore Files in Request Output [List Files]
    4b. Download Files in a Request (Automation) [Download File]
  5. Explore AρρEEARS Quality Service [Quality API]
    5a. List Quality Layers [List Quality Layers]
    5b. Show Quality Values [List Quality Values]
    5c. Decode Quality Values [Decode Quality Values]
  6. BONUS: Import Request Output and Visualize
    6a. Import a GeoTIFF
    6b. Plot a GeoTIFF

Dependencies:


AρρEEARS Information:

To access AρρEEARS, visit: https://lpdaacsvc.cr.usgs.gov/appeears/

For comprehensive documentation of the full functionality of the AρρEEARS API, please see the AρρEEARS API Documentation

Throughout the tutorial, specific sections of the API documentation can be accessed by clicking on the bracketed [] links in the section headings.


Files Used in this Tutorial:

Source Code used to Generate this Tutorial:


1. Getting Started


1a. Set Up the Working Environment

Import the required packages, set the input/working directory, and create an output directory for the results.

In [1]:
# Import packages 
import requests as r
import getpass, pprint, time, os, cgi, json
import geopandas as gpd

If you are missing any of the packages above, download them in order to use the full functionality of this tutorial.

In [2]:
# Set input directory, change working directory
inDir = 'D:/appeears-api-getting-started/'           # IMPORTANT: Update to reflect directory on your OS
os.chdir(inDir)                                      # Change to working directory
api = 'https://lpdaacsvc.cr.usgs.gov/appeears/api/'  # Set the AρρEEARS API to a variable

If you plan to execute this tutorial on your own OS, `inDir` above needs to be changed.


1b. Login [Login]

To submit a request, you must first login to the AρρEEARS API. The AρρEEARS API requires the same NASA Earthdata Login as the AρρEEARS user interface. Use the getpass package to enter your NASA Earthdata login Username and Password. When prompted after executing the code block below, enter your username followed by your password.

In [3]:
user = getpass.getpass(prompt = 'Enter NASA Earthdata Login Username: ')      # Input NASA Earthdata Login Username
password = getpass.getpass(prompt = 'Enter NASA Earthdata Login Password: ')  # Input NASA Earthdata Login Password
Enter NASA Earthdata Login Username: ········
Enter NASA Earthdata Login Password: ········

Use the requests package to post your username and password. A successful login will provide you with a token to be used later in this tutorial to submit a request. For more information or if you are experiencing difficulties, please see the API Documentation.

In [4]:
token_response = r.post('{}login'.format(api), auth=(user, password)).json() # Insert API URL, call login service, provide credentials & return json
del user, password                                                           # Remove user and password information
token_response                                                               # Print response
Out[4]:
{'token_type': 'Bearer',
 'token': '0EEkLrwSofg86GfSu3Zm2bNgb-x1-TRDQkRBn2B3qA0_CK2dNB3jbk6EkgST6SWapwNNhJvnJ9J2en4yFKfQ3g',
 'expiration': '2020-04-30T18:26:32Z'}

Above, you should see a Bearer token. Notice that this token will expire approximately 48 hours after being acquired.


2. Query Available Products [Product API]

2a. Search and Explore Available Products [List Products]

The product API provides details about all of the products and layers available in AρρEEARS. Below, call the product API to list all of the products available in AρρEEARS.

In [5]:
product_response = r.get('{}product'.format(api)).json()                         # request all products in the product service
print('AρρEEARS currently supports {} products.'.format(len(product_response)))  # Print no. products available in AppEEARS
AρρEEARS currently supports 120 products.

Next, create a dictionary indexed by product name, making it easier to query a specific product.

In [6]:
products = {p['ProductAndVersion']: p for p in product_response} # Create a dictionary indexed by product name & version
products['MCD15A3H.006']                                         # Print information for MCD15A3H.006 LAI/FPAR Product
Out[6]:
{'Product': 'MCD15A3H',
 'Platform': 'Combined MODIS',
 'Description': 'Leaf Area Index (LAI) and Fraction of Photosynthetically Active Radiation (FPAR)',
 'RasterType': 'Tile',
 'Resolution': '500m',
 'TemporalGranularity': '4 day',
 'Version': '006',
 'Available': True,
 'DocLink': 'https://doi.org/10.5067/MODIS/MCD15A3H.006',
 'Source': 'LP DAAC',
 'TemporalExtentStart': '2002-07-04',
 'TemporalExtentEnd': 'Present',
 'Deleted': False,
 'DOI': '10.5067/MODIS/MCD15A3H.006',
 'ProductAndVersion': 'MCD15A3H.006'}

The product service provides many useful details, including if a product is currently available in AρρEEARS, a description, and information on the spatial and temporal resolution.

Below, make a list of all product+version names, and search for products containing Leaf Area Index in their description.

In [7]:
prodNames = {p['ProductAndVersion'] for p in product_response} # Make list of all products (including version)
for p in prodNames:                                            # Make for loop to search list of products 'Description' for a keyword                
    if 'Leaf Area Index' in products[p]['Description']:
        pprint.pprint(products[p])                             # Print info for each product containing LAI in its description
{'Available': True,
 'DOI': '10.5067/VIIRS/VNP15A2H.001',
 'Deleted': False,
 'Description': 'Leaf Area Index (LAI) and Fraction of Photosynthetically '
                'Active Radiation (FPAR)',
 'DocLink': 'https://doi.org/10.5067/viirs/vnp15a2h.001',
 'Platform': 'S-NPP NASA VIIRS',
 'Product': 'VNP15A2H',
 'ProductAndVersion': 'VNP15A2H.001',
 'RasterType': 'Tile',
 'Resolution': '500m',
 'Source': 'LP DAAC',
 'TemporalExtentEnd': 'Present',
 'TemporalExtentStart': '2012-01-19',
 'TemporalGranularity': '8 day',
 'Version': '001'}
{'Available': True,
 'DOI': '10.5067/MODIS/MYD15A2H.006',
 'Deleted': False,
 'Description': 'Leaf Area Index (LAI) and Fraction of Photosynthetically '
                'Active Radiation (FPAR)',
 'DocLink': 'https://doi.org/10.5067/MODIS/MYD15A2H.006',
 'Platform': 'Aqua MODIS',
 'Product': 'MYD15A2H',
 'ProductAndVersion': 'MYD15A2H.006',
 'RasterType': 'Tile',
 'Resolution': '500m',
 'Source': 'LP DAAC',
 'TemporalExtentEnd': 'Present',
 'TemporalExtentStart': '2002-07-04',
 'TemporalGranularity': '8 day',
 'Version': '006'}
{'Available': True,
 'DOI': '10.5067/MODIS/MCD15A2H.006',
 'Deleted': False,
 'Description': 'Leaf Area Index (LAI) and Fraction of Photosynthetically '
                'Active Radiation (FPAR)',
 'DocLink': 'https://doi.org/10.5067/MODIS/MCD15A2H.006',
 'Platform': 'Combined MODIS',
 'Product': 'MCD15A2H',
 'ProductAndVersion': 'MCD15A2H.006',
 'RasterType': 'Tile',
 'Resolution': '500m',
 'Source': 'LP DAAC',
 'TemporalExtentEnd': 'Present',
 'TemporalExtentStart': '2002-07-04',
 'TemporalGranularity': '8 day',
 'Version': '006'}
{'Available': True,
 'DOI': '10.5067/MODIS/MOD15A2H.006',
 'Deleted': False,
 'Description': 'Leaf Area Index (LAI) and Fraction of Photosynthetically '
                'Active Radiation (FPAR)',
 'DocLink': 'https://doi.org/10.5067/MODIS/MOD15A2H.006',
 'Platform': 'Terra MODIS',
 'Product': 'MOD15A2H',
 'ProductAndVersion': 'MOD15A2H.006',
 'RasterType': 'Tile',
 'Resolution': '500m',
 'Source': 'LP DAAC',
 'TemporalExtentEnd': 'Present',
 'TemporalExtentStart': '2000-02-18',
 'TemporalGranularity': '8 day',
 'Version': '006'}
{'Available': True,
 'DOI': '10.5067/MODIS/MCD15A3H.006',
 'Deleted': False,
 'Description': 'Leaf Area Index (LAI) and Fraction of Photosynthetically '
                'Active Radiation (FPAR)',
 'DocLink': 'https://doi.org/10.5067/MODIS/MCD15A3H.006',
 'Platform': 'Combined MODIS',
 'Product': 'MCD15A3H',
 'ProductAndVersion': 'MCD15A3H.006',
 'RasterType': 'Tile',
 'Resolution': '500m',
 'Source': 'LP DAAC',
 'TemporalExtentEnd': 'Present',
 'TemporalExtentStart': '2002-07-04',
 'TemporalGranularity': '4 day',
 'Version': '006'}

Using the info above, start a list of desired products by using the highest temporal resolution LAI product, MCD15A3H.006.

In [8]:
prods = ['MCD15A3H.006']     # Start a list for products to be requested, beginning with MCD15A3H.006
prods.append('MOD11A2.006')  # Append the MOD11A2.006 8 day LST product to the list of products desired
prods.append('SRTMGL1_NC.003')  # Append the SRTMGL1_NC.003 product to the list of products desired
prods                        # Print list
Out[8]:
['MCD15A3H.006', 'MOD11A2.006', 'SRTMGL1_NC.003']

2b. Search and Explore Available Layers [List Layers]

The product API allows you to call all of the layers available for a given product. Each product is referenced by its ProductAndVersion property. For a list of the layer names only, print the keys from the dictionary below.

In [9]:
lst_response = r.get('{}product/{}'.format(api, prods[1])).json()  # Request layers for the 2nd product (index 1) in the list: MOD11A2.006
list(lst_response.keys())
Out[9]:
['Clear_sky_days',
 'Clear_sky_nights',
 'Day_view_angl',
 'Day_view_time',
 'Emis_31',
 'Emis_32',
 'LST_Day_1km',
 'LST_Night_1km',
 'Night_view_angl',
 'Night_view_time',
 'QC_Day',
 'QC_Night']

Use the dictionary key 'LST_Day_1km' to see the information for that layer in the response.

In [10]:
lst_response['LST_Day_1km'] # Print layer response
Out[10]:
{'AddOffset': 0.0,
 'Available': True,
 'DataType': 'float32',
 'Description': 'Day Land Surface Temperature',
 'Dimensions': ['time', 'YDim', 'XDim'],
 'FillValue': 0,
 'IsQA': False,
 'Layer': 'LST_Day_1km',
 'OrigDataType': 'uint16',
 'OrigValidMax': 65535,
 'OrigValidMin': 7500,
 'QualityLayers': "['QC_Day']",
 'QualityProductAndVersion': 'MOD11A2.006',
 'ScaleFactor': 0.02,
 'Units': 'Kelvin',
 'ValidMax': 1310.699951,
 'ValidMin': 150.0,
 'XSize': 1200,
 'YSize': 1200}

AρρEEARS also allows subsetting data spectrally (by band). Create a tupled list with product name and specific layers desired.

In [11]:
layers = [(prods[1],'LST_Day_1km'),(prods[1],'LST_Night_1km')]  # Create tupled list linking desired product with desired layers

Next, request the layers for the MCD15A3H.006 product.

In [12]:
lai_response = r.get('{}product/{}'.format(api, prods[0])).json()  # Request layers for the 1st product (index 0) in the list: MCD15A3H.006
list(lai_response.keys())                                          # Print the LAI layer names
Out[12]:
['FparExtra_QC',
 'FparLai_QC',
 'FparStdDev_500m',
 'Fpar_500m',
 'LaiStdDev_500m',
 'Lai_500m']
In [13]:
lai_response['Lai_500m']['Description']  # Make sure the correct layer is requested
Out[13]:
'Leaf area index'

Above, Lai_500m is the desired layer within the MCD15A3h.006 product.

Next, append Lai_500m to the tupled list of desired product/layers.

In [14]:
layers.append((prods[0],'Lai_500m')) # Append to tupled list linking desired product with desired layers

Thirdly, request the layers for the SRTMGL1_NC.003 product.

In [15]:
dem_response = r.get('{}product/{}'.format(api, prods[2])).json()  # Request layers for the 3rd product (index 2) in the list: SRTMGL1_NC.003
list(dem_response.keys())                                          # Print the SRTM DEM layer names 
Out[15]:
['SRTMGL1_DEM']

Finally, append SRTMGL1_DEM to the tupled list of desired products/layers.

In [16]:
layers.append((prods[2], 'SRTMGL1_DEM')) # Append to tupled list linking desired product with desired layers

Below, take the tupled list (layers) and create a list of dictionaries to store each layer+product combination. This will make it easier to insert into the json file used to submit a request in Section 3.

In [17]:
prodLayer = []
for l in layers:
    prodLayer.append({
            "layer": l[1],
            "product": l[0]
          })
prodLayer
Out[17]:
[{'layer': 'LST_Day_1km', 'product': 'MOD11A2.006'},
 {'layer': 'LST_Night_1km', 'product': 'MOD11A2.006'},
 {'layer': 'Lai_500m', 'product': 'MCD15A3H.006'},
 {'layer': 'SRTMGL1_DEM', 'product': 'SRTMGL1_NC.003'}]

3. Submit an Area Request [Tasks]

The Submit task API call provides a way to submit a new request to be processed. It can accept data via JSON, query string, or a combination of both. In the example below, compile a json and submit a request. Tasks in AρρEEARS correspond to each request associated with your user account. Therefore, each of the calls to this service requires an authentication token (see Section 1c.), which is stored in a header below.

In [18]:
token = token_response['token']                      # Save login token to a variable
head = {'Authorization': 'Bearer {}'.format(token)}  # Create a header to store token information, needed to submit a request

3a. Import a Shapefile

In this section, begin by importing a shapefile using the geopandas package. The shapefile is publically available for download from the NPS website.

In [19]:
nps = gpd.read_file('{}nps_boundary.shp'.format(inDir + os.sep)) # Read in shapefile as dataframe using geopandas
print(nps.head())                                                # Print first few lines of dataframe
  UNIT_CODE                                          GIS_Notes  \
0      AMME  LEGACY: contact allen_mccoy@nps.gov for additi...   
1      EBLA  LEGACY: contact allen_mccoy@nps.gov for additi...   
2      LARO  LEGACY: contact allen_mccoy@nps.gov for additi...   
3      LEWI  LEGACY: contact allen_mccoy@nps.gov for additi...   
4      OLYM  LEGACY: contact allen_mccoy@nps.gov for additi...   

                                    UNIT_NAME   DATE_EDIT STATE REGION  \
0                      American Memorial Park  2015-04-22    MP     PW   
1  Ebey's Landing National Historical Reserve  2015-04-22    WA     PW   
2     Lake Roosevelt National Recreation Area  2015-04-22    WA     PW   
3    Lewis and Clark National Historical Park  2015-04-22    WA     PW   
4                       Olympic National Park  2015-04-22    WA     PW   

   GNIS_ID                    UNIT_TYPE CREATED_BY METADATA  \
0  1879026                         Park     Legacy     None   
1  1888910  National Historical Reserve     Legacy     None   
2  1531834     National Recreation Area     Legacy     None   
3  2055170     National Historical Park     Legacy     None   
4  1530459                National Park     Legacy     None   

                 PARKNAME                                           geometry  
0  American Memorial Park  POLYGON ((145.72350 15.22246, 145.72352 15.222...  
1          Ebey's Landing  POLYGON ((-122.65290 48.25379, -122.62396 48.2...  
2          Lake Roosevelt  MULTIPOLYGON (((-118.45200 47.84213, -118.4520...  
3         Lewis and Clark  MULTIPOLYGON (((-124.07495 46.30228, -124.0746...  
4                 Olympic  MULTIPOLYGON (((-124.38061 47.60210, -124.3807...  

Below, query the geopandas dataframe for the national park that you are interested in using for your region of interest, here Grand Canyon National Park.

In [20]:
nps_gc = nps[nps['UNIT_NAME']=='Grand Canyon National Park'].to_json() # Extract Grand Canyon NP and set to variable
nps_gc = json.loads(nps_gc)                                            # Convert to json format

3b. Search and Explore Available Projections [Spatial API]

The spatial API provides some helper services used to support submitting area task requests. The call below will retrieve the list of supported projections in AρρEEARS.

In [21]:
projections = r.get('{}spatial/proj'.format(api)).json()  # Call to spatial API, return projs as json
projections                                               # Print projections and information
Out[21]:
[{'Name': 'native',
  'Description': 'Native Projection',
  'Platforms': '',
  'Proj4': '',
  'Datum': '',
  'EPSG': '',
  'Units': '',
  'GridMapping': '',
  'Available': True},
 {'Name': 'geographic',
  'Description': 'Geographic',
  'Platforms': "['SRTM', 'ECOSTRESS', 'SSEBop ET', 'GPW', 'ASTER GDEM', 'NASADEM']",
  'Proj4': '+proj=longlat +datum=WGS84 +no_defs',
  'Datum': 'wgs84',
  'EPSG': 4326.0,
  'Units': 'degrees',
  'GridMapping': 'latitude_longitude',
  'Available': True},
 {'Name': 'sinu_modis',
  'Description': 'MODIS Sinusoidal',
  'Platforms': "['Combined MODIS', 'Terra MODIS', 'Aqua MODIS', 'S-NPP NASA VIIRS', 'Global WELD']",
  'Proj4': '+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs',
  'Datum': '',
  'EPSG': '',
  'Units': 'meters',
  'GridMapping': 'sinusoidal',
  'Available': True},
 {'Name': 'albers_weld_alaska',
  'Description': 'WELD Albers Equal Area Alaska',
  'Platforms': "['WELD']",
  'Proj4': '+proj=aea +lat_1=55 +lat_2=65 +lat_0=50 +lon_0=-154 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs',
  'Datum': 'wgs84',
  'EPSG': '',
  'Units': 'meters',
  'GridMapping': 'albers_conical_equal_area',
  'Available': True},
 {'Name': 'albers_weld_conus',
  'Description': 'WELD Albers Equal Area CONUS',
  'Platforms': "['WELD']",
  'Proj4': '+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23 +lon_0=-96 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs',
  'Datum': 'wgs84',
  'EPSG': '',
  'Units': 'meters',
  'GridMapping': 'albers_conical_equal_area',
  'Available': True},
 {'Name': 'albers_ard_alaska',
  'Description': 'Landsat ARD Albers Equal Area Alaska',
  'Platforms': "['Landsat ARD']",
  'Proj4': '+proj=aea +lat_1=55 +lat_2=65 +lat_0=50 +lon_0=-154 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs',
  'Datum': 'wgs84',
  'EPSG': '',
  'Units': 'meters',
  'GridMapping': 'albers_conical_equal_area',
  'Available': True},
 {'Name': 'albers_ard_conus',
  'Description': 'Landsat ARD Albers Equal Area CONUS',
  'Platforms': "['Landsat ARD']",
  'Proj4': '+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23 +lon_0=-96 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs',
  'Datum': 'wgs84',
  'EPSG': '',
  'Units': 'meters',
  'GridMapping': 'albers_conical_equal_area',
  'Available': True},
 {'Name': 'albers_ard_hawaii',
  'Description': 'Landsat ARD Albers Equal Area Hawaii',
  'Platforms': "['Landsat ARD']",
  'Proj4': '+proj=aea +lat_1=8 +lat_2=18 +lat_0=3 +lon_0=-157 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs',
  'Datum': 'wgs84',
  'EPSG': '',
  'Units': 'meters',
  'GridMapping': 'albers_conical_equal_area',
  'Available': True},
 {'Name': 'easegrid_2_global',
  'Description': 'EASE-Grid 2.0 Global',
  'Platforms': "['SMAP']",
  'Proj4': '+proj=cea +lon_0=0 +lat_ts=30 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs',
  'Datum': 'wgs84',
  'EPSG': 6933.0,
  'Units': 'meters',
  'GridMapping': 'lambert_cylindrical_equal_area',
  'Available': True},
 {'Name': 'easegrid_2_north',
  'Description': 'EASE-Grid 2.0 Northern Hemisphere',
  'Platforms': "['SMAP']",
  'Proj4': '+proj=laea +lat_0=90 +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs',
  'Datum': 'wgs84',
  'EPSG': 6931.0,
  'Units': 'meters',
  'GridMapping': 'lambert_cylindrical_equal_area',
  'Available': True},
 {'Name': 'laea_sphere_19',
  'Description': 'Lambert Azimuthal Equal Area Sphere 19',
  'Platforms': "['eMODIS Smoothed NDVI']",
  'Proj4': '+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs',
  'Datum': '',
  'EPSG': '',
  'Units': 'meters',
  'GridMapping': 'lambert_azimuthal_equal_area',
  'Available': True}]

Create a dictionary of projections with projection Name as the keys.

In [22]:
projs = {}                                  # Create an empty dictionary
for p in projections: projs[p['Name']] = p  # Fill dictionary with `Name` as keys
list(projs.keys())                          # Print dictionary keys
Out[22]:
['native',
 'geographic',
 'sinu_modis',
 'albers_weld_alaska',
 'albers_weld_conus',
 'albers_ard_alaska',
 'albers_ard_conus',
 'albers_ard_hawaii',
 'easegrid_2_global',
 'easegrid_2_north',
 'laea_sphere_19']
In [23]:
projs['geographic']
Out[23]:
{'Name': 'geographic',
 'Description': 'Geographic',
 'Platforms': "['SRTM', 'ECOSTRESS', 'SSEBop ET', 'GPW', 'ASTER GDEM', 'NASADEM']",
 'Proj4': '+proj=longlat +datum=WGS84 +no_defs',
 'Datum': 'wgs84',
 'EPSG': 4326.0,
 'Units': 'degrees',
 'GridMapping': 'latitude_longitude',
 'Available': True}

3c. Compile a JSON [Task Object]

In this section, begin by setting up the information needed to compile an acceptable json for submitting an AρρEEARS area request. For detailed information on required json parameters, see the API Documentation.

In [24]:
task_name = input('Enter a Task Name: ') # User-defined name of the task: 'NPS Vegetation Area' used in example
Enter a Task Name: NPS Vegetation Area
In [25]:
task_type = ['point','area']        # Type of task, area or point
proj = projs['geographic']['Name']  # Set output projection 
outFormat = ['geotiff', 'netcdf4']  # Set output file format type
startDate = '07-01-2017'            # Start of the date range for which to extract data: MM-DD-YYYY
endDate = '07-31-2017'              # End of the date range for which to extract data: MM-DD-YYYY
recurring = False                   # Specify True for a recurring date range
#yearRange = [2000,2016]            # if recurring = True, set yearRange, change start/end date to MM-DD

Below, compile the JSON to be submitted as an area request. Notice that nps_gc is inserted from the shapefile transformed to a json via the geopandas and json packages above in section 3a.

In [26]:
task = {
    'task_type': task_type[1],
    'task_name': task_name,
    'params': {
         'dates': [
         {
             'startDate': startDate,
             'endDate': endDate
         }],
         'layers': prodLayer,
         'output': {
                 'format': {
                         'type': outFormat[0]}, 
                         'projection': proj},
         'geo': nps_gc,
    }
}

3d. Submit a Task Request [Submit Task]

Below, post a call to the API task service, using the task json created above.

In [27]:
task_response = r.post('{}task'.format(api), json=task, headers=head).json()  # Post json to the API task service, return response as json
task_response                                                                 # Print task response
Out[27]:
{'task_id': '2c6e29a3-262a-448a-9887-ae0f5722282b', 'status': 'pending'}

3e. Retrieve Task Status [Retrieve Task]

This API call will list all of the requests associated with your user account, automatically sorted by date descending with the most recent requests listed first.

The AρρEEARS API contains some helpful formatting resources. Below, limit the API response to 2 entries and set pretty to True to format the response as an organized json, making it easier to read. Additional information on AρρEEARS API pagination and formatting can be found in the API documentation.

In [28]:
params = {'limit': 2, 'pretty': True} # Limit API response to 2 most recent entries, return as pretty json
In [29]:
tasks_response = r.get('{}task'.format(api), params=params, headers=head).json() # Query task service, setting params and header 
tasks_response                                                                   # Print tasks response
Out[29]:
[{'error': None,
  'params': {'dates': [{'endDate': '07-31-2017', 'startDate': '07-01-2017'}],
   'layers': [{'layer': 'LST_Day_1km', 'product': 'MOD11A2.006'},
    {'layer': 'LST_Night_1km', 'product': 'MOD11A2.006'},
    {'layer': 'Lai_500m', 'product': 'MCD15A3H.006'},
    {'layer': 'SRTMGL1_DEM', 'product': 'SRTMGL1_NC.003'}],
   'output': {'format': {'type': 'geotiff'}, 'projection': 'geographic'}},
  'status': 'processing',
  'created': '2020-04-28T18:45:14.197345',
  'task_id': '2c6e29a3-262a-448a-9887-ae0f5722282b',
  'updated': '2020-04-28T18:49:08.292185',
  'user_id': 'appeears.testing@gmail.com',
  'estimate': {'request_size': 196969757.51610887},
  'retry_at': None,
  'task_name': 'NPS Vegetation Area',
  'task_type': 'area',
  'api_version': 'v1',
  'svc_version': '2.39',
  'web_version': None,
  'expires_on': '2020-05-28T18:49:08.292185'},
 {'params': {'dates': [{'endDate': '12-31-2017', 'startDate': '01-01-2017'}],
   'layers': [{'layer': 'LST_Day_1km', 'product': 'MOD11A2.006'},
    {'layer': 'LST_Night_1km', 'product': 'MOD11A2.006'},
    {'layer': 'Lai_500m', 'product': 'MCD15A3H.006'}]},
  'status': 'pending',
  'created': '2020-04-28T18:27:32.969647',
  'task_id': '18f9e5ca-06a3-4ef2-8e66-2149ddc44d44',
  'updated': '2020-04-28T18:27:32.975751',
  'user_id': 'appeears.testing@gmail.com',
  'estimate': {'request_size': 272},
  'task_name': 'NPS Vegetation',
  'task_type': 'point',
  'api_version': 'v1',
  'svc_version': '2.39',
  'web_version': None,
  'expires_on': '2020-05-28T18:27:32.975751'}]

Next, take the task id returned from the task_response that was generated when submitting your request, and use the AρρEEARS API status service to check the status of your request.

In [30]:
task_id = task_response['task_id']                                               # Set task id from request submission
status_response = r.get('{}status/{}'.format(api, task_id), headers=head).json() # Call status service with specific task ID & user credentials
status_response                                                        
Out[30]:
{'task_id': '2c6e29a3-262a-448a-9887-ae0f5722282b',
 'updated': '2020-04-28T18:49:20.920000',
 'user_id': 'appeears.testing@gmail.com',
 'progress': {'details': [{'desc': 'Initializing',
    'step': 1,
    'pct_complete': 0},
   {'desc': 'Downloading', 'step': 2, 'pct_complete': 0},
   {'desc': 'Subsetting', 'step': 3, 'pct_complete': 0},
   {'desc': 'Generating Files', 'step': 4, 'pct_complete': 0},
   {'desc': 'Extracting Stats', 'step': 5, 'pct_complete': 0},
   {'desc': 'Finalizing', 'step': 6, 'pct_complete': 0}],
  'summary': 0},
 'status_id': 'e9623851-ef94-4f3d-bf5f-78b9ddb2f6a0',
 'status_type': 'task'}

Above, if your request is still processing, you can find information on the status of how close it is to completing.

Below, call the task service for your request every 20 seconds to check the status of your request.

In [31]:
# Ping API until request is complete, then continue to Section 4
starttime = time.time()
while r.get('{}task/{}'.format(api, task_id), headers=head).json()['status'] != 'done':
    print(r.get('{}task/{}'.format(api, task_id), headers=head).json()['status'])
    time.sleep(20.0 - ((time.time() - starttime) % 20.0))
print(r.get('{}task/{}'.format(api, task_id), headers=head).json()['status'])
processing
processing
processing
done

4. Download a Request [Bundle API]

Before downloading the request output, set up an output directory to store the output files, and examine the files contained in the request output.

In [32]:
destDir = os.path.join(inDir, task_name)                # Set up output directory using input directory and task name
if not os.path.exists(destDir):os.makedirs(destDir)     # Create the output directory

4a. Explore Files in Request Output [List Files]

The bundle API provides information about completed tasks. For any completed task, a bundle can be queried to return the files contained as a part of the task request. Below, call the bundle API and return all of the output files.

In [33]:
bundle = r.get('{}bundle/{}'.format(api,task_id)).json()  # Call API and return bundle contents for the task_id as json
bundle                                                    # Print bundle contents
Out[33]:
{'files': [{'sha256': '64287eaefa844410766f6400be442a220458cb06baa66afdf7c124861ada94de',
   'file_id': '74a65cb6-fbfe-4dd4-aee4-3d225757c08d',
   'file_name': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_Lai_500m_doy2017181_aid0001.tif',
   'file_size': 13511,
   'file_type': 'tif'},
  {'sha256': '61d98140d71b2bce3cccb6af6ebb150905651ac79f3918bcd4c6269aadc9dc81',
   'file_id': 'a73e01b9-05e9-4215-a3e2-b8917c8150fa',
   'file_name': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_Lai_500m_doy2017185_aid0001.tif',
   'file_size': 13430,
   'file_type': 'tif'},
  {'sha256': 'b3e2aefffc0b75c1211330cae71d6add77a0a49e4d66753450103e47a27336a4',
   'file_id': '07a27810-4739-47cf-a65f-c4d8254c320f',
   'file_name': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_Lai_500m_doy2017189_aid0001.tif',
   'file_size': 13706,
   'file_type': 'tif'},
  {'sha256': '10d92a1091f9bac168cd48a88762cd9a367a131d3f6a29b6200e944f27cd70ff',
   'file_id': '62af7444-f950-45ae-a907-c88e99716414',
   'file_name': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_Lai_500m_doy2017193_aid0001.tif',
   'file_size': 13955,
   'file_type': 'tif'},
  {'sha256': '1a19d2672c96065b50fdca9d5574df8ad1f514828425a36a6359d7d3eeaec9f2',
   'file_id': '122b0da6-8f01-48de-b6dd-62d3e627501e',
   'file_name': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_Lai_500m_doy2017197_aid0001.tif',
   'file_size': 14178,
   'file_type': 'tif'},
  {'sha256': 'b4b5dc4b5f9b64be93472987a99f988d97af8d879dd0ee5f5dc3ef818444a836',
   'file_id': '8ab4ae97-5e1d-4dcb-b60c-4f9600985964',
   'file_name': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_Lai_500m_doy2017201_aid0001.tif',
   'file_size': 14329,
   'file_type': 'tif'},
  {'sha256': '0bbb15476a2c6e47817b2e6d9a592bc853c2e96f3272dd6a439a3460e0b81595',
   'file_id': '4cb851b4-e2e6-49e2-9499-1a1adcb2367d',
   'file_name': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_Lai_500m_doy2017205_aid0001.tif',
   'file_size': 13389,
   'file_type': 'tif'},
  {'sha256': '1424981436bdbd39409f1b60224e9af6d2bea9d71363d69762025b17eeef9748',
   'file_id': '0186dead-163f-4b5e-b54d-87c8a924859e',
   'file_name': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_Lai_500m_doy2017209_aid0001.tif',
   'file_size': 13588,
   'file_type': 'tif'},
  {'sha256': '22de4f04c20daa5f5439f8d643f6f4ec6fd1a09e94ea05ce86d07ef25501d9fb',
   'file_id': 'b8fddf95-9fad-4386-884a-4780a37a47a3',
   'file_name': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparLai_QC_doy2017181_aid0001.tif',
   'file_size': 8956,
   'file_type': 'tif'},
  {'sha256': 'caa891a3dde1b8bb6917e219b1b810836a48b77a5a74f74b2357d5fea1d75c62',
   'file_id': '075375ac-0a15-4a68-86bd-5f4b9386c1e8',
   'file_name': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparLai_QC_doy2017185_aid0001.tif',
   'file_size': 9433,
   'file_type': 'tif'},
  {'sha256': 'dde9a9ba54a19e6c845fe04d6b7d92e29b984d56c2c2d916c857f1d18296e2dd',
   'file_id': '44739ec2-cc48-4825-8b47-b541f4330c29',
   'file_name': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparLai_QC_doy2017189_aid0001.tif',
   'file_size': 9524,
   'file_type': 'tif'},
  {'sha256': '029db95b2f22b7fbd3ff3894baf9ff0c46c906747af221ab00d48c6cdd49c4c7',
   'file_id': '23c07fca-45ed-43d8-8e78-e4ceca6d77b4',
   'file_name': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparLai_QC_doy2017193_aid0001.tif',
   'file_size': 9993,
   'file_type': 'tif'},
  {'sha256': '6cb158c6b69f0aa748b0922ec1841a4d5ac5d4a25a5035bca6bf7da0bced1d34',
   'file_id': '825b9a6e-b1bb-4137-a60b-ae4d20e8c188',
   'file_name': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparLai_QC_doy2017197_aid0001.tif',
   'file_size': 8684,
   'file_type': 'tif'},
  {'sha256': '7a6a46eedd41a3235fc6b6b9091152d0d65d3179ceec393e925193e5404e74c6',
   'file_id': 'd4d2bc11-8580-4d23-8d92-2e3f610656b5',
   'file_name': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparLai_QC_doy2017201_aid0001.tif',
   'file_size': 10744,
   'file_type': 'tif'},
  {'sha256': 'c6efb2040a0be927cd0d7e240f809b9ea0077d12fec2b0e30a172a6cf89d9155',
   'file_id': '8cdbde28-cd5a-4991-9313-7ed31b2481d9',
   'file_name': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparLai_QC_doy2017205_aid0001.tif',
   'file_size': 10342,
   'file_type': 'tif'},
  {'sha256': '426bc731e9429c83ce5a3a04e56afa0314c52832036e7af5d372fd382a4f2c66',
   'file_id': 'a9e363c1-d9c4-4ea0-a205-85d81db2c948',
   'file_name': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparLai_QC_doy2017209_aid0001.tif',
   'file_size': 11689,
   'file_type': 'tif'},
  {'sha256': 'a8b4b8ef72f1167f4f912a6eb35ba73ebc378dcddb142e28532c901972333edf',
   'file_id': '4475f3de-032b-48df-ae48-494fe62326f5',
   'file_name': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparExtra_QC_doy2017181_aid0001.tif',
   'file_size': 9149,
   'file_type': 'tif'},
  {'sha256': '2b289f7e9ecf8e9075a921b51fdbabb27fa80f833aeee504e4cd605bfbd57fab',
   'file_id': 'c07a86b1-6670-4a36-8a57-95d01391bbcc',
   'file_name': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparExtra_QC_doy2017185_aid0001.tif',
   'file_size': 10533,
   'file_type': 'tif'},
  {'sha256': '6415fb68fe8cce01a14901ee8a9ede48a7239020546bbd1b607048fd4baaa7e5',
   'file_id': '8218ca07-7976-4cee-af6e-5e4576e8bee1',
   'file_name': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparExtra_QC_doy2017189_aid0001.tif',
   'file_size': 10475,
   'file_type': 'tif'},
  {'sha256': 'e60135e4d001df83c57e6a3743fe35beae4e36460e224f4186ad6c64e1efea9c',
   'file_id': 'b1ac9d34-bb93-40ea-8361-e3354bd3e34d',
   'file_name': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparExtra_QC_doy2017193_aid0001.tif',
   'file_size': 11353,
   'file_type': 'tif'},
  {'sha256': '7f4acb8e977df1ea0cf2be060726dbd005f0b03b856292b5eaafc84db66013b4',
   'file_id': '39c1db9d-a106-4af3-8fb8-365990abd6a2',
   'file_name': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparExtra_QC_doy2017197_aid0001.tif',
   'file_size': 11255,
   'file_type': 'tif'},
  {'sha256': 'cda73704484ec7213e1f93bc4e1da20c2d50cae9821eb87e21100f5649ccb6cb',
   'file_id': '6a0511f8-5b79-4266-b996-77779b88ac16',
   'file_name': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparExtra_QC_doy2017201_aid0001.tif',
   'file_size': 12170,
   'file_type': 'tif'},
  {'sha256': 'f1de569a3c0c02236a77d8c846a84d5d55497b3059edaf46814c9a68867781de',
   'file_id': '3b43c3b5-ae62-4a13-8997-9023ceee6ebf',
   'file_name': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparExtra_QC_doy2017205_aid0001.tif',
   'file_size': 11735,
   'file_type': 'tif'},
  {'sha256': 'a38c4dc6ff873faf80e754e7e02126adb93df91ceff6f6988eaf0e54a64a4b6f',
   'file_id': '7f77015a-d3af-4835-a65e-9d270ca0cf25',
   'file_name': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparExtra_QC_doy2017209_aid0001.tif',
   'file_size': 12710,
   'file_type': 'tif'},
  {'sha256': 'a8d77aa17a0f6da39f16174213ff2603c57f466691960aaf126602373b5a52cb',
   'file_id': '3e2bb46a-be5e-4d9b-8761-a193dca0cadd',
   'file_name': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Day_1km_doy2017177_aid0001.tif',
   'file_size': 20481,
   'file_type': 'tif'},
  {'sha256': 'c965ee94a3bf626d82f2dfaf308b61b72115069fb23d0dfc62c0da2c66406a67',
   'file_id': 'd64b77da-862d-4760-bc8e-7befc6de4958',
   'file_name': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Day_1km_doy2017185_aid0001.tif',
   'file_size': 20664,
   'file_type': 'tif'},
  {'sha256': '036adcce40c04e2afe422644c8aaf203c983dcef2a9e36b7f0c056cd2dd58a93',
   'file_id': '992ba6bf-27e7-4837-b3a4-82fc6e01c9a5',
   'file_name': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Day_1km_doy2017193_aid0001.tif',
   'file_size': 20844,
   'file_type': 'tif'},
  {'sha256': '1dc336d1e26997fed6d1c4de3919107e75101ca2ff2e3ce18d635641e7419608',
   'file_id': '7b31f7f6-d240-4145-a0e4-31a419d3bd5a',
   'file_name': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Day_1km_doy2017201_aid0001.tif',
   'file_size': 20944,
   'file_type': 'tif'},
  {'sha256': '5cab6e321514c8f3add5c91b577dfacee06c3d13a063130075914f4f01c1ccc5',
   'file_id': 'a3b6e57d-3c5d-4ccc-b5a3-6fd6f463a9cb',
   'file_name': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Day_1km_doy2017209_aid0001.tif',
   'file_size': 20993,
   'file_type': 'tif'},
  {'sha256': '435cc1b72f0e96d751c3a19f16a04493dcb6b548286b2968ca316919f8812362',
   'file_id': 'f3fdc1d4-1b4e-4027-b528-138b195aee34',
   'file_name': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Night_1km_doy2017177_aid0001.tif',
   'file_size': 20758,
   'file_type': 'tif'},
  {'sha256': '1f8295096211e7751eb699e777437c5a201835fb5a6c2a7f6030491bdb06c57d',
   'file_id': '61474797-4137-4b41-ac88-3b56401d536d',
   'file_name': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Night_1km_doy2017185_aid0001.tif',
   'file_size': 20882,
   'file_type': 'tif'},
  {'sha256': '947fd577427e473844f0aa557c70043bb06f314a900a769e8981a5a2c437cd7b',
   'file_id': '9b5eb8fb-c72f-4dc3-919a-55cf0b8e0b7d',
   'file_name': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Night_1km_doy2017193_aid0001.tif',
   'file_size': 20832,
   'file_type': 'tif'},
  {'sha256': '1306d0da9645c8cd8e7629b37284d0646ce505d76a3254d1c5d99ae1f4d1b0ed',
   'file_id': 'b7f1f5bf-b8d2-447a-a0f9-7e98a1f8063e',
   'file_name': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Night_1km_doy2017201_aid0001.tif',
   'file_size': 20691,
   'file_type': 'tif'},
  {'sha256': 'c52d84bbff96920fe070c11fb46ad8c83f5bc75d15be5ec4330360a454e82afa',
   'file_id': '47438ee9-a71b-4773-9ddf-e6b359b2894a',
   'file_name': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Night_1km_doy2017209_aid0001.tif',
   'file_size': 20574,
   'file_type': 'tif'},
  {'sha256': '3442611d4b2370b3552e3561d3f8ded0c898bc61e246161a7f4b7c899fd22be2',
   'file_id': '9a5591bb-b8f6-45e3-ab0c-daaa473a898e',
   'file_name': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Day_doy2017177_aid0001.tif',
   'file_size': 2414,
   'file_type': 'tif'},
  {'sha256': '933a08c149f3873f6f6e0337398f5998492c8d52e0caf681c39374dcb276f153',
   'file_id': 'ed890c9b-3f5f-4100-bf61-6fb152c065a7',
   'file_name': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Day_doy2017185_aid0001.tif',
   'file_size': 2837,
   'file_type': 'tif'},
  {'sha256': '481f106913854fa7b6442fc19f705105971fe4f5392b6f01a72c67fd5557ab02',
   'file_id': '83db2acc-9f3e-4a40-ba7b-77c67713841f',
   'file_name': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Day_doy2017193_aid0001.tif',
   'file_size': 2538,
   'file_type': 'tif'},
  {'sha256': 'd33633c31aade5eb062a8150cf1bce026fc1f3ee6eb48010314649835027bfc3',
   'file_id': '0d1af98d-b766-473d-bc35-1195ebbcc105',
   'file_name': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Day_doy2017201_aid0001.tif',
   'file_size': 2894,
   'file_type': 'tif'},
  {'sha256': '89c21b49eb3c1d55ecf8af0b9054b6f37f34d02d70b54c802495e2f76ce79b0a',
   'file_id': 'ce8d303c-3734-48a9-8291-10bb82f1ef95',
   'file_name': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Day_doy2017209_aid0001.tif',
   'file_size': 2990,
   'file_type': 'tif'},
  {'sha256': '1455174185f312a01a56addfd1eed3983c10241311e7477653b6c49d2caf10c1',
   'file_id': 'bc6c66bc-eec1-4d9a-ad90-e83bdc64f066',
   'file_name': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Night_doy2017177_aid0001.tif',
   'file_size': 2192,
   'file_type': 'tif'},
  {'sha256': 'ac601e6891acf8251bd1353b3f84c910b16f4eb43fcbab3ad569e386356e1fa8',
   'file_id': 'c55b948c-5243-4701-98d5-66f08fbbf8bf',
   'file_name': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Night_doy2017185_aid0001.tif',
   'file_size': 2306,
   'file_type': 'tif'},
  {'sha256': '9dfbaef652adde3ec65160917fbe0ff67f9ea6b81c6909397fd1e09ba0e85ea0',
   'file_id': '1d2a866f-af29-40d0-9dd5-8893edef101f',
   'file_name': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Night_doy2017193_aid0001.tif',
   'file_size': 2728,
   'file_type': 'tif'},
  {'sha256': 'fe0759760c84a0594bf6c69f7a0b936cee6dda4334848ec6abaf816a62829563',
   'file_id': 'bb741985-9ea3-4597-9b57-b8d542c33800',
   'file_name': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Night_doy2017201_aid0001.tif',
   'file_size': 2772,
   'file_type': 'tif'},
  {'sha256': '7fa520c65985020ad1944da57b0d8d46df73e57d7fb8b9db4669e7409c10e761',
   'file_id': '7375ea13-074f-4bc7-87c0-0c39aed9053e',
   'file_name': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Night_doy2017209_aid0001.tif',
   'file_size': 2856,
   'file_type': 'tif'},
  {'sha256': '79d6acccd66f866c91a4cec862a6e558d927b1513185b64ce1e3cb482c17e4fd',
   'file_id': '566b500c-6278-4cc2-a8d1-f518636201ea',
   'file_name': 'SRTMGL1_NC.003_2000001_to_2020119/SRTMGL1_NC.003_SRTMGL1_DEM_doy2000042_aid0001.tif',
   'file_size': 13874330,
   'file_type': 'tif'},
  {'sha256': '0fa295c8992a799dc0b73247ad19b2c1e97bb18584fe0582f2216820b33877bd',
   'file_id': 'edef0905-7e14-47bf-be1c-4e2168f2685d',
   'file_name': 'SRTMGL1_NUMNC.003_2000001_to_2020119/SRTMGL1_NUMNC.003_SRTMGL1_NUM_doy2000042_aid0001.tif',
   'file_size': 2389821,
   'file_type': 'tif'},
  {'sha256': 'e62f9a6a8284ac1be7a2d1e07aa139727d90fa79149446abba6465c825dbf85e',
   'file_id': '64959e7c-d35c-4767-a825-242ec85391d5',
   'file_name': 'MCD15A3H-006-FparLai-QC-lookup.csv',
   'file_size': 3939,
   'file_type': 'csv'},
  {'sha256': '88e341b6839e1d85a41b615ef9c380f58f9883d91109ef192fce8690feb6673b',
   'file_id': '414f8021-3b47-4e13-a9c5-5507d7e4abe1',
   'file_name': 'MCD15A3H-006-FparExtra-QC-lookup.csv',
   'file_size': 4737,
   'file_type': 'csv'},
  {'sha256': 'f5ad5254fb2cd4e1c751bba66cb13d1ffa6bb699d9f24aa631caea95d844d8c6',
   'file_id': 'e2e89e54-b8a0-4568-943e-4f412dad696b',
   'file_name': 'MOD11A2-006-QC-Day-lookup.csv',
   'file_size': 516,
   'file_type': 'csv'},
  {'sha256': '84265a384dcc629d7e4d37b1b92c784c396bfdd8211d2b030b21840621dbf211',
   'file_id': '2346401f-29f5-4d9c-bf22-31ba578ab737',
   'file_name': 'MOD11A2-006-QC-Night-lookup.csv',
   'file_size': 631,
   'file_type': 'csv'},
  {'sha256': 'e712cb891b6844c15eeda5cad9912c60fc6fd6426a229356622ad11be2ab4f0f',
   'file_id': 'c3e3ed00-9366-4f65-b16d-b7ec9f4b243b',
   'file_name': 'SRTMGL1-NUMNC-003-SRTMGL1-NUM-lookup.csv',
   'file_size': 1542,
   'file_type': 'csv'},
  {'sha256': '595588d38b6ebb1383080eb0b20f1f244b8516f5b8c33daf9d7d430186cf1d59',
   'file_id': 'daa4de51-259d-401e-bad8-0539e6c34abf',
   'file_name': 'MCD15A3H-006-FparLai-QC-Statistics-QA.csv',
   'file_size': 912,
   'file_type': 'csv'},
  {'sha256': '4ce4394c42ecdfda48d0621645f9c1cec93f69e244c9a82118e22c26b114383c',
   'file_id': '9b6ce8ee-a5df-45c3-945d-cf6ea887fdea',
   'file_name': 'MCD15A3H-006-FparExtra-QC-Statistics-QA.csv',
   'file_size': 1093,
   'file_type': 'csv'},
  {'sha256': 'df22a5f731d3b8ebc839d9127c6ae858f28ce9108ff0b22ca2a82f433f4400aa',
   'file_id': '6503b05d-461c-4f40-a94b-a73846533714',
   'file_name': 'MOD11A2-006-QC-Day-Statistics-QA.csv',
   'file_size': 305,
   'file_type': 'csv'},
  {'sha256': '305ff2e43ea91991a7d7d6fe43c8e2870ddad64ba42be2e794cce9b935fea923',
   'file_id': '9ab88bd2-4764-46d5-a16a-c74e21e85596',
   'file_name': 'MOD11A2-006-QC-Night-Statistics-QA.csv',
   'file_size': 328,
   'file_type': 'csv'},
  {'sha256': 'aef8909e6c8b117bfcf715f4904939caf4317ba39ea9a8a6573d76934eb451b6',
   'file_id': 'c446cdc6-26fc-4c10-b851-019d018c3246',
   'file_name': 'SRTMGL1-NUMNC-003-SRTMGL1-NUM-Statistics-QA.csv',
   'file_size': 552,
   'file_type': 'csv'},
  {'sha256': 'd88970a8a643e1fcae65ae1e5640d585795a385b68fc3336e131ba3b721bfe93',
   'file_id': 'fe1f62bd-9590-4c95-a704-afe8c4dcfa24',
   'file_name': 'MCD15A3H-006-Statistics.csv',
   'file_size': 1251,
   'file_type': 'csv'},
  {'sha256': 'b807d7efdfb6f572c1daeac9b7b70a49ac2aae96d551eba61eea0a8309c56e6c',
   'file_id': '53f8414a-2815-4302-92b1-f486398f851a',
   'file_name': 'MOD11A2-006-Statistics.csv',
   'file_size': 1860,
   'file_type': 'csv'},
  {'sha256': '8575912cdf419539b0c6263888e074faf9f43aa4213df0dcf7578a8d208cd7bd',
   'file_id': 'b7fc8225-274e-414f-9d4d-6ef671f225bd',
   'file_name': 'SRTMGL1-NC-003-Statistics.csv',
   'file_size': 335,
   'file_type': 'csv'},
  {'sha256': '1db1f9792ba045db344656a65a54afe1349e94714be7e1e10216147ff3da7c2e',
   'file_id': '06950fc0-f8b7-48f4-b0d6-f704bbe97b6e',
   'file_name': 'NPS-Vegetation-Area-granule-list.txt',
   'file_size': 4574,
   'file_type': 'txt'},
  {'sha256': 'a518aa3cba8a88c2cec093869ae373e1699d8e523805b0a20dfb2d294c0546ee',
   'file_id': '830bff87-ff48-478f-9937-5da204c02ca7',
   'file_name': 'NPS-Vegetation-Area-request.json',
   'file_size': 13614045,
   'file_type': 'json'},
  {'sha256': '66079538a89f8d5236f7a00514facacf48bc07536125f8e31331d14316938ba2',
   'file_id': '2f653148-fc7d-4bb1-9402-f18e9392c5e2',
   'file_name': 'NPS-Vegetation-Area-MCD15A3H-006-metadata.xml',
   'file_size': 22169,
   'file_type': 'xml'},
  {'sha256': 'c174e8165646131933719d2e0308399dde77102b9ff4dd269cbd500d3b887eb0',
   'file_id': '8f0be1d3-880d-4709-acd9-5141b3839246',
   'file_name': 'NPS-Vegetation-Area-MOD11A2-006-metadata.xml',
   'file_size': 22133,
   'file_type': 'xml'},
  {'sha256': 'd86e28f1a3105f71302ddeba5ff75e72f21812e51cae9f872597b7c8dd3d9e5b',
   'file_id': '04a0e3fe-01f3-448c-b3ef-c0276b588946',
   'file_name': 'NPS-Vegetation-Area-SRTMGL1-NC-003-metadata.xml',
   'file_size': 22085,
   'file_type': 'xml'},
  {'sha256': '34e426464fff07c719f144d33291cd3894673775f0c38b0486ffffaabb99ce72',
   'file_id': '99ed43f8-916d-49af-897e-1abcddc6b67b',
   'file_name': 'README.txt',
   'file_size': 25013,
   'file_type': 'txt'}],
 'created': '2020-04-28T18:49:52.000065',
 'task_id': '2c6e29a3-262a-448a-9887-ae0f5722282b',
 'updated': '2020-04-28T18:51:28.428289',
 'bundle_type': 'area'}

4b. Download Files in a Request (Automation) [Download File]

Now, use the contents of the bundle to select the file name and id and store as a dictionary.

In [34]:
files = {}                                                       # Create empty dictionary
for f in bundle['files']: files[f['file_id']] = f['file_name']   # Fill dictionary with file_id as keys and file_name as values
files    
Out[34]:
{'74a65cb6-fbfe-4dd4-aee4-3d225757c08d': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_Lai_500m_doy2017181_aid0001.tif',
 'a73e01b9-05e9-4215-a3e2-b8917c8150fa': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_Lai_500m_doy2017185_aid0001.tif',
 '07a27810-4739-47cf-a65f-c4d8254c320f': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_Lai_500m_doy2017189_aid0001.tif',
 '62af7444-f950-45ae-a907-c88e99716414': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_Lai_500m_doy2017193_aid0001.tif',
 '122b0da6-8f01-48de-b6dd-62d3e627501e': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_Lai_500m_doy2017197_aid0001.tif',
 '8ab4ae97-5e1d-4dcb-b60c-4f9600985964': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_Lai_500m_doy2017201_aid0001.tif',
 '4cb851b4-e2e6-49e2-9499-1a1adcb2367d': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_Lai_500m_doy2017205_aid0001.tif',
 '0186dead-163f-4b5e-b54d-87c8a924859e': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_Lai_500m_doy2017209_aid0001.tif',
 'b8fddf95-9fad-4386-884a-4780a37a47a3': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparLai_QC_doy2017181_aid0001.tif',
 '075375ac-0a15-4a68-86bd-5f4b9386c1e8': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparLai_QC_doy2017185_aid0001.tif',
 '44739ec2-cc48-4825-8b47-b541f4330c29': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparLai_QC_doy2017189_aid0001.tif',
 '23c07fca-45ed-43d8-8e78-e4ceca6d77b4': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparLai_QC_doy2017193_aid0001.tif',
 '825b9a6e-b1bb-4137-a60b-ae4d20e8c188': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparLai_QC_doy2017197_aid0001.tif',
 'd4d2bc11-8580-4d23-8d92-2e3f610656b5': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparLai_QC_doy2017201_aid0001.tif',
 '8cdbde28-cd5a-4991-9313-7ed31b2481d9': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparLai_QC_doy2017205_aid0001.tif',
 'a9e363c1-d9c4-4ea0-a205-85d81db2c948': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparLai_QC_doy2017209_aid0001.tif',
 '4475f3de-032b-48df-ae48-494fe62326f5': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparExtra_QC_doy2017181_aid0001.tif',
 'c07a86b1-6670-4a36-8a57-95d01391bbcc': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparExtra_QC_doy2017185_aid0001.tif',
 '8218ca07-7976-4cee-af6e-5e4576e8bee1': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparExtra_QC_doy2017189_aid0001.tif',
 'b1ac9d34-bb93-40ea-8361-e3354bd3e34d': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparExtra_QC_doy2017193_aid0001.tif',
 '39c1db9d-a106-4af3-8fb8-365990abd6a2': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparExtra_QC_doy2017197_aid0001.tif',
 '6a0511f8-5b79-4266-b996-77779b88ac16': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparExtra_QC_doy2017201_aid0001.tif',
 '3b43c3b5-ae62-4a13-8997-9023ceee6ebf': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparExtra_QC_doy2017205_aid0001.tif',
 '7f77015a-d3af-4835-a65e-9d270ca0cf25': 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparExtra_QC_doy2017209_aid0001.tif',
 '3e2bb46a-be5e-4d9b-8761-a193dca0cadd': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Day_1km_doy2017177_aid0001.tif',
 'd64b77da-862d-4760-bc8e-7befc6de4958': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Day_1km_doy2017185_aid0001.tif',
 '992ba6bf-27e7-4837-b3a4-82fc6e01c9a5': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Day_1km_doy2017193_aid0001.tif',
 '7b31f7f6-d240-4145-a0e4-31a419d3bd5a': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Day_1km_doy2017201_aid0001.tif',
 'a3b6e57d-3c5d-4ccc-b5a3-6fd6f463a9cb': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Day_1km_doy2017209_aid0001.tif',
 'f3fdc1d4-1b4e-4027-b528-138b195aee34': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Night_1km_doy2017177_aid0001.tif',
 '61474797-4137-4b41-ac88-3b56401d536d': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Night_1km_doy2017185_aid0001.tif',
 '9b5eb8fb-c72f-4dc3-919a-55cf0b8e0b7d': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Night_1km_doy2017193_aid0001.tif',
 'b7f1f5bf-b8d2-447a-a0f9-7e98a1f8063e': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Night_1km_doy2017201_aid0001.tif',
 '47438ee9-a71b-4773-9ddf-e6b359b2894a': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Night_1km_doy2017209_aid0001.tif',
 '9a5591bb-b8f6-45e3-ab0c-daaa473a898e': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Day_doy2017177_aid0001.tif',
 'ed890c9b-3f5f-4100-bf61-6fb152c065a7': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Day_doy2017185_aid0001.tif',
 '83db2acc-9f3e-4a40-ba7b-77c67713841f': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Day_doy2017193_aid0001.tif',
 '0d1af98d-b766-473d-bc35-1195ebbcc105': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Day_doy2017201_aid0001.tif',
 'ce8d303c-3734-48a9-8291-10bb82f1ef95': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Day_doy2017209_aid0001.tif',
 'bc6c66bc-eec1-4d9a-ad90-e83bdc64f066': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Night_doy2017177_aid0001.tif',
 'c55b948c-5243-4701-98d5-66f08fbbf8bf': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Night_doy2017185_aid0001.tif',
 '1d2a866f-af29-40d0-9dd5-8893edef101f': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Night_doy2017193_aid0001.tif',
 'bb741985-9ea3-4597-9b57-b8d542c33800': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Night_doy2017201_aid0001.tif',
 '7375ea13-074f-4bc7-87c0-0c39aed9053e': 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Night_doy2017209_aid0001.tif',
 '566b500c-6278-4cc2-a8d1-f518636201ea': 'SRTMGL1_NC.003_2000001_to_2020119/SRTMGL1_NC.003_SRTMGL1_DEM_doy2000042_aid0001.tif',
 'edef0905-7e14-47bf-be1c-4e2168f2685d': 'SRTMGL1_NUMNC.003_2000001_to_2020119/SRTMGL1_NUMNC.003_SRTMGL1_NUM_doy2000042_aid0001.tif',
 '64959e7c-d35c-4767-a825-242ec85391d5': 'MCD15A3H-006-FparLai-QC-lookup.csv',
 '414f8021-3b47-4e13-a9c5-5507d7e4abe1': 'MCD15A3H-006-FparExtra-QC-lookup.csv',
 'e2e89e54-b8a0-4568-943e-4f412dad696b': 'MOD11A2-006-QC-Day-lookup.csv',
 '2346401f-29f5-4d9c-bf22-31ba578ab737': 'MOD11A2-006-QC-Night-lookup.csv',
 'c3e3ed00-9366-4f65-b16d-b7ec9f4b243b': 'SRTMGL1-NUMNC-003-SRTMGL1-NUM-lookup.csv',
 'daa4de51-259d-401e-bad8-0539e6c34abf': 'MCD15A3H-006-FparLai-QC-Statistics-QA.csv',
 '9b6ce8ee-a5df-45c3-945d-cf6ea887fdea': 'MCD15A3H-006-FparExtra-QC-Statistics-QA.csv',
 '6503b05d-461c-4f40-a94b-a73846533714': 'MOD11A2-006-QC-Day-Statistics-QA.csv',
 '9ab88bd2-4764-46d5-a16a-c74e21e85596': 'MOD11A2-006-QC-Night-Statistics-QA.csv',
 'c446cdc6-26fc-4c10-b851-019d018c3246': 'SRTMGL1-NUMNC-003-SRTMGL1-NUM-Statistics-QA.csv',
 'fe1f62bd-9590-4c95-a704-afe8c4dcfa24': 'MCD15A3H-006-Statistics.csv',
 '53f8414a-2815-4302-92b1-f486398f851a': 'MOD11A2-006-Statistics.csv',
 'b7fc8225-274e-414f-9d4d-6ef671f225bd': 'SRTMGL1-NC-003-Statistics.csv',
 '06950fc0-f8b7-48f4-b0d6-f704bbe97b6e': 'NPS-Vegetation-Area-granule-list.txt',
 '830bff87-ff48-478f-9937-5da204c02ca7': 'NPS-Vegetation-Area-request.json',
 '2f653148-fc7d-4bb1-9402-f18e9392c5e2': 'NPS-Vegetation-Area-MCD15A3H-006-metadata.xml',
 '8f0be1d3-880d-4709-acd9-5141b3839246': 'NPS-Vegetation-Area-MOD11A2-006-metadata.xml',
 '04a0e3fe-01f3-448c-b3ef-c0276b588946': 'NPS-Vegetation-Area-SRTMGL1-NC-003-metadata.xml',
 '99ed43f8-916d-49af-897e-1abcddc6b67b': 'README.txt'}

Use the files dictionary and a for loop to automate downloading all of the output files into the output directory.

In [35]:
for f in files:
    dl = r.get('{}bundle/{}/{}'.format(api, task_id, f), stream=True)                                # Get a stream to the bundle file
    filename = os.path.basename(cgi.parse_header(dl.headers['Content-Disposition'])[1]['filename'])  # Parse the name from Content-Disposition header 
    filepath = os.path.join(destDir, filename)                                                       # Create output file path
    with open(filepath, 'wb') as f:                                                                  # Write file to dest dir
        for data in dl.iter_content(chunk_size=8192): f.write(data) 
print('Downloaded files can be found at: {}'.format(destDir))
Downloaded files can be found at: D:/appeears-api-getting-started/NPS Vegetation Area

5. Explore AρρEEARS Quality Service [Quality API]

The quality API provides quality details about all of the data products available in AρρEEARS. Below are examples of how to query the quality API for listing quality products, layers, and values. The final example (Section 5c.) demonstrates how AρρEEARS quality services can be leveraged to decode pertinent quality values for your data.

First, reset pagination to include offset which allows you to set the number of results to skip before starting to return entries. Next, make a call to list all of the data product layers and the associated quality product and layer information.

In [36]:
params = {'limit': 6, 'pretty': True, 'offset': 20}                     # Limit response to 6 entries, start w/ 20th entry, return pretty json
quality_response = r.get('{}quality'.format(api), params=params).json() # Call quality API using pagination and return json
quality_response                                                        # Print response
Out[36]:
[{'ProductAndVersion': 'CU_LT05.001',
  'Layer': 'SRB1',
  'QualityProductAndVersion': 'CU_LT05.001',
  'QualityLayers': ['PIXELQA']},
 {'ProductAndVersion': 'CU_LT05.001',
  'Layer': 'SRB2',
  'QualityProductAndVersion': 'CU_LT05.001',
  'QualityLayers': ['PIXELQA']},
 {'ProductAndVersion': 'CU_LT05.001',
  'Layer': 'SRB3',
  'QualityProductAndVersion': 'CU_LT05.001',
  'QualityLayers': ['PIXELQA']},
 {'ProductAndVersion': 'CU_LT05.001',
  'Layer': 'SRB4',
  'QualityProductAndVersion': 'CU_LT05.001',
  'QualityLayers': ['PIXELQA']},
 {'ProductAndVersion': 'CU_LT05.001',
  'Layer': 'SRB5',
  'QualityProductAndVersion': 'CU_LT05.001',
  'QualityLayers': ['PIXELQA']},
 {'ProductAndVersion': 'CU_LT05.001',
  'Layer': 'SRB7',
  'QualityProductAndVersion': 'CU_LT05.001',
  'QualityLayers': ['PIXELQA']}]

5a. List Quality Layers [List Quality Layers]

This API call will list all of the quality layer information for a product.

In [37]:
product = 'MCD15A3H.006'                                        # Product used in the example
ql_response = r.get('{}quality/{}'.format(api,product)).json()  # Call API to retrieve quality layers for selected product
ql_response                                                     # Print response
Out[37]:
[{'ProductAndVersion': 'MCD15A3H.006',
  'Layer': 'Fpar_500m',
  'QualityProductAndVersion': 'MCD15A3H.006',
  'QualityLayers': ['FparLai_QC', 'FparExtra_QC']},
 {'ProductAndVersion': 'MCD15A3H.006',
  'Layer': 'FparStdDev_500m',
  'QualityProductAndVersion': 'MCD15A3H.006',
  'QualityLayers': ['FparLai_QC', 'FparExtra_QC']},
 {'ProductAndVersion': 'MCD15A3H.006',
  'Layer': 'Lai_500m',
  'QualityProductAndVersion': 'MCD15A3H.006',
  'QualityLayers': ['FparLai_QC', 'FparExtra_QC']},
 {'ProductAndVersion': 'MCD15A3H.006',
  'Layer': 'LaiStdDev_500m',
  'QualityProductAndVersion': 'MCD15A3H.006',
  'QualityLayers': ['FparLai_QC', 'FparExtra_QC']}]

5b. Show Quality Values [List Quality Values]

This API call will list all of the values for a given quality layer.

In [38]:
qlayer = ql_response[1]['QualityLayers'][0]                                # Set quality layer from ql_response for 'Lai_500m'
qv_response = r.get('{}quality/{}/{}'.format(api, product, qlayer)).json() # Call API for list of bit-word quality values
qv_response                                                                # Print response
Out[38]:
[{'ProductAndVersion': 'MCD15A3H.006',
  'QualityLayer': 'FparLai_QC',
  'Name': 'MODLAND',
  'Value': 0,
  'Description': 'Good quality (main algorithm with or without saturation)',
  'Acceptable': True},
 {'ProductAndVersion': 'MCD15A3H.006',
  'QualityLayer': 'FparLai_QC',
  'Name': 'MODLAND',
  'Value': 1,
  'Description': 'Other Quality (back-up algorithm or fill values)',
  'Acceptable': False},
 {'ProductAndVersion': 'MCD15A3H.006',
  'QualityLayer': 'FparLai_QC',
  'Name': 'Sensor',
  'Value': 0,
  'Description': 'Terra',
  'Acceptable': None},
 {'ProductAndVersion': 'MCD15A3H.006',
  'QualityLayer': 'FparLai_QC',
  'Name': 'Sensor',
  'Value': 1,
  'Description': 'Aqua',
  'Acceptable': None},
 {'ProductAndVersion': 'MCD15A3H.006',
  'QualityLayer': 'FparLai_QC',
  'Name': 'DeadDetector',
  'Value': 0,
  'Description': 'Detectors apparently fine for up to 50% of channels 1, 2',
  'Acceptable': None},
 {'ProductAndVersion': 'MCD15A3H.006',
  'QualityLayer': 'FparLai_QC',
  'Name': 'DeadDetector',
  'Value': 1,
  'Description': 'Dead detectors caused >50% adjacent detector retrieval',
  'Acceptable': None},
 {'ProductAndVersion': 'MCD15A3H.006',
  'QualityLayer': 'FparLai_QC',
  'Name': 'CloudState',
  'Value': 0,
  'Description': 'Significant clouds NOT present (clear)',
  'Acceptable': None},
 {'ProductAndVersion': 'MCD15A3H.006',
  'QualityLayer': 'FparLai_QC',
  'Name': 'CloudState',
  'Value': 1,
  'Description': 'Significant clouds WERE present',
  'Acceptable': None},
 {'ProductAndVersion': 'MCD15A3H.006',
  'QualityLayer': 'FparLai_QC',
  'Name': 'CloudState',
  'Value': 2,
  'Description': 'Mixed cloud present in pixel',
  'Acceptable': None},
 {'ProductAndVersion': 'MCD15A3H.006',
  'QualityLayer': 'FparLai_QC',
  'Name': 'CloudState',
  'Value': 3,
  'Description': 'Cloud state not defined, assumed clear',
  'Acceptable': None},
 {'ProductAndVersion': 'MCD15A3H.006',
  'QualityLayer': 'FparLai_QC',
  'Name': 'SCF_QC',
  'Value': 0,
  'Description': 'Main (RT) method used, best result possible (no saturation)',
  'Acceptable': None},
 {'ProductAndVersion': 'MCD15A3H.006',
  'QualityLayer': 'FparLai_QC',
  'Name': 'SCF_QC',
  'Value': 1,
  'Description': 'Main (RT) method used with saturation. Good, very usable',
  'Acceptable': None},
 {'ProductAndVersion': 'MCD15A3H.006',
  'QualityLayer': 'FparLai_QC',
  'Name': 'SCF_QC',
  'Value': 2,
  'Description': 'Main (RT) method failed due to bad geometry, empirical algorithm used',
  'Acceptable': None},
 {'ProductAndVersion': 'MCD15A3H.006',
  'QualityLayer': 'FparLai_QC',
  'Name': 'SCF_QC',
  'Value': 3,
  'Description': 'Main (RT) method failed due to problems other than geometry, empirical algorithm used',
  'Acceptable': None},
 {'ProductAndVersion': 'MCD15A3H.006',
  'QualityLayer': 'FparLai_QC',
  'Name': 'SCF_QC',
  'Value': 4,
  'Description': "Pixel not produced at all, value couldn't be retrieved (possible reasons: bad L1B data, unusable MOD09GA data)",
  'Acceptable': None}]

5c. Decode Quality Values [Decode Quality Values]

This API call will decode the bits for a given quality value.

In [39]:
val = 1                                                                            # Set a specific value
q_response = r.get('{}quality/{}/{}/{}'.format(api, product, qlayer, val)).json()  # Call quality API for specific value
q_response                                                                         # Print response
Out[39]:
{'Binary Representation': '0b00000001',
 'MODLAND': {'bits': '0b1',
  'description': 'Other Quality (back-up algorithm or fill values)'},
 'Sensor': {'bits': '0b0', 'description': 'Terra'},
 'DeadDetector': {'bits': '0b0',
  'description': 'Detectors apparently fine for up to 50% of channels 1, 2'},
 'CloudState': {'bits': '0b00',
  'description': 'Significant clouds NOT present (clear)'},
 'SCF_QC': {'bits': '0b000',
  'description': 'Main (RT) method used, best result possible (no saturation)'}}

6. BONUS: Import Request Output and Visualize

Here, import one of the output GeoTIFFs and show some basic visualizations using the matplotlib package.

In [40]:
# Import packages
import matplotlib.pyplot as plt
import numpy as np
from osgeo import gdal
list(files.values())  # List files downloaded
Out[40]:
['MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_Lai_500m_doy2017181_aid0001.tif',
 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_Lai_500m_doy2017185_aid0001.tif',
 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_Lai_500m_doy2017189_aid0001.tif',
 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_Lai_500m_doy2017193_aid0001.tif',
 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_Lai_500m_doy2017197_aid0001.tif',
 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_Lai_500m_doy2017201_aid0001.tif',
 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_Lai_500m_doy2017205_aid0001.tif',
 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_Lai_500m_doy2017209_aid0001.tif',
 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparLai_QC_doy2017181_aid0001.tif',
 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparLai_QC_doy2017185_aid0001.tif',
 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparLai_QC_doy2017189_aid0001.tif',
 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparLai_QC_doy2017193_aid0001.tif',
 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparLai_QC_doy2017197_aid0001.tif',
 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparLai_QC_doy2017201_aid0001.tif',
 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparLai_QC_doy2017205_aid0001.tif',
 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparLai_QC_doy2017209_aid0001.tif',
 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparExtra_QC_doy2017181_aid0001.tif',
 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparExtra_QC_doy2017185_aid0001.tif',
 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparExtra_QC_doy2017189_aid0001.tif',
 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparExtra_QC_doy2017193_aid0001.tif',
 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparExtra_QC_doy2017197_aid0001.tif',
 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparExtra_QC_doy2017201_aid0001.tif',
 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparExtra_QC_doy2017205_aid0001.tif',
 'MCD15A3H.006_2017179_to_2017212/MCD15A3H.006_FparExtra_QC_doy2017209_aid0001.tif',
 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Day_1km_doy2017177_aid0001.tif',
 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Day_1km_doy2017185_aid0001.tif',
 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Day_1km_doy2017193_aid0001.tif',
 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Day_1km_doy2017201_aid0001.tif',
 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Day_1km_doy2017209_aid0001.tif',
 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Night_1km_doy2017177_aid0001.tif',
 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Night_1km_doy2017185_aid0001.tif',
 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Night_1km_doy2017193_aid0001.tif',
 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Night_1km_doy2017201_aid0001.tif',
 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_LST_Night_1km_doy2017209_aid0001.tif',
 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Day_doy2017177_aid0001.tif',
 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Day_doy2017185_aid0001.tif',
 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Day_doy2017193_aid0001.tif',
 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Day_doy2017201_aid0001.tif',
 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Day_doy2017209_aid0001.tif',
 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Night_doy2017177_aid0001.tif',
 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Night_doy2017185_aid0001.tif',
 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Night_doy2017193_aid0001.tif',
 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Night_doy2017201_aid0001.tif',
 'MOD11A2.006_2017175_to_2017212/MOD11A2.006_QC_Night_doy2017209_aid0001.tif',
 'SRTMGL1_NC.003_2000001_to_2020119/SRTMGL1_NC.003_SRTMGL1_DEM_doy2000042_aid0001.tif',
 'SRTMGL1_NUMNC.003_2000001_to_2020119/SRTMGL1_NUMNC.003_SRTMGL1_NUM_doy2000042_aid0001.tif',
 'MCD15A3H-006-FparLai-QC-lookup.csv',
 'MCD15A3H-006-FparExtra-QC-lookup.csv',
 'MOD11A2-006-QC-Day-lookup.csv',
 'MOD11A2-006-QC-Night-lookup.csv',
 'SRTMGL1-NUMNC-003-SRTMGL1-NUM-lookup.csv',
 'MCD15A3H-006-FparLai-QC-Statistics-QA.csv',
 'MCD15A3H-006-FparExtra-QC-Statistics-QA.csv',
 'MOD11A2-006-QC-Day-Statistics-QA.csv',
 'MOD11A2-006-QC-Night-Statistics-QA.csv',
 'SRTMGL1-NUMNC-003-SRTMGL1-NUM-Statistics-QA.csv',
 'MCD15A3H-006-Statistics.csv',
 'MOD11A2-006-Statistics.csv',
 'SRTMGL1-NC-003-Statistics.csv',
 'NPS-Vegetation-Area-granule-list.txt',
 'NPS-Vegetation-Area-request.json',
 'NPS-Vegetation-Area-MCD15A3H-006-metadata.xml',
 'NPS-Vegetation-Area-MOD11A2-006-metadata.xml',
 'NPS-Vegetation-Area-SRTMGL1-NC-003-metadata.xml',
 'README.txt']

6a. Import a GeoTIFF

To perform the next step below, you will need to have GDAL installed on your OS. Open the GeoTIFF file for the SRTM DEM, and read in as an array.

In [41]:
dem = gdal.Open(destDir + '/SRTMGL1_NC.003_SRTMGL1_DEM_doy2000042_aid0001.tif' ) # Read file in
demBand = dem.GetRasterBand(1)                                          # Read the band (layer)
demData = demBand.ReadAsArray().astype('float')                         # Import band as an array with type float

Next, query the metadata for the fill value, and set fill value equal to nan.

In [42]:
demFill = demBand.GetNoDataValue()            # Returns fill value
demData[demData == demFill] = np.nan          # Set fill value to nan

6b. Plot a GeoTIFF

In this section, begin by highlighting the functionality of the matplotlib plotting package.

In [43]:
# Set matplotlib plots inline
%matplotlib inline 

First, make a basic plot of the DEM data.

In [44]:
plt.imshow(demData);  # Visualize a basic plot of the DEM data

Next, add some additional parameters to the plot.

In [47]:
import warnings
warnings.filterwarnings("ignore")

fig = plt.figure(figsize = (10,7.5))  # Set the figure size (x,y)
plt.axis('off')                       # Remove the axes' values
ax = fig.add_subplot(111)             

# Plot the array, using a colormap and setting a custom linear stretch based on the min/max Elevation values
plt.imshow(demData, vmin = np.nanmin(demData), vmax = np.nanmax(demData), cmap = 'terrain');

Finally, add important map items including a legend and title.

In [48]:
plt.style.use("dark_background")                                                       # Default to a black background
fig2 = plt.figure(figsize=(10,7.5))                                                    # Set the figure size
plt.axis('off')                                                                        # Remove the axes' values
ax1 = fig2.add_subplot(111)                                                            # Make a subplot
fig2.subplots_adjust(top=3.8)                                                          # Adjust spacing
ax1.set_title('SRTM DEM: Grand Canyon NP',fontsize=15,fontweight='bold',color='white') # Add title

# Plot the masked data, using a colormap and setting a custom linear stretch based on the min/max DEM values
im = plt.imshow(demData, vmin = np.nanmin(demData), vmax = np.nanmax(demData), cmap = 'terrain');

cb = plt.colorbar(im, orientation='horizontal', fraction=0.047, pad=0.004, shrink=0.6) # Add a colormap legend
cb.set_label(label='Elevation (m)', color = 'white')                                   # Set Label and color
cb.outline.set_edgecolor('white')                                                      # Set edge color

This example can provide a template to use for your own research workflows. Leveraging the AρρEEARS API for searching, extracting, and formatting analysis ready data, and importing it directly into Python means that you can keep your entire research workflow in a single software program, from start to finish.


Contact Information

Material written by Cole Krehbiel$^{1}$

Contact: LPDAAC@usgs.gov

Voice: +1-605-594-6116

Organization: Land Processes Distributed Active Archive Center (LP DAAC)

Website: https://lpdaac.usgs.gov/

Date last modified: 04-28-2020

$^{1}$Innovate! Inc., contractor to the U.S. Geological Survey, Earth Resources Observation and Science (EROS) Center, Sioux Falls, South Dakota, 57198-001, USA. Work performed under USGS contract G15PD00467 for LP DAAC$^{2}$.

$^{2}$LP DAAC Work performed under NASA contract NNG14HH33I.