Example #1
0
def plotFeaturesTraj(features, tab, N, folder=None, show=False):
    
    fig=p.figure(figsize=(24,13))   
    num=0; plots=[]; labels=[]; first=True
    fig.suptitle('Evolution of features in time')#("Plate {0}, well {1}".format(plate, well))
    colors = makeColorRamp(N, basic_colors, hex_output=True)
    #calculus={}
    for feat in features1:
        num+=1
        print '------------------', feat, '---------------------'
        #calculus.update({feat:[]})
        m=100; M=-100; i=0
        ax=fig.add_subplot(4,4, num) 
        X=[]; Y=[];
        for plate in features:
            for well in features[plate]:
                print plate, well
                x=[]; y=[]
                cFeatures = features[plate][well]
                tabC = tab[plate][well]
                index=featuresListArray.index(feat)
                ff=True
                for k in range(len(cFeatures)):
                    if np.isnan(tabC[k][index]):
                        continue
                    y=tabC[k][index]
                    x=cFeatures[k].beginning
                    
                    if first and ff:   
                        plots.append(ax.scatter(x, y,s=6, color=colors[i]))
                        #ax.text(x, y, '{}_{}'.format(cFeatures[k].numCellule, cFeatures[k].id))
                        labels.append('{0}_{1}'.format(plate, well))
                    else:
                        ax.scatter(x, y,s=2, color=colors[i])
                        #ax.text(x, y, '{}'.format(cFeatures[k].numCellule))
                    ff=False
                #coeff de correlation pour la droite x=y
                    X.append(x); Y.append(y)
        
                i+=1
        m=min(Y); M=max(Y)   
        m=m*1.2; M=M*1.2
        first=False
        #print m, M
        #        pdb.set_trace()
        ax.set_title(feat)
        #ax.set_xlabel('Training set data'); 
        ax.set_ylabel('Predicted data')
        #ax.plot([m,M], [m, M], color='black')
        ax.set_ylim(m, M)
    fig.legend(tuple(plots), tuple(labels), 'lower right')
    if show:
        p.show()
    elif folder is not None:
        fig.savefig(os.path.join(folder, 'featuresTraj_{}.png'.format(well))) 
        
    return 1
Example #2
0
def plotComparison(correspF, correspTF, N):
    
    fig=p.figure()   
    num=0; plots=[]; labels=[]; first=True
    fig.suptitle('Comparison between training set and predicted data')#("Plate {0}, well {1}".format(plate, well))
    colors = makeColorRamp(N, basic_colors, hex_output=True)
    calculus={}
    for feat in features1:
        num+=1
        print '------------------', feat, '---------------------'
        calculus.update({feat:[]})
        m=100; M=-100; i=0
        ax=fig.add_subplot(4,4, num) 
        X=[]; Y=[]
        for plate in correspF:
            for well in correspF[plate]:
                print plate, well
                x=[]; y=[]
                cCorrespF = correspF[plate][well]
                cCorrespTF = correspTF[plate][well]
                if len(cCorrespF)!=len(cCorrespTF):
                    raise LengthError
                for k in range(len(cCorrespF)):
                    if cCorrespF[k].features[feat] is None or cCorrespTF[k].features[feat] is None:
                        continue
                    y.append(cCorrespF[k].features[feat])
                    x.append(cCorrespTF[k].features[feat])
                #pdb.set_trace()    
                if first:   
                    plots.append(ax.scatter(x, y, color=colors[i]))
                    labels.append('{0}_{1}'.format(plate, well))
                else:
                    ax.scatter(x, y, color=colors[i])
                #coeff de correlation pour la droite x=y
                X.extend(x); Y.extend(y)
                m=min(m, min(y)); M=max(M, max(y))
                i+=1
        X=np.array(X); Y=np.array(Y)
        coeff_corr=np.mean((X-np.mean(X))*(Y-np.mean(Y)))/float(np.sqrt(np.var(X)*np.var(Y)))
        residues=np.mean((X-Y)**2)
        print "taille de l'echantillon", len(X)
        print 'coeff corr', coeff_corr
        print 'residues', residues
        calculus[feat].extend([len(X), coeff_corr, residues])       
        m=m*1.2; M=M*1.2
        first=False
        #print m, M
        #        pdb.set_trace()
        ax.set_title(feat)
        #ax.set_xlabel('Training set data'); 
        ax.set_ylabel('Predicted data')
        ax.plot([m,M], [m, M], color='black')
        ax.set_ylim(m, M)
    fig.legend(tuple(plots), tuple(labels), 'lower right')
    p.show()
        
    return calculus    
