In [66]:
# Query `apiso:ServiceType` on geoport pycsw

In [67]:
from owslib.csw import CatalogueServiceWeb
from owslib import fes
import numpy as np

In [140]:
endpoint = 'http://geoport.whoi.edu/csw' 
#endpoint = 'http://data.nodc.noaa.gov/geoportal/csw'
csw = CatalogueServiceWeb(endpoint,timeout=60)
print csw.version


2.0.2

In [141]:
csw.get_operation_by_name('GetRecords').constraints


Out[141]:
[Constraint: SupportedISOQueryables - ['apiso:DistanceValue', 'apiso:Abstract', 'apiso:RevisionDate', 'apiso:Subject', 'apiso:KeywordType', 'apiso:Title', 'apiso:CRS', 'apiso:PublicationDate', 'apiso:Type', 'apiso:AlternateTitle', 'apiso:BoundingBox', 'apiso:AnyText', 'apiso:ParentIdentifier', 'apiso:Modified', 'apiso:Operation', 'apiso:Format', 'apiso:TempExtent_end', 'apiso:DistanceUOM', 'apiso:OrganisationName', 'apiso:ServiceType', 'apiso:TempExtent_begin', 'apiso:ResourceLanguage', 'apiso:ServiceTypeVersion', 'apiso:OperatesOn', 'apiso:Denominator', 'apiso:HasSecurityConstraints', 'apiso:OperatesOnIdentifier', 'apiso:GeographicDescriptionCode', 'apiso:Language', 'apiso:Identifier', 'apiso:OperatesOnName', 'apiso:TopicCategory', 'apiso:CreationDate', 'apiso:CouplingType'],
 Constraint: AdditionalQueryables - ['apiso:Lineage', 'apiso:Classification', 'apiso:Creator', 'apiso:Relation', 'apiso:OtherConstraints', 'apiso:SpecificationTitle', 'apiso:ResponsiblePartyRole', 'apiso:SpecificationDateType', 'apiso:Degree', 'apiso:Contributor', 'apiso:ConditionApplyingToAccessAndUse', 'apiso:SpecificationDate', 'apiso:AccessConstraints', 'apiso:Publisher'],
 Constraint: SupportedDublinCoreQueryables - ['dc:contributor', 'dc:source', 'dc:language', 'dc:title', 'dc:subject', 'dc:creator', 'dc:type', 'ows:BoundingBox', 'dct:modified', 'dct:abstract', 'dc:relation', 'dc:date', 'dc:identifier', 'dc:publisher', 'dc:format', 'csw:AnyText', 'dc:rights']]

In [142]:
try:
    csw.get_operation_by_name('GetDomain')
    csw.getdomain('apiso:ServiceType', 'property')
    print(csw.results['values'])
except:
    print('GetDomain not supported')


['THREDDS OPeNDAP,Open Geospatial Consortium Web Map Service (WMS),THREDDS NetCDF Subset Service', 'THREDDS OPeNDAP,Open Geospatial Consortium Web Map Service (WMS),THREDDS NetCDF Subset Service,THREDDS HTTP Service', 'THREDDS OPeNDAP,THREDDS HTTP Service']

In [143]:
val = 'CMG_Portal'
#val = 'COADS'
filter1 = fes.PropertyIsLike(propertyname='apiso:AnyText',literal=('*%s*' % val),
                        escapeChar='\\',wildCard='*',singleChar='?')
filter_list = [ filter1 ]

In [144]:
csw.getrecords2(constraints=filter_list,maxrecords=100,esn='full')
print len(csw.records.keys())
for rec in list(csw.records.keys()):
    print csw.records[rec].title


