Using the NOAA ERDDAP web service, extract the latest data from a specified NDBC Station. Then using the Unidata "grid as point" NetCDF Subset Service, extract a time series closest to a specified lon,lat location.
At first we use the NetCDF Subset Web Form below to construct the query, but then reuse the URL generated by the form directly in the Python code below. In this way different time periods, depths or variables may be extracted without returning to the form, and analyzed and visualized in Python without saving and loading CSV files.
In [15]:
from IPython.display import HTML
In [16]:
import pandas as pd
import time
import datetime as dt
In [17]:
station = '44098' # Block Island
In [18]:
# Specify desired time range
# ....relative to right now ....
tstart = dt.datetime.utcnow() - dt.timedelta(days=4)
tstop = dt.datetime.utcnow() + dt.timedelta(days=1)
start=tstart.strftime('%Y-%m-%dT%H:%M:%SZ')
stop=tstop.strftime('%Y-%m-%dT%H:%M:%SZ')
# ... or specific times (UTC)
#start = '2014-08-24T00:00:00Z'
#stop = '2014-08-28T00:00:00Z'
print start,'\n', stop
In [19]:
#HTML('http://coastwatch.pfeg.noaa.gov/erddap/tabledap/cwwcNDBCMet.html')
In [20]:
url='http://coastwatch.pfeg.noaa.gov/erddap/tabledap/cwwcNDBCMet.csv?\
station,time,longitude,latitude,wvht\
&station="%s"&time>=%s&time<=%s' % (station,start,stop)
print url
In [21]:
# read CSV observations into Pandas DataFrame
df_obs = pd.read_csv(url,index_col='time',parse_dates=True,skiprows=[1])
In [22]:
lon=df_obs['longitude'][0]
lat=df_obs['latitude'][0]
print lon,lat
In [23]:
#HTML("http://geoport.whoi.edu/thredds/ncss/grid/bbleh/spring2012/pointDataset.html")
In [24]:
var = 'Hwave'
url='http://geoport.whoi.edu/thredds/ncss/grid/coawst_4/use/fmrc/coawst_4_use_best.ncd?\
var=%s&latitude=%f&longitude=%f&time_start=%s&time_end=%s&\
vertCoord=&accept=csv' % (var,lat,lon,start,stop)
print(url)
In [25]:
#load model data CSV into Pandas DataFrame
df_mod = pd.read_csv(url,index_col='date',parse_dates=True)
In [26]:
fig, ax = plt.subplots(figsize=(12, 4))
ax = df_mod['Hwave[unit="meter"]'].plot(ax=ax, legend=True)
df_obs['wvht'].plot(ax=ax, legend=True)
ax.set_title('Wave Height at Station %s' % station);
In [26]:
In [26]:
In [26]: