Skip to content

Commit

Permalink
Merge pull request #241 from jrleeman/NDBC_Service
Browse files Browse the repository at this point in the history
Add NDBC simple web service
  • Loading branch information
dopplershift authored Aug 9, 2018
2 parents d28cac0 + a5dcdb4 commit f057105
Show file tree
Hide file tree
Showing 19 changed files with 7,135 additions and 5 deletions.
15 changes: 11 additions & 4 deletions docs/api/simplewebservice.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,23 @@
:members:
:special-members: __init__

======================================
====================================
:mod:`siphon.simplewebservice.igra2`
======================================
====================================
.. automodule:: siphon.simplewebservice.igra2
:members:
:special-members: __init__

======================================
===================================
:mod:`siphon.simplewebservice.acis`
======================================
===================================
.. automodule:: siphon.simplewebservice.acis
:members:
:special-members: __init__

===================================
:mod:`siphon.simplewebservice.ndbc`
===================================
.. automodule:: siphon.simplewebservice.ndbc
:members:
:special-members: __init__
2 changes: 1 addition & 1 deletion docs/installguide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This includes:
* Core Python developers will
`stop support for Python 2.7 January 1, 2020 <https://pythonclock.org/>`_
* NumPy feature releases will be
`Python 3 only starting January 1, 2019 <https://docs.scipy.org/doc/numpy/neps/dropping-python2.7-proposal.html>`_,
`Python 3 only starting January 1, 2019 <http://www.numpy.org/neps/nep-0014-dropping-python2.7-proposal.html>`_,
and support for the last release supporting Python 2 will end January 1, 2020.
* XArray will drop
`2.7 January 1, 2019 as well <https://github.com/pydata/xarray/issues/1830>`_
Expand Down
7 changes: 7 additions & 0 deletions examples/ndbc/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.. _ndbc_examples:

National Data Buoy Center (NDBC)
--------------------------------

Examples of requesting data from the National Data Buoy Center latest and realtime
data sources.
42 changes: 42 additions & 0 deletions examples/ndbc/buoy_met_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright (c) 2018 Siphon Contributors.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause
"""
NDBC Buoy Meteorological Data Request
=====================================
The NDBC keeps a 45-day recent rolling file for each buoy. This examples shows how to access
the basic meteorological data from a buoy and make a simple plot.
"""

import matplotlib.pyplot as plt

from siphon.simplewebservice.ndbc import NDBC

####################################################
# Get a pandas data frame of all of the observations, meteorological data is the default
# observation set to query.
df = NDBC.realtime_observations('41002')
df.head()

####################################################
# Let's make a simple time series plot to checkout what the data look like.
fig, (ax1, ax2, ax3) = plt.subplots(3, 1, figsize=(12, 10))
ax2b = ax2.twinx()

# Pressure
ax1.plot(df['time'], df['pressure'], color='black')
ax1.set_ylabel('Pressure [hPa]')

# Wind speed, gust, direction
ax2.plot(df['time'], df['wind_speed'], color='tab:orange')
ax2.plot(df['time'], df['wind_gust'], color='tab:olive', linestyle='--')
ax2b.plot(df['time'], df['wind_direction'], color='tab:blue', linestyle='-')
ax2.set_ylabel('Wind Speed [m/s]')
ax2b.set_ylabel('Wind Direction')

# Water temperature
ax3.plot(df['time'], df['water_temperature'], color='tab:brown')
ax3.set_ylabel('Water Temperature [degC]')

plt.show()
23 changes: 23 additions & 0 deletions examples/ndbc/buoy_type_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (c) 2018 Siphon Contributors.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause
"""
NDBC Buoy Data Request (of any type)
====================================
The NDBC keeps a 40-day recent rolling file for each buoy. This examples shows how to access
the other types of data available for a buoy.
"""

from siphon.simplewebservice.ndbc import NDBC

####################################################
# Request the types of data available from a given buoy.
data_aval = NDBC.buoy_data_types('41002')
print(data_aval)

####################################################
# Get a pandas data frame of all of the observations, meteorological data is the default
# observation set to query.
df = NDBC.realtime_observations('41002', data_type='supl')
df.head()
42 changes: 42 additions & 0 deletions examples/ndbc/latest_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright (c) 2018 Siphon Contributors.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause
"""
NDBC Latest Data Request
========================
This example shows how to use siphon's `simplewebswervice` support query the most recent
observations from all of the NDBC buoys at once.
"""

import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt

from siphon.simplewebservice.ndbc import NDBC

####################################################
# Get a pandas data frame of all of the observations
df = NDBC.latest_observations()
df.head()

####################################################
# In this case I'm going to drop buoys that do not have water temperature measurements.
df.dropna(subset=['water_temperature'], inplace=True)

####################################################
# Let's make a simple plot of the buoy positions and color by water temperature
proj = ccrs.LambertConformal(central_latitude=45., central_longitude=-100.,
standard_parallels=[30, 60])

fig = plt.figure(figsize=(17., 11.))
ax = plt.axes(projection=proj)
ax.coastlines('50m', edgecolor='black')
ax.add_feature(cfeature.OCEAN.with_scale('50m'))
ax.add_feature(cfeature.LAND.with_scale('50m'))
ax.set_extent([-85, -75, 25, 30], ccrs.PlateCarree())

ax.scatter(df['longitude'], df['latitude'], c=df['water_temperature'],
transform=ccrs.PlateCarree())

plt.show()
Loading

0 comments on commit f057105

Please sign in to comment.