Exploring CSW access in Python using OWSLib with CMGP Geonetwork


In [1]:
from IPython.core.display import HTML
HTML('<iframe src=http://cmgds.marine.usgs.gov/geonetwork/srv/en/main.home width=900 height=280></iframe>')


Out[1]:

In [2]:
from owslib.csw import CatalogueServiceWeb

In [3]:
# connect to CSW, explore it's properties
#endpoint = 'http://www.ngdc.noaa.gov/geoportal/csw' # NGDC Geoportal
#endpoint = 'http://data.nodc.noaa.gov/geoportal/csw'  # NODC Geoportal: collection level
    
#endpoint = 'http://geodiscover.cgdi.ca/wes/serviceManagerCSW/csw'  # NRCAN CUSTOM
#endpoint = 'http://geoport.whoi.edu/gi-cat/services/cswiso' # USGS Woods Hole GI_CAT
#endpoint = 'http://cida.usgs.gov/gdp/geonetwork/srv/en/csw' # USGS CIDA Geonetwork
#endpoint = 'http://www.nodc.noaa.gov/geoportal/csw'   # NODC Geoportal: granule level

endpoint = 'http://cmgds.marine.usgs.gov/geonetwork/srv/en/csw'  # USGS Coastal & Marine Program Geonetwork
csw = CatalogueServiceWeb(endpoint,timeout=30)
csw.version


Out[3]:
'2.0.2'

In [4]:
[op.name for op in csw.operations]


Out[4]:
['GetCapabilities',
 'DescribeRecord',
 'GetDomain',
 'GetRecords',
 'GetRecordById',
 'Transaction']

In [5]:
#bbox=[-141,42,-52,84]
bbox=[-71.5, 39.5, -63.0, 46]
csw.getrecords(keywords=['sea_water_temperature'],bbox=bbox,maxrecords=10)
csw.results


Out[5]:
{'matches': 0, 'nextrecord': 0, 'returned': 0}

In [6]:
csw.getrecords(maxrecords=5)

In [7]:
for rec,item in csw.records.iteritems():
    print item.title


MOSAIC_05M.TIF:  GeoTIFF image of acoustic backscatter collected by the U.S. Geological Survey within the Upper St. Clair River between Michigan and Ontario, Canada, 2008 (GeoTIFF).
ALEU_250M_LCC_WGS84.TIF - Aleutian Arc U.S. EEZ GLORIA sidescan-sonar composite mosaic (LCC, 250 m, WGS84)
BS_250M_LCC_NAD27.TIF - Bering Sea U.S. EEZ GLORIA sidescan-sonar composite mosaic (LCC, 250 m, Clarke1866)
High-Resolution Seismic Reflection and Marine Magnetic Data Along the Hosgri Fault Zone--Cayucos to Pismo Beach, California
HW1_250M_LCC_WGS84.TIF - Hawaii I - Southeastern Hawaiian Ridge U.S. EEZ GLORIA sidescan-sonar composite mosaic (LCC, 250 m, WGS84)

In [8]:
print(csw.records.keys())


['3bbcce0c-f6ef-4993-885f-058ccb102512', 'ff570263-b0e5-46d7-ae55-20551dd7cb01', '57ddfabf-aa4c-46f6-8bb3-7416372b1f24', '48d62bb5-7ff0-463b-9cef-afecbc739bfd', '918f1915-c7e0-4cff-9e32-9a22a5d76089']

In [9]:
# choose a sample record
a=csw.records['3bbcce0c-f6ef-4993-885f-058ccb102512']

In [10]:
print a.title


MOSAIC_05M.TIF:  GeoTIFF image of acoustic backscatter collected by the U.S. Geological Survey within the Upper St. Clair River between Michigan and Ontario, Canada, 2008 (GeoTIFF).

In [11]:
# unfortunately the "uris" property is empty
print a.uris


[]

In [12]:
# yet I can see the URIs here:
print a.xml


<csw:SummaryRecord xmlns:dct="http://purl.org/dc/terms/" xmlns:geonet="http://www.fao.org/geonetwork" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <dc:identifier>3bbcce0c-f6ef-4993-885f-058ccb102512</dc:identifier>
      <dc:title>MOSAIC_05M.TIF:  GeoTIFF image of acoustic backscatter collected by the U.S. Geological Survey within the Upper St. Clair River between Michigan and Ontario, Canada, 2008 (GeoTIFF).</dc:title>
      <dc:subject>General
        U.S. Geological Survey
        USGS
        Woods Hole Coastal and Marine Science Center
        WHCMSC
        Coastal and Marine Geology Program
        CMGP
        surficial sediment
        sidescan-sonar
        interferometry
        SEA SWATHplus 234 kHz
        acoustic backscatter
        WHCMSC field activity serial number 08016
        GeoTIFF Image
        USGS R/V Rafael</dc:subject>
      <dc:subject>ISO 19115 Topic Category
        geoscientificInformation
        imageryBaseMapsEarthCover
        inlandWaters</dc:subject>
      <dc:subject>General
        North America
        United States
        Michigan
        Great Lakes
        Upper Great Lakes
        Lake Huron
        St. Clair River
        Upper St. Clair River
        Canada
        Ontario</dc:subject>
      <dct:abstract>In 2008, the U.S. Geological Survey (USGS), Woods Hole Coastal and Marine Science Center (WHCMSC), in cooperation with the U.S. Army Corps of Engineers conducted a geophysical and sampling survey of the riverbed of the Upper St. Clair River between Port Huron, MI, and Sarnia, Ontario, Canada. The objectives were to define the Quaternary geologic framework of the St. Clair River to evaluate the relationship between morphologic change of the riverbed and underlying stratigraphy. This report presents the geophysical and sample data collected from the St. Clair River, May 29-June 6, 2008 as part of the International Upper Great Lakes Study, a 5-year project funded by the International Joint Commission of the United States and Canada to examine whether physical changes in the St. Clair River are affecting water levels within the upper Great Lakes, to assess regulation plans for outflows from Lake Superior, and to examine the potential effect of climate change on the Great Lakes water levels ( http://www.iugls.org). This document makes available the data that were used in a separate report, U.S. Geological Survey Open-File Report 2009-1137, which detailed the interpretations of the Quaternary geologic framework of the region. This report includes a description of the suite of high-resolution acoustic and sediment-sampling systems that were used to map the morphology, surficial sediment distribution, and underlying geology of the Upper St. Clair River during USGS field activity 2008-016-FA . Video and photographs of the riverbed were also collected and are included in this data release. Future analyses will be focused on substrate erosion and its effects on river-channel morphology and geometry. Ultimately, the International Upper Great Lakes Study will attempt to determine where physical changes in the St. Clair River affect water flow and, subsequently, water levels in the Upper Great Lakes.

For more information on the seismic surveys see http://woodshole.er.usgs.gov/operations/ia/public_ds_in
fo.php?fa=2008-016-FA</dct:abstract>
      <dct:modified>20110125</dct:modified>
      <dc:type>Raster
    
      Pixel
      15001
      10001
      1</dc:type>
    </csw:SummaryRecord>
    

In [13]:
# lets look at the references
a.references


Out[13]:
[]

In [14]:
# get specific ServiceType URL from records
def service_urls(records,service_string='urn:x-esri:specification:ServiceType:OPeNDAP'):
    urls=[]
    for key,rec in records.iteritems():
        #create a generator object, and iterate through it until the match is found
        #if not found, gets the default value (here "none")
        url = next((d['url'] for d in rec.references if d['scheme'] == service_string), None)
        if url is not None:
            urls.append(url)
    return urls

In [15]:
dap_urls = service_urls(csw.records,service_string='urn:x-esri:specification:ServiceType:ArcIMS:Metadata:Onlink')
print dap_urls


[]

In [15]: