Read realtime data from NERACOOS ERDDAP

Exploring use of Python to formulate NERACOOS ERDDAP data requests and process the responses.

Initialize


In [15]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

In [16]:
# Use ERDDAP's built-in relative time functionality to get last 48 hours:
start='now-7days'
stop='now'
# or specify a specific period:
start = '2014-08-27T00:00:00Z'
stop =  '2014-08-29T00:00:00Z'

Obtain data from NetCDF Subset Service


In [17]:
url='http://thredds-test.unidata.ucar.edu/thredds/ncss/grib/NCEP/GFS/Global_0p5deg/Best?var=Temperature_height_above_ground&latitude=41.533656&longitude=289.35&time_start=%s&time_end=%s&vertCoord=1&accept=csv' % (start,stop)

In [18]:
df_met = pd.read_csv(url,index_col='date',parse_dates=True)  # skip the units row
new_index = pd.date_range(start=df.index[0],end=df.index[-1],freq='15min') df.reindex(new_index).interpolate(limit=10)

In [12]:
df_met['Temperature_height_above_ground[unit="K"]'].plot()


Out[12]:
<matplotlib.axes.AxesSubplot at 0x7f108722f810>

In [36]:
# read met data (E01_met)
url='http://www.neracoos.org/erddap/tabledap/E01_met_all.csv?\
station,time,air_temperature,barometric_pressure,wind_gust,wind_speed,\
wind_direction,visibility\
&time>=%s&time<=%s' % (start,stop)

df_met = pd.read_csv(url,index_col='time',parse_dates=True,skiprows=[1])  # skip the units row

In [37]:
# read wave data (E01_accelerometer)
url='http://www.neracoos.org/erddap/tabledap/E01_accelerometer_all.csv?\
station,time,mooring_site_desc,significant_wave_height,dominant_wave_period&\
time>=%s&time<=%s' % (start,stop)

# Load the CSV data directly into Pandas
df_wave = pd.read_csv(url,index_col='time',parse_dates=True,skiprows=[1])  # skip the units row

In [40]:
# List last ten records
df_sb.tail(10)


Out[40]:
station depth longitude latitude attenuation sigma_t temperature salinity
time
2014-06-30 07:00:00 E0131 87 -69.3578 43.7148 1.000772 25.425750 5.9821 32.304817
2014-06-30 08:00:00 E0131 87 -69.3578 43.7148 1.001006 25.426762 5.9769 32.305300
2014-06-30 09:00:00 E0131 87 -69.3578 43.7148 0.890862 25.397400 5.9913 32.270332
2014-06-30 10:00:00 E0131 87 -69.3578 43.7148 1.030441 25.438414 5.9383 32.314144
2014-06-30 11:00:00 E0131 87 -69.3578 43.7148 0.963295 25.463295 5.8957 32.339146
2014-06-30 12:00:00 E0131 87 -69.3578 43.7148 0.923289 25.457102 5.9048 32.332690
2014-06-30 13:00:00 E0131 87 -69.3578 43.7148 0.876964 25.449490 5.9135 32.324383
2014-06-30 14:00:00 E0131 87 -69.3578 43.7148 0.835218 25.429472 5.9374 32.302685
2014-06-30 15:00:00 E0131 87 -69.3578 43.7148 0.804611 25.412160 5.9744 32.286430
2014-06-30 16:00:00 E0131 87 -69.3578 43.7148 0.959462 25.449951 5.9332 32.327972

In [81]:
df_sb['sigma_t'].plot(figsize=(12,4),title=df_sb['station'][0]);legend(loc=2)
df_sb['attenuation'].plot(figsize=(12,4),secondary_y=True,legend=True)


Out[81]:
<matplotlib.axes.AxesSubplot at 0x7f4fe23be5d0>

In [86]:
p1=df_met['wind_speed'].plot(figsize=(12,4));legend(loc=2)
p2=df_wave['significant_wave_height'].plot(secondary_y=True,legend=True)



In [74]:
p1.get_label()


Out[74]:
''

In [64]:
df[['wind_speed','significant_wave_height']].plot(figsize=(12,4))


Out[64]:
<matplotlib.axes.AxesSubplot at 0x7f4fe2b43bd0>

In [50]:
df_wave.plot(figsize=(12,4));



In [43]:
scatter(df_sb['sigma_t'],df_sb['attenuation'])
grid()



In [44]:
def tsplot(sobs,tobs):
    smin=sobs.min()
    smax=sobs.max()
    tmin=tobs.min()
    tmax=tobs.max()
    s_inc=(smax-smin)/8.
    t_inc=(tmax-tmin)/8.
    t = np.arange(tmin,tmax+t_inc,t_inc)
    s = np.arange(smin,smax+s_inc,s_inc)
    S, T = np.meshgrid(s, t)
    st = sw.dens0(S, T) - 1000
    st_inc=(st.max()-st.min())/8.
    levels = np.arange(st.min(),st.max()+st_inc,st_inc)
    from matplotlib import rcParams
    from matplotlib.ticker import MultipleLocator
    rcParams['xtick.direction'] = 'out'
    rcParams['ytick.direction'] = 'out'
    fig, ax = plt.subplots(figsize=(6, 4))
 #   ax.xaxis.set_major_locator(MultipleLocator(0.5))
 #   ax.xaxis.set_minor_locator(MultipleLocator(0.1))
 #   ax.yaxis.set_major_locator(MultipleLocator(5))
 #   ax.yaxis.set_minor_locator(MultipleLocator(1))
    ax.set_ylabel(u"Temperature \u00b0C")
    ax.set_xlabel(r"Salinity [g kg$^{-1}$]")
    ax.axis([smin,smax,tmin,tmax])

    cs = ax.contour(s, t, st, colors='black', levels=levels)
    ax.clabel(cs, fontsize=9, inline=1, fmt='%3.2f')
    #sg = ax.contour(s, t, sigma_theta, linestyle='--', colors='grey', levels=[0, line])
    #ax.clabel(sg, fontsize=9, inline=1, fmt='%2.1f')
    ax.plot(sobs,tobs,'o')

In [45]:
tsplot(df['salinity'],df['temperature'])



In [ ]: