コード例 #1
0
    def plotSpeedMainChannelNonDimensional(self, savepath=None, d0=None, BatchID  = '', BatchIDC ='', show=False, plotDaugtherChannel=False):
        if not hasattr(self, 'sortedSpeedMain'):
            self.averageSpeed()
        
        #get drag coefficients
        if d0 !=None:
            import track_capsule_TJ_v0p10 as tc
            lamb=d0/np.sqrt(4*7.8)
            k1, k2 = tc.getDragCoef(lamb)
            G=k2/k1
            lambD=d0/4.0
            if lambD > 0.95:
                lambTemp=0.95
            else:
                lambTemp=lambD
            k1D, k2D = tc.getDragCoef(lambTemp)
            GD=k2D/k1D
        
        c = self.coloursForMarker()
        
        size=6
        fig = plt.figure(figsize=(8, 6), dpi=200,)
        ax2 = fig.add_subplot(111) #ax2.text(minVolumnFlux+maxVolumnFlux*0.1self.sortedSpeedMain, ((2*minVolumnFlux*1000.0/60)/32.0), s2, fontsize=10)
        
        ms=[]
        for ii in range(len(self.volumFluxesList)):
            meanSpeed = ((self.volumFluxesList[ii]*1000.0/60)/32.0)
            ms.append(meanSpeed)
            xvalue = np.repeat(self.volumFluxesList[ii], len(self.sortedSpeedMain[ii]))
            plt.errorbar(x=xvalue, y=(self.sortedSpeedMain[ii]/self.pixelsPmm)/meanSpeed, marker = 'o', color = c[0], markersize=4,linestyle='None')
        ms=np.array(ms)
        plt.errorbar(x=self.volumFluxesList, y=(self.aveSpeedMain/self.pixelsPmm)/ms, yerr=(self.aveSpeedMainSTD/self.pixelsPmm)/ms, marker = 's', color = c[2], label='Mean Speed Main Channel',  markersize=size,linestyle='None') #
        self.meanSpeedMainND = np.mean((self.aveSpeedMain/self.pixelsPmm)/ms)
        self.meanSpeedMainNDSTD = np.std((self.aveSpeedMain/self.pixelsPmm)/ms)
        
        if plotDaugtherChannel:
            msD=[]
            for ii in range(len(self.volumFluxesList)):
                meanSpeed = ((self.volumFluxesList[ii]*1000.0/60)/(2*16.0))
                msD.append(meanSpeed)
                xvalue = np.repeat(self.volumFluxesList[ii], len(self.sortedSpeedDaugther[ii]))
                plt.errorbar(x=xvalue, y=(self.sortedSpeedDaugther[ii]/self.pixelsPmm)/meanSpeed, marker = '<', color = c[1], markersize=4,linestyle='None') #label='Speed Daugther Channel',
            msD=np.array(msD)
            plt.errorbar(x=self.volumFluxesList, y=(self.aveSpeedDaugther/self.pixelsPmm)/msD, yerr=(self.aveSpeedDaugtherSTD/self.pixelsPmm)/msD, marker = 'h', color = c[3],  label='Mean Speed Daugther Channel', markersize=size,linestyle='None')
            self.meanSpeedDaugtherND = np.mean((self.aveSpeedDaugther/self.pixelsPmm)/msD)
            self.meanSpeedDaugtherNDSTD = np.std((self.aveSpeedDaugther/self.pixelsPmm)/msD)
        sampleNum=len(self.SpeedMain)
        
        self.findNonDimensionalgradientSpeedChannel()
        if d0 !=None:
            self.mainChannelGradientDifferencToPredicted = (2.0*G) - self.NDAverageSpeedMain
            self.daugtherChannelGradientDifferencToPredicted = (2.0*GD) - self.NDAverageSpeedDaugther
            if lambTemp == lambD:
                s2='Error based on standard deviation of sample \nGradient difference to predicted main = %.2f, daugther = %.2f \nNumber of data points = %d \nLag factor G = %.2f with $\lambda $ = %.2f and $d_0$ = %.2f $mm$ \nLag factor G = %.2f with $\lambda $ = %.2f in Daugther' %(self.mainChannelGradientDifferencToPredicted, self.daugtherChannelGradientDifferencToPredicted, sampleNum, G, lamb, d0, GD, lambD)
            else:

                s2='Error based on standard deviation of sample \nGradient difference to predicted main = %.2f, daugther = %.2f \nNumber of data points = %d \nLag factor G = %.2f with $\lambda $ = %.2f and $d_0$ = %.2f $mm$ \nLag factor G = %.2f with for $\lambda $ = 0.95 (actually is $\lambda $ = %.2f) in Daugther' %(self.mainChannelGradientDifferencToPredicted, self.daugtherChannelGradientDifferencToPredicted, sampleNum, G, lamb, d0, GD, lambD)                
        else:
            s2='Error based on standard deviation of sample \nNumber of data points = %d' %sampleNum
        
        xmin, xmax = plt.xlim()
        plt.xlim([xmin, xmax*1.05])
        xmin, xmax = plt.xlim()
        ymin, ymax = plt.ylim()
        plt.ylim([ymin, ymax*1.05])
        ymin, ymax = plt.ylim()

        #fit
        if d0 !=None:
            
            labelm='Predicted Speed Main Gradient = %.2f' %(2.0*G)
            plt.plot([xmin, xmax], [2*G, 2*G], label=labelm, color='y', linestyle=':', linewidth=1)
            if plotDaugtherChannel:
                labeld='Predicted Speed Daugther Gradient = %.2f' %(2.0*GD)
                plt.plot([xmin, xmax], [2*GD, 2*GD], label=labeld, color='m', linestyle=':', linewidth=1)
