本文整理汇总了Python中pyroms_toolbox.nc_create_roms_file函数的典型用法代码示例。如果您正苦于以下问题:Python nc_create_roms_file函数的具体用法?Python nc_create_roms_file怎么用?Python nc_create_roms_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了nc_create_roms_file函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: remap_clm
def remap_clm(src_file, src_varname, src_grd, dst_grd, dxy=20, cdepth=0, kk=0, dst_dir='./'):
# get time
nctime.long_name = 'time'
nctime.units = 'days since 1900-01-01 00:00:00'
# time reference "days since 1900-01-01 00:00:00"
# ref = datetime(1900, 1, 1, 0, 0, 0)
# ref = date2num(ref)
# tag = src_file.rsplit('/')[-1].rsplit('_')[-2].rsplit('-')[0]
# print tag
# year = int(tag[:4])
# month = int(tag[4:6])
# day = int(tag[6:])
# time = datetime(year, month, day, 0, 0, 0)
# time = date2num(time)
# time = time - ref
# time = time + 2.5 # 5-day average
cdf = netCDF.Dataset(src_file)
src_var = cdf.variables[src_varname][0]
time = cdf.variables['ocean_time'][0]
# create IC file
dst_file = src_file.rsplit('/')[-1]
dst_file = dst_dir + dst_file[:-3] + '_' + src_varname + '_clim_' + dst_grd.name + '.nc'
print '\nCreating file', dst_file
if os.path.exists(dst_file) is True:
os.remove(dst_file)
pyroms_toolbox.nc_create_roms_file(dst_file, dst_grd, nctime)
# open IC file
nc = netCDF.Dataset(dst_file, 'a', format='NETCDF3_64BIT')
#load var
cdf = netCDF.Dataset(src_file)
src_var = cdf.variables[src_varname]
#get missing value
spval = src_var._FillValue
src_var = src_var[0]
# determine variable dimension
#ndim = len(src_var.dimensions)
ndim = len(src_var.shape)
if src_varname == 'ssh':
pos = 't'
Cpos = 'rho'
z = src_grd.z_t
Mp, Lp = dst_grd.hgrid.mask_rho.shape
wts_file = 'remap_weights_GLBa0.08_to_PALAU1_bilinear_t_to_rho.nc'
dst_varname = 'zeta'
dimensions = ('ocean_time', 'eta_rho', 'xi_rho')
long_name = 'free-surface'
units = 'meter'
field = 'free-surface, scalar, series'
vartime = 'ocean_time'
elif src_varname == 'temp':
pos = 't'
Cpos = 'rho'
z = src_grd.z_t
Mp, Lp = dst_grd.hgrid.mask_rho.shape
wts_file = 'remap_weights_GLBa0.08_to_PALAU1_bilinear_t_to_rho.nc'
dst_varname = 'temp'
dimensions = ('ocean_time', 's_rho', 'eta_rho', 'xi_rho')
long_name = 'potential temperature'
units = 'Celsius'
field = 'temperature, scalar, series'
vartime = 'ocean_time'
elif src_varname == 'salt':
pos = 't'
Cpos = 'rho'
z = src_grd.z_t
Mp, Lp = dst_grd.hgrid.mask_rho.shape
wts_file = 'remap_weights_GLBa0.08_to_PALAU1_bilinear_t_to_rho.nc'
dst_varname = 'salt'
dimensions = ('ocean_time', 's_rho', 'eta_rho', 'xi_rho')
long_name = 'salinity'
units = 'PSU'
field = 'salinity, scalar, series'
vartime = 'ocean_time'
else:
raise ValueError, 'Undefined src_varname'
if ndim == 3:
# build intermediate zgrid
zlevel = -z[::-1,0,0]
nzlevel = len(zlevel)
dst_zcoord = pyroms.vgrid.z_coordinate(dst_grd.vgrid.h, zlevel, nzlevel)
dst_grdz = pyroms.grid.ROMS_Grid(dst_grd.name+'_Z', dst_grd.hgrid, dst_zcoord)
# create variable in file
print 'Creating variable', dst_varname
nc.createVariable(dst_varname, 'f8', dimensions, fill_value=spval)
nc.variables[dst_varname].long_name = long_name
nc.variables[dst_varname].units = units
nc.variables[dst_varname].field = field
nc.variables[dst_varname].time = vartime
#.........这里部分代码省略.........
示例2: remapping
#.........这里部分代码省略.........
# srcfile argument
if type(srcfile).__name__ == "list":
nfile = len(srcfile)
elif type(srcfile).__name__ == "str":
srcfile = sorted(glob.glob(srcfile))
nfile = len(srcfile)
else:
raise ValueError, "src_srcfile must be a str or a list of str"
# get wts_file
if type(wts_files).__name__ == "str":
wts_files = sorted(glob.glob(wts_files))
# loop over the srcfile
for nf in range(nfile):
print "Working with file", srcfile[nf], "..."
# get time
ocean_time = pyroms.utility.get_nc_var("ocean_time", srcfile[nf])
ntime = len(ocean_time[:])
# trange argument
if trange is None:
trange = range(ntime)
else:
trange = range(trange[0], trange[1] + 1)
# create destination file
dstfile = dstdir + os.path.basename(srcfile[nf])[:-3] + "_" + dstgrd.name + ".nc"
print "Creating destination file", dstfile
if os.path.exists(dstfile) is True:
os.remove(dstfile)
pyroms_toolbox.nc_create_roms_file(dstfile, dstgrd, ocean_time)
# open destination file
nc = netCDF.Dataset(dstfile, "a", format="NETCDF3_CLASSIC")
nctidx = 0
# loop over time
for nt in trange:
nc.variables["ocean_time"][nctidx] = ocean_time[nt]
# loop over variable
for nv in range(nvar):
print " "
print "remapping", varname[nv], "from", srcgrd.name, "to", dstgrd.name
print "time =", ocean_time[nt]
# get source data
src_var = pyroms.utility.get_nc_var(varname[nv], srcfile[nf])
# determine variable dimension
ndim = len(src_var.dimensions) - 1
# get spval
try:
spval = src_var._FillValue
except:
raise Warning, "Did not find a _FillValue attribute."
# irange
if irange is None:
iirange = (0, src_var._shape()[-1])
else:
示例3: remap_bdry_uv
def remap_bdry_uv(src_file, src_grd, dst_grd, dxy=20, cdepth=0, kk=2, dst_dir='./'):
# get time
nctime.long_name = 'time'
nctime.units = 'days since 1900-01-01 00:00:00'
# get dimensions
Mp, Lp = dst_grd.hgrid.mask_rho.shape
# create destination file
dst_file = src_file.rsplit('/')[-1]
dst_fileu = dst_dir + dst_file[:-3] + '_u_bdry_' + dst_grd.name + '.nc'
print '\nCreating destination file', dst_fileu
if os.path.exists(dst_fileu) is True:
os.remove(dst_fileu)
pyroms_toolbox.nc_create_roms_file(dst_fileu, dst_grd, nctime)
dst_filev = dst_dir + dst_file[:-3] + '_v_bdry_' + dst_grd.name + '.nc'
print 'Creating destination file', dst_filev
if os.path.exists(dst_filev) is True:
os.remove(dst_filev)
pyroms_toolbox.nc_create_roms_file(dst_filev, dst_grd, nctime)
# open destination file
ncu = netCDF.Dataset(dst_fileu, 'a', format='NETCDF3_64BIT')
ncv = netCDF.Dataset(dst_filev, 'a', format='NETCDF3_64BIT')
#load var
cdf = netCDF.Dataset(src_file)
src_varu = cdf.variables['u']
src_varv = cdf.variables['v']
time = cdf.variables['ocean_time'][0]
#get missing value
spval = src_varu._FillValue
src_varu = cdf.variables['u'][0]
src_varv = cdf.variables['v'][0]
# get weights file
wts_file = 'remap_weights_GLBa0.08_to_ARCTIC2_bilinear_t_to_rho.nc'
# build intermediate zgrid
zlevel = -src_grd.z_t[::-1,0,0]
nzlevel = len(zlevel)
dst_zcoord = pyroms.vgrid.z_coordinate(dst_grd.vgrid.h, zlevel, nzlevel)
dst_grdz = pyroms.grid.ROMS_Grid(dst_grd.name+'_Z', dst_grd.hgrid, dst_zcoord)
# create variable in destination file
print 'Creating variable u_north'
ncu.createVariable('u_north', 'f8', ('ocean_time', 's_rho', 'xi_u'), fill_value=spval)
ncu.variables['u_north'].long_name = '3D u-momentum north boundary condition'
ncu.variables['u_north'].units = 'meter second-1'
ncu.variables['u_north'].field = 'u_north, scalar, series'
print 'Creating variable u_south'
ncu.createVariable('u_south', 'f8', ('ocean_time', 's_rho', 'xi_u'), fill_value=spval)
ncu.variables['u_south'].long_name = '3D u-momentum south boundary condition'
ncu.variables['u_south'].units = 'meter second-1'
ncu.variables['u_south'].field = 'u_south, scalar, series'
print 'Creating variable u_east'
ncu.createVariable('u_east', 'f8', ('ocean_time', 's_rho', 'eta_u'), fill_value=spval)
ncu.variables['u_east'].long_name = '3D u-momentum east boundary condition'
ncu.variables['u_east'].units = 'meter second-1'
ncu.variables['u_east'].field = 'u_east, scalar, series'
print 'Creating variable u_west'
ncu.createVariable('u_west', 'f8', ('ocean_time', 's_rho', 'eta_u'), fill_value=spval)
ncu.variables['u_west'].long_name = '3D u-momentum west boundary condition'
ncu.variables['u_west'].units = 'meter second-1'
ncu.variables['u_west'].field = 'u_east, scalar, series'
# create variable in destination file
print 'Creating variable ubar_north'
ncu.createVariable('ubar_north', 'f8', ('ocean_time', 'xi_u'), fill_value=spval)
ncu.variables['ubar_north'].long_name = '2D u-momentum north boundary condition'
ncu.variables['ubar_north'].units = 'meter second-1'
ncu.variables['ubar_north'].field = 'ubar_north, scalar, series'
print 'Creating variable ubar_south'
ncu.createVariable('ubar_south', 'f8', ('ocean_time', 'xi_u'), fill_value=spval)
ncu.variables['ubar_south'].long_name = '2D u-momentum south boundary condition'
ncu.variables['ubar_south'].units = 'meter second-1'
ncu.variables['ubar_south'].field = 'ubar_south, scalar, series'
print 'Creating variable ubar_east'
ncu.createVariable('ubar_east', 'f8', ('ocean_time', 'eta_u'), fill_value=spval)
ncu.variables['ubar_east'].long_name = '2D u-momentum east boundary condition'
ncu.variables['ubar_east'].units = 'meter second-1'
ncu.variables['ubar_east'].field = 'ubar_east, scalar, series'
print 'Creating variable ubar_west'
ncu.createVariable('ubar_west', 'f8', ('ocean_time', 'eta_u'), fill_value=spval)
ncu.variables['ubar_west'].long_name = '2D u-momentum west boundary condition'
ncu.variables['ubar_west'].units = 'meter second-1'
ncu.variables['ubar_west'].field = 'ubar_east, scalar, series'
print 'Creating variable v_north'
ncv.createVariable('v_north', 'f8', ('ocean_time', 's_rho', 'xi_v'), fill_value=spval)
ncv.variables['v_north'].long_name = '3D v-momentum north boundary condition'
ncv.variables['v_north'].units = 'meter second-1'
#.........这里部分代码省略.........
示例4: remap_bdry
def remap_bdry(src_file, src_varname, src_grd, dst_grd, dmax=0, cdepth=0, kk=0, dst_dir='./'):
ystart=240
# get time
nctime.long_name = 'time'
nctime.units = 'days since 1900-01-01 00:00:00'
# time reference "days since 1900-01-01 00:00:00"
ref = datetime(1900, 1, 1, 0, 0, 0)
ref = date2num(ref)
tag = src_file.rsplit('/')[-1].rsplit('_')[-1].rsplit('-')[0]
year = int(tag[:4])
month = int(tag[4:6])
day = int(tag[6:])
time = datetime(year, month, day, 0, 0, 0)
time = date2num(time)
time = time - ref
time = time + 2.5 # 5-day average
# create boundary file
dst_file = src_file.rsplit('/')[-1]
dst_file = dst_dir + dst_file[:-4] + '_' + src_varname + '_bdry_' + dst_grd.name + '.nc'
print '\nCreating boundary file', dst_file
if os.path.exists(dst_file) is True:
os.remove(dst_file)
pyroms_toolbox.nc_create_roms_file(dst_file, dst_grd, nctime)
# open boundary file
nc = netCDF.Dataset(dst_file, 'a', format='NETCDF3_64BIT')
#load var
cdf = netCDF.Dataset(src_file)
src_var = cdf.variables[src_varname]
#get missing value
spval = src_var._FillValue
# determine variable dimension
ndim = len(src_var.dimensions)
# global grid
if ndim == 3:
src_var = src_var[:]
src_var = src_var[:,np.r_[ystart:np.size(src_var,1),-1],:]
elif ndim == 2:
src_var = src_var[:]
src_var = src_var[np.r_[ystart:np.size(src_var,0),-1],:]
if src_varname == 'ssh':
Bpos = 't'
Cpos = 'rho'
z = src_grd.z_t
Mp, Lp = dst_grd.hgrid.mask_rho.shape
wts_file = 'remap_weights_SODA_2.1.6_to_ARCTIC2_bilinear_t_to_rho.nc'
dst_varname = 'zeta'
dimensions = ('ocean_time', 'eta_rho', 'xi_rho')
long_name = 'free-surface'
dst_varname_north = 'zeta_north'
dimensions_north = ('ocean_time', 'xi_rho')
long_name_north = 'free-surface north boundary condition'
field_north = 'zeta_north, scalar, series'
dst_varname_south = 'zeta_south'
dimensions_south = ('ocean_time', 'xi_rho')
long_name_south = 'free-surface south boundary condition'
field_south = 'zeta_south, scalar, series'
dst_varname_east = 'zeta_east'
dimensions_east = ('ocean_time', 'eta_rho')
long_name_east = 'free-surface east boundary condition'
field_east = 'zeta_east, scalar, series'
dst_varname_west = 'zeta_west'
dimensions_west = ('ocean_time', 'eta_rho')
long_name_west = 'free-surface west boundary condition'
field_west = 'zeta_west, scalar, series'
units = 'meter'
elif src_varname == 'temp':
Bpos = 't'
Cpos = 'rho'
z = src_grd.z_t
Mp, Lp = dst_grd.hgrid.mask_rho.shape
wts_file = 'remap_weights_SODA_2.1.6_to_ARCTIC2_bilinear_t_to_rho.nc'
dst_varname = 'temperature'
dst_varname_north = 'temp_north'
dimensions_north = ('ocean_time', 's_rho', 'xi_rho')
long_name_north = 'potential temperature north boundary condition'
field_north = 'temp_north, scalar, series'
dst_varname_south = 'temp_south'
dimensions_south = ('ocean_time', 's_rho', 'xi_rho')
long_name_south = 'potential temperature south boundary condition'
field_south = 'temp_south, scalar, series'
dst_varname_east = 'temp_east'
dimensions_east = ('ocean_time', 's_rho', 'eta_rho')
long_name_east = 'potential temperature east boundary condition'
field_east = 'temp_east, scalar, series'
dst_varname_west = 'temp_west'
dimensions_west = ('ocean_time', 's_rho', 'eta_rho')
long_name_west = 'potential temperature west boundary condition'
field_west = 'temp_west, scalar, series'
units = 'Celsius'
elif src_varname == 'salt':
Bpos = 't'
#.........这里部分代码省略.........
示例5: remap
def remap(src_varname, src_file, src_grd, dst_grd, dst_file, dmax=0, cdepth=0, kk=0, dst_dir='./'):
# get time
nctime.long_name = 'time'
nctime.units = 'days since 1900-01-01 00:00:00'
# create tide file
print '\nCreating tide file', dst_file
if os.path.exists(dst_file) is True:
os.remove(dst_file)
pyroms_toolbox.nc_create_roms_file(dst_file, dst_grd, nctime)
# open tide file
nc = netCDF.Dataset(dst_file, 'a', format='NETCDF3_64BIT')
# load var
cdf = netCDF.Dataset(src_file)
src_var = cdf.variables[src_varname]
# get missing value
spval = src_var.missing_value
if src_varname == 'h_re':
z = src_grd.z_t
Mp, Lp = dst_grd.hgrid.mask_rho.shape
wts_file = 'remap_weights_' + src_grd.name + '_to_' + dst_grd.name + '_bilinear_t_to_rho.nc'
dst_varname = 'h_re'
dimensions = ('ocean_time', 'eta_rho', 'xi_rho')
long_name = 'tidal constituent amplitude (real)'
units = 'meter'
field = 'free-surface, scalar, series'
if src_varname == 'h_im':
z = src_grd.z_t
Mp, Lp = dst_grd.hgrid.mask_rho.shape
wts_file = 'remap_weights_' + src_grd.name + '_to_' + dst_grd.name + '_bilinear_t_to_rho.nc'
dst_varname = 'h_im'
dimensions = ('ocean_time', 'eta_rho', 'xi_rho')
long_name = 'tidal constituent amplitude (imaginary)'
units = 'meter'
field = 'free-surface, scalar, series'
if src_varname == 'u_re':
z = src_grd.z_t
Mp, Lp = dst_grd.hgrid.mask_rho.shape
wts_file = 'remap_weights_' + src_grd.name + '_to_' + dst_grd.name + '_bilinear_u_to_rho.nc'
dst_varname = 'h_re'
dimensions = ('ocean_time', 'eta_rho', 'xi_rho')
long_name = 'tidal constituent x-velocity (real)'
units = 'meter per second'
field = 'x-velocity, scalar, series'
if src_varname == 'u_im':
z = src_grd.z_t
Mp, Lp = dst_grd.hgrid.mask_rho.shape
wts_file = 'remap_weights_' + src_grd.name + '_to_' + dst_grd.name + '_bilinear_u_to_rho.nc'
dst_varname = 'u_im'
dimensions = ('ocean_time', 'eta_rho', 'xi_rho')
long_name = 'tidal constituent x-velocity (imaginary)'
units = 'meter per second'
field = 'x-velocity, scalar, series'
if src_varname == 'v_re':
z = src_grd.z_t
Mp, Lp = dst_grd.hgrid.mask_rho.shape
wts_file = 'remap_weights_' + src_grd.name + '_to_' + dst_grd.name + '_bilinear_v_to_rho.nc'
dst_varname = 'v_re'
dimensions = ('ocean_time', 'eta_rho', 'xi_rho')
long_name = 'tidal constituent y-velocity (real)'
units = 'meter per second'
field = 'y-velocity, scalar, series'
if src_varname == 'v_im':
z = src_grd.z_t
Mp, Lp = dst_grd.hgrid.mask_rho.shape
wts_file = 'remap_weights_' + src_grd.name + '_to_' + dst_grd.name + '_bilinear_v_to_rho.nc'
dst_varname = 'v_im'
dimensions = ('ocean_time', 'eta_rho', 'xi_rho')
long_name = 'tidal constituent y-velocity (imaginary)'
units = 'meter per second'
field = 'y-velocity, scalar, series'
else:
raise ValueError, 'Undefined src_varname'
# create variable in file
print 'Creating variable', dst_varname
nc.createVariable(dst_varname, 'f8', dimensions, fill_value=spval)
# nc.createVariable(dst_varname, 'f8', dimensions)
nc.variables[dst_varname].long_name = long_name
nc.variables[dst_varname].units = units
nc.variables[dst_varname].field = field
# remapping
print 'remapping', dst_varname, 'from', src_grd.name, \
'to', dst_grd.name
# horizontal interpolation using scrip weights
print 'horizontal interpolation using scrip weights'
dst_var = pyroms.remapping.remap(src_var, wts_file, spval=spval)
# write data in destination file
print 'write data in destination file\n'
#.........这里部分代码省略.........
示例6: remap_bio_woa
def remap_bio_woa(argdict, src_grd, dst_grd, dmax=0, cdepth=0, kk=0, dst_dir='./'):
# NWGOA3 grid sub-sample
xrange=src_grd.xrange; yrange=src_grd.yrange
src_varname = argdict['tracer']
tracer = src_varname
src_file = argdict['file']
units = argdict['units']
longname = argdict['longname']
nframe = argdict['frame']
if src_varname == 'sio4':
src_varname = 'si'
# get time
nctime.long_name = 'time'
nctime.units = 'days since 1900-01-01 00:00:00'
# create clim file
dst_file = tracer + '.nc'
dst_file = dst_dir + dst_grd.name + '_clim_bio_' + dst_file
print 'Creating clim file', dst_file
if os.path.exists(dst_file) is True:
os.remove(dst_file)
pyroms_toolbox.nc_create_roms_file(dst_file, dst_grd, nctime)
# open clim file
nc = netCDF.Dataset(dst_file, 'a', format='NETCDF3_64BIT')
#load var
cdf = netCDF.Dataset(src_file)
src_var = cdf.variables[src_varname]
# correct time to some classic value
days_in_month = np.array([31,28.25,31,30,31,30,31,31,30,31,30,31])
time = days_in_month[:nframe].sum() + days_in_month[nframe] / 2.
#get missing value
spval = src_var._FillValue
spval2 = -1.0e+10
# determine variable dimension
ndim = len(src_var.dimensions) - 1
# NWGOA3 grid sub-sample
if ndim == 3:
src_var = src_var[nframe,:, yrange[0]:yrange[1]+1, xrange[0]:xrange[1]+1]
elif ndim == 2:
src_var = src_var[nframe,yrange[0]:yrange[1]+1, xrange[0]:xrange[1]+1]
if tracer == 'no3':
unit_conversion = 1. / 1e6 / 1.035
elif tracer == 'po4':
unit_conversion = 1. / 1e6 / 1.035
elif tracer == 'o2':
unit_conversion = 1. / 1035 / 22391.6 * 1000.0
elif tracer == 'sio4':
unit_conversion = 1. / 1e6 / 1.035
src_var = src_var * unit_conversion
Bpos = 't'
Cpos = 'rho'
z = src_grd.z_t
Mp, Lp = dst_grd.hgrid.mask_rho.shape
wts_file = 'remap_weights_ESM2M_to_NWGOA3_bilinear_t_to_rho.nc'
dst_varname = tracer
dimensions = ('ocean_time', 's_rho', 'eta_rho', 'xi_rho')
long_name = longname
field = tracer + ', scalar, series'
units = units
if ndim == 3:
# build intermediate zgrid
zlevel = -z[::-1]
nzlevel = len(zlevel)
dst_zcoord = pyroms.vgrid.z_coordinate(dst_grd.vgrid.h, zlevel, nzlevel)
dst_grdz = pyroms.grid.ROMS_Grid(dst_grd.name+'_Z', dst_grd.hgrid, dst_zcoord)
# create variable in file
print 'Creating variable', dst_varname
nc.createVariable(dst_varname, 'f8', dimensions, fill_value=spval2)
nc.variables[dst_varname].long_name = long_name
nc.variables[dst_varname].units = units
nc.variables[dst_varname].field = field
#nc.variables[dst_varname_north]._FillValue = spval
# remapping
print 'remapping', dst_varname, 'from', src_grd.name, \
'to', dst_grd.name
if ndim == 3:
# flood the grid
print 'flood the grid'
src_varz = pyroms_toolbox.BGrid_GFDL.flood(src_var, src_grd, Bpos=Bpos, spval=spval, \
#.........这里部分代码省略.........
示例7: remapping_bound_sig
def remapping_bound_sig(varname, srcfile, wts_files, srcgrd, dst_grd, \
rotate_sig=False, trange=None, irange=None, jrange=None, \
dstdir='./' ,zlevel=None, dmax=0, cdepth=0, kk=0):
'''
A remapping function to go from a ROMS grid to another ROMS grid.
This is for 2D tensors: internal ice stress, hard-coding for sig11, sig22,
sig12.
'''
# get input and output grid
if type(srcgrd).__name__ == 'ROMS_Grid':
srcgrd = srcgrd
else:
srcgrd = pyroms.grid.get_ROMS_grid(srcgrd)
if type(dst_grd).__name__ == 'ROMS_Grid':
dst_grd = dst_grd
else:
dst_grd = pyroms.grid.get_ROMS_grid(dst_grd)
# varname argument
if type(varname).__name__ == 'list':
nvar = len(varname)
elif type(varname).__name__ == 'str':
varname = [varname]
nvar = len(varname)
else:
raise ValueError, 'varname must be a str or a list of str'
# srcfile argument
if type(srcfile).__name__ == 'list':
nfile = len(srcfile)
elif type(srcfile).__name__ == 'str':
srcfile = sorted(glob.glob(srcfile))
nfile = len(srcfile)
else:
raise ValueError, 'src_srcfile must be a str or a list of str'
# get wts_file
if type(wts_files).__name__ == 'str':
wts_files = sorted(glob.glob(wts_files))
sides = ['_west','_east','_north','_south']
long = {'_west':'Western', '_east':'Eastern', \
'_north':'Northern', '_south':'Southern'}
dimexcl = {'_west':'xi', '_east':'xi', \
'_north':'eta', '_south':'eta'}
nctidx = 0
# loop over the srcfile
for nf in range(nfile):
print 'Working with file', srcfile[nf], '...'
# get time
ocean_time = pyroms.utility.get_nc_var('ocean_time', srcfile[nf])
ntime = len(ocean_time[:])
# trange argument
if trange is None:
trange = range(ntime)
# create destination file
if nctidx == 0:
dstfile = dstdir + os.path.basename(srcfile[nf])[:-3] + '_' \
+ dst_grd.name + '_bdry.nc'
if os.path.exists(dstfile) is False:
print 'Creating destination file', dstfile
pyroms_toolbox.nc_create_roms_file(dstfile, dst_grd, \
ocean_time, lgrid=False)
# open destination file
nc = netCDF.Dataset(dstfile, 'a', format='NETCDF3_64BIT')
# loop over time
for nt in trange:
nc.variables['ocean_time'][nctidx] = ocean_time[nt]
# loop over variable
for nv in range(nvar):
print ' '
print 'remapping', varname[nv], 'from', srcgrd.name, \
'to', dst_grd.name
print 'time =', ocean_time[nt]
Mp, Lp = dst_grd.hgrid.mask_rho.shape
# get source data
src_var = pyroms.utility.get_nc_var(varname[nv], srcfile[nf])
# get spval
try:
spval = src_var._FillValue
except:
raise Warning, 'Did not find a _FillValue attribute.'
# irange
if irange is None:
iirange = (0,src_var.shape[-1])
else:
iirange = irange
#.........这里部分代码省略.........
示例8: remapping_bound
#.........这里部分代码省略.........
nfile = len(srcfile)
else:
raise ValueError, 'src_srcfile must be a str or a list of str'
# get wts_file
if type(wts_files).__name__ == 'str':
wts_files = sorted(glob.glob(wts_files))
sides = ['_west','_east','_north','_south']
long = {'_west':'Western', '_east':'Eastern', \
'_north':'Northern', '_south':'Southern'}
dimexcl = {'_west':'xi', '_east':'xi', \
'_north':'eta', '_south':'eta'}
nctidx = 0
# loop over the srcfile
for nf in range(nfile):
print 'Working with file', srcfile[nf], '...'
# get time
ocean_time = pyroms.utility.get_nc_var('ocean_time', srcfile[nf])
ntime = len(ocean_time[:])
# trange argument
if trange is None:
trange = range(ntime)
# create destination file
if nctidx == 0:
dstfile = dstdir + os.path.basename(srcfile[nf])[:-3] + '_' \
+ dst_grd.name + '_bdry.nc'
if os.path.exists(dstfile) is False:
print 'Creating destination file', dstfile
pyroms_toolbox.nc_create_roms_file(dstfile, dst_grd, \
ocean_time, lgrid=False)
# open destination file
nc = netCDF.Dataset(dstfile, 'a', format='NETCDF3_64BIT')
# loop over time
for nt in trange:
nc.variables['ocean_time'][nctidx] = ocean_time[nt]
# loop over variable
for nv in range(nvar):
print ' '
print 'remapping', varname[nv], 'from', srcgrd.name, \
'to', dst_grd.name
print 'time =', ocean_time[nt]
Mp, Lp = dst_grd.hgrid.mask_rho.shape
# get source data
src_var = pyroms.utility.get_nc_var(varname[nv], srcfile[nf])
# determine variable dimension
ndim = len(src_var.dimensions)-1
# get spval
try:
spval = src_var._FillValue
except:
raise Warning, 'Did not find a _FillValue attribute.'
# irange
if irange is None:
示例9: remap
def remap(src_file, src_varname, src_grd, dst_grd, dmax=0, cdepth=0, kk=0, dst_dir='./'):
# YELLOW grid sub-sample
xrange=(225, 275); yrange=(190, 240)
# get time
nctime.long_name = 'time'
nctime.units = 'days since 1900-01-01 00:00:00'
# time reference "days since 1900-01-01 00:00:00"
ref = datetime(1900, 1, 1, 0, 0, 0)
ref = date2num(ref)
tag = src_file.rsplit('/')[-1].rsplit('_')[-1].rsplit('-')[0]
year = int(tag[:4])
month = int(tag[4:6])
day = int(tag[6:])
time = datetime(year, month, day, 0, 0, 0)
time = date2num(time)
time = time - ref
time = time + 2.5 # 5-day average
# create IC file
dst_file = src_file.rsplit('/')[-1]
dst_file = dst_dir + dst_file[:-4] + '_' + src_varname + '_ic_' + dst_grd.name + '.nc'
print '\nCreating file', dst_file
if os.path.exists(dst_file) is True:
os.remove(dst_file)
pyroms_toolbox.nc_create_roms_file(dst_file, dst_grd, nctime)
# open IC file
nc = netCDF.Dataset(dst_file, 'a', format='NETCDF3_CLASSIC')
#load var
cdf = netCDF.Dataset(src_file)
src_var = cdf.variables[src_varname]
#get missing value
spval = src_var._FillValue
# determine variable dimension
ndim = len(src_var.dimensions)
# YELLOW grid sub-sample
if ndim == 3:
src_var = src_var[:, yrange[0]:yrange[1]+1, xrange[0]:xrange[1]+1]
elif ndim == 2:
src_var = src_var[yrange[0]:yrange[1]+1, xrange[0]:xrange[1]+1]
if src_varname == 'ssh':
Bpos = 't'
Cpos = 'rho'
z = src_grd.z_t
Mp, Lp = dst_grd.hgrid.mask_rho.shape
wts_file = 'remap_weights_SODA_2.1.6_to_YELLOW_bilinear_t_to_rho.nc'
dst_varname = 'zeta'
dimensions = ('ocean_time', 'eta_rho', 'xi_rho')
long_name = 'free-surface'
units = 'meter'
field = 'free-surface, scalar, series'
elif src_varname == 'temp':
Bpos = 't'
Cpos = 'rho'
z = src_grd.z_t
Mp, Lp = dst_grd.hgrid.mask_rho.shape
wts_file = 'remap_weights_SODA_2.1.6_to_YELLOW_bilinear_t_to_rho.nc'
dst_varname = 'temp'
dimensions = ('ocean_time', 's_rho', 'eta_rho', 'xi_rho')
long_name = 'potential temperature'
units = 'Celsius'
field = 'temperature, scalar, series'
elif src_varname == 'salt':
Bpos = 't'
Cpos = 'rho'
z = src_grd.z_t
Mp, Lp = dst_grd.hgrid.mask_rho.shape
wts_file = 'remap_weights_SODA_2.1.6_to_YELLOW_bilinear_t_to_rho.nc'
dst_varname = 'salt'
dimensions = ('ocean_time', 's_rho', 'eta_rho', 'xi_rho')
long_name = 'salinity'
units = 'PSU'
field = 'salinity, scalar, series'
else:
raise ValueError, 'Undefined src_varname'
if ndim == 3:
# build intermediate zgrid
zlevel = -z[::-1,0,0]
nzlevel = len(zlevel)
dst_zcoord = pyroms.vgrid.z_coordinate(dst_grd.vgrid.h, zlevel, nzlevel)
dst_grdz = pyroms.grid.ROMS_Grid(dst_grd.name+'_Z', dst_grd.hgrid, dst_zcoord)
# create variable in file
print 'Creating variable', dst_varname
nc.createVariable(dst_varname, 'f8', dimensions, fill_value=spval)
nc.variables[dst_varname].long_name = long_name
nc.variables[dst_varname].units = units
nc.variables[dst_varname].field = field
#nc.variables[dst_varname_north]._FillValue = spval
#.........这里部分代码省略.........
示例10: remapping_tensor
def remapping_tensor(varname, srcfile, wts_files, srcgrd, dstgrd, \
rotate_sig=False, trange=None, irange=None, jrange=None, \
dstdir='./', shapiro=False):
'''
A remapping function to go from a ROMS grid to another ROMS grid.
This is for 2D tensors: internal ice stress, hard-coding for sig11, sig22,
sig12.
'''
# get input and output grid
if type(srcgrd).__name__ == 'ROMS_Grid':
srcgrd = srcgrd
else:
srcgrd = pyroms.grid.get_ROMS_grid(srcgrd)
if type(dstgrd).__name__ == 'ROMS_Grid':
dstgrd = dstgrd
else:
dstgrd = pyroms.grid.get_ROMS_grid(dstgrd)
# varname argument
if type(varname).__name__ == 'list':
nvar = len(varname)
elif type(varname).__name__ == 'str':
varname = [varname]
nvar = len(varname)
else:
raise ValueError, 'varname must be a str or a list of str'
# srcfile argument
if type(srcfile).__name__ == 'list':
nfile = len(srcfile)
elif type(srcfile).__name__ == 'str':
srcfile = sorted(glob.glob(srcfile))
nfile = len(srcfile)
else:
raise ValueError, 'src_srcfile must be a str or a list of str'
# get wts_file
if type(wts_files).__name__ == 'str':
wts_files = sorted(glob.glob(wts_files))
# loop over the srcfile
for nf in range(nfile):
print 'Working with file', srcfile[nf], '...'
# get time
ocean_time = pyroms.utility.get_nc_var('ocean_time', srcfile[nf])
ntime = len(ocean_time[:])
# trange argument
if trange is None:
trange = range(ntime)
# create destination file
dstfile = dstdir + os.path.basename(srcfile[nf])[:-3] + '_' + dstgrd.name + '.nc'
if os.path.exists(dstfile) is False:
print 'Creating destination file', dstfile
pyroms_toolbox.nc_create_roms_file(dstfile, dstgrd, ocean_time)
# open destination file
nc = netCDF.Dataset(dstfile, 'a', format='NETCDF3_64BIT')
nctidx = 0
# loop over time
for nt in trange:
nc.variables['ocean_time'][nctidx] = ocean_time[nt]
# loop over variable
for nv in range(nvar):
print ' '
print 'remapping', varname[nv], 'from', srcgrd.name, \
'to', dstgrd.name
print 'time =', ocean_time[nt]
# get source data
src_var = pyroms.utility.get_nc_var(varname[nv], srcfile[nf])
# get spval
try:
spval = src_var._FillValue
except:
raise Warning, 'Did not find a _FillValue attribute.'
# irange
if irange is None:
iirange = (0,src_var.shape[-1])
else:
iirange = irange
# jrange
if jrange is None:
jjrange = (0,src_var.shape[-2])
else:
jjrange = jrange
# determine where on the C-grid these variable lies
if src_var.dimensions[2].find('_rho') != -1:
Cpos='rho'
else:
#.........这里部分代码省略.........
示例11: remap
def remap(src_varname, src_file, src_grd, dst_grd, dst_file, dmax=0, cdepth=0, kk=0, dst_dir='./'):
# CCS grid sub-sample
xrange=src_grd.xrange; yrange=src_grd.yrange
# get time
nctime.long_name = 'time'
nctime.units = 'days since 1900-01-01 00:00:00'
# create IC file
print '\nCreating initial condition file', dst_file
if os.path.exists(dst_file) is True:
os.remove(dst_file)
pyroms_toolbox.nc_create_roms_file(dst_file, dst_grd, nctime)
# open IC file
nc = netCDF.Dataset(dst_file, 'a', format='NETCDF3_64BIT')
#load var
cdf = netCDF.Dataset(src_file)
src_var = cdf.variables[src_varname]
tmp = cdf.variables['time'][:]
if len(tmp) > 1:
print 'error : multiple frames in input file' ; exit()
else:
time = tmp[0]
# we need to correct the time axis
ref_soda = dt.datetime(1980,1,1,0,0)
ref_roms = dt.datetime(1900,1,1,0,0)
ndays = (ref_soda - ref_roms).days
time = time + ndays
#get missing value
spval = src_var.missing_value
# determine variable dimension
ndim = len(src_var.dimensions) - 1
# CCS grid sub-sample
if ndim == 3:
src_var = src_var[0,:, yrange[0]:yrange[1]+1, xrange[0]:xrange[1]+1]
elif ndim == 2:
src_var = src_var[0,yrange[0]:yrange[1]+1, xrange[0]:xrange[1]+1]
if src_varname == 'ssh':
Bpos = 't'
Cpos = 'rho'
z = src_grd.z_t
Mp, Lp = dst_grd.hgrid.mask_rho.shape
wts_file = 'remap_weights_' + src_grd.name + '_to_' + dst_grd.name + '_bilinear_t_to_rho.nc'
dst_varname = 'zeta'
dimensions = ('ocean_time', 'eta_rho', 'xi_rho')
long_name = 'free-surface'
units = 'meter'
field = 'free-surface, scalar, series'
elif src_varname == 'temp':
src_var = src_var
Bpos = 't'
Cpos = 'rho'
z = src_grd.z_t
Mp, Lp = dst_grd.hgrid.mask_rho.shape
wts_file = 'remap_weights_' + src_grd.name + '_to_' + dst_grd.name + '_bilinear_t_to_rho.nc'
dst_varname = 'temp'
dimensions = ('ocean_time', 's_rho', 'eta_rho', 'xi_rho')
long_name = 'potential temperature'
units = 'Celsius'
field = 'temperature, scalar, series'
elif src_varname == 'salt':
Bpos = 't'
Cpos = 'rho'
z = src_grd.z_t
Mp, Lp = dst_grd.hgrid.mask_rho.shape
wts_file = 'remap_weights_' + src_grd.name + '_to_' + dst_grd.name + '_bilinear_t_to_rho.nc'
dst_varname = 'salt'
dimensions = ('ocean_time', 's_rho', 'eta_rho', 'xi_rho')
long_name = 'salinity'
units = 'PSU'
field = 'salinity, scalar, series'
else:
raise ValueError, 'Undefined src_varname'
if ndim == 3:
# build intermediate zgrid
zlevel = -z[::-1]
nzlevel = len(zlevel)
dst_zcoord = pyroms.vgrid.z_coordinate(dst_grd.vgrid.h, zlevel, nzlevel)
dst_grdz = pyroms.grid.ROMS_Grid(dst_grd.name+'_Z', dst_grd.hgrid, dst_zcoord)
# create variable in file
print 'Creating variable', dst_varname
nc.createVariable(dst_varname, 'f8', dimensions, fill_value=spval)
nc.variables[dst_varname].long_name = long_name
nc.variables[dst_varname].units = units
nc.variables[dst_varname].field = field
#nc.variables[dst_varname_north]._FillValue = spval
#.........这里部分代码省略.........
示例12: remapping
#.........这里部分代码省略.........
nvar = nvar - 2
# srcfile argument
if type(srcfile).__name__ == "list":
nfile = len(srcfile)
elif type(srcfile).__name__ == "str":
srcfile = sorted(glob.glob(srcfile))
nfile = len(srcfile)
else:
raise ValueError, "src_srcfile must be a str or a list of str"
# get wts_file
if type(wts_files).__name__ == "str":
wts_files = sorted(glob.glob(wts_files))
# loop over the srcfile
for nf in range(nfile):
print "Working with file", srcfile[nf], "..."
# get time
ocean_time = pyroms.utility.get_nc_var("ocean_time", srcfile[nf])
ntime = len(ocean_time[:])
# trange argument
if trange is None:
trange = range(ntime)
else:
trange = range(trange[0], trange[1] + 1)
# create destination file
dstfile = dstdir + os.path.basename(srcfile[nf])[:-3] + "_" + dstgrd.name + ".nc"
if os.path.exists(dstfile) is False:
print "Creating destination file", dstfile
pyroms_toolbox.nc_create_roms_file(dstfile, dstgrd, ocean_time)
# open destination file
nc = netCDF.Dataset(dstfile, "a", format="NETCDF3_CLASSIC")
nctidx = 0
# loop over time
for nt in trange:
nc.variables["ocean_time"][nctidx] = ocean_time[nt]
# loop over variable
for nv in range(nvar):
print " "
print "remapping", varname[nv], "from", srcgrd.name, "to", dstgrd.name
print "time =", ocean_time[nt]
# get source data
src_var = pyroms.utility.get_nc_var(varname[nv], srcfile[nf])
# determine variable dimension
ndim = len(src_var.dimensions) - 1
# get spval
try:
spval = src_var._FillValue
except:
raise Warning, "Did not find a _FillValue attribute."
# irange
if irange is None:
iirange = (0, src_var._shape()[-1])
else:
示例13: station_bound
#.........这里部分代码省略.........
if type(srcfile).__name__ == 'list':
nfile = len(srcfile)
elif type(srcfile).__name__ == 'str':
srcfile = sorted(glob.glob(srcfile))
nfile = len(srcfile)
else:
raise ValueError, 'src_srcfile must be a str or a list of str'
sides = ['_west','_east','_north','_south']
long = {'_west':'Western', '_east':'Eastern', \
'_north':'Northern', '_south':'Southern'}
dimincl = {'_west':'eta_rho', '_east':'eta_rho', \
'_north':'xi_rho', '_south':'xi_rho'}
nctidx = 0
# loop over the srcfile
for nf in range(nfile):
print 'Working with file', srcfile[nf], '...'
# get time
ocean_time = pyroms.utility.get_nc_var('ocean_time', srcfile[nf])
ntime = len(ocean_time[:])
# trange argument
if trange is None:
trange = range(ntime)
# create destination file
if nctidx == 0:
dstfile = dstdir + os.path.basename(srcfile[nf])[:-3] + '_' \
+ dst_grd.name + '_bdry.nc'
if os.path.exists(dstfile) is False:
print 'Creating destination file', dstfile
pyroms_toolbox.nc_create_roms_file(dstfile, dst_grd, \
ocean_time, lgrid=False)
# open destination file
nc = netCDF.Dataset(dstfile, 'a', format='NETCDF3_64BIT')
# loop over time
for nt in trange:
nc.variables['ocean_time'][nctidx] = ocean_time[nt]
# loop over variable
for nv in range(nvar):
print ' '
print 'extracting', varname[nv], 'from', srcgrd.name, \
'to', dst_grd.name
print 'time =', ocean_time[nt]
Mp, Lp = dst_grd.hgrid.mask_rho.shape
if varname[nv] == uvar:
Lp = Lp-1
if varname[nv] == vvar:
Mp = Mp-1
# get source data
src_var = pyroms.utility.get_nc_var(varname[nv], srcfile[nf])
# determine variable dimension
ndim = len(src_var.dimensions)-1
# get spval
try:
spval = src_var._FillValue
except:
示例14: remap_bdry_uv
def remap_bdry_uv(src_file, src_grd, dst_grd, dmax=0, cdepth=0, kk=0, dst_dir='./'):
# YELLOW grid sub-sample
xrange=(225, 275); yrange=(190, 240)
# get time
nctime.long_name = 'time'
nctime.units = 'days since 1900-01-01 00:00:00'
# time reference "days since 1900-01-01 00:00:00"
ref = datetime(1900, 1, 1, 0, 0, 0)
ref = date2num(ref)
tag = src_file.rsplit('/')[-1].rsplit('_')[-1].rsplit('-')[0]
year = int(tag[:4])
month = int(tag[4:6])
day = int(tag[6:])
time = datetime(year, month, day, 0, 0, 0)
time = date2num(time)
time = time - ref
time = time + 2.5 # 5-day average
# get dimensions
Mp, Lp = dst_grd.hgrid.mask_rho.shape
# create destination file
dst_file = src_file.rsplit('/')[-1]
dst_fileu = dst_dir + dst_file[:-4] + '_u_bdry_' + dst_grd.name + '.nc'
print '\nCreating destination file', dst_fileu
if os.path.exists(dst_fileu) is True:
os.remove(dst_fileu)
pyroms_toolbox.nc_create_roms_file(dst_fileu, dst_grd, nctime)
dst_filev = dst_dir + dst_file[:-4] + '_v_bdry_' + dst_grd.name + '.nc'
print 'Creating destination file', dst_filev
if os.path.exists(dst_filev) is True:
os.remove(dst_filev)
pyroms_toolbox.nc_create_roms_file(dst_filev, dst_grd, nctime)
# open destination file
ncu = netCDF.Dataset(dst_fileu, 'a', format='NETCDF3_CLASSIC')
ncv = netCDF.Dataset(dst_filev, 'a', format='NETCDF3_CLASSIC')
#load var
cdf = netCDF.Dataset(src_file)
src_varu = cdf.variables['u']
src_varv = cdf.variables['v']
#get missing value
spval = src_varu._FillValue
# YELLOW grid sub-sample
src_varu = src_varu[:, yrange[0]:yrange[1]+1, xrange[0]:xrange[1]+1]
src_varv = src_varv[:, yrange[0]:yrange[1]+1, xrange[0]:xrange[1]+1]
# get weights file
wts_file = 'remap_weights_SODA_2.1.6_to_YELLOW_bilinear_uv_to_rho.nc'
# build intermediate zgrid
zlevel = -src_grd.z_t[::-1,0,0]
nzlevel = len(zlevel)
dst_zcoord = pyroms.vgrid.z_coordinate(dst_grd.vgrid.h, zlevel, nzlevel)
dst_grdz = pyroms.grid.ROMS_Grid(dst_grd.name+'_Z', dst_grd.hgrid, dst_zcoord)
# create variable in destination file
print 'Creating variable u_north'
ncu.createVariable('u_north', 'f8', ('ocean_time', 's_rho', 'xi_u'), fill_value=spval)
ncu.variables['u_north'].long_name = '3D u-momentum north boundary condition'
ncu.variables['u_north'].units = 'meter second-1'
ncu.variables['u_north'].field = 'u_north, scalar, series'
print 'Creating variable u_south'
ncu.createVariable('u_south', 'f8', ('ocean_time', 's_rho', 'xi_u'), fill_value=spval)
ncu.variables['u_south'].long_name = '3D u-momentum south boundary condition'
ncu.variables['u_south'].units = 'meter second-1'
ncu.variables['u_south'].field = 'u_south, scalar, series'
print 'Creating variable u_east'
ncu.createVariable('u_east', 'f8', ('ocean_time', 's_rho', 'eta_u'), fill_value=spval)
ncu.variables['u_east'].long_name = '3D u-momentum east boundary condition'
ncu.variables['u_east'].units = 'meter second-1'
ncu.variables['u_east'].field = 'u_east, scalar, series'
print 'Creating variable u_west'
ncu.createVariable('u_west', 'f8', ('ocean_time', 's_rho', 'eta_u'), fill_value=spval)
ncu.variables['u_west'].long_name = '3D u-momentum west boundary condition'
ncu.variables['u_west'].units = 'meter second-1'
ncu.variables['u_west'].field = 'u_east, scalar, series'
# create variable in destination file
print 'Creating variable ubar_north'
ncu.createVariable('ubar_north', 'f8', ('ocean_time', 'xi_u'), fill_value=spval)
ncu.variables['ubar_north'].long_name = '2D u-momentum north boundary condition'
ncu.variables['ubar_north'].units = 'meter second-1'
ncu.variables['ubar_north'].field = 'ubar_north, scalar, series'
print 'Creating variable ubar_south'
ncu.createVariable('ubar_south', 'f8', ('ocean_time', 'xi_u'), fill_value=spval)
ncu.variables['ubar_south'].long_name = '2D u-momentum south boundary condition'
ncu.variables['ubar_south'].units = 'meter second-1'
ncu.variables['ubar_south'].field = 'ubar_south, scalar, series'
print 'Creating variable ubar_east'
ncu.createVariable('ubar_east', 'f8', ('ocean_time', 'eta_u'), fill_value=spval)
ncu.variables['ubar_east'].long_name = '2D u-momentum east boundary condition'
ncu.variables['ubar_east'].units = 'meter second-1'
ncu.variables['ubar_east'].field = 'ubar_east, scalar, series'
print 'Creating variable ubar_west'
#.........这里部分代码省略.........
示例15: remapping
def remapping(varname, srcfile, wts_files, srcgrd, dstgrd, \
rotate_uv=False, trange=None, irange=None, jrange=None, \
dstdir='./' ,zlevel=None, dmax=0, cdepth=0, kk=0, \
uvar='u', vvar='v', rotate_part=False):
'''
A remapping function to go from a ROMS grid to another ROMS grid.
If the u/v variables need to be rotated, it must be called for each
u/v pair (such as u/v, uice/vice).
'''
# get input and output grid
if type(srcgrd).__name__ == 'ROMS_Grid':
srcgrd = srcgrd
else:
srcgrd = pyroms.grid.get_ROMS_grid(srcgrd)
if type(dstgrd).__name__ == 'ROMS_Grid':
dstgrd = dstgrd
else:
dstgrd = pyroms.grid.get_ROMS_grid(dstgrd)
# build intermediate zgrid
if zlevel is None:
zlevel = np.array([-7500.,-7000.,-6500.,-6000.,-5500.,-5000.,\
-4500.,-4000.,-3500.,-3000.,-2500.,-2000.,-1750.,\
-1500.,-1250.,-1000.,-900.,-800.,-700.,-600.,-500.,\
-400.,-300.,-250.,-200.,-175.,-150.,-125.,-100.,-90.,\
-80.,-70.,-60.,-50.,-45.,-40.,-35.,-30.,-25.,-20.,-17.5,\
-15.,-12.5,-10.,-7.5,-5.,-2.5,0.])
else:
zlevel = np.sort(-abs(zlevel))
nzlevel = len(zlevel)
src_zcoord = pyroms.vgrid.z_coordinate(srcgrd.vgrid.h, zlevel, nzlevel)
dst_zcoord = pyroms.vgrid.z_coordinate(dstgrd.vgrid.h, zlevel, nzlevel)
srcgrdz = pyroms.grid.ROMS_Grid(srcgrd.name+'_Z', srcgrd.hgrid, src_zcoord)
dstgrdz = pyroms.grid.ROMS_Grid(dstgrd.name+'_Z', dstgrd.hgrid, dst_zcoord)
# varname argument
if type(varname).__name__ == 'list':
nvar = len(varname)
elif type(varname).__name__ == 'str':
varname = [varname]
nvar = len(varname)
else:
raise ValueError, 'varname must be a str or a list of str'
# if we're working on u and v, we'll compute ubar,vbar afterwards
compute_ubar = False
if (varname.__contains__('u') == 1 and varname.__contains__('v') == 1) or \
(varname.__contains__('u_eastward') == 1 and varname.__contains__('v_northward') == 1):
compute_ubar = True
print 'ubar/vbar to be computed from u/v'
if varname.__contains__('ubar'):
varname.remove('ubar')
nvar = nvar-1
if varname.__contains__('vbar'):
varname.remove('vbar')
nvar = nvar-1
# if rotate_uv=True, check that u and v are in varname
if rotate_uv is True:
if varname.__contains__(uvar) == 0 or varname.__contains__(vvar) == 0:
raise Warning, 'varname must include uvar and vvar in order to' \
+ ' rotate the velocity field'
else:
varname.remove(uvar)
varname.remove(vvar)
nvar = nvar-2
# srcfile argument
if type(srcfile).__name__ == 'list':
nfile = len(srcfile)
elif type(srcfile).__name__ == 'str':
srcfile = sorted(glob.glob(srcfile))
nfile = len(srcfile)
else:
raise ValueError, 'src_srcfile must be a str or a list of str'
# get wts_file
if type(wts_files).__name__ == 'str':
wts_files = sorted(glob.glob(wts_files))
# loop over the srcfile
for nf in range(nfile):
print 'Working with file', srcfile[nf], '...'
# get time
ocean_time = pyroms.utility.get_nc_var('ocean_time', srcfile[nf])
ntime = len(ocean_time[:])
# trange argument
if trange is None:
trange = range(ntime)
# create destination file
dstfile = dstdir + os.path.basename(srcfile[nf])[:-3] + '_' + dstgrd.name + '.nc'
if os.path.exists(dstfile) is False:
print 'Creating destination file', dstfile
pyroms_toolbox.nc_create_roms_file(dstfile, dstgrd, ocean_time)
# open destination file
#.........这里部分代码省略.........