In [9]:
import netCDF4
import numpy as np
In [10]:
def start_stop(url,tvar):
nc = netCDF4.Dataset(url)
time_var = nc[tvar]
first = netCDF4.num2date(time_var[0],time_var.units)
last = netCDF4.num2date(time_var[-1],time_var.units)
print(first.strftime('%Y-%b-%d %H:%M'))
print(last.strftime('%Y-%b-%d %H:%M'))
In [11]:
url='http://hfrnet.ucsd.edu/thredds/dodsC/HFR/USWC/6km/hourly/RTV/HFRADAR,_US_West_Coast,_6km_Resolution,_Hourly_RTV_best.ncd'
tvar='time'
start_stop(url,tvar)
In [12]:
nc = netCDF4.Dataset(url)
t = nc[tvar][:]
print(nc[tvar].units)
Calculate the average time step
In [13]:
print np.mean(np.diff(t))
So we have time steps of about 1 hour
Now calculate the unique time steps
In [14]:
print(np.unique(np.diff(t)).data)
So there are gaps of 2, 3, 6, 9, 10, 14 and 19 hours in the otherwise hourly data
In [15]:
nc['time'][:]
Out[15]:
In [ ]:
In [ ]: