def plot_weighted(self,
                      mapp,
                      ax=None,
                      weighting='linear',
                      second_map=None,
                      indices=None,
                      **plot_args):
        """
        Generate weighted plot

        :param mapp:
        :type mapp:

        :param ax: axes object

        :param weighting: weighting function, 'linear' or 'dual'.
        :type weighting: str

        :param second_map:

        :param indices:

        .. todo:: __doc__
        """
        if ax is None:
            fig = plt.figure()
            ax = fig.add_subplot(111)
        else:
            fig = ax.get_figure()

        if self.color_list is None:
            color_list = get_colors(len(mapp[0][-1]) + 1)
            color_list.pop(0)  #remove black
        else:
            color_list = self.color_list

        pts, datas = zip(*list(mapp))
        if indices is None:
            indices = range(0, len(datas[0]))
        rgbs = []
        datas = zip(*datas)
        datas = [d for id, d in enumerate(datas) if id in indices]
        datas = zip(*datas)
        if second_map:
            pts2, datas2 = zip(*second_map)
            datas2 = zip(*datas2)
            datas2 = [d for id, d in enumerate(datas2) if id in indices]
            datas2 = zip(*datas2)
        else:
            datas2 = datas
        for data, data2 in zip(datas, datas2):
            if weighting == 'linear':
                rs, gs, bs = zip(*color_list)
                r = 1 - sum(float((1 - ri) * di) for ri, di in zip(rs, data))
                g = 1 - sum(float((1 - gi) * di) for gi, di in zip(gs, data))
                b = 1 - sum(float((1 - bi) * di) for bi, di in zip(bs, data))
                eff_res = self.resolution * self.resolution_enhancement
                rgbs.append([r, g, b])
            elif weighting == 'dual':
                rs, gs, bs = zip(*color_list)
                r = 1 - sum(
                    float((1 - ri) * di * d2i)
                    for ri, di, d2i in zip(rs, data, data2))
                g = 1 - sum(
                    float((1 - gi) * di * d2i)
                    for gi, di, d2i in zip(gs, data, data2))
                b = 1 - sum(
                    float((1 - bi) * di * d2i)
                    for bi, di, d2i in zip(bs, data, data2))
                eff_res = 300
                rgbs.append([r, g, b])
        r, g, b = zip(*rgbs)
        x, y = zip(*pts)
        xi = np.linspace(min(x), max(x), eff_res)
        yi = np.linspace(min(y), max(y), eff_res)
        ri = griddata(x, y, r, xi, yi)
        gi = griddata(x, y, g, xi, yi)
        bi = griddata(x, y, b, xi, yi)
        rgb_array = np.zeros((eff_res, eff_res, 3))
        for i in range(0, eff_res):
            for j in range(0, eff_res):
                rgb_array[i, j, 0] = ri[i, j]
                rgb_array[i, j, 1] = gi[i, j]
                rgb_array[i, j, 2] = bi[i, j]
        xminmax, yminmax = self.descriptor_ranges
        xmin, xmax = xminmax
        ymin, ymax = yminmax
        ax.imshow(rgb_array, extent=[xmin, xmax, ymin, ymax], origin='lower')
        self.plot_descriptor_pts(mapp, i, ax)
        if getattr(self, 'n_xticks', None):
            ax.xaxis.set_major_locator(MaxNLocator(self.n_xticks))
        if getattr(self, 'n_yticks', None):
            ax.yaxis.set_major_locator(MaxNLocator(self.n_yticks))
        ax.set_xlabel(self.descriptor_labels[0])
        ax.set_ylabel(self.descriptor_labels[1])
        if self.aspect:
            ax.set_aspect(self.aspect)
            ax.apply_aspect()
        return fig
Esempio n. 2
0
    def plot_weighted(self, mapp, ax=None, weighting='linear',
                      second_map=None, indices=None, **plot_args):
        """
        Generate weighted plot

        :param mapp:
        :type mapp:

        :param ax: axes object

        :param weighting: weighting function, 'linear' or 'dual'.
        :type weighting: str

        :param second_map:

        :param indices:

        .. todo:: __doc__
        """
        if ax is None:
            fig = plt.figure()
            ax = fig.add_subplot(111)
        else:
            fig = ax.get_figure()

        if self.color_list is None:
            color_list = get_colors(len(mapp[0][-1]) + 1)
            color_list.pop(0)  # remove black
        else:
            color_list = self.color_list

        pts, datas = zip(*mapp)
        if indices is None:
            indices = range(0, len(datas[0]))
        rgbs = []
        datas = zip(*datas)
        datas = [d for id, d in enumerate(datas) if id in indices]
        datas = zip(*datas)
        if second_map:
            pts2, datas2 = zip(*second_map)
            datas2 = zip(*datas2)
            datas2 = [d for id, d in enumerate(datas2) if id in indices]
            datas2 = zip(*datas2)
        else:
            datas2 = datas
        for data, data2 in zip(datas, datas2):
            if weighting == 'linear':
                rs, gs, bs = zip(*color_list)
                r = 1 - sum(float((1 - ri) * di) for ri, di in zip(rs, data))
                g = 1 - sum(float((1 - gi) * di) for gi, di in zip(gs, data))
                b = 1 - sum(float((1 - bi) * di) for bi, di in zip(bs, data))
                eff_res = self.resolution * self.resolution_enhancement
                rgbs.append([r, g, b])
            elif weighting == 'dual':
                rs, gs, bs = zip(*color_list)
                r = 1 - sum(float((1 - ri) * di * d2i)
                            for ri, di, d2i in zip(rs, data, data2))
                g = 1 - sum(float((1 - gi) * di * d2i)
                            for gi, di, d2i in zip(gs, data, data2))
                b = 1 - sum(float((1 - bi) * di * d2i)
                            for bi, di, d2i in zip(bs, data, data2))
                eff_res = 300
                rgbs.append([r, g, b])
        r, g, b = zip(*rgbs)
        x, y = zip(*pts)
        xi = np.linspace(min(x), max(x), eff_res)
        yi = np.linspace(min(y), max(y), eff_res)
        ri = griddata(x, y, r, xi, yi)
        gi = griddata(x, y, g, xi, yi)
        bi = griddata(x, y, b, xi, yi)
        rgb_array = np.zeros((eff_res, eff_res, 3))
        for i in range(0, eff_res):
            for j in range(0, eff_res):
                rgb_array[i, j, 0] = ri[i, j]
                rgb_array[i, j, 1] = gi[i, j]
                rgb_array[i, j, 2] = bi[i, j]
        xminmax, yminmax = self.descriptor_ranges
        xmin, xmax = xminmax
        ymin, ymax = yminmax
        ax.imshow(rgb_array, extent=[xmin, xmax, ymin, ymax], origin='lower')
        self.plot_descriptor_pts(mapp, i, ax)
        if getattr(self, 'n_xticks', None):
            ax.xaxis.set_major_locator(MaxNLocator(self.n_xticks))
        if getattr(self, 'n_yticks', None):
            ax.yaxis.set_major_locator(MaxNLocator(self.n_yticks))
        ax.set_xlabel(self.descriptor_labels[0])
        ax.set_ylabel(self.descriptor_labels[1])
        if self.aspect:
            ax.set_aspect(self.aspect)
            ax.apply_aspect()
        return fig