def __init__(self, specList, x): """ This method initializes the species list for this abundance dict, and also points to the numeric abundance array it wraps around. Parameters specList : list list of species names for this abundanceDict; each list element must be a string x : array of rank 1 or 2 array of abundances; the length of the first dimension of x must be equal to the length of specList """ # Make sure input specList and x are properly formatted if np.ndim(x) < 1: raise despoticError( "x must be a numpy array of rank >= 1") elif x.shape[0] != len(specList): raise despoticError( "first dimension of x must be same length as specList") self.x = x self.__specDict = collections.OrderedDict( zip(specList, range(len(specList))))
def __init__(self, specList, x): """ This method initializes the species list for this abundance dict, and also points to the numeric abundance array it wraps around. Parameters specList : list list of species names for this abundanceDict; each list element must be a string x : array of rank 1 or 2 array of abundances; the length of the first dimension of x must be equal to the length of specList """ # Make sure input specList and x are properly formatted if np.ndim(x) < 1: raise despoticError("x must be a numpy array of rank >= 1") elif x.shape[0] != len(specList): raise despoticError( "first dimension of x must be same length as specList") self.x = x self.__specDict = collections.OrderedDict( zip(specList, range(len(specList))))
def popitem(self): """ raises an error, since abundanceDicts are immutable """ raise despoticError( "cannot delete species from abundanceDict")
def __delitem__(self, key): """ raises an error, since abundanceDicts are immutable """ raise despoticError( "cannot delete species from abundanceDict")
def __setitem__(self, key, value): """ __setitem__ sets the value in the array x corresponding to the input species name. """ if key not in self.__specDict: raise despoticError("cannot add new species to abundanceDict") self.x[self.__specDict[key]] = value
def __pow__(self, other): if type(other) == type(self): if self.keys() != other.keys(): raise despoticError("cannot add abundanceDict " + "objects containing different species") return abundanceDict(self.keys(), self.x**other.x) else: return abundanceDict(self.keys(), self.x**other)
def __setitem__(self, key, value): """ __setitem__ sets the value in the array x corresponding to the input species name. """ if key not in self.__specDict: raise despoticError( "cannot add new species to abundanceDict") self.x[self.__specDict[key]] = value
def __pow__(self, other): if type(other) == type(self): if self.keys() != other.keys(): raise despoticError( "cannot add abundanceDict " + "objects containing different species") return abundanceDict(self.keys(), self.x ** other.x) else: return abundanceDict(self.keys(), self.x ** other)
def popitem(self): """ raises an error, since abundanceDicts are immutable """ raise despoticError("cannot delete species from abundanceDict")
def __delitem__(self, key): """ raises an error, since abundanceDicts are immutable """ raise despoticError("cannot delete species from abundanceDict")