Wind Speed and Gust from NDBC SOS service

Get CSV data from NDBC SOS service using OWSlib, then read CSV data and plot using Pandas


In [20]:
from datetime import datetime
import cStringIO
import pandas as pd
from owslib.sos import SensorObservationService

In [21]:
# pick a buoy, any buoy
#sta_id='44066'  # texas tower
sta_id='44013'  # boston buoy

In [22]:
# pick a start & stop time
start = '2013-06-12T00:00:00Z'
stop = '2013-06-14T00:00:00Z'

In [23]:
from IPython.core.display import HTML
HTML('<iframe src=http://www.ndbc.noaa.gov/station_page.php?station=%s width=950 height=400></iframe>' % sta_id)


Out[23]:

In [24]:
ndbc=SensorObservationService('http://sdf.ndbc.noaa.gov/sos/server.php?request=GetCapabilities&service=SOS')

In [25]:
id=ndbc.identification
id.title


Out[25]:
'National Data Buoy Center SOS'

In [26]:
contents = ndbc.contents
network = contents['network-all']
network.description


Out[26]:
'All stations on the NDBC SOS server'

In [27]:
id.title


Out[27]:
'National Data Buoy Center SOS'

In [28]:
rfs = network.response_formats

In [29]:
print '\n'.join(rfs)


text/xml;subtype="om/1.0.0"
text/csv
text/tab-separated-values
application/vnd.google-earth.kml+xml
text/xml;schema="ioos/0.6.1"
application/ioos+xml;version=0.6.1

In [30]:
station = contents['station-%s' % sta_id]

In [31]:
station.name


Out[31]:
'urn:ioos:station:wmo:44013'

In [32]:
station.description


Out[32]:
'BOSTON 16 NM East of Boston, MA'

In [33]:
getob = ndbc.get_operation_by_name('getobservation')

In [34]:
getob.parameters


Out[34]:
{'observedProperty': {'values': ['air_temperature',
   'air_pressure_at_sea_level',
   'sea_water_electrical_conductivity',
   'currents',
   'sea_water_salinity',
   'sea_floor_depth_below_sea_surface',
   'sea_water_temperature',
   'waves',
   'winds']},
 'responseFormat': {'values': ['text/xml;subtype="om/1.0.0"',
   'text/csv',
   'text/tab-separated-values',
   'application/vnd.google-earth.kml+xml',
   'text/xml;schema="ioos/0.6.1"',
   'application/ioos+xml;version=0.6.1']}}

In [35]:
# issue the SOS get_obs request
response = ndbc.get_observation(offerings=['urn:ioos:station:wmo:%s' % sta_id],
                                 responseFormat='text/csv',
                                 observedProperties=['winds'],
                                 eventTime='%s/%s' % (start,stop))

In [36]:
df2 = pd.read_csv(cStringIO.StringIO(response.strip()),index_col='date_time',parse_dates=True)  # skip the units row

In [37]:
df2.head()


Out[37]:
&ltclass 'pandas.core.frame.DataFrame'>
DatetimeIndex: 5 entries, 2013-06-12 00:50:00 to 2013-06-12 04:50:00
Data columns (total 9 columns):
station_id                      5  non-null values
sensor_id                       5  non-null values
latitude (degree)               5  non-null values
longitude (degree)              5  non-null values
depth (m)                       5  non-null values
wind_from_direction (degree)    5  non-null values
wind_speed (m/s)                5  non-null values
wind_speed_of_gust (m/s)        5  non-null values
upward_air_velocity (m/s)       0  non-null values
dtypes: float64(7), object(2)

In [38]:
df2[['wind_speed_of_gust (m/s)','wind_speed (m/s)']].plot(figsize=(12,4),title=station.description,legend=True)


Out[38]:
<matplotlib.axes.AxesSubplot at 0x44fc350>