Published: April 28, 2020
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.
Connect to the AρρEEARS API, query the list of available products, submit a point sample request, download the request, become familiar with the AρρEEARS Quality API, and import the results into Python for visualization. AρρEEARS point requests allow users to subset their desired data using latitude/longitude geographic coordinate pairs (points) for a time period of interest, and for specific data layers within data products. AρρEEARS returns the valid data from the parameters defined within the sample request.
To access AρρEEARS, visit: https://appeears.earthdatacloud.nasa.gov/
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.
# Import packages
import requests as r
import getpass, pprint, time, os, cgi
# 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://appeears.earthdatacloud.nasa.gov/api/' # Set the AρρEEARS API to a variable
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.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: ········
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.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
{'token_type': 'Bearer',
'token': '0EEkLrwSofg86GfSu3Zm2bNgb-x1-TRDQkRBn2B3qA0_CK2dNB3jbk6EkgST6SWapwNNhJvnJ9J2en4yFKfQ3g',
'expiration': '2022-05-06T19:29:39Z'}
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 AρρEEARS
AρρEEARS currently supports 155 products.
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
{'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'}
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/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/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/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'}
{'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'}
MCD15A3H.006
.prods = ['MCD15A3H.006'] # Start a list for products to be requested, beginning with MCD15A3H.006
prods.append('MOD11A2.061') # Append MOD11A2.061 8 day LST product to the list of products desired
prods
['MCD15A3H.006', 'MOD11A2.061']
ProductAndVersion
property. For a list of the layer names only, print the keys from the dictionary below.lst_response = r.get('{}product/{}'.format(api, prods[1])).json() # Request layers for the 2nd product (index 1) in the list: MOD11A2.061
list(lst_response.keys())
['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']
'LST_Day_1km'
to see the information for that layer in the response.lst_response['LST_Day_1km'] # Print layer response
{'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.061',
'ScaleFactor': 0.02,
'Units': 'Kelvin',
'ValidMax': 1310.699951,
'ValidMin': 150.0,
'XSize': 1200,
'YSize': 1200}
layers = [(prods[1],'LST_Day_1km'),(prods[1],'LST_Night_1km')] # Create tupled list linking desired product with desired layers
MCD15A3H.006
product.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
['FparExtra_QC',
'FparLai_QC',
'FparStdDev_500m',
'Fpar_500m',
'LaiStdDev_500m',
'Lai_500m']
lai_response['Lai_500m']['Description'] # Make sure the correct layer is requested
'Leaf area index'
Lai_500m
is the desired layer within the MCD15A3h.006
product.Lai_500m
to the tupled list of desired product/layers.layers.append((prods[0],'Lai_500m')) # Append to tupled list linking desired product with desired layers
prodLayer = []
for l in layers:
prodLayer.append({
"layer": l[1],
"product": l[0]
})
prodLayer
[{'layer': 'LST_Day_1km', 'product': 'MOD11A2.061'},
{'layer': 'LST_Night_1km', 'product': 'MOD11A2.061'},
{'layer': 'Lai_500m', 'product': 'MCD15A3H.006'}]
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 request
task_name = input('Enter a Task Name: ') # User-defined name of the task 'NPS Vegetation' used here
Enter a Task Name: NPS Vegetation
task_type = ['point','area'] # Type of task, area or point
startDate = '01-01-2017' # Start of the date range for which to extract data: MM-DD-YYYY
endDate = '12-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
id
and category
properties to further identify your selected coordinates.coordinates = [{
"id": "0",
"longitude": "-112.127134",
"latitude": "36.206228",
"category": "Grand Canyon"
}, {
"id": "1",
"longitude": "-112.973760",
"latitude": "37.289327",
"category": "Zion"
}]
task = {
'task_type': task_type[0],
'task_name': task_name,
'params': {
'dates': [
{
'startDate': startDate,
'endDate': endDate
}],
'layers': prodLayer,
'coordinates': coordinates
}
}
pprint.pprint(task)
{'params': {'coordinates': [{'category': 'Grand Canyon',
'id': '0',
'latitude': '36.206228',
'longitude': '-112.127134'},
{'category': 'Zion',
'id': '1',
'latitude': '37.289327',
'longitude': '-112.973760'}],
'dates': [{'endDate': '12-31-2017', 'startDate': '01-01-2017'}],
'layers': [{'layer': 'LST_Day_1km', 'product': 'MOD11A2.061'},
{'layer': 'LST_Night_1km', 'product': 'MOD11A2.061'},
{'layer': 'Lai_500m', 'product': 'MCD15A3H.006'}]},
'task_name': 'NPS Vegetation',
'task_type': 'point'}
task
json created above.task_response = r.post('{}task'.format(api), json=task, headers=head).json() # Post json to API task service, return response as json
task_response # Print task response
{'task_id': 'c04b23b7-4e8c-4e67-b44e-596975d27834', 'status': 'pending'}
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.params = {'limit': 2, 'pretty': True} # Limit API response to 2 most recent entries, return as pretty json
tasks_response = r.get('{}task'.format(api),params = params, headers=head).json() # Query task service setting params & header
tasks_response # Print tasks response
[{'params': {'dates': [{'endDate': '12-31-2017', 'startDate': '01-01-2017'}],
'layers': [{'layer': 'LST_Day_1km', 'product': 'MOD11A2.061'},
{'layer': 'LST_Night_1km', 'product': 'MOD11A2.061'},
{'layer': 'Lai_500m', 'product': 'MCD15A3H.006'}]},
'status': 'pending',
'created': '2022-05-04T21:18:03.552611',
'task_id': 'c04b23b7-4e8c-4e67-b44e-596975d27834',
'updated': '2022-05-04T21:18:03.756101',
'user_id': 'user@email.com',
'estimate': {'request_size': 272},
'has_swath': False,
'task_name': 'NPS Vegetation',
'task_type': 'point',
'api_version': 'v1',
'svc_version': '3.2.1',
'web_version': None,
'has_nsidc_daac': False,
'expires_on': '2022-06-03T21:18:03.756101'},
{'error': None,
'params': {'dates': [{'endDate': '07-31-2017', 'startDate': '07-01-2017'}],
'layers': [{'layer': 'LST_Day_1km', 'product': 'MOD11A2.061'},
{'layer': 'LST_Night_1km', 'product': 'MOD11A2.061'},
{'layer': 'Lai_500m', 'product': 'MCD15A3H.006'},
{'layer': 'SRTMGL1_DEM', 'product': 'SRTMGL1_NC.003'}],
'output': {'format': {'type': 'geotiff'}, 'projection': 'geographic'}},
'status': 'done',
'created': '2022-05-04T19:33:52.325868',
'task_id': 'e6151799-8ee9-46da-af8c-f47c2cc2bd8b',
'updated': '2022-05-04T20:34:12.538237',
'user_id': 'user@email.com',
'attempts': 1,
'estimate': {'request_size': 196969757.51610893},
'retry_at': None,
'completed': '2022-05-04T20:34:12.491500',
'has_swath': False,
'task_name': 'NPS Vegetation Area',
'task_type': 'area',
'api_version': 'v1',
'svc_version': '3.2.1',
'web_version': None,
'size_category': '1',
'has_nsidc_daac': False,
'expires_on': '2022-06-03T20:34:12.538237'}]
task_response
that was generated when submitting your request, and use the AρρEEARS API status service to check the status of your request.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 w/ specific task ID & username
status_response # Print response
{'task_id': 'c04b23b7-4e8c-4e67-b44e-596975d27834',
'status': 'pending',
'user_id': 'user@email.com',
'updated': '2022-05-04T21:18:03.756101',
'status_type': 'task'}
# 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'])
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
pending
processing
processing
done
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
bundle = r.get('{}bundle/{}'.format(api,task_id), headers=head).json() # Call API and return bundle contents for the task_id as json
bundle # Print bundle contents
{'files': [{'sha256': '7667d1ad461ebc51ba9ad76e48ffb63f871bdb347965f31187917d5b2026fca8',
'file_id': '3bc7d25a-3260-4ca7-ac9a-cc2ba6ef83ce',
'file_name': 'NPS-Vegetation-MCD15A3H-006-results.csv',
'file_size': 104878,
'file_type': 'csv'},
{'sha256': 'bf56bcfb08b2247775c9cd9e0c8ca113a8795cbf502485e75737c4186c958598',
'file_id': '65ceedbe-7084-46b2-81eb-64bc0fa2cdf1',
'file_name': 'NPS-Vegetation-MOD11A2-061-results.csv',
'file_size': 42367,
'file_type': 'csv'},
{'sha256': '5ce24e6dc38bfdc569a40c8e9306cffaaa500d4c474b40e5dc11e8d7ff6381d9',
'file_id': '43c42b6d-6d29-425c-bc64-25c8e95fadd6',
'file_name': 'NPS-Vegetation-granule-list.txt',
'file_size': 32572,
'file_type': 'txt'},
{'sha256': '1162cf7e870e50dd9b084cf1fe802e95a627b8893ecbcfb81bbe39ee90ef5745',
'file_id': '8b1198f0-bd5f-4323-852d-10df2fbddcc1',
'file_name': 'NPS-Vegetation-request.json',
'file_size': 886,
'file_type': 'json'},
{'sha256': '4751f89517c2485f6b0c7b4e550d7422c7c58e08fd2b5d362bd0b7d4ee74e631',
'file_id': 'b59eb6cf-d583-44e4-97e9-cf5f351f269e',
'file_name': 'NPS-Vegetation-MCD15A3H-006-metadata.xml',
'file_size': 17247,
'file_type': 'xml'},
{'sha256': '4a1947f0887f0dbc04f907c5792351bd82389922804f56b7f45bb6d286dfa0f4',
'file_id': '28f69545-9fe1-4155-9564-d30f3dd812d9',
'file_name': 'NPS-Vegetation-MOD11A2-061-metadata.xml',
'file_size': 17209,
'file_type': 'xml'},
{'sha256': 'be0524b50147e62eb0b3801a33ce40325f2755b046ab74fd93e4aaf902777b10',
'file_id': 'f126a367-f501-42fc-a986-dffdeb1e0813',
'file_name': 'README.txt',
'file_size': 19330,
'file_type': 'txt'}],
'created': '2022-05-04T20:29:39Z',
'task_id': 'c04b23b7-4e8c-4e67-b44e-596975d27834',
'updated': '2022-05-04T22:18:03.756101'',
'bundle_type': 'point'}
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 # Print dictionary
{'3bc7d25a-3260-4ca7-ac9a-cc2ba6ef83ce': 'NPS-Vegetation-MCD15A3H-006-results.csv',
'65ceedbe-7084-46b2-81eb-64bc0fa2cdf1': 'NPS-Vegetation-MOD11A2-061-results.csv',
'43c42b6d-6d29-425c-bc64-25c8e95fadd6': 'NPS-Vegetation-granule-list.txt',
'8b1198f0-bd5f-4323-852d-10df2fbddcc1': 'NPS-Vegetation-request.json',
'b59eb6cf-d583-44e4-97e9-cf5f351f269e': 'NPS-Vegetation-MCD15A3H-006-metadata.xml',
'28f69545-9fe1-4155-9564-d30f3dd812d9': 'NPS-Vegetation-MOD11A2-061-metadata.xml',
'f126a367-f501-42fc-a986-dffdeb1e0813': 'README.txt'}
files
dictionary and a for
loop to automate downloading all of the output files into the output directory.for f in files:
dl = r.get('{}bundle/{}/{}'.format(api, task_id, f), headers=head, stream=True, allow_redirects = "TRUE") # Get a stream to the bundle file
if files[f].endswith('.tif'):
filename = files[f].split('/')[1]
else:
filename = files[f]
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
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.params = {'limit': 6, 'pretty': True, 'offset': 20} # Limit 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
[{'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']}]
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
[{'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']}]
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
[{'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}]
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
{'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)'}}
matplotlib
package.# Import Packages
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
list(files.values()) # List files downloaded
['NPS-Vegetation-MCD15A3H-006-results.csv',
'NPS-Vegetation-MOD11A2-061-results.csv',
'NPS-Vegetation-granule-list.txt',
'NPS-Vegetation-request.json',
'NPS-Vegetation-MCD15A3H-006-metadata.xml',
'NPS-Vegetation-MOD11A2-061-metadata.xml',
'README.txt']
Pandas
package to import the CSV file containing the results from the AρρEEARS request.df = pd.read_csv(os.path.join(destDir,'NPS-Vegetation-MOD11A2-061-results.csv')) # Import CSV to a Pandas dataframe
df.columns # Print dataframe column names
Index(['Category', 'ID', 'Latitude', 'Longitude', 'Date', 'MODIS_Tile',
'MOD11A2_061_Line_Y_1km', 'MOD11A2_061_Sample_X_1km',
'MOD11A2_061_LST_Day_1km', 'MOD11A2_061_LST_Night_1km',
'MOD11A2_061_QC_Day', 'MOD11A2_061_QC_Night',
'MOD11A2_061_QC_Day_bitmask', 'MOD11A2_061_QC_Day_MODLAND',
'MOD11A2_061_QC_Day_MODLAND_Description',
'MOD11A2_061_QC_Day_Data_Quality_flag',
'MOD11A2_061_QC_Day_Data_Quality_flag_Description',
'MOD11A2_061_QC_Day_Emis_Error_flag',
'MOD11A2_061_QC_Day_Emis_Error_flag_Description',
'MOD11A2_061_QC_Day_LST_Error_Flag',
'MOD11A2_061_QC_Day_LST_Error_Flag_Description',
'MOD11A2_061_QC_Night_bitmask', 'MOD11A2_061_QC_Night_MODLAND',
'MOD11A2_061_QC_Night_MODLAND_Description',
'MOD11A2_061_QC_Night_Data_Quality_flag',
'MOD11A2_061_QC_Night_Data_Quality_flag_Description',
'MOD11A2_061_QC_Night_Emis_Error_flag',
'MOD11A2_061_QC_Night_Emis_Error_flag_Description',
'MOD11A2_061_QC_Night_LST_Error_Flag',
'MOD11A2_061_QC_Night_LST_Error_Flag_Description'],
dtype='object')
lstDay_GC = df['MOD11A2_061_LST_Day_1km'][df.Category == 'Grand Canyon'] # Filter df for the pixel from GC, only keep LST Day 1 km column
dates = df['Date'] # Create list of dates
lst_response.keys() # Print response of product service call from earlier in the tutorial
dict_keys(['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'])
lst_response['LST_Day_1km'] # Print product information service for the desired layer
{'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.061',
'ScaleFactor': 0.02,
'Units': 'Kelvin',
'ValidMax': 1310.699951,
'ValidMin': 150.0,
'XSize': 1200,
'YSize': 1200}
lstFill = lst_response['LST_Day_1km']['FillValue'] # Set fill value
units = lst_response['LST_Day_1km']['Units'] # Set units
# Set matplotlib plots inline
%matplotlib inline
plt.style.use("dark_background") # Set default background to black instead of white
fig = plt.figure(1, figsize=(25, 7.5)) # Set the figure size
ax = fig.add_subplot(111) # Create a subplot
ax.plot(lstDay_GC[lstDay_GC!=lstFill], 'k', lw=2.5, color='#1f77b4') # Filter out fill values and plot as blue line
ax.plot(lstDay_GC[lstDay_GC!=lstFill], 'bo', ms=10, color='#1f77b4', alpha = 0.5) # Filter out fill values and plot as blue circle
ax.set_xticks((np.arange(0,len(lstDay_GC)))) # Set the x ticks
ax.set_xticklabels(dates, rotation=45,fontsize=10) # Set the x tick labels
ax.set_yticks((np.arange(250,325, 10))) # Arrange the y ticks
ax.set_yticklabels(np.arange(250,325, 10),fontsize=12,fontweight='bold') # Set the Y tick labels
ax.set_xlabel('Date',fontsize=16,fontweight='bold') # Set x-axis label
ax.set_ylabel("{}({})".format('LST_Day_1km', units),fontsize=16,fontweight='bold') # Set y-axis label
ax.set_title('Time Series',fontsize=20,fontweight='bold'); # Set title
LST_Day_1km
and LST_Night_1km
.lstNight_GC = df['MOD11A2_061_LST_Night_1km'][df.Category == 'Grand Canyon'] # Filter df for pixel from GC, only keep LST Night
fig = plt.figure(1, figsize=(25, 7.5)) # Set the figure size
plt.style.use("dark_background") # Set default background to black instead of white
ax = fig.add_subplot(111) # Create a subplot
ax.plot(lstDay_GC[lstDay_GC!=lstFill], 'k', lw=2.5, color='#1f77b4') # Filter out fill values and plot as a blue line
ax.plot(lstNight_GC[lstNight_GC!=lstFill], 'k', lw=2.5, color='#e60000') # Filter out fill values and plot as a red line
ax.legend(('LST_Day_1km', 'LST_Night_1km'),loc='upper left') # Add a legend
ax.plot(lstDay_GC[lstDay_GC!=lstFill], 'bo', ms=10, color='#1f77b4', alpha = 0.5) # Filter out fill values and plot as a blue circle
ax.plot(lstNight_GC[lstNight_GC!=lstFill], 'bo', ms=10, color='#e60000', alpha = 0.5) # Filter out fill values and plot as a red circle
ax.set_xticks((np.arange(0,len(lstDay_GC)))) # Set the x ticks
ax.set_xticklabels(dates, rotation=45,fontsize=10) # Set the x tick labels
ax.set_yticks((np.arange(250,325, 10))) # Arrange the y ticks
ax.set_yticklabels(np.arange(250,325, 10),fontsize=12,fontweight='bold') # Set the Y tick labels
ax.set_xlabel('Date',fontsize=16,fontweight='bold') # Set x-axis label
ax.set_ylabel("{}({})".format('LST_Day_1km', units),fontsize=16,fontweight='bold') # Set y-axis label
ax.set_title('Daytime and Nighttime LST at Grand Canyon NP',fontsize=20,fontweight='bold'); # Set title
matplotlib
.lstDay_Z = df['MOD11A2_061_LST_Day_1km'][df.Category == 'Zion'] # Filter for pixel from Zion, only keep LST Day
lstDay_Z[lstDay_Z==lstFill] = np.nan # Set fill values = nan for plotting purposes
lstDay_GC[lstDay_GC==lstFill] = np.nan # Set fill values = nan for plotting purposes
fig = plt.figure(1, figsize=(10, 7.5)) # Set the figure size
plt.style.use("dark_background") # Set default background to black
fig.suptitle('MODIS LST: Grand Canyon vs. Zion National Park, 2017',fontsize=20,fontweight='bold') # Add a title for the plot
ax = fig.add_subplot(111) # Add subplot
ax.set_ylabel("{} {} ({})".format('Grand Canyon:','LST_Day_1km',units),fontsize=16,fontweight='bold') # Set y-axis label
ax.set_xlabel("{} {} ({})".format('Zion:','LST_Day_1km', units),fontsize=16,fontweight='bold') # Set x-axis label
ax.scatter(lstDay_GC, lstDay_Z , alpha=1, c='#1f77b4', edgecolors='none', s=50, label="LST_Day"); # Plot values for both points