示例#1
0
    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))))
示例#2
0
    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))))
示例#3
0
 def popitem(self):
     """
     raises an error, since abundanceDicts are
     immutable
     """
     raise despoticError(
         "cannot delete species from abundanceDict")
示例#4
0
 def __delitem__(self, key):
     """
     raises an error, since abundanceDicts are
     immutable
     """
     raise despoticError(
         "cannot delete species from abundanceDict")
示例#5
0
 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
示例#6
0
 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)
示例#7
0
 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
示例#8
0
 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)
示例#9
0
 def popitem(self):
     """
     raises an error, since abundanceDicts are
     immutable
     """
     raise despoticError("cannot delete species from abundanceDict")
示例#10
0
 def __delitem__(self, key):
     """
     raises an error, since abundanceDicts are
     immutable
     """
     raise despoticError("cannot delete species from abundanceDict")