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


Python Dataset.createVLType方法代码示例

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


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

示例1: setUp

# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import createVLType [as 别名]
 def setUp(self):
     self.file = FILE_NAME
     f = Dataset(self.file,'w')
     vlen_t = f.createVLType(VL_BASETYPE, VL_NAME)
     f.createDimension(DIM1_NAME,nlons)
     f.createDimension(DIM2_NAME,nlats)
     strings_alt = f.createVariable(VAR3_NAME, datas.astype(str).dtype,
                                    (DIM2_NAME, DIM1_NAME))
     strings_alt[:] = datas.astype(str)
     f.close()
开发者ID:lesliekim,项目名称:netcdf4-python,代码行数:12,代码来源:tst_vlen.py

示例2: setUp

# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import createVLType [as 别名]
 def setUp(self):
     self.file = FILE_NAME
     f = Dataset(self.file,'w')
     vlen_t = f.createVLType(VL_BASETYPE, VL_NAME)
     f.createDimension(DIM1_NAME,nlons)
     f.createDimension(DIM2_NAME,nlats)
     ragged = f.createVariable(VAR1_NAME, vlen_t,\
             (DIM2_NAME,DIM1_NAME))
     strings = f.createVariable(VAR2_NAME, str,\
             (DIM2_NAME,DIM1_NAME))
     ragged[:] = data
     ragged[-1,-1] = data[-1,-1]
     strings[:] = datas
     strings[-2,-2] = datas[-2,-2]
     f.close()
开发者ID:8900,项目名称:netCDF4-Python,代码行数:17,代码来源:tst_vlen.py

示例3: setUp

# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import createVLType [as 别名]
    def setUp(self):

        import netCDF4
        if netCDF4.__netcdf4libversion__ < "4.4.1":
            self.skip = True
            try:
                self.skipTest("This test requires NetCDF 4.4.1 or later.")
            except AttributeError:
                # workaround for Python 2.6 (skipTest(reason) is new
                # in Python 2.7)
                pass
        else:
            self.skip = False

        self.file = FILE_NAME
        f = Dataset(self.file, 'w')
        vlen_type = f.createVLType(np.float64, 'vltest')
        f.createDimension('x', None)
        v = f.createVariable('vl', vlen_type, 'x')
        w = f.createVariable('vl2', np.float64, 'x')
        f.close()
开发者ID:Unidata,项目名称:netcdf4-python,代码行数:23,代码来源:tst_vlen.py

示例4: tuple

# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import createVLType [as 别名]
for data in statdat[:]:
    for name in statdat.dtype.names:
        if data[name].dtype.kind == 'S': # a string
            # convert array of characters back to a string for display.
            print name,': value =',chartostring(data[name]),\
            ': units=',chartostring(statdat.units[name])
        elif data[name].dtype.kind == 'V': # a nested compound type
            print name,data[name].dtype.names,': value=',data[name],': units=',\
            tuple([chartostring(s) for s in tuple(statdat.units[name])])
        else: # a numeric type.
            print name,': value=',data[name],': units=',chartostring(statdat.units[name])
    print '----'
f.close()

f = Dataset('tst_vlen.nc','w')
vlen_t = f.createVLType(numpy.int32, 'phony_vlen')
x = f.createDimension('x',3)
y = f.createDimension('y',4)
vlvar = f.createVariable('phony_vlen_var', vlen_t, ('y','x'))
import random
data = numpy.empty(len(y)*len(x),object)
for n in range(len(y)*len(x)):
    data[n] = numpy.arange(random.randint(1,10),dtype='int32')+1
data = numpy.reshape(data,(len(y),len(x)))
vlvar[:] = data
print 'vlen variable =\n',vlvar[:]
print f
print f.variables['phony_vlen_var']
print f.vltypes['phony_vlen']
z = f.createDimension('z', 10)
strvar = f.createVariable('strvar',str,'z')
开发者ID:hhiester,项目名称:convert2vtk,代码行数:33,代码来源:tutorial.py

示例5: test_tutorial

# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import createVLType [as 别名]

#.........这里部分代码省略.........
# now that wind_data_t is defined, create the station data type.
    station_data_t = f.createCompoundType(statdtype,'station_data')
# create nested compound data types to hold the units variable attribute.
    winddtype_units = numpy.dtype([('speed','S1',NUMCHARS),('direction','S1',NUMCHARS)])
    statdtype_units = numpy.dtype([('latitude', 'S1',NUMCHARS), ('longitude', 'S1',NUMCHARS),
                                   ('surface_wind',winddtype_units),
                                   ('temp_sounding','S1',NUMCHARS),
                                   ('location_name','S1',NUMCHARS),
                                   ('press_sounding','S1',NUMCHARS)])
# create the wind_data_units type first, since it will nested inside
# the station_data_units data type.
    wind_data_units_t = f.createCompoundType(winddtype_units,'wind_data_units')
    station_data_units_t =\
        f.createCompoundType(statdtype_units,'station_data_units')
# create a variable of of type 'station_data_t'
    statdat = f.createVariable('station_obs', station_data_t, ('station',))
# create a numpy structured array, assign data to it.
    data = numpy.empty(1,station_data_t)
    data['latitude'] = 40.
    data['longitude'] = -105.
    data['surface_wind']['speed'] = 12.5
    data['surface_wind']['direction'] = 270
    data['temp_sounding'] = (280.3,272.,270.,269.,266.,258.,254.1,250.,245.5,240.)
    data['press_sounding'] = range(800,300,-50)
    # variable-length string datatypes are not supported inside compound types, so
# to store strings in a compound data type, each string must be
# stored as fixed-size (in this case 80) array of characters.
    data['location_name'] = stringtoarr('Boulder, Colorado, USA',NUMCHARS)
# assign structured array to variable slice.
    statdat[0] = data
# or just assign a tuple of values to variable slice
# (will automatically be converted to a structured array).
    statdat[1] = (40.78,-73.99,(-12.5,90),
                  (290.2,282.5,279.,277.9,276.,266.,264.1,260.,255.5,243.),
                  range(900,400,-50),stringtoarr('New York, New York, USA',NUMCHARS))
    print(f.cmptypes)
    windunits = numpy.empty(1,winddtype_units)
    stationobs_units = numpy.empty(1,statdtype_units)
    windunits['speed'] = stringtoarr('m/s',NUMCHARS)
    windunits['direction'] = stringtoarr('degrees',NUMCHARS)
    stationobs_units['latitude'] = stringtoarr('degrees north',NUMCHARS)
    stationobs_units['longitude'] = stringtoarr('degrees west',NUMCHARS)
    stationobs_units['surface_wind'] = windunits
    stationobs_units['location_name'] = stringtoarr('None', NUMCHARS)
    stationobs_units['temp_sounding'] = stringtoarr('Kelvin',NUMCHARS)
    stationobs_units['press_sounding'] = stringtoarr('hPa',NUMCHARS)
    statdat.units = stationobs_units
# close and reopen the file.
    f.close()
    f = Dataset('compound_example.nc')
    print(f)
    statdat = f.variables['station_obs']
    print(statdat)
# print out data in variable.
    print('data in a variable of compound type:')
    print('----')
    for data in statdat[:]:
        for name in statdat.dtype.names:
            if data[name].dtype.kind == 'S': # a string
                # convert array of characters back to a string for display.
                units = chartostring(statdat.units[name])
                print(name,': value =',chartostring(data[name]),\
                          ': units=',units)
            elif data[name].dtype.kind == 'V': # a nested compound type
                units_list = [chartostring(s) for s in tuple(statdat.units[name])]
                print(name,data[name].dtype.names,': value=',data[name],': units=',\
                          units_list)
            else: # a numeric type.
                units = chartostring(statdat.units[name])
                print(name,': value=',data[name],': units=',units)
                print('----')
    f.close()
    f = Dataset('tst_vlen.nc','w')
    vlen_t = f.createVLType(numpy.int32, 'phony_vlen')
    x = f.createDimension('x',3)
    y = f.createDimension('y',4)
    vlvar = f.createVariable('phony_vlen_var', vlen_t, ('y','x'))
    import random
    data = numpy.empty(len(y)*len(x),object)
    for n in range(len(y)*len(x)):
        data[n] = numpy.arange(random.randint(1,10),dtype='int32')+1
        data = numpy.reshape(data,(len(y),len(x)))
        vlvar[:] = data
        print(vlvar)
        print('vlen variable =\n',vlvar[:])
        print(f)
        print(f.variables['phony_vlen_var'])
        print(f.vltypes['phony_vlen'])
        z = f.createDimension('z', 10)
        strvar = f.createVariable('strvar',str,'z')
        chars = '1234567890aabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    data = numpy.empty(10,object)
    for n in range(10):
        stringlen = random.randint(2,12)
        data[n] = ''.join([random.choice(chars) for i in range(stringlen)])
        strvar[:] = data
        print('variable-length string variable:\n',strvar[:])
        print(f)
        print(f.variables['strvar'])
    f.close()
开发者ID:kmunve,项目名称:TSanalysis,代码行数:104,代码来源:crocus_forcing_nc.py


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