Data Access through PO.DAAC Web Services Example

Data Access through PO.DAAC Web Services Example

Postby rmkim1 » Wed Mar 25, 2015 3:53 pm

PO.DAAC Web Service Python Example

Introduction: PO.DAAC provides Web Services Application Programming Interface(API) that can be accessed through standard web protocol. These Web Services are used to discover PO.DAAC data. The example below demonstrates how PO.DAAC Web Services are used to discover granules in Python.

Agenda: Use PO.DAAC Web Services to 1. Search ASCATA-L2-Coastal granules with time and region. 2. Retrieve metadata and subset.

Step 1

import necessary python libraries

Code: Select all
import sys
import urllib2
import xml.etree.ElementTree
import downloadUtil

* is included in the demo package.

Step 2

Prepare inputs to run Granule Search Service. There are four inputs. datasetId is the PO.DAAC id which can be found from PO.DAAC dataset page such as Start and end are the dates in <year>-<month>-<day>T<hour>:<minutes>:<second>Z format. bbox is in degrees in the following order. West, South, East, North

Code: Select all
datasetId = 'PODAAC-ASOP2-COB01'

Step 3

Invoke Granule Search Web Service. Search Web Service API Documentation is located at

Code: Select all
searchRootURL = ''
searchURL = searchRootURL + '?datasetId=' + datasetId + '&startTime=' + start + '&endTime=' + end + '&bbox=' + bbox
search_results = urllib2.urlopen(searchURL).read()

Step 4

The search result is in Atom format. Parse the search results to retrieve granule names.

Code: Select all
xmlTree = xml.etree.ElementTree.fromstring(search_results)
atomNS = "{}"
entries = xmlTree.getiterator(atomNS + "entry")
granule_names = [x.getiterator(atomNS + "title")[0].text.strip() for x in entries]
print granule_names

Step 5

For each granules in the granule_names, retrieve metadata and subset by invoking Granule Metadata Service and Granule Extract Service. Metadata Web Service API documentation is located at and Extract Web Service API documentation is located at

Code: Select all
metadataRootURL = ''
extractRootURL = ''
for g in granule_names:
    metadataURL = metadataRootURL + '?datasetId=' + datasetId + '&granuleName=' + g + '&format=iso'
    extractURL = extractRootURL + '?datasetId=' + datasetId + '&granuleName=' + g + '&bbox=' + bbox + '&format=netcdf'

    downloadUtil.downloadFile(metadataURL, './metadata', g + '_metadata.xml')
    downloadUtil.downloadFile(extractURL, './subsetted', g + '')

Download the Python code described in this example
The attachment is no longer available
(1.33 KiB) Downloaded 738 times
Posts: 1
Joined: Thu Mar 12, 2015 12:01 pm

Return to PO.DAAC Web Services