Example #3
0
    def plot(self, resultDict=None, show=False):
        if resultDict == None:
            f=open(os.path.join(self.outFolder, self.outFile))
            resultDict= pickle.load(f); f.close()
            
        if type(resultDict.keys()[0])==str:
            #meaning we are dealing with many alg results
            pass
        elif type(resultDict.keys()[0])==tuple:
        #plotting legend plot
            param_set = resultDict.keys()[0]
            try:
                print self.classNames
            except AttributeError:
                self.classNames = resultDict[param_set].keys()
            f=p.figure(figsize=(17,17))
            ax=f.add_subplot(111)
            
            for morpho in resultDict[param_set]:
                r = resultDict[param_set][morpho]
                colors = makeColorRamp(17, hex_output=True)
                ax.errorbar(np.mean(r[1]), np.mean(r[0]), xerr = np.std(r[1]), yerr=np.std(r[0]), 
                            color =colors[self.classNames.index(morpho)], fmt = markers[methods.index(self.algo)],
                           label = '{} {}'.format(self.algo, morpho))
            ax.legend()
            f.suptitle("Algorithm {}".format(self.algo))
            p.savefig(os.path.join(self.outFolder, 'legend {}.png'.format(self.algo)))
            
        #plotting result plot, one for all classes and one for each morphological class
            plots = {morphological_class : p.subplots(2, sharex=True) for morphological_class in self.classNames}
            
            f=p.figure(figsize=(17,17))
            ax=f.add_subplot(121)
            
            for param_set in resultDict:
                param_dict=dict(param_set)
                for morpho in resultDict[param_set]:
                    r = resultDict[param_set][morpho]
                    ax.errorbar(np.mean(r[1]), np.mean(r[0]), xerr = np.std(r[1]), yerr=np.std(r[0]), 
                            color =colors[self.classNames.index(morpho)], fmt = markers[methods.index(self.algo)],
                           label = '{} {}'.format(self.algo, morpho))
                    
                    plots[morpho][1][0].errorbar(np.mean(r[1]), np.mean(r[0]), xerr = np.std(r[1]), yerr=np.std(r[0]), 
                            color =colors[whiten_param.index(param_dict['whiten'])], fmt = markers[pca_param.index(param_dict['pca'])],
                           label = 'W{} PCA {}'.format(param_dict['whiten'],param_dict["pca"]))
                    plots[morpho][1][0].grid(True)
                    plots[morpho][1][0].set_xlim(0,1)
                    plots[morpho][1][0].set_ylim(0,1)
                    plots[morpho][1][0].set_xlabel("Nb of class elements in cluster/cluster size")
                    plots[morpho][1][0].set_ylabel("Nb of class elements in cluster/class size")
                    #plots[morpho][1][0].legend()

            ax.grid(True)
            ax.set_xlim(0,1)
            ax.set_ylim(0,1)
            ax.set_xlabel("Nb of class elements in cluster/cluster size")
            ax.set_ylabel("Nb of class elements in cluster/class size")
            
            ax=f.add_subplot(122)
            for param_set in resultDict:
                param_dict=dict(param_set)
                for morpho in resultDict[param_set]:
                    r = resultDict[param_set][morpho]
                    ax.errorbar(np.mean(r[3]), np.mean(r[2]), xerr = np.std(r[3]), yerr=np.std(r[2]), 
                            color =colors[self.classNames.index(morpho)], fmt = markers[methods.index(self.algo)],
                           label = '{} {}'.format(self.algo, morpho))
                    
                    plots[morpho][1][1].errorbar(np.mean(r[3]), np.mean(r[2]), xerr = np.std(r[3]), yerr=np.std(r[2]), 
                            color =colors[whiten_param.index(param_dict['whiten'])], fmt = markers[pca_param.index(param_dict['pca'])],
                           label = 'W{} PCA {}'.format(param_dict['whiten'],param_dict["pca"]))
                    plots[morpho][1][1].grid(True)
                    plots[morpho][1][1].set_xlim(0,1)
                    plots[morpho][1][1].set_ylim(0,1)
                    plots[morpho][1][1].set_xlabel("Entropy of cluster which is the one with the most elements from this class")
                    plots[morpho][1][1].set_ylabel("Entropy of class with regard to the clustering")
            ax.grid(True)
            ax.set_xlim(0,1)
            ax.set_ylim(0,1)
            ax.set_xlabel("Entropy of cluster which is the one with the most elements from this class")
            ax.set_ylabel("Entropy of class with regard to the clustering")
            

            f.suptitle("Algorithm {}".format(self.algo))
            
            for morpho in plots:
                plots[morpho][0].suptitle("Algorithm {}, class {}".format(self.algo, morpho))
                plots[morpho][0].savefig(os.path.join(self.outFolder, 'figure {} {}.png'.format(morpho, self.algo)))
            
            if show:
                p.show()
            else:
                p.savefig(os.path.join(self.outFolder, 'figure {}.png'.format(self.algo)))