[gradsusr] generating a 4 dimensional netcdf file from http://nomads.ncep.noaa.gov:9090/dods/rtofs/rtofs_global20141116/rtofs_glo_3dz_forecast_daily_uvel

Jason Snyder jmssnyder at ucdavis.edu
Mon Nov 17 17:04:17 EST 2014


I am trying to generate a 4 dimensional netcdf file with time, level,
latitude, longitude from the the files on website:

http://nomads.ncep.noaa.gov:9090/dods/rtofs/rtofs_global20141116/rtofs_glo_3dz_forecast_daily_uvel


for zonal ocean current velocities at different depths through python
scripts.

I have the following python script but alas it is not allowing me to
generate the desired netcdf file:

#!/usr/bin/python
from pydap.client import open_url
from datetime import *
import datetime
now = datetime.datetime.now()
import pickle
import pupynere
import shutil

datasetu = open_url('
http://nomads.ncep.noaa.gov:9090/dods/rtofs/rtofs_global'+now.strftime(
"%Y%m%d")+'/rtofs_glo_3dz_forecast_daily_uvel')
datasetv = open_url('
http://nomads.ncep.noaa.gov:9090/dods/rtofs/rtofs_global'+now.strftime(
"%Y%m%d")+'/rtofs_glo_3dz_forecast_daily_vvel')

#sst = dataset['sst']
#sst.shape
#h=0
#for t in sst.time[:]:
    # print h
#    datestr=str(date.fromordinal(int(t)))
#    hour=int(24*(t-int(t)))
#    hourstr=str(hour);
#    if(hour<10): hourstr='0'+hourstr
#    w=datestr.split('-')
#    w.append(hourstr)
#    filename = w[0] + w[1] + w[2] + w[3] + 'sst.pickle'
#    if((int(w[3])%12)==0):
#        print h,filename
#        f = open(filename,'wb')
#        sgrd=sst.sst[h,0]
#        pickle.dump(sgrd,f)
#        f.close()
#    h=h+1

u = datasetu['u']
l = u.lat
lo = u.lon
le = u.lev
print u.shape
print l.shape
print lo.shape
print le.shape

f=open("lats.pickle","wb")
pickle.dump(l[428:430],f)
f.close

f=open("lons.pickle","wb")
pickle.dump(lo[2028:2030],f)
f.close

f=open("levs.pickle","wb")
pickle.dump(le[1:5],f)
f.close

f = pupynere.netcdf_file("hycom.nc",'w')
f.createDimension("latitude",2)
f.createDimension("longitude",2)
f.createDimension("level",4)

lats=f.createVariable("latitude","f",("latitude",))
lats[:]=l[2028:2030]
lons=f.createVariable("longitude","f",("longitude",))
lons[:]=lo[428:430]
levs=f.createVariable("level","f",("level",))
levs[:]=le[1:5]

h=0
print ">>>>>>>>U Velocity"
for t in u.time[:]:
    datestr=str(date.fromordinal(int(t)))
    hour=int(24*(t-int(t)))
    hourstr=str(hour);
    if(hour<10): hourstr='0'+hourstr
    w=datestr.split('-')
    w.append(hourstr)
#    filename= w[0] + w[1] + w[2] + w[3] + 'u.pickle'
    if((int(w[3])%12)==0):
#        print h,filename
#        f = open(filename,'wb')
        #print u.u[h,1:5,428:430,2028:2030]
        ugrd = f.createVariable("ugrd","f",("level","latitude","longitude"))
        ugrd = u.u[h,1:5,428:430,2028:2030]
        print ugrd
#        u[:] = ugrd
#        ugrd.units = "m/s"
#        ugrd=u.u[h,0]
#        pickle.dump(u.u[h,1:5,428:430,2028:2030],f)
#        f.close()
    h=h+1



Anyway suggestions?


Thanks,

Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20141117/cc9ba8b1/attachment-0001.html 


More information about the gradsusr mailing list