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]:
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)
In [8]:
# Specify the input location as wkt (text/plain)
geom = shapely.geometry.LineString(line)
location = geom.to_wkt()
location, startdate, enddate
Out[8]:
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]
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]:
In [11]: