示例#1
0
    def variables(self):
        '''
        Get all variables.
        '''
        vars = []
        for var in self.dataset.getDataInfo().getVariables():
            vars.append(DimVariable(var))

        return vars
示例#2
0
 def __getitem__(self, key):
     if isinstance(key, basestring):
         vnames = self.dataset.getDataInfo().getVariableNames()
         if key in vnames:
             return DimVariable(self.dataset.getDataInfo().getVariable(key), self)
         else:
             print key + ' is not a variable name'
             raise ValueError()
     else:
         print key + ' is not a variable name'
         raise ValueError()
示例#3
0
 def addvar(self, varname, datatype, dims, group=None):
     '''
     Add a variable.
     
     :param varname: (*string*) Variable name.
     :param datatype: (*string*) Data type [string | int | long | float | double |
         char].
     :param dims: (*list*) Dimensions.        
     '''
     dt = self.__getdatatype(datatype)        
     return DimVariable(ncvariable=self.ncfile.addVariable(group, varname, dt, dims))
示例#4
0
 def addvar(self, varname, datatype, dims, attrs=None, group=None):
     '''
     Add a variable.
     
     :param varname: (*string*) Variable name.
     :param datatype: (*string*) Data type [string | int | long | float | double |
         char].
     :param dims: (*list*) Dimensions.
     :param attrs: (*dict*) Attributes.
     '''
     dt = self.__getdatatype(datatype)
     if isinstance(dims[0], Dimension):
         ncdims = []
         for dim in dims:
             ncdims.append(self.ncfile.findDimension(dim.getName()))
         var = DimVariable(
             ncvariable=self.ncfile.addVariable(group, varname, dt, ncdims))
     else:
         var = DimVariable(
             ncvariable=self.ncfile.addVariable(group, varname, dt, dims))
     if not attrs is None:
         for key in attrs:
             var.addattr(key, attrs[key])
     return var
示例#5
0
 def __getitem__(self, key):
     if isinstance(key, basestring):
         #print key
         return DimVariable(self.dataset.getDataInfo().getVariable(key),
                            self)
     return None
示例#6
0
 def addvar(self, varname, datatype, dims, group=None):
     dt = self.__getdatatype(datatype)
     return DimVariable(
         ncvariable=self.ncfile.addVariable(group, varname, dt, dims))