I already have written a ncks code to extract data from the Hycom Database, however, due to server issues I can only download one timestep at a time. I need a loop that allows me to download singular timestep data for the time period of one month.
ncks -d time,2015-12-01T00:00:00Z -d depth,0.00,1000.00,1 -v water_temp,salinity,water_u,water_v,surf_el -d lon,161.45,171.28 -d lat,-4.75,3.43 'http://tds.hycom.org/thredds/dodsC/GLBv0.08/expt_53.X/data/2015' test.nc
4D Variables I want to download: water_temp, salinity, water_u, water_v (their dimensions are time, latitude, longitude, depth)
3D Variables I want to download: surf_el (dimensions are time, latitude and longitude)
For the 4D variables, I want the depth to bet between 0 and 1000m. That code is for a singular time, I want to cover the period between 2015/12/01 and 2015/12/31. The whole December of 2015.
Here some Python working code:
import netCDF4
from netCDF4 import Dataset
dec = Dataset('http://tds.hycom.org/thredds/dodsC/GLBv0.08/expt_53.X/data/2015')
print(dec.variables.keys()) #odict_keys(['depth', 'lat', 'lon', 'time', 'tau', 'water_u', 'water_u_bottom', 'water_v', 'water_v_bottom', 'water_temp', 'water_temp_bottom', 'salinity', 'salinity_bottom', 'surf_el'])
long = dec.variables['lon']
lati = dec.variables['lat']
time = dec.variables['time']
for d in dec.dimensions.items():
print(d)
#('depth', <class 'netCDF4._netCDF4.Dimension'>: name = 'depth', size = 40)
#('lat', <class 'netCDF4._netCDF4.Dimension'>: name = 'lat', size = 3251)
#('lon', <class 'netCDF4._netCDF4.Dimension'>: name = 'lon', size = 4500)
#('time', <class 'netCDF4._netCDF4.Dimension'>: name = 'time', size = 2861)