#                print('%s \n%s' %(labelm, labeld))
                
        
        label1='Mean Main Channel, m=%.2f +/- %.2f' %(self.NDAverageSpeedMain, self.NDAverageSpeedMainErr)
        plt.plot([xmin, xmax], [self.NDAverageSpeedMain, self.NDAverageSpeedMain], label=label1, color='b', linestyle='-.', linewidth=1)
        
        if plotDaugtherChannel:
            label1='Mean Daugther Channel, m=%.2f +/- %.2f ' %(self.NDAverageSpeedDaugther, self.NDAverageSpeedDaugtherErr)
            plt.plot([xmin, xmax], [self.NDAverageSpeedDaugther, self.NDAverageSpeedDaugther], label=label1, color='g', linestyle='--', linewidth=1)
        
        plt.show()
        
        ymin, ymax = plt.ylim()
        ax2.text(xmin+xmax*0.3, ymin+ymax*0.01, s2, fontsize=10)
        plt.show()
        
        plt.title("Speed Nondimensional -  " +BatchID)
        plt.xlabel("Volumn Flux [ml/min]")
        plt.ylabel("Speed as fraction of Mean Speed")
        
        plt.legend(loc='upper left', fontsize=6, ncol=2)
        
        if savepath != None:
            plt.savefig(savepath+"Speed_ND_Graph_" +BatchIDC+".png", dpi=300)
        
        if show:
            plt.show()
        else:
            plt.close()
