Check the start/stop time of a netcdf/OPeNDAP dataset


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)


2011-Oct-01 00:00
2016-Aug-12 19:00

In [12]:
nc = netCDF4.Dataset(url)
t = nc[tvar][:]
print(nc[tvar].units)


hours since 2011-10-01T00:00:00Z

Calculate the average time step


In [13]:
print np.mean(np.diff(t))


1.00136121477

So we have time steps of about 1 hour

Now calculate the unique time steps


In [14]:
print(np.unique(np.diff(t)).data)


[  1.   2.   3.   6.   9.  10.  14.  19.]

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]:
masked_array(data = [0.0 1.0 2.0 ..., 42665.0 42666.0 42667.0],
             mask = [False False False ..., False False False],
       fill_value = nan)

In [ ]:


In [ ]: