def variables(self): ''' Get all variables. ''' vars = [] for var in self.dataset.getDataInfo().getVariables(): vars.append(DimVariable(var)) return vars
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()
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))
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
def __getitem__(self, key): if isinstance(key, basestring): #print key return DimVariable(self.dataset.getDataInfo().getVariable(key), self) return None
def addvar(self, varname, datatype, dims, group=None): dt = self.__getdatatype(datatype) return DimVariable( ncvariable=self.ncfile.addVariable(group, varname, dt, dims))