当前位置: 首页>>代码示例>>Python>>正文


Python NetCDFFile.read方法代码示例

本文整理汇总了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
开发者ID:GeoscienceAustralia,项目名称:PF3D,代码行数:84,代码来源:interface.py


注:本文中的Scientific.IO.NetCDF.NetCDFFile.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。