In [1]:
# for in memory files
import cStringIO 
import datetime
# for plotting
import matplotlib.pyplot as plt
import matplotlib.style
matplotlib.style.use('ggplot')
%matplotlib inline
# for geometry/wkt format
import shapely.geometry
# the service
import owslib.wps
# tables
import pandas

In [2]:
# this is the server that we'll use
url = 'http://wps.openearth.nl/wps'

# these are the inputs that we want to provide
line = [[3,52], [3,53], [3,54]]
startdate = datetime.datetime.now().isoformat() 
enddate = (datetime.datetime.now() + datetime.timedelta(days=10)).isoformat()
frequency = 'HOURLY'

In [3]:
# Open the server
# By default it will execute a GetCapabilities invocation to the remote service (skip_caps) 
server = owslib.wps.WebProcessingService(url)

In [4]:
# This is the list of process
server.processes


Out[4]:
[<owslib.wps.Process at 0x116191d90>,
 <owslib.wps.Process at 0x116191e50>,
 <owslib.wps.Process at 0x116600050>]

In [5]:
# Each process is an object that can be queried
# Store them by identifier and fill the data on the inputs by running the describeprocess function
processes = {process.identifier: server.describeprocess(process.identifier) for process in server.processes}

In [6]:
# Get the process of interest
process = processes['tidal_predict']

In [7]:
# Which inputs are required
inputs = {input.identifier: input for input  in process.dataInputs}
for name, input in inputs.items():
    print(name, input.dataType)
# What does location expect
for value in inputs['location'].supportedValues:
    print(value.mimeType)


('startdate', '//www.w3.org/TR/xmlschema-2/#string')
('frequency', '//www.w3.org/TR/xmlschema-2/#string')
('enddate', '//www.w3.org/TR/xmlschema-2/#string')
('location', 'ComplexData')
text/plain
application/xml
application/json

In [8]:
# Specify the input location as wkt (text/plain)
geom = shapely.geometry.LineString(line)
location = geom.to_wkt()
location, startdate, enddate


Out[8]:
('LINESTRING (3.0000000000000000 52.0000000000000000, 3.0000000000000000 53.0000000000000000, 3.0000000000000000 54.0000000000000000)',
 '2014-11-02T21:52:48.652908',
 '2014-11-12T21:52:48.652968')

In [9]:
# inputs is a list of tuples
# make a dict and use items
inputs = dict(
    location=location, 
    startdate=startdate, 
    enddate=enddate, 
    frequency=frequency
    )
# if this goes wrong, use verbose=True
result = server.execute('tidal_predict', inputs=inputs.items())
# you can also use getOutput to save to a file
output = result.processOutputs[0]


Executing WPS request...
Execution status=ProcessSucceeded
Percent completed=0
Status message=PyWPS Process tidal_predict successfully calculated

In [10]:
# looks like a file
f = cStringIO.StringIO(output.data[0])
df = pandas.DataFrame.from_csv(f)

In [12]:
# group the data by location 
grouped = df.groupby(by=['lat','lon'])
# make figure and axes
fig, ax = plt.subplots(figsize=(20,13))
# add a line for each group
for (index, group) in grouped:
    ax.plot(group.index, group.h, label=str(index))
# add the legend
ax.legend(loc='best')
ax.set_xlabel('time')
ax.set_ylabel('astronamical tide [m]')
ax.set_title("{}".format(process.title))


Out[12]:
<matplotlib.text.Text at 0x11663b2d0>

In [11]: