Пример #1
0
 def __call__(self, x):
     if itertools2.isiterable(x):
         return (self(x) for x in x)
     if x in self.pdf:
         return self.pdf[x]
     else:
         return 0
Пример #2
0
 def __call__(self,x):
     if isiterable(x):
         return (self(x) for x in x)
     if x in self.pdf:
         return self.pdf[x]
     else:
         return 0
Пример #3
0
    def convert(self, target, **kwargs):
        """ 
        :param target: str of desired colorspace, or none for default
        :return: color in target colorspace
        """
        import networkx as nx
        target = target.lower() if target else self.space
        if target not in self._values:
            try:
                path = converters.shortest_path(self.space, target)
            except nx.exception.NetworkXNoPath:
                raise NotImplementedError(
                    'no conversion between %s and %s color spaces' %
                    (self.space, target))
            kwargs[
                'illuminant'] = self.illuminant  # to avoid incoherent cached values
            for u, v in itertools2.pairwise(path):
                if v not in self._values:
                    edge = converters[u][v][0]
                    c = edge['f'](self._values[u], **kwargs)

                    if itertools2.isiterable(c):  #but not a string
                        c = tuple(map(float, c))
                    self._values[v] = c
        return self._values[target]
Пример #4
0
    def convert(self, target, **kwargs):
        """ 
        :param target: str of desired colorspace, or none for default
        :return: color in target colorspace
        """
        import networkx as nx
        target=target.lower() if target else self.space
        if target not in self._values:
            try:
                path=converters.shortest_path(self.space, target)
            except nx.exception.NetworkXNoPath:
                raise NotImplementedError(
                    'no conversion between %s and %s color spaces'
                    %(self.space, target)
                )
            kwargs['illuminant']=self.illuminant # to avoid incoherent cached values
            for u,v in itertools2.pairwise(path):
                if v not in self._values:
                    edge=converters[u][v][0]
                    c=edge['f'](self._values[u],**kwargs)

                    if itertools2.isiterable(c): #but not a string
                        c=tuple(map(float,c))
                    self._values[v]=c
        return self._values[target]
Пример #5
0
    def __init__(self, data=[], **kwargs):
        """inits a table, optionally by reading a Excel, csv or html file
        :param data: list of list of cells, or string as filename
        :param titles: optional list of strings used as column id
        :param footer: optional list of functions used as column reducers
        """
        try:
            self.titles = data.titles
        except AttributeError:
            self.titles = kwargs.pop('titles', [])
        try:
            self.footer = data.footer
        except AttributeError:
            self.footer = kwargs.pop('footer', [])

        filename = None
        if isinstance(data, str):
            filename = data
            data = []
        else:  # ensure data is 2D and mutable
            if isinstance(data, dict):
                data = data.values()
            for row in data:
                if not itertools2.isiterable(row):  # build a column
                    row = [row]
                self.append(row)

        if filename:
            self.load(filename, **kwargs)
Пример #6
0
    def __call__(self, x):
        '''returns value of Expr at point x '''
        if itertools2.isiterable(x):
            return [self(x) for x in x]

        i = self.index(x)
        xx = self._x(x)
        return self.y[i](xx)
Пример #7
0
 def addcol(self, title, val=None, i=0):
     '''add column to the right'''
     col = len(self.titles)
     self.titles.append(title)
     if not itertools2.isiterable(val):
         val = [val]*(len(self)-i)
     for v in val:
         self.set(i, col, v)
         i += 1
     return self
Пример #8
0
 def setcol(self, col, value, i=0):
     """set column values
     :param col: int or string column index
     :param value: single value assigned to whole column or iterable assigned to each cell
     :param i: optional int : index of first row to assign
     """
     j = self._i(col)
     if itertools2.isiterable(value):
         for v in value:
             self.set(i, j, v)
             i += 1
     else:
         for i in range(i, len(self)):
             self.set(i, j, value)
Пример #9
0
 def __call__(self, x=None, **kwargs):
     '''evaluate the Expr at x OR compose self(x())'''
     if isinstance(x, Expr):  # composition
         return self.applx(x)
     if itertools2.isiterable(x):
         return [self(x) for x in x]  # return a displayable list
     if x is not None:
         kwargs['x'] = x
     kwargs['self'] = self  # allows to call methods such as in Stats
     self.context.variables = kwargs
     try:
         e = self.context.eval(self.body)
     except TypeError:  # some params remain symbolic
         return self
     except Exception as error:  # ZeroDivisionError, OverflowError
         return None
     if math2.is_number(e):
         return e
     return Expr(e, self.context)
Пример #10
0
 def __call__(self, x=None, **kwargs):
     '''evaluate the Expr at x OR compose self(x())'''
     if isinstance(x, Expr):  # composition
         return self.applx(x)
     if itertools2.isiterable(x):
         return [self(x) for x in x]  # return a displayable list
     if x is not None:
         kwargs['x'] = x
     kwargs['self'] = self  # allows to call methods such as in Stats
     self.context.variables = kwargs
     try:
         e = self.context.eval(self.body)
     except TypeError:  # some params remain symbolic
         return self
     except Exception as error:  # ZeroDivisionError, OverflowError
         return None
     if math2.is_number(e):
         return e
     return Expr(e, self.context)
Пример #11
0
    def __init__(self, data, align=None, fmt=None, tag=None, style={}):
        """
        :param data: (list of) cell value(s) of any type
        :param align: (list of) string for HTML align attribute
        :param fmt: (list of) format string applied applied to data
        :param tag: (list of) tags called to build each cell. defaults to 'td'
        :param style: (list of) dict or string for HTML style attribute
        """

        if not itertools2.isiterable(data):
            data = [data]
        data = list(data)  # to make it mutable

        # ensure params have the same length as data

        if not isinstance(style, list):
            style = [style]
        style = style+[None]*(len(data)-len(style))

        if not isinstance(align, list):
            align = [align]
        align = align+[None]*(len(data)-len(align))

        if not isinstance(fmt, list):
            fmt = [fmt]
        fmt = fmt+[None]*(len(data)-len(fmt))

        if not tag:
            tag = 'td'
        if not isinstance(tag, list):
            tag = [tag]*(len(data))  # make a full row, in case it's a 'th'
        # fill the row with None, which will be 'td's
        tag = tag+[None]*(len(data)-len(fmt))

        for i, cell in enumerate(data):
            if not isinstance(cell, Cell):
                cell = Cell(cell, align[i], fmt[i], tag[i], style[i])
            else:
                pass  # ignore attribs for now
            data[i] = cell

        self.data = data
Пример #12
0
 def __call__(self, x=None, **kwargs):
     if itertools2.isiterable(x):
         return (self(x) for x in x)
     return self.pdf(x)
Пример #13
0
 def __call__(self,x=None,**kwargs):
     if isiterable(x):
         return (self(x) for x in x)
     return self.pdf(x)