9
USGS Barnegat Bay Model for Hurricane Sandy : run076
COAWST Hindcast:Barnegat Bay:ADCIRC tides,Real rivers,Plume,Lowpass Espresso bdry,NAM,new bathy
USGS Chincoteague Bay Model for Hurricane Sandy
USGS Chincoteague Bay Model for EPR
COAWST Forecast System : USGS : US East Coast and Gulf of Mexico (Experimental)
COAWST Hindcast:MVCO/CBlast 2007:ripples with SWAN-40m res
USGS-CMG-COAWST Model: Hurricane Sandy, NYB05 700m Nest
USGS-CMG-COAWST Model: Hurricane Sandy, SHF05 2km Nest
USGS-CMG-COAWST Model: Hurricane Sandy, USE27 6km Nest

In [226]:
for rec in list(csw.records.keys()):
    print(csw.records[rec].references[2]['url'])


http://geoport-dev.whoi.edu/thredds/dodsC/clay/usgs/users/zdefne/run076/his/00_dir_roms_display.ncml
http://geoport-dev.whoi.edu/thredds/dodsC/usgs/data0/bbleh/spring2012/00_dir_roms.ncml
http://geoport-dev.whoi.edu/thredds/dodsC/clay/usgs/users/abeudin/chinco/Sandy/withbedload/00_dir_roms.ncml
http://geoport-dev.whoi.edu/thredds/dodsC/clay/usgs/users/nganju/chincoteague_bedelevation/00_dir_roms.ncml
http://geoport-dev.whoi.edu/thredds/dodsC/coawst_4/use/fmrc/coawst_4_use_best.ncd
http://geoport-dev.whoi.edu/thredds/dodsC/usgs/data0/mvco_ce/mvco_output/spatial_7_ar0fd/00_dir_roms.ncml
http://geoport-dev.whoi.edu/thredds/dodsC/clay/usgs/users/jcwarner/Projects/Sandy/triple_nest/00_dir_NYB05.ncml
http://geoport-dev.whoi.edu/thredds/dodsC/clay/usgs/users/jcwarner/Projects/Sandy/triple_nest/00_dir_SHF05.ncml
http://geoport-dev.whoi.edu/thredds/dodsC/clay/usgs/users/jcwarner/Projects/Sandy/triple_nest/00_dir_USE27.ncml

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


COAWST Hindcast:Barnegat Bay:ADCIRC tides,Real rivers,Plume,Lowpass Espresso bdry,NAM,new bathy
Out[222]:
[{'scheme': 'WWW:LINK',
  'url': 'http://geoport-dev.whoi.edu/thredds/dodsC/usgs/data0/bbleh/spring2012/00_dir_roms.ncml.html'},
 {'scheme': 'WWW:LINK',
  'url': 'http://www.ncdc.noaa.gov/oa/wct/wct-jnlp-beta.php?singlefile=http://geoport-dev.whoi.edu/thredds/dodsC/usgs/data0/bbleh/spring2012/00_dir_roms.ncml'},
 {'scheme': 'OPeNDAP:OPeNDAP',
  'url': 'http://geoport-dev.whoi.edu/thredds/dodsC/usgs/data0/bbleh/spring2012/00_dir_roms.ncml'},
 {'scheme': 'OGC:WMS',
  'url': 'http://geoport-dev.whoi.edu/thredds/wms/usgs/data0/bbleh/spring2012/00_dir_roms.ncml?service=WMS&version=1.3.0&request=GetCapabilities'},
 {'scheme': 'UNIDATA:NCSS',
  'url': 'http://geoport-dev.whoi.edu/thredds/ncss/usgs/data0/bbleh/spring2012/00_dir_roms.ncml/dataset.html'},
 {'scheme': 'file',
  'url': 'http://geoport-dev.whoi.edu/thredds/fileServer/usgs/data0/bbleh/spring2012/00_dir_roms.ncml'}]

In [74]:
csw.request


