Testing CSW filtering with FES

Trying to do: (sea_surface_height_above_geoid OR sea_surface_height OR ..) NOT Averages with time extents and bounding box


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

In [2]:
box=[-76.4751, 38.3890, -71.7432, 42.9397]

# ... 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:%M')
stop_date  = jd_stop.strftime('%Y-%m-%d %H:%M')
print start_date,'to',stop_date


2014-03-10 21:02 to 2014-03-16 21:02

In [3]:
endpoint = 'http://www.ngdc.noaa.gov/geoportal/csw' # NGDC Geoportal
csw = CatalogueServiceWeb(endpoint,timeout=60)
csw.version


Out[3]:
'2.0.2'

In [4]:
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 [5]:
or_filt = fes.Or([fes.PropertyIsLike(propertyname='apiso:AnyText',literal=('*%s*' % val),
                    escapeChar='\\',wildCard='*',singleChar='?') for val in std_name_list])

In [6]:
val = 'Averages'
not_filt = fes.Not([fes.PropertyIsLike(propertyname='apiso:AnyText',literal=('*%s*' % val),
                        escapeChar='\\',wildCard='*',singleChar='?')])

In [7]:
# hopefully something like this will be implemented in fes soon
def dateRange(start_date='1900-01-01',stop_date='2100-01-01',constraint='overlaps'):
    if constraint == 'overlaps':
        start = fes.PropertyIsLessThanOrEqualTo(propertyname='apiso:TempExtent_begin', literal=stop_date)
        stop = fes.PropertyIsGreaterThanOrEqualTo(propertyname='apiso:TempExtent_end', literal=start_date)
    elif constraint == 'within':
        start = fes.PropertyIsGreaterThanOrEqualTo(propertyname='apiso:TempExtent_begin', literal=start_date)
        stop = fes.PropertyIsLessThanOrEqualTo(propertyname='apiso:TempExtent_end', literal=stop_date)
    return start,stop

In [8]:
# convert User Input into FES filters
start,stop = dateRange(start_date,stop_date)
bbox = fes.BBox(box)

In [9]:
filter_list = [fes.And([ bbox, start, stop, or_filt, not_filt]) ]
csw.getrecords2(constraints=filter_list,maxrecords=1000)
print len(csw.records.keys())
for rec,item in csw.records.iteritems():
    print item.title


6
DBOFS - Delaware Bay Operational Forecast System - NOAA CO-OPS - POM
NECOFS GOM3 (FVCOM) - Northeast US - Latest Forecast
CBOFS - Chesapeake Bay Operational Forecast System - NOAA CO-OPS - POM
ROMS ESPRESSO Real-Time Operational IS4DVAR Forecast System Version 2 (NEW) 2013-present FMRC History (Best)
NYOFS - New York and New Jersey Operational Forecast System - NOAA CO-OPS - POM
NECOFS GOM3 Wave - Northeast US - Latest Forecast

In [9]: