本文整理汇总了Python中netCDF4.Dataset.__getattribute__方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.__getattribute__方法的具体用法?Python Dataset.__getattribute__怎么用?Python Dataset.__getattribute__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类netCDF4.Dataset
的用法示例。
在下文中一共展示了Dataset.__getattribute__方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getrealization
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import __getattribute__ [as 别名]
def getrealization(f):
""" Returns the realization from a filename and directory path.
This is dependant on the cmip naming convention
Parameters
----------
string : name of file including path
Returns
-------
string of realization number
"""
nc = Dataset(f, 'r')
return str(nc.__getattribute__('realization'))
示例2: getfrequency
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import __getattribute__ [as 别名]
def getfrequency(f):
""" Returns the frequency from a filename and directory path.
ex. 'day', 'mon', 'yr', 'fx'
This is dependant on a specific directory organization
Parameters
----------
string : name of file including path
Returns
-------
string of frequency
"""
nc = Dataset(f, 'r')
return str(nc.__getattribute__('frequency'))
示例3: getrealm
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import __getattribute__ [as 别名]
def getrealm(f):
""" Returns the realm from a filename and directory path.
This is dependant on a specific directory organization
Parameters
----------
string : name of file including path
Returns
-------
string of realm
"""
nc = Dataset(f, 'r')
realm = str(nc.__getattribute__('modeling_realm'))
if 'seaIce' in realm:
realm = 'seaIce'
return realm
示例4: getexperiment
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import __getattribute__ [as 别名]
def getexperiment(f):
nc = Dataset(f, 'r')
return str(nc.__getattribute__('experiment'))
示例5: NetCDFFacade
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import __getattribute__ [as 别名]
class NetCDFFacade(object):
def __init__(self, filename=None, dataset=None):
if filename is not None:
try:
self.data_set = Dataset(filename, 'r', format='NETCDF4_CLASSIC')
except RuntimeError as re:
raise ValueError('%s: %s' % (re.args[0], filename))
elif dataset is not None:
self.data_set = dataset
else:
raise ValueError('Either filename or dataset must be provided')
def get_dim_size(self, dimName):
dimensions = self.data_set.dimensions
for currentDimName in dimensions:
if currentDimName == dimName:
return len(dimensions[currentDimName])
def get_global_attribute(self, attributeName):
globalAttributes = self.data_set.ncattrs
for currentAttribute in globalAttributes():
if currentAttribute == attributeName:
return self.data_set.__getattribute__(attributeName)
def get_variable(self, variableName):
variables = self.data_set.variables
for currentVarName in variables:
if currentVarName == variableName:
return variables[currentVarName]
return None
def get_variable_attribute(self, variableName, attributeName):
variable = self.get_variable(variableName)
if hasattr(variable, attributeName):
return variable.__getattribute__(attributeName)
return None
def get_dimension_string(self, variableName):
variable = self.get_variable(variableName)
dimensionString = ""
for dimName in variable._getdims():
dimensionString = "%s%s " % (dimensionString, dimName)
dimensionString = dimensionString.strip()
return dimensionString
def get_dim_length(self, variableName, index=0):
variable = self.get_variable(variableName)
variableDimensions = variable._getdims()
for i in range(len(variableDimensions)):
if i == index:
dimName = variableDimensions[i]
return self.get_dim_size(dimName)
def get_data(self, variableName, origin, shape):
variable = self.get_variable(variableName)
dimCount = len(variable._getdims())
if dimCount != len(origin) or dimCount != len(shape):
raise ValueError("len(origin) and len(shape) must be equal to number of dimensions of variable '" + variableName + "'")
index_array = []
for dimIndex in range(0, dimCount):
current_index = range(origin[dimIndex], origin[dimIndex] + shape[dimIndex])
index_array.append(current_index)
# ensure that resulting array has same dimension as variable
# unfortunately, the netcdf lib reduces the array's rank in some cases
array = variable[index_array]
if len(array.shape) < len(variable._getdims()):
new_shape = []
for d in range(dimCount - len(array.shape)):
new_shape.append(1)
for i in array.shape:
new_shape.append(i)
array = array.reshape(new_shape)
return array
def close(self):
self.data_set.close()
def get_dimensions(self, variable_name=None):
result = []
if variable_name is None:
for dimension in self.data_set.dimensions:
result.append(dimension)
return result
return (self.get_variable(variable_name))._getdims()
def is_coordinate_or_reference_variable(self, ncVariable):
return len(ncVariable._getdims()) == 1
#.........这里部分代码省略.........