0

I am trying to make a python script to make a 4 dimensional netcdf file from the website I have the following python script:

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

and

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

I get a netcdf file with the following attributes:

netcdf hycom {
dimensions:
    latitude = 30 ;
    longitude = 30 ;
    level = 4 ;
variables:
    float v(level, latitude, longitude) ;
        v:units = "m/s" ;
    float u(level, latitude, longitude) ;
        u:units = "m/s" ;
    float longitude(longitude) ;
        longitude:units = "degrees_east" ;
    float level(level) ;
    float latitude(latitude) ;
        latitude:units = "degrees_north" ;

data:

 longitude = 107.492, 107.5753, 107.6587, 107.742, 107.8253, 107.9087, 
    107.992, 108.0753, 108.1586, 108.242, 108.3253, 108.4086, 108.492, 
    108.5753, 108.6586, 108.742, 108.8253, 108.9086, 108.9919, 109.0753, 
    109.1586, 109.2419, 109.3253, 109.4086, 109.4919, 109.5752, 109.6586, 
    109.7419, 109.8252, 109.9086 ;

 level = 10, 20, 30, 50 ;

 latitude = 76.66, 76.74333, 76.82666, 76.90999, 76.99332, 77.07665, 
    77.15998, 77.24331, 77.32664, 77.40997, 77.4933, 77.57663, 77.65996, 
    77.74329, 77.82662, 77.90995, 77.99328, 78.07661, 78.15994, 78.24327, 
    78.3266, 78.40993, 78.49326, 78.57659, 78.65992, 78.74325, 78.82658, 
    78.90991, 78.99324, 79.07657 ;
}

However when I try to open the file on grads I get the following message:

ga-> sdfopen hycom.nc
Scanning self-describing file:  hycom.nc
SDF file has no discernable time coordinate -- using default values.
gadsdf: SDF file does not have any non-coordinate variables.

I have been able to successfully make netcdf files from 2d hycom data but not from the 3d hycom data. Do you know what I need to do to create a 3d hycom netcdf file with levels, longitude, latitude, and time.

The shape file is (9,33,2142,4369) or (time, level,latitude,longitude).

 #!/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')

u = datasetu['u']
u.shape
print ">>>>> u.shape is",u.shape
print u[1,1:5,400:430,2000:2030]

v = datasetv['v']
v.shape
print v[1,1:5,400:430,2000:2030]
y=u.lat
x=u.lon
z=u.lev

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

lats=f.createVariable("latitude","f",("latitude",))
lats[:]=y[2000:2030]
lons=f.createVariable("longitude","f",("longitude",))
lons[:]=x[400:430]
levs=f.createVariable("level","f",("level",))
levs[:]=z[5]

lats.units = 'degrees_north'
lons.units = 'degrees_east'
levs.units = 'meters below sea level'


#print u[1,0,400:430,2000:2030]
ucur = f.createVariable("u","f",("level","latitude","longitude"))
ucur[:]=u[1,1:5,400:430,2000:2030]
ucur.units = "m/s"
########################################################
#print v[0,0,1000:1400,1000:1400]
vcur = f.createVariable("v","f",("level","latitude","longitude"))
vcur[:]=v[1,1:5,400:430,2000:2030]
vcur.units = "m/s"

1 Answer 1

1

You need to match the shapes between ucar and u and vcur and v during the write out procedure. Since you are extracting a 3D slice of u and v, you need to make sure that you populate 3 dimensions of ucur and vcar:

ucur[:,:,:] = u[1,1:5,400:430,2000:2030]
vcur[:,:,:] = v[1,1:5,400:430,2000:2030]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.