#!/usr/bin/env python # coding: utf-8 # # Check the start/stop time of a netcdf/OPeNDAP dataset # In[1]: import netCDF4 import numpy as np # In[2]: def start_stop(url,tvar): nc = netCDF4.Dataset(url) ncv = nc.variables time_var = ncv[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[3]: 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[4]: nc = netCDF4.Dataset(url) ncv = nc.variables t = ncv[tvar][:] print(ncv[tvar].units) # Calculate the average time step # In[5]: print np.mean(np.diff(t)) # So we have time steps of about 1 hour # Now calculate the unique time steps # In[6]: 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