Out[74]:
'<csw:GetRecords xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" outputSchema="http://www.opengis.net/cat/csw/2.0.2" outputFormat="application/xml" version="2.0.2" service="CSW" resultType="results" maxRecords="100" xsi:schemaLocation="http://www.opengis.net/cat/csw/2.0.2 http://schemas.opengis.net/csw/2.0.2/CSW-discovery.xsd"><csw:Query typeNames="csw:Record"><csw:ElementSetName>full</csw:ElementSetName><csw:Constraint version="1.1.0"><ogc:Filter><ogc:PropertyIsLike wildCard="*" singleChar="?" escapeChar="\\"><ogc:PropertyName>apiso:AnyText</ogc:PropertyName><ogc:Literal>*CMG_Portal*</ogc:Literal></ogc:PropertyIsLike></ogc:Filter></csw:Constraint></csw:Query></csw:GetRecords>'

In [75]:
csw.records[choice].xml


Out[75]:
'<csw:Record xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:inspire_common="http://inspire.ec.europa.eu/schemas/common/1.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:dct="http://purl.org/dc/terms/" xmlns:ows="http://www.opengis.net/ows" xmlns:apiso="http://www.opengis.net/cat/csw/apiso/1.0" xmlns:gml="http://www.opengis.net/gml" xmlns:dif="http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:srv="http://www.isotc211.org/2005/srv" xmlns:ogc="http://www.opengis.net/ogc" xmlns:fgdc="http://www.opengis.net/cat/csw/csdgm" xmlns:inspire_ds="http://inspire.ec.europa.eu/schemas/inspire_ds/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:os="http://a9.com/-/spec/opensearch/1.1/" xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"><dc:identifier>USGS_BBLEH_SANDY_076</dc:identifier><dc:title>USGS Barnegat Bay Model for Hurricane Sandy : run076</dc:title><dc:type>dataset</dc:type><dc:subject>CMG_Portal</dc:subject><dc:subject>Sandy_Portal</dc:subject><dc:subject>Zafer Defne</dc:subject><dc:subject>sea_surface_height_above_datum</dc:subject><dc:subject>barotropic_x_sea_water_velocity</dc:subject><dc:subject>barotropic_y_sea_water_velocity</dc:subject><dc:subject>x_sea_water_velocity</dc:subject><dc:subject>y_sea_water_velocity</dc:subject><dc:subject>sea_water_potential_temperature</dc:subject><dc:subject>sea_water_salinity</dc:subject><dc:subject>sea_surface_wave_significant_height</dc:subject><dc:subject>ocean_s_coordinate_g1</dc:subject><dc:subject>ocean_s_coordinate_g1</dc:subject><dc:subject>longitude</dc:subject><dc:subject>latitude</dc:subject><dc:subject>longitude</dc:subject><dc:subject>latitude</dc:subject><dc:subject>longitude</dc:subject><dc:subject>latitude</dc:subject><dc:subject>longitude</dc:subject><dc:subject>latitude</dc:subject><dc:subject>time</dc:subject><dc:subject>ocean_sigma_coordinate</dc:subject><dct:references scheme="WWW:LINK">http://geoport-dev.whoi.edu/thredds/dodsC/clay/usgs/users/zdefne/run076/his/00_dir_roms_display.ncml.html</dct:references><dct:references scheme="WWW:LINK">http://www.ncdc.noaa.gov/oa/wct/wct-jnlp-beta.php?singlefile=http://geoport-dev.whoi.edu/thredds/dodsC/clay/usgs/users/zdefne/run076/his/00_dir_roms_display.ncml</dct:references><dct:references scheme="OPeNDAP:OPeNDAP">http://geoport-dev.whoi.edu/thredds/dodsC/clay/usgs/users/zdefne/run076/his/00_dir_roms_display.ncml</dct:references><dct:references scheme="OGC:WMS">http://geoport-dev.whoi.edu/thredds/wms/clay/usgs/users/zdefne/run076/his/00_dir_roms_display.ncml?service=WMS&amp;version=1.3.0&amp;request=GetCapabilities</dct:references><dct:references scheme="UNIDATA:NCSS">http://geoport-dev.whoi.edu/thredds/ncss/grid/clay/usgs/users/zdefne/run076/his/00_dir_roms_display.ncml/dataset.html</dct:references><dct:references scheme="file">http://geoport-dev.whoi.edu/thredds/fileServer/clay/usgs/users/zdefne/run076/his/00_dir_roms_display.ncml</dct:references><dc:relation/><dct:modified>2016-04-13</dct:modified><dct:abstract>Simulation of hydrodynamics and sediment transport in Barnegat Bay, NJ during Hurricane Sandy.</dct:abstract><dc:date>2016-04-13</dc:date><ows:BoundingBox crs="urn:x-ogc:def:crs:EPSG:6.11:4326" dimensions="2"><ows:LowerCorner>39.44 -74.44</ows:LowerCorner><ows:UpperCorner>40.14 -74.0</ows:UpperCorner></ows:BoundingBox></csw:Record>'

