In [22]:
import netCDF4
%matplotlib inline
from scipy.stats import binned_statistic_2d
import datetime as dt
import pandas as pd
import oceans
import matplotlib.pyplot as plt
import numpy as np
In [2]:
url='http://dods.ndbc.noaa.gov/thredds/dodsC/data/stdmet/brbn4/brbn4.ncml'
nc = netCDF4.Dataset(url)
ncv = nc.variables
In [3]:
ncv.keys()
Out[3]:
In [4]:
time_var = ncv['time']
dtime = netCDF4.num2date(time_var[:],time_var.units)
In [7]:
# Extract desired times. Here we select a specific time of interest
start = dt.datetime(2010,8,1,0,0,0)
istart = netCDF4.date2index(start,time_var,select='nearest')
stop = dt.datetime(2010,9,1,0,0,0)
istop = netCDF4.date2index(stop,time_var,select='nearest')
In [8]:
# Get all time records of variable [vname] at indices [iy,ix]
vname = 'wind_spd'
var = ncv[vname]
var.shape
wspd = var[istart:istop,:,:].ravel()
In [9]:
vname = 'wind_dir'
var = ncv[vname]
var.shape
wdir = var[istart:istop,:,:].ravel()
In [10]:
tim = dtime[istart:istop]
In [11]:
# Create Pandas time series object
ts = pd.Series(wspd,index=tim)
In [12]:
ts.plot()
Out[12]:
In [17]:
u,v = oceans.spdir2uv(wspd,wdir,deg=True)
In [21]:
fig=plt.figure(figsize=(12,4))
plt.plot(tim,u,tim,v)
Out[21]:
In [27]:
f1,x,y,bin1 = binned_statistic_2d(u, v, u, statistic='mean', bins=10, range=None)
f2,x,y,bin2 = binned_statistic_2d(u, v, v, statistic='mean', bins=10, range=None)
In [30]:
u
Out[30]:
In [ ]:
url='http://tds.marine.rutgers.edu/thredds/dodsC/met/ncdc-nam-3hour/swrad_nam_3hourly_MAB_and_GoM_2009.nc'