コード例 #2
0
    def plotSpeedMainChannel(self, savepath=None, d0=None, BatchID  = '', BatchIDC ='', show=False, plotDaugtherChannel=False):
        self.findSpeedGradient()
        c1, c2, c3, c4 =  self.coloursForMarker()
        
        #get drag coefficients
        if d0 !=None:
            import track_capsule_TJ_v0p10 as tc
            lamb1=d0[0]/np.sqrt(4*7.8)
            k11, k21 = tc.getDragCoef(lamb1)
            G1=k21/k11
            lamb2=d0[1]/np.sqrt(4*7.8)
            k12, k22 = tc.getDragCoef(lamb2)
            G2=k22/k12
            if plotDaugtherChannel:
                templambda1=d0[0]/4.0
                if templambda1 > 0.95:
                    print('lambda daugther too big, set to 0.95')
                    templambda1=0.95
                lambD1=templambda1
                k1D1, k2D1 = tc.getDragCoef(lambD1)
                GD1=(k2D1/k1D1)
                templambda2=d0[1]/4.0
                if templambda2 > 0.95:
                    print('lambda daugther too big, set to 0.95')
                    templambda2=0.95
                lambD2=templambda2
                k1D2, k2D2 = tc.getDragCoef(lambD2)
                GD2=(k2D2/k1D2)

        fig = plt.figure(figsize=(8, 6), dpi=200,)
        ax2 = fig.add_subplot(111) #ax2.text(minVolumnFlux+maxVolumnFlux*0.1, ((2*minVolumnFlux*1000.0/60)/32.0), s2, fontsize=10)
        
        size3p5=6
        #errorbar average3p5beforSTD
        plt.errorbar(self.volumFluxesList, self.aveSpeedMain1/self.pixelsPmm, yerr=self.aveSpeedMainSTD1/self.pixelsPmm, linestyle='None',  marker='h', color = c1, label='Speed Main Channel Capsule 1', markersize=size3p5) #
        plt.errorbar(self.volumFluxesList, self.aveSpeedMain2/self.pixelsPmm, yerr=self.aveSpeedMainSTD2/self.pixelsPmm, linestyle='None',  marker='p', color = c3, label='Speed Main Channel Capsule 2', markersize=size3p5) #
        if plotDaugtherChannel:
