本文整理汇总了Python中Scientific.IO.NetCDF.NetCDFFile.read方法的典型用法代码示例。如果您正苦于以下问题:Python NetCDFFile.read方法的具体用法?Python NetCDFFile.read怎么用?Python NetCDFFile.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scientific.IO.NetCDF.NetCDFFile
的用法示例。
在下文中一共展示了NetCDFFile.read方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: contour_hazardmap
# 需要导入模块: from Scientific.IO.NetCDF import NetCDFFile [as 别名]
# 或者: from Scientific.IO.NetCDF.NetCDFFile import read [as 别名]
def contour_hazardmap(scenario, verbose=True):
"""Contouring hazard map from Fall3d NetCDF outputs located in directory given by the variable
model_output_directory specified in scenario.
The name of the hazard map is assumed to be HazardMaps.res.nc as per Fall3d
"""
filename = 'HazardMaps.res.nc' # Hardwired name as per Fall3d
from Scientific.IO.NetCDF import NetCDFFile
# Get params from model script
params = get_scenario_parameters(scenario)
model_output_directory = params['model_output_directory']
absolutefilename = os.path.join(model_output_directory, filename)
if verbose:
print 'Contouring hazard map %s' % absolutefilename
# Converting NetCDF to ASCII files
# Get variables
fid = NetCDFFile(absolutefilename)
variables = fid.variables.keys()
if verbose:
print 'Contouring variables %s' % str(variables)
for var in variables:
# Ignore x, y and time variables.
if var in ['x', 'y', 'time']:
continue
# Look for data
if var.startswith('PLOAD'):
contours = params['PLOAD_contours']
units = params['PLOAD_units']
attribute_name = var
elif var.startswith('ISOCHRO'):
contours = params['ISOCHRON_contours']
units = params['ISOCHRON_units']
attribute_name = var
else:
if verbose: print 'WARNING: Undefined variable %s' % var
continue
# Look for projection file
basename, _ = os.path.splitext(absolutefilename)
prjfilename = basename + '.prj'
if not os.path.exists(prjfilename):
msg = 'Projection file %s must be present for contouring to work.\n' % prjfilename
msg += 'You can copy the projection file from one of the individual scenarios used to produce the hazard map'
raise Exception(msg)
fid = open(prjfilename)
WKT_projection = fid.read()
fid.close()
ascii_filename=nc2asc(absolutefilename,
subdataset=attribute_name,
projection=WKT_projection)
for filename in os.listdir(model_output_directory):
if filename.endswith('%s.asc' % attribute_name.lower()):
# Contour all generated ASCII files
_generate_contours(filename, contours, units, attribute_name,
output_dir=model_output_directory,
WKT_projection=True,
verbose=verbose)
if verbose:
print 'Contouring of hazard map done in directory: %s' % model_output_directory