def my_range(start, end, step):
while start <= end:
yield start
start += step
url='
http://tds.hycom.org/thredds/dodsC/datasets/GLBy0.08/expt_93.0/data/forecasts/hycom_glby_930_2021082312_t024_uv3z.nc'
url2='
http://tds.hycom.org/thredds/dodsC/datasets/GLBy0.08/expt_93.0/data/forecasts/hycom_glby_930_2021082312_t024_ts3z.nc'
dataset=open_url(url)
dataset2=open_url(url2)
print("list is ",list(dataset.keys()))
date = dataset['time']
print("shape is ",date.shape)
dateT = int(str(date[0].data)[1:-2])
print("date is ",dateT)
dttme=datetime.strptime('2000-01-01 00:00:00', '%Y-%m-%d %H:%M:%S') + timedelta(hours=dateT)
dttme2=datetime.strftime(dttme, "%Y%m%d%H")
print("The date being processed is ",dttme2)
xl=0
xu=4499
yl=0
yu=4000
water_u = dataset['water_u']
water_v = dataset['water_v']
water_temp = dataset2['water_temp']
print("1) ssu file ....")
text_file = open("ssu_"+dttme2+".xyz","w")
for j in my_range(int(yl),int(yu),2):
for i in my_range(int(xl),int(xu),2):
latt=int(j)
lonn=int(i)
u=float(str(water_u[0,2,latt,lonn][:].array.data)[4:-4])/1000
ustr=str(u)
text_file.write(ustr+"\n")
What can I do to get this to run faster? The wget works fairly rapidly for whole netcdf files but I only need the first top levels of the hycom data and not the whole netcdf file so that is why I am using opendap.
Thank you for your help.