本文整理汇总了Python中anuga.file.netcdf.NetCDFFile.variables[elev_name][:]方法的典型用法代码示例。如果您正苦于以下问题:Python NetCDFFile.variables[elev_name][:]方法的具体用法?Python NetCDFFile.variables[elev_name][:]怎么用?Python NetCDFFile.variables[elev_name][:]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anuga.file.netcdf.NetCDFFile
的用法示例。
在下文中一共展示了NetCDFFile.variables[elev_name][:]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: most2nc
# 需要导入模块: from anuga.file.netcdf import NetCDFFile [as 别名]
# 或者: from anuga.file.netcdf.NetCDFFile import variables[elev_name][:] [as 别名]
def most2nc(input_file, output_file, inverted_bathymetry=False, verbose=True):
"""Convert a MOST file to NetCDF format.
input_file the input file to convert
output_file the name of the oputput NetCDF file to create
inverted_bathymetry ??
verbose True if the function is to be verbose
"""
# variable names
long_name = 'LON'
lat_name = 'LAT'
elev_name = 'ELEVATION'
# set up bathymetry
if inverted_bathymetry:
up = -1.
else:
up = +1.
# read data from the MOST file
in_file = open(input_file,'r')
if verbose: log.critical('reading header')
nx_ny_str = in_file.readline()
nx_str,ny_str = nx_ny_str.split()
nx = int(nx_str)
ny = int(ny_str)
h1_list=[]
for i in range(nx):
h1_list.append(float(in_file.readline()))
h2_list=[]
for j in range(ny):
h2_list.append(float(in_file.readline()))
h2_list.reverse()
if verbose: log.critical('reading depths')
in_depth_list = in_file.readlines()
in_file.close()
out_depth_list = [[]]
if verbose: log.critical('processing depths')
k=1
for in_line in in_depth_list:
for string in in_line.split():
#j = k/nx
out_depth_list[(k-1)/nx].append(float(string)*up)
if k==nx*ny:
break
if k-(k/nx)*nx ==0:
out_depth_list.append([])
k+=1
in_file.close()
out_depth_list.reverse()
depth_list = out_depth_list
# write the NetCDF file
if verbose: log.critical('writing results')
out_file = NetCDFFile(output_file, netcdf_mode_w)
out_file.createDimension(long_name,nx)
out_file.createVariable(long_name,'d',(long_name,))
out_file.variables[long_name].point_spacing='uneven'
out_file.variables[long_name].units='degrees_east'
out_file.variables[long_name][:] = h1_list
out_file.createDimension(lat_name,ny)
out_file.createVariable(lat_name,'d',(lat_name,))
out_file.variables[lat_name].point_spacing='uneven'
out_file.variables[lat_name].units='degrees_north'
out_file.variables[lat_name][:] = h2_list
out_file.createVariable(elev_name,'d',(lat_name,long_name))
out_file.variables[elev_name].point_spacing='uneven'
out_file.variables[elev_name].units='meters'
out_file.variables[elev_name][:] = depth_list
out_file.close()