Add bounding box constraint. To specify lon,lat order for bbox (which we want to do so that we can use the same bbox with either geoportal server or pycsw requests), we need to request the bounding box specifying the CRS84 coordinate reference system. The CRS84 option is available in pycsw 1.1.10+. The ability to specify the crs in the bounding box request is available in owslib 0.8.12+. For more info on the bounding box problem and how it was solved, see this pycsw issue, this geoportal server issue, and this owslib issue


In [76]:
bbox = [-87.40, 34.25, -63.70, 66.70]    # [lon_min, lat_min, lon_max, lat_max]
bbox_filter = fes.BBox(bbox,crs='urn:ogc:def:crs:OGC:1.3:CRS84')
filter_list = [fes.And([filter1, bbox_filter])]
csw.getrecords2(constraints=filter_list, maxrecords=1000)

In [77]:
print(len(csw.records.keys()))
for rec in list(csw.records.keys()):
    print('title:'+csw.records[rec].title) 
    print('identifier:'+csw.records[rec].identifier)
    print('modified:'+csw.records[rec].modified)
    print(' ')


9
title:USGS Barnegat Bay Model for Hurricane Sandy : run076
identifier:USGS_BBLEH_SANDY_076
modified:2016-04-13
 
title:COAWST Hindcast:Barnegat Bay:ADCIRC tides,Real rivers,Plume,Lowpass Espresso bdry,NAM,new bathy
identifier:gov.usgs.cmgp:COAWST.Barnegat_Bay.spring2012
modified:2016-04-13
 
title:USGS Chincoteague Bay Model for Hurricane Sandy
identifier:gov.usgs.cmg:USGS_CHINCO_SANDY
modified:2016-04-13
 
title:USGS Chincoteague Bay Model for EPR
identifier:gov.usgs.cmg:USGS_CHINCO_EPR
modified:2016-04-13
 
title:COAWST Forecast System : USGS : US East Coast and Gulf of Mexico (Experimental)
identifier:gov.usgs.cmgp:COAWST.USEAST.Forecast
modified:2016-04-13
 
title:COAWST Hindcast:MVCO/CBlast 2007:ripples with SWAN-40m res
identifier:gov.usgs.cmgp:COAWST.MVCO.CBLAST.spatial_7_ar0fd
modified:2016-04-13
 
title:USGS-CMG-COAWST Model: Hurricane Sandy, NYB05 700m Nest
identifier:gov.usgs.cmg:USGS_COAWST_Sandy_NYB05_sim6
modified:2016-04-13
 
title:USGS-CMG-COAWST Model: Hurricane Sandy, SHF05 2km Nest
identifier:gov.usgs.cmg:USGS_COAWST_Sandy_SHF05_sim6
modified:2016-04-13
 
title:USGS-CMG-COAWST Model: Hurricane Sandy, USE27 6km Nest
identifier:gov.usgs.cmg:USGS_COAWST_Sandy_USE27_sim6
modified:2016-04-13
 

