Explore ScienceBase CSW Services

Test support for different types of CSW queries in USGS ScienceBase. In ScienceBase, each item has a CSW which contains all child items. Thus I clicked on the json link on the top level Hurricane Sandy link, and located the CSW endpoint within.


In [7]:
from pylab import *
from owslib.csw import CatalogueServiceWeb
from owslib import fes
import datetime as dt
from numpy import random

In [8]:
# top level USGS Hurricane Sandy community CSW link
#https://www.sciencebase.gov/catalog/item/519bee13e4b0e4e151f0232c/csw?service=CSW&version=2.0.2&request=GetCapabilities
endpoint='https://www.sciencebase.gov/catalog/item/519bee13e4b0e4e151f0232c/csw'
# san francisco bay
#endpoint='https://beta.sciencebase.gov/catalog/item/5064c1cee4b0050306265490/csw'

In [24]:
#box=[-180, -90, 180, 90]

box=[-76.4751, 38.3890, -71.7432, 42.9397]  # new york harbor region
#box=[-72.0, 41.0, -69.0, 43.0]   # gulf of maine
box =[-123.0, 37.0, -120., 38.] # san fran bay
box = [-75., 38., -73., 41.] # barnegat bay

# specific specific times (UTC) ...

# hurricane sandy
jd_start = dt.datetime(2012,10,26)
jd_stop = dt.datetime(2012,11,2)

# 2014 feb 10-15 storm
jd_start = dt.datetime(2014,2,10)
jd_stop = dt.datetime(2014,2,15)

# 2014 recent
jd_start = dt.datetime(2014,3,8)
jd_stop = dt.datetime(2014,3,11)

# 2011 
#jd_start = dt.datetime(2013,4,20)
#jd_stop = dt.datetime(2013,4,24)

# ... or relative to now
jd_start = dt.datetime.utcnow()- dt.timedelta(days=3)
jd_stop = dt.datetime.utcnow() + dt.timedelta(days=3)

start_date = jd_start.strftime('%Y-%m-%d %H:00')
stop_date  = jd_stop.strftime('%Y-%m-%d %H:00')

jd_start = dt.datetime.strptime(start_date,'%Y-%m-%d %H:%M')
jd_stop = dt.datetime.strptime(stop_date,'%Y-%m-%d %H:%M')

print start_date,'to',stop_date


2014-04-25 21:00 to 2014-05-01 21:00

In [49]:
# Bounding Box [lon_min, lat_min, lon_max, lat_max]
box=[-75., 39., -71., 41.5]  # new york harbor region
#box=[-72.0, 41.0, -69.0, 43.0]   # gulf of maine
#box=[-160.0, 18.0, -154., 23.0] #hawaii
box=[-75, 38, -73, 40] #barnegat

In [50]:
bbox = fes.BBox(box)

In [51]:
std_name_list=['water_surface_height_above_reference_datum',
    'sea_surface_height_above_geoid','sea_surface_elevation',
    'sea_surface_height_above_reference_ellipsoid','sea_surface_height_above_sea_level',
    'sea_surface_height','water level']

In [52]:
std_name_list=['GDP','output']

In [53]:
csw = CatalogueServiceWeb(endpoint,timeout=60)
csw.version


Out[53]:
'2.0.2'

In [54]:
for oper in csw.operations:
    if oper.name == 'GetRecords':
        print oper.constraints


{'AdditionalQueryables': {'values': ['sb:collection', 'sb:servicetype']}, 'SupportedCommonQueryables': {'values': ['AnyText', 'Title', 'Abstract', 'Subject']}}

In [55]:
csw.getrecords2(maxrecords=1000,esn='full')
print len(csw.records.keys())
for rec,item in csw.records.iteritems():
    print item.title


35
Migratory birds
Jamaica Bay
Submerged aquatic vegetation (SAV) CRSSA image classification of the Barnegat Bay - Little Egg Harbor estuary, New Jersey: 2009
Barnegat Bay Ecologically Sensitive Areas
Theme 2: Impacts to Coastal Beaches and Barriers
NWI maps
Modeling Hurricane Sandy Impacts and Storm Surge Protection of Coastal Forest Resources of Atlantic Coast DOI Parks and Refuges
Forsythe plovers
Theme 4: Impacts on Environmental Quality
Hurricane Sandy Storm Surge
Hurricane Sandy (FEMA 4086DR-NJ-USGS-01)
Decision Support for Coastal Science and Management
Hurricane Sandy Publications
Change map
NEXRAD birds
Barrow project area
Coastal topography?Northeast Atlantic coast, post-hurricane Sandy, 2012
Hurricane Sandy (FEMA MA-12102506-USGS-01)
SET cores
Products
Outer Banks birds
Theme 3: Impacts of Storm Surge
Sedge Island Marine Conservation Zone
Monitoring storm tide and flooding from Hurricane Sandy along the Atlantic coast of the United States, October 2012
Hurricane Sandy (FEMA DE-12102505-USGS-01)
Hurricane Sandy (FEMA 3353EM-CT-USGS-01)
Inundation
Theme 5: Impacts to Coastal Ecosystems
NJ Delmarva
Hurricane Sandy Storm Surge
Hurricane Sandy Projects
Theme 1: Coastal Topographic and Bathymetric Data
Coastal Change Processes
SET monitoring
Decision support for ecological recovery and resilience

In [56]:
val='Barnegat'
text_filt = fes.PropertyIsLike(propertyname='AnyText',literal=('*%s*' % val))

filter_list = [text_filt ]

In [57]:
# try request using multiple filters "and" syntax: [[filter1,filter2]]
csw.getrecords2(constraints=filter_list,maxrecords=1000,esn='full')
print len(csw.records.keys())


2

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


Submerged aquatic vegetation (SAV) CRSSA image classification of the Barnegat Bay - Little Egg Harbor estuary, New Jersey: 2009
Barnegat Bay Ecologically Sensitive Areas

In [59]:
val='Barnegat'
text_filt = fes.PropertyIsLike(propertyname='AnyText',literal=('*%s*' % val))

filter_list = [fes.And([ bbox, text_filt]) ]
# try request using multiple filters "and" syntax: [[filter1,filter2]]
csw.getrecords2(constraints=filter_list,maxrecords=1000,esn='full')
print len(csw.records.keys())


35

In [60]:
val='Barnegat'
filter_list = [ bbox]
# try request using multiple filters "and" syntax: [[filter1,filter2]]
csw.getrecords2(constraints=filter_list,maxrecords=1000,esn='full')
print len(csw.records.keys())


0

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

In [62]:
choice=random.choice(list(csw.records.keys()))
print choice
csw.records[choice].references


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-62-6361c64444f8> in <module>()
----> 1 choice=random.choice(list(csw.records.keys()))
      2 print choice
      3 csw.records[choice].references

/home/local/python27_epd/lib/python2.7/site-packages/numpy/random/mtrand.so in mtrand.RandomState.choice (numpy/random/mtrand/mtrand.c:7299)()

ValueError: a must be non-empty

In [63]:
foo=csw.records[choice]


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-63-cdaae0520fcb> in <module>()
----> 1 foo=csw.records[choice]

KeyError: '5227ba5fe4b0767cef419fd5'

In [20]:
print(foo.xml)


<csw:Record xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcmiBox="http://dublincore.org/documents/2000/07/11/dcmi-box/" xmlns:dct="http://purl.org/dc/terms/" xmlns:gml="http://www.opengis.net/gml" xmlns:ows="http://www.opengis.net/ows">
      <dc:identifier>5227ba5fe4b0767cef419fd5</dc:identifier>
      <dc:title>Forsythe plovers</dc:title>
      <dct:modified>2014-03-31T15:48:34.240Z</dct:modified>
      <dct:abstract>&lt;strong&gt;&lt;strong&gt;&lt;strong&gt;Background/Overview&lt;/strong&gt;&lt;br /&gt; Fewer than 2,000 breeding pairs of Piping Plovers ( &lt;em&gt;Charadrius melodus&lt;/em&gt;) were detected on the Atlantic coast in 2012. The Atlantic Coast Piping Plover is a federally-listed, threatened shorebird that inhabits beaches of barrier islands, ocean fronts, bays and inlets, tidal creeks/marshes, peninsulas, and sand bars. These are precisely the habitats that were altered by Hurricane Sandy. The storm eroded or flattened the shoreline of inlets and tidal creeks, breached barrier islands, altered the amount and topography of sand on beaches, washed dunes to the backside of barrier islands, and created sand/gravel overwash habitat on marshes. These changes to the coastal fringes may diminish nesting opportunities for plovers or may create new nesting habitat. Understanding the reproductive response of Piping Plovers to changes in beach habitats will better inform decision-making as plans are made for beach restoration in areas affected by Hurricane Sandy.&lt;br /&gt; &lt;br /&gt; Geographic Location&lt;/strong&gt;&lt;br /&gt; The New Jersey coast on Edwin B. Forsythe National Wildlife Refuge (NWR)(Figure 1). The refuge has been monitoring nesting Piping Plovers on the Holgate and Little Beach Island Units for 26 years. The Holgate Unit is located in the southern region of Long Beach Island in Ocean County. The Little Beach Unit is located in Atlantic County, between Beach Haven Inlet and Brigantine Inlet. Both Units are designated National Wilderness Areas and are closed to the public during the nesting season (April &#8211; August). The refuge lies within the zone of Hurricane Sandy&#8217;s &#8220;highest impact&#8221;; Piping Plover habitat was altered as a result of beach erosion, marsh overwash and exposed rubble (&lt;em&gt;Hurricane Sandy Rapid Assessment Final Report, 2013, Atlantic Flyway Shorebird Business Strategy Planning Team, Manomet Center for Conservation Sciences and the National Fish and Wildlife Foundation&lt;/em&gt;).&amp;nbsp;&lt;br /&gt; &amp;nbsp;&lt;br /&gt; &lt;strong&gt;Partners&lt;/strong&gt;&lt;br /&gt; Virginia Rettig, Refuge Manager, and Paul Castelli, Refuge Biologist, USFWS, Edwin B. Forsythe NWR; Christina Davis, Senior Environmental Specialist, New Jersey Division of Fish and Wildlife, Endangered and Nongame Species Program; and Todd Pover, Beach Nesting Bird Project Manager, Conserve Wildlife Foundation of New Jersey&lt;br /&gt; &amp;nbsp;&lt;br /&gt; &lt;strong&gt;Timeline and milestones&lt;/strong&gt;&lt;br /&gt; Work will commence upon arrival of funds. July - Sept 2013: Joint USGS-USFWS workshop for development of a model set examining ecological factors and reproductive success of the Piping Plover on E. B. Forsythe NWR (hypothesis generation). August 2013&#8211; March 2014: Measurement of ecological factors identified in the workshop using remotely-sensed data (data collection). Analysis of refuge&#8217;s archival nesting data for Holgate and Little Beach Island Units, and AIC model selection (analysis). April &#8211; August 2013: Post-storm field data collection of nesting Piping Plovers on Holgate and Little Beach Island Units (data collection).&lt;br /&gt; &amp;nbsp;&lt;br /&gt; &lt;strong&gt;Budget/staffing&lt;/strong&gt;. Total: $178,200 (includes $25,668 indirect). USGS salaries: $86,228; interagency agreement with USFWS (salary for 6 interns and supplies/equipment for field surveys): $40,079; 2008 and 2013 aerial photography: $14,705; Travel: $5,700; Supplies: $5,820.&lt;br /&gt; &amp;nbsp;&lt;br /&gt; &lt;strong&gt;Deliverables&lt;/strong&gt;&lt;br /&gt; First allocation products include: (1) A model of the ecological factors affecting reproductive success of Piping Plovers using Edwin B. Forsythe NWR, 1987 &#8211; 2012, (2)A map of changes in Piping Plover nesting habitat caused by Hurricane Sandy. The map will be based on photo interpretation of 2008 and 2013 stereo aerial photography.&lt;/strong&gt;</dct:abstract>
    </csw:Record>
  

In [20]: