Page 1 of 1

Data Access through PO.DAAC Web Services Example

PostPosted: Wed Mar 25, 2015 3:53 pm
by rmkim1
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


* downloadUtil.py 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 https://podaac.jpl.nasa.gov/dataset/ASCATA-L2-Coastal. 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'
start='2015-01-01T00:00:00Z'
end='2015-01-02T00:00:00Z'
bbox=-45,-45,45,45



Step 3

Invoke Granule Search Web Service. Search Web Service API Documentation is located at https://podaac.jpl.nasa.gov/ws/search/granule

Code: Select all
searchRootURL = 'https://podaac.jpl.nasa.gov/ws/search/granule/'
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 = "{http://www.w3.org/2005/Atom}"
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 https://podaac.jpl.nasa.gov/ws/metadata/granule and Extract Web Service API documentation is located at https://podaac.jpl.nasa.gov/ws/extract/granule

Code: Select all
metadataRootURL = 'https://podaac.jpl.nasa.gov/ws/metadata/granule/'
extractRootURL = 'https://podaac.jpl.nasa.gov/ws/extract/granule/'
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 + '_subsetted.nc')



Download the Python code described in this example
The attachment demoPython.zip is no longer available