import netCDF4
import numpy as np

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'))

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)

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

"""
Explanation: Check the start/stop time of a netcdf/OPeNDAP dataset
End of explanation
"""


print np.mean(np.diff(t))

"""
Explanation: Calculate the average time step
End of explanation
"""


print(np.unique(np.diff(t)).data)

"""
Explanation: So we have time steps of about 1 hour
Now calculate the unique time steps
End of explanation
"""


nc['time'][:]

"""
Explanation: So there are gaps of 2, 3, 6, 9, 10, 14 and 19 hours in the otherwise hourly data
End of explanation
"""