#            plt.errorbar(self.volumFlux, self.SpeedDaugther/self.pixelsPmm,  linestyle='None',  marker='s', color = 'g', label='Speed Daugther Channel', markersize=3) #
            plt.errorbar(self.volumFluxesList, self.aveSpeedDaugther1/self.pixelsPmm, yerr=self.aveSpeedDaugtherSTD1/self.pixelsPmm,  linestyle='None',  marker='o', color = c2, label='Speed Daugther Channel Capsule 1', markersize=size3p5) #
            plt.errorbar(self.volumFluxesList, self.aveSpeedDaugther2/self.pixelsPmm, yerr=self.aveSpeedDaugtherSTD2/self.pixelsPmm,  linestyle='None',  marker='s', color = c3, label='Speed Daugther Channel Capsule 2', markersize=size3p5) #
        sampleNum1=len(self.speedMain1)
        if d0 !=None:
            if plotDaugtherChannel:
                s2 = 'Error based on standard deviation of sample \nNumber of data points = %d \nLag factor G = %.2f / %.2f with $\lambda $ = %.2f / %.2f and $d_0$ = %.2f /%.2f $mm$ \nLag factor Daugther G = %.2f /%.2f with $\lambda $ = %.2f / %.2f' %(sampleNum1, G1, G2, lamb1, lamb2, d0[0], d0[1], GD1, GD2, lambD1, lambD2)
            else:
                s2='Error based on standard deviation of sample \nNumber of data points = %d \nLag factor G = %.2f / %.2f with $\lambda $ = %.2f / %.2f and $d_0$ = %.2f $mm$' %(sampleNum1, G1, G2, lamb1, lamb2, d0[0], d0[1])
        else:
            s2='Error based on standard deviation of sample \nNumber of data points = %d' %sampleNum
            
        xmin, xmax = plt.xlim()
        plt.xlim([xmin, xmax*1.05])
        xmin, xmax = plt.xlim()
        ymin, ymax = plt.ylim()
        ax2.text(xmin+xmax*0.02, ymin+ymax*0.7, s2, fontsize=10)
        #fit
        if d0 !=None:
            label='Predicted Speed Gradient Main 1 = %.2f' %G1
            plt.plot([xmin, xmax], [((2*G1*xmin*1000.0/60)/32.0), ((2*G1*xmax*1000.0/60)/32.0)], label=label, color=c1, linestyle=':', linewidth=1)
            label='Predicted Speed Gradient Main 2 = %.2f' %G2            
            plt.plot([xmin, xmax], [((2*G2*xmin*1000.0/60)/32.0), ((2*G2*xmax*1000.0/60)/32.0)], label=label, color=c3, linestyle=':', linewidth=1)
            
        label1='Fit Main Channel 1, m=%.2f +/- %.2f and $R^2$ = %.2f' %(self.gradientSpeedMain1, self.gradientSpeedMainErr1,self.gradientSpeedMainR21)
        plt.plot([xmin, xmax], [self.straightLine(xmin, self.gradientSpeedMain1), self.straightLine(xmax, self.gradientSpeedMain1)], label=label1, color=c1, linestyle='-.', linewidth=1)
        label1='Fit Main Channel 2, m=%.2f +/- %.2f and $R^2$ = %.2f' %(self.gradientSpeedMain2, self.gradientSpeedMainErr2,self.gradientSpeedMainR22)
        plt.plot([xmin, xmax], [self.straightLine(xmin, self.gradientSpeedMain2), self.straightLine(xmax, self.gradientSpeedMain2)], label=label1, color=c3, linestyle='-.', linewidth=1)
             
        if plotDaugtherChannel:
            label1='Fit Daugther Channel 1, m=%.2f +/- %.2f and $R^2$ = %.2f' %(self.gradientSpeedDaugther1, self.gradientSpeedDaugtherErr1,self.gradientSpeedDaugtherR21)
            plt.plot([xmin, xmax], [self.straightLine(xmin, self.gradientSpeedDaugther1), self.straightLine(xmax, self.gradientSpeedDaugther1)], label=label1, color=c2, linestyle='--', linewidth=1)
            label1='Fit Daugther Channel 2, m=%.2f +/- %.2f and $R^2$ = %.2f' %(self.gradientSpeedDaugther2, self.gradientSpeedDaugtherErr2,self.gradientSpeedDaugtherR22)
            plt.plot([xmin, xmax], [self.straightLine(xmin, self.gradientSpeedDaugther2), self.straightLine(xmax, self.gradientSpeedDaugther2)], label=label1, color=c4, linestyle='--', linewidth=1)
            if d0 !=None:
                label='Predicted Speed Gradient Daugther 1= %.2f' %GD1
                plt.plot([xmin, xmax], [((2*GD1*xmin*1000.0/60)/32.0), ((2*GD1*xmax*1000.0/60)/32.0)], label=label, color=c2, linestyle=':', linewidth=1)
                label='Predicted Speed Gradient Daugther 2= %.2f' %GD2
                plt.plot([xmin, xmax], [((2*GD2*xmin*1000.0/60)/32.0), ((2*GD2*xmax*1000.0/60)/32.0)], label=label, color=c4, linestyle=':', linewidth=1)
        
        plt.plot([xmin, xmax], [((2*xmin*1000.0/60)/32.0), ((2*xmax*1000.0/60)/32.0)], label='2 x Mean Speed', color='k', linestyle='--', linewidth=1)
        plt.plot([xmin, xmax], [((xmin*1000.0/60)/32.0), ((xmax*1000.0/60)/32.0)], label='Mean Speed', color='k', linestyle='-', linewidth=1)
        
        plt.show()
        
        plt.title("Average Speed Main Channel -  " +BatchID)
        plt.xlabel("Volumn Flux [ml/min]")
        plt.ylabel("Speed   [mm/s]")
        
        plt.legend(loc=2, fontsize=6)
        
        if savepath != None:
            plt.savefig(savepath+"SpeedWFit_Graph_" +BatchIDC+".png", dpi=300)
        
        if show:
            plt.show()
        else:
            plt.close()