# Path: opc/utils/idw.py
# def idw(sample, base, maxdist):
#     """
#     A rudimentary implementation of inverse distance weighting.
#     for a given point in a series, examine that points neighbors
#     with more distant values having an increasing diminished
#     impact on the result.
# 
#     Start off with the most distant pair, taking the average. Then
#     this value is half as significant as the next-closest pair
#     in the series. Repeat until we reach the point itself, in
#     which case this has double weighting (-0 and +0 being the same
#     thing.
#     """
# 
#     default = sample[base]
#     total = None
# 
#     for distance in range(maxdist, -1, -1):
#         samples = (
#             _relative(sample, base, distance, default),
#             _relative(sample, base, -distance, default)
#             )
# 
#         if total is None:
#             total = sum(samples)/2
#         else:
#             total = (total + sum(samples)/2)/2
# 
#     return total


from .utils import idw
    from exceptions import AttributeError
import numpy as np
        colormap cells
        """
        steps = float(index1) - index0
        delta = [(color1[gun] - color0[gun]) / steps for gun in range(3)]

        for index in range(index0, index1):
            c = [color0[gun] + delta[gun] * (index-index0) for gun in range(3)]
            self.cmap[index] = c

    def convert(self, point, scale=None):
        """
        Get the color associated with the given index. This method allows for
        scaling up or down, in the case where the desired range is either
        bigger or smaller than the colormap
        """
        if scale:
            point = point * self.size/scale

        index = int(min(self.size-1, max(0, point)))
        return self.cmap[index]

    def apply(self, data, scale=None):
        scale = self.size-1 if scale is None else scale
        return self.cmap[(data*scale).astype(np.int)]

    def soften(self, neighbors=1):
        """
        Use inverse distance weighting to soften the transitions between colors
        in the map, looking out by NEIGHBORS entries left and right.
        """

# Path: opc/utils/idw.py
# def idw(sample, base, maxdist):
#     """
#     A rudimentary implementation of inverse distance weighting.
#     for a given point in a series, examine that points neighbors
#     with more distant values having an increasing diminished
#     impact on the result.
# 
#     Start off with the most distant pair, taking the average. Then
#     this value is half as significant as the next-closest pair
#     in the series. Repeat until we reach the point itself, in
#     which case this has double weighting (-0 and +0 being the same
#     thing.
#     """
# 
#     default = sample[base]
#     total = None
# 
#     for distance in range(maxdist, -1, -1):
#         samples = (
#             _relative(sample, base, distance, default),
#             _relative(sample, base, -distance, default)
#             )
# 
#         if total is None:
#             total = sum(samples)/2
#         else:
#             total = (total + sum(samples)/2)/2
# 
#     return total


# Path: opc/colormap.py
from .utils import idw
    from exceptions import AttributeError
import numpy as np

        colormap cells
        """
        steps = float(index1) - index0
        delta = [(color1[gun] - color0[gun]) / steps for gun in range(3)]

        for index in range(index0, index1):
            c = [color0[gun] + delta[gun] * (index-index0) for gun in range(3)]
            self.cmap[index] = c

    def convert(self, point, scale=None):
        """
        Get the color associated with the given index. This method allows for
        scaling up or down, in the case where the desired range is either
        bigger or smaller than the colormap
        """
        if scale:
            point = point * self.size/scale

        index = int(min(self.size-1, max(0, point)))
        return self.cmap[index]

    def apply(self, data, scale=None):
        scale = self.size-1 if scale is None else scale
        return self.cmap[(data*scale).astype(np.int)]

    def soften(self, neighbors=1):
        """
        Use inverse distance weighting to soften the transitions between colors
        in the map, looking out by NEIGHBORS entries left and right.
        """

        self.cmap = idw.soften_2d(self.cmap, neighbors)