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


Python NetCDFFile.sync方法代码示例

本文整理汇总了Python中Scientific.IO.NetCDF.NetCDFFile.sync方法的典型用法代码示例。如果您正苦于以下问题:Python NetCDFFile.sync方法的具体用法?Python NetCDFFile.sync怎么用?Python NetCDFFile.sync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Scientific.IO.NetCDF.NetCDFFile的用法示例。


在下文中一共展示了NetCDFFile.sync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: modify_filter

# 需要导入模块: from Scientific.IO.NetCDF import NetCDFFile [as 别名]
# 或者: from Scientific.IO.NetCDF.NetCDFFile import sync [as 别名]
def modify_filter(gridfilename, ttlname, indflag = 1):

  tm = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))

  ncfile = Dataset(gridfilename, 'a')

  if indflag:
    grid_center_lat_var = ncfile.variables['grid_center_lat']
    setattr(grid_center_lat_var, 'units', 'degrees')
    grid_center_lon_var = ncfile.variables['grid_center_lon']
    setattr(grid_center_lon_var, 'units', 'degrees')
    grid_corner_lat_var = ncfile.variables['grid_corner_lat']
    setattr(grid_corner_lat_var, 'units', 'degrees')
    grid_corner_lon_var = ncfile.variables['grid_corner_lon']
    setattr(grid_corner_lon_var, 'units', 'degrees')
  
  setattr(ncfile, 'title', ttlname)
  setattr(ncfile, 'modifydate', tm)

  if hasattr(ncfile, 'grid_name'):
    delattr(ncfile, 'grid_name')

  if hasattr(ncfile, 'map_method'):
    delattr(ncfile, 'map_method')

  ncfile.sync()
  ncfile.close()
开发者ID:xunzhang,项目名称:Threp,代码行数:29,代码来源:modify_filter.py

示例2: writeNcFile

# 需要导入模块: from Scientific.IO.NetCDF import NetCDFFile [as 别名]
# 或者: from Scientific.IO.NetCDF.NetCDFFile import sync [as 别名]
def writeNcFile(data, fileName=None, oldStyle=1):
    if not ncOk:
        raise Exception('module Scientific.IO.NetCDF not found, writeNcFile() failed!')
    if not fileName:
        fileName = data['name']+'_weather.nc'
    f = NetCDFFile(fileName, 'w')
    f.createDimension('time', data['time'].shape[0])
    f.file_format = file_format
    if oldStyle:
        f.createDimension('scalar', 1)
    if data.has_key('comment'):
        f.comment = data['comment']
    else:
        f.comment = 'created by MeteonormFile.py (v%s)' % version
    if data.has_key('source_file'):
        f.source_file = str(data['source_file'])
    for vn in ('latitude', 'longitude', 'height'):
        setattr(f, vn, data[vn])
        if oldStyle:
            v = f.createVariable(vn, 'd', ('scalar', ))
            v[:] = [data[vn]]
    setattr(f, 'longitude_0', 15.0*data['timezone'])
    if oldStyle:
        v = f.createVariable('longitude_0', 'd', ('scalar', ))
        v[:] = [15.0 * data['timezone']]
    for vn in variables.keys():
        t = variables[vn][1]
        v = f.createVariable(vn, t, ('time',))
        v[:] = data[vn].astype(t)
        oname = variables[vn][0]
        if oname.startswith('<'): oname = oname[1:]
        if oname.endswith('>'): oname = oname[:-1]
        v.original_name = oname
        v.unit = variables[vn][2]
    f.sync()
    f.close()
开发者ID:jraedler,项目名称:SimuVis4,代码行数:38,代码来源:MeteonormFile.py

示例3: _ParNetCDFFile

# 需要导入模块: from Scientific.IO.NetCDF import NetCDFFile [as 别名]
# 或者: from Scientific.IO.NetCDF.NetCDFFile import sync [as 别名]

#.........这里部分代码省略.........
                    mode = 'r', local_access = False):
        """
        @param filename: the name of the netCDF file
        @type filename: C{str}
        @param split_dimension: the name of the dimension along which the data
                                is distributed over the processors
        @type split_dimension: C{str}
        @param mode: read ('r'), write ('w'), or append ('a')
        @type mode: C{str}
        @param local_access: if C{False}, processor 0 is the only one to
                             access the file, all others communicate with
                             processor 0. If C{True} (only for reading), each
                             processor accesses the file directly. In the
                             latter case, the file must be accessible on all
                             processors under the same name. A third mode is
                             'auto', which uses some heuristics to decide
                             if the file is accessible everywhere: it checks
                             for existence of the file, then compares
                             the size on all processors, and finally verifies
                             that the same variables exist everywhere, with
                             identical names, types, and sizes.
        @type local_access: C{bool} or C{str}
        """
        if mode != 'r':
            local_access = 0
        self.pid = pid
        self.nprocs = nprocs
        self.filename = filename
        self.split = split_dimension
        self.local_access = local_access
        self.read_only = mode == 'r'
        if local_access or pid == 0:
            self.file = NetCDFFile(filename, mode)
            try:
                length = self.file.dimensions[split_dimension]
                if length is None:
                    length = -1
            except KeyError:
                length = None
            variables = {}
            for name, var in self.file.variables.items():
                variables[name] = (name, var.dimensions)
                if length < 0 and split_dimension in var.dimensions:
                    index = list(var.dimensions).index(split_dimension)
                    length = var.shape[index]
        else:
            self.file = None
            self.split = split_dimension
            length = None
            variables = None
        if not local_access:
            length = self.broadcast(length)
            variables = self.broadcast(variables)
        if length is not None:
            self._divideData(length)
        self.variables = {}
        for name, var in variables.items():
            self.variables[name] = _ParNetCDFVariable(self, var[0], var[1],
                                                      split_dimension)

    def __repr__(self):
        return repr(self.filename)

    def close(self):
        if self.local_access or self.pid == 0:
            self.file.close()

    def createDimension(self, name, length):
        if name == self.split:
            if length is None:
                raise ValueError("Split dimension cannot be unlimited")
            self._divideData(length)
        if self.pid == 0:
            self.file.createDimension(name, length)

    def createVariable(self, name, typecode, dimensions):
        if self.pid == 0:
            var = self.file.createVariable(name, typecode, dimensions)
            dim = var.dimensions
        else:
            dim = 0
        name, dim = self.broadcast((name, dim))
        self.variables[name] = _ParNetCDFVariable(self, name, dim, self.split)
        return self.variables[name]

    def _divideData(self, length):
        chunk = (length+self.nprocs-1)/self.nprocs
        self.first = min(self.pid*chunk, length)
        self.last = min(self.first+chunk, length)
        if (not self.local_access) and self.pid == 0:
            self.parts = []
            for pid in range(self.nprocs):
                first = pid*chunk
                last = min(first+chunk, length)
                self.parts.append((first, last))

    def sync(self):
        if self.pid == 0:
            self.file.sync()
    flush = sync
开发者ID:davem22101,项目名称:semanticscience,代码行数:104,代码来源:IO.py


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