コード例 #1
0
    def showMap(self,
                imageNumber,
                neuronSize,
                shareIntensity=False,
                borderWidth=2,
                facecolor='#ffaadd'):
        print(shareIntensity)
        if facecolor != "#ffaadd":
            print(
                "WARNING! using non recommended background color! The results will look ugly."
            )
        figure = pyplot.figure(figsize=(16, 16))
        figure.patch.set_alpha(0.0)
        figure.patch.set_facecolor(facecolor)
        pyplot.subplots_adjust(left=0.01,
                               right=0.99,
                               bottom=0.01,
                               top=0.99,
                               wspace=0.1,
                               hspace=0.1)

        if self.__som_layout == 1:
            print("hexagonal map")
            image = tools.calculate_map(self.__somWidth,
                                        self.__somHeight,
                                        self.__maps[imageNumber],
                                        neuronSize,
                                        neuronSize,
                                        shareIntensity=shareIntensity,
                                        border=borderWidth,
                                        shape="hex")
        else:
            print("cartesian map")
            image = tools.calculate_map(self.__somWidth,
                                        self.__somHeight,
                                        self.__maps[imageNumber],
                                        neuronSize,
                                        neuronSize,
                                        shareIntensity=shareIntensity,
                                        border=borderWidth,
                                        shape="box")

        ax = pyplot.subplot()
        cmap = matplotlib.cm.get_cmap("jet")
        cmap.set_bad(facecolor, 1.)
        #Uses image.T because the file is read in as C notation when it's actually Fortran notation.
        ax.imshow(image.T, aspect=1, interpolation="nearest", cmap=cmap)
        ax.set_xticks([])
        ax.set_yticks([])
        ax.axis("off")
        fileName = save + '/' + name + '%d.pdf' % imageNumber
        pyplot.savefig(fileName, bbox_inches='tight', dpi=150)
        if (display == 1):
            pyplot.show()
コード例 #2
0
    def showMap(self, channel, shareIntensity = True, borderWidth = 2, facecolor = '#ffaadd'):
        print(shareIntensity)
        if facecolor != "#ffaadd":
            print ("WARNING! using non recommended background color! The results will look ugly.")
        figure = pyplot.figure(figsize=(16, 16))
        figure.patch.set_alpha(0.0)
        figure.patch.set_facecolor(facecolor)
        pyplot.subplots_adjust(left = 0.01, right = 0.99, bottom = 0.01, top = 0.99, wspace = 0.1, hspace = 0.1)
        start=int(len(self.__neurons[0]) / self.__numberOfChannels * channel)
        end=int(len(self.__neurons[0]) / self.__numberOfChannels * (channel+1))
        if self.isHexMap():
            print ("hexagonal map")
            image = tools.calculate_map(self.__somWidth, self.__somHeight, self.__neurons[:,start:end], self.__neuronWidth, self.__neuronHeight, shareIntensity=shareIntensity, border=borderWidth, shape="hex")
        else:
            print ("quadratic map")
            image = tools.calculate_map(self.__somWidth, self.__somHeight, self.__neurons[:,start:end], self.__neuronWidth, self.__neuronHeight, shareIntensity=shareIntensity, border=borderWidth, shape="box")

        ax = pyplot.subplot()
        if somColor==0:
            cmap = matplotlib.cm.get_cmap("jet")
        else:
            if channel==0:
                cmap = matplotlib.cm.get_cmap("Blues")
            elif channel==1:
                cmap = matplotlib.cm.get_cmap("Reds")
            elif channel==2:
                cmap = matplotlib.cm.get_cmap("Greens")
            elif channel==3:
                cmap = matplotlib.cm.get_cmap("Purples")
            elif channel==4:
                cmap = matplotlib.cm.get_cmap("Greys")
            elif channel==5:
                cmap = matplotlib.cm.get_cmap("Oranges")
            else:
                cmap = matplotlib.cm.get_cmap()
        cmap.set_bad(facecolor,1.)
        #Uses image.T because the file is read in as C notation when it's actually Fortran notation.
        ax.imshow(image.T, aspect=1, interpolation="nearest", cmap=cmap)
        ax.set_xticks([])
        ax.set_yticks([])
        ax.axis("off")
        fileName = save+'/'+name+'%d.pdf' %channel
        pyplot.savefig(fileName,bbox_inches='tight',dpi=150)
        if(display==1):
            pyplot.show()