In [17]:
from owslib.sos import SensorObservationService
import pdb
from owslib.etree import etree
import pandas as pd
import datetime as dt
In [18]:
# ncSOS endpoint with time series data
#url='http://geoport-dev.whoi.edu/thredds/sos/usgs/data2/notebook/1211-A1H.cdf'
url='http://www.neracoos.org:8180/thredds/sos/UMO/DSG/SOS/A01/Accelerometer/HistoricRealtime/Agg.ncml'
sos = SensorObservationService(url)
contents = sos.contents
In [19]:
sos.contents
Out[19]:
In [20]:
off = sos.offerings[1]
off.name
Out[20]:
In [21]:
off.response_formats
Out[21]:
In [22]:
off.observed_properties
Out[22]:
In [23]:
#pdb.set_trace()
response = sos.get_observation(offerings=['A01'],
responseFormat='text/xml;schema="om/1.0.0"',
observedProperties=['significant_wave_height'])
In [24]:
print response[0:1400]
In [25]:
def parse_om_xml(response):
# extract data and time from OM-XML response
root = etree.fromstring(response)
# root.findall(".//{%(om)s}Observation" % root.nsmap )
values = root.find(".//{%(swe)s}values" % root.nsmap )
date_value = array( [ (dt.datetime.strptime(d,"%Y-%m-%dT%H:%M:%SZ"),float(v))
for d,v in [l.split(',') for l in values.text.split()]] )
time = date_value[:,0]
data = date_value[:,1]
return data,time
In [26]:
data, time = parse_om_xml(response)
In [27]:
ts = pd.Series(data,index=time)
In [28]:
ts.plot(figsize(12,4));
In [29]:
# Try adding a time range to the getobs request:
start = '2010-03-01T00:00:00Z'
stop = '2010-04-15T00:00:00Z'
response = sos.get_observation(offerings=['A01'],
responseFormat='text/xml;schema="om/1.0.0"',
observedProperties=['significant_wave_height'],
eventTime='%s/%s' % (start,stop))
In [30]:
data, time = parse_om_xml(response)
In [31]:
ts = pd.Series(data,index=time)
In [32]:
ts.plot(figsize(12,4));