In [78]:
val = 'wms'
filter2 = fes.PropertyIsLike(propertyname='apiso:ServiceType',literal=('*%s*' % val),
                        escapeChar='\\',wildCard='*',singleChar='?')
filter_list = [fes.And([filter1, filter2, bbox_filter])]
csw.getrecords2(constraints=filter_list, maxrecords=1000)

In [79]:
print(len(csw.records.keys()))
for rec in list(csw.records.keys()):
    print('title:'+csw.records[rec].title) 
    print('identifier:'+csw.records[rec].identifier)
    print('modified:'+csw.records[rec].modified)
    print(' ')


9
title:USGS Barnegat Bay Model for Hurricane Sandy : run076
identifier:USGS_BBLEH_SANDY_076
modified:2016-04-13
 
title:COAWST Hindcast:Barnegat Bay:ADCIRC tides,Real rivers,Plume,Lowpass Espresso bdry,NAM,new bathy
identifier:gov.usgs.cmgp:COAWST.Barnegat_Bay.spring2012
modified:2016-04-13
 
title:USGS Chincoteague Bay Model for Hurricane Sandy
identifier:gov.usgs.cmg:USGS_CHINCO_SANDY
modified:2016-04-13
 
title:USGS Chincoteague Bay Model for EPR
identifier:gov.usgs.cmg:USGS_CHINCO_EPR
modified:2016-04-13
 
title:COAWST Forecast System : USGS : US East Coast and Gulf of Mexico (Experimental)
identifier:gov.usgs.cmgp:COAWST.USEAST.Forecast
modified:2016-04-13
 
title:COAWST Hindcast:MVCO/CBlast 2007:ripples with SWAN-40m res
identifier:gov.usgs.cmgp:COAWST.MVCO.CBLAST.spatial_7_ar0fd
modified:2016-04-13
 
title:USGS-CMG-COAWST Model: Hurricane Sandy, NYB05 700m Nest
identifier:gov.usgs.cmg:USGS_COAWST_Sandy_NYB05_sim6
modified:2016-04-13
 
title:USGS-CMG-COAWST Model: Hurricane Sandy, SHF05 2km Nest
identifier:gov.usgs.cmg:USGS_COAWST_Sandy_SHF05_sim6
modified:2016-04-13
 
title:USGS-CMG-COAWST Model: Hurricane Sandy, USE27 6km Nest
identifier:gov.usgs.cmg:USGS_COAWST_Sandy_USE27_sim6
modified:2016-04-13
 

In [80]:
val = 'Warner'
#val = 'COADS'
filter1 = fes.PropertyIsLike(propertyname='apiso:AnyText',literal=('*%s*' % val),
                        escapeChar='\\',wildCard='*',singleChar='?')
filter_list = [ filter1 ]
csw.getrecords2(constraints=filter_list, maxrecords=1000)

In [81]:
print(len(csw.records.keys()))
for rec in list(csw.records.keys()):
    print('title:'+csw.records[rec].title) 
    print('identifier:'+csw.records[rec].identifier)
    print('modified:'+csw.records[rec].modified)
    print(' ')


4
title:COAWST Forecast System : USGS : US East Coast and Gulf of Mexico (Experimental)
identifier:gov.usgs.cmgp:COAWST.USEAST.Forecast
modified:2016-04-13
 
title:USGS-CMG-COAWST Model: Hurricane Sandy, NYB05 700m Nest
identifier:gov.usgs.cmg:USGS_COAWST_Sandy_NYB05_sim6
modified:2016-04-13
 
title:USGS-CMG-COAWST Model: Hurricane Sandy, SHF05 2km Nest
identifier:gov.usgs.cmg:USGS_COAWST_Sandy_SHF05_sim6
modified:2016-04-13
 
title:USGS-CMG-COAWST Model: Hurricane Sandy, USE27 6km Nest
identifier:gov.usgs.cmg:USGS_COAWST_Sandy_USE27_sim6
modified:2016-04-13
 

In [ ]:


In [ ]:


In [ ]: