예제 #1
0
파일: VNA.py 프로젝트: docprofsky/pysdrvna
 def PlotFFTInput(self):
   """Plot Time Domain of FFT Input Slice for Last Measurement"""
   fig = self.CreateFigure("FFT Input")
   sp = fig.add_subplot(111)
   xaxis = range(0,self.fftn)
   sp.plot(xaxis,[x.real for x in self.fftia],'.-',color='b',label='I')
   sp.plot(xaxis,[x.imag for x in self.fftia],'.-',color='r',label='Q')    
   sp.set_ylabel("Magnitude")
   sp.set_xlabel("Sample")
   #sp.legend(bbox_to_anchor=(1,-0.1))  
   sp.legend(loc=2,bbox_to_anchor=(0,-0.1),ncol=4)   
   plt.show()    
예제 #2
0
파일: VNA.py 프로젝트: docprofsky/pysdrvna
 def PlotFD(self,dbfs=True):
   """Plot Frequency Domain for Last Measurement"""
   freqspectrum = np.abs(self.fftoa)
   freqspectrum = np.concatenate( [freqspectrum[self.fftn/2:self.fftn],freqspectrum[0:self.fftn/2]] )
   if dbfs:
     zerodb = 20*np.log10(self.fftn/2)
     freqspectrum = (20*np.log10(abs(freqspectrum))) - zerodb
     
   fig = self.CreateFigure("Frequency Domain")
   sp = fig.add_subplot(111)
   
   xaxis = np.r_[0:self.fftn] * (self.Sr/self.fftn)
   xaxis = np.concatenate( [(xaxis[self.fftn/2:self.fftn] - self.Sr),xaxis[0:self.fftn/2]])
   sp.plot(xaxis,freqspectrum,'.-',color='b',label='Spectrum')
   sp.set_ylabel("dBFS")
   sp.set_xlabel("Frequency")
   sp.legend(loc=2,bbox_to_anchor=(0,-0.1),ncol=4)   
   plt.show()          
예제 #3
0
파일: VNA.py 프로젝트: docprofsky/pysdrvna
 def PlotTD(self):
   """Plot Time Domain of Jack Input and Output Arrays for Last Measurement"""
   fig = self.CreateFigure("Time Domain")
   sp = fig.add_subplot(111)
   xaxis = range(0,len(self.iIa))
   sp.plot(xaxis,self.iIa,'.-',color='b',label='iI')
   ## 180 phase shift as complex portion is created with -1j
   sp.plot(xaxis,-1*self.iQa,'.-',color='r',label='iQ')
   sp.plot(xaxis,self.oIa,'.-',color='c',label='oI')
   sp.plot(xaxis,self.oQa,'.-',color='m',label='oQ') 
   ## Identify RTFrames
   maxy = self.oIa.max()
   sp.plot([self.rtframes,self.rtframes],[-maxy,maxy],'k-',lw=3,label='RT Frames')
   ## Identify Sync Index
   sp.plot([self.synci+self.sync2fft,self.synci+self.sync2fft],[-maxy,maxy],'g-',lw=3,label='FFT Start')
   sp.plot([self.synci+self.sync2fft+self.fftn,self.synci+self.sync2fft+self.fftn],[-maxy,maxy],'y-',lw=3,label='FFT End')      
   sp.set_ylabel("Magnitude")
   sp.set_xlabel("Sample")
   #sp.legend(bbox_to_anchor=(1,-0.1))  
   sp.legend(loc=2,bbox_to_anchor=(0,-0.1),ncol=7)   
   plt.show()        
def plot_reg_bayes(df, xy, traces_ind, traces_hier, feat='no_feat', burn_ind=2000, burn_hier=None, quad=False, clr_school=True):
    """ create plot for bayesian derived regression lines, no groups """
    
    keys = traces_ind.keys()         
    fig, axes1d = plt.subplots(nrows=1, ncols=len(keys), sharex=True, sharey=True, figsize=(8*len(keys),8))
    fig.suptitle('Bayesian hierarchical regression of pre-test vs post-test scores')
    cm_cmap = cm.get_cmap('Set2')

    clrs = {}
    clrs['ind'] = ['#00F5FF','#006266','#00585C']
    clrs['hier'] = ['#FF7538','#661f00','#572610']
    
    point_clrs = 'cm_cmap(grp.clr)' if clr_school else 'cm_cmap(j/len(keys))'
    
    if len(keys) == 1:
        axes1d = [axes1d]
        
    for j, (sp, key) in enumerate(zip(axes1d,keys)):
        
        # scatterplot datapoints and subplot count title
        if feat == 'no_feat':
            x = df[xy['x']]
            y = df[xy['y']]
            for grpkey, grp in df.groupby('schoolid'):
                sp.scatter(grp[xy['x']],grp[xy['y']],s=40,color=eval(point_clrs),label='{} ({})'.format(grpkey,len(grp))
                           ,alpha=0.7,edgecolor='#333333')

        if feat != 'no_feat':
            x = df.loc[df[feat] == key,xy['x']]
            y = df.loc[df[feat] == key,xy['y']]
            for grpkey, grp in df.loc[df[feat] == key].groupby('schoolid'):
                sp.scatter(grp[xy['x']],grp[xy['y']],s=40,color=eval(point_clrs),label='{} ({})'.format(grpkey,len(grp))
                           ,alpha=0.7,edgecolor='#333333')
            
        sp.annotate('{} ({} samples)'.format(key,len(x))
            ,xy=(0.5,1),xycoords='axes fraction',size=14,ha='center'
            ,xytext=(0,6),textcoords='offset points')

        if clr_school:
            sp.legend(scatterpoints=1, loc=8, ncol=1, bbox_to_anchor=(1.0, 0.35), fancybox=True, shadow=True)
        
        # setup xlims and plot 1:1 line # BODGED the xlims
        xfit = np.linspace(x.min(), x.max(), 10)
        sp.plot(np.array([65,135]),np.array([65,135]),linestyle='dotted',linewidth=0.5,color='#666666')
        
        # plot actual data mean
        sp.scatter(x.mean(),y.mean(),marker='+',s=500,color='#551A8B')
        
        # plot regression: individual
        alpha = traces_ind[key]['alpha'][burn_ind:]
        beta = traces_ind[key]['beta'][burn_ind:]
        yfit = alpha[:, None] + beta[:, None] * xfit   # <- yfit for all samples at x in xfit ind
        yfit_at_xmean = alpha[:, None] + beta[:, None] * x.mean()
        note = '{}\nslope:  {:.2f}\nincpt: {:.2f}\nmeanx: {:.2f}\nin@mx: {:.2f}'.format('individual'
                            ,beta.mean(), alpha.mean(), x.mean(), yfit_at_xmean.mean()-x.mean())
        
        if quad:
            gamma = traces_ind[key]['gamma'][burn_ind:]
            yfit = alpha[:, None] + beta[:, None] * xfit + gamma[:, None] * xfit ** 2
            yfit_at_xmean = alpha[:, None] + beta[:, None] * x.mean() + gamma[:, None] * x.mean() ** 2
            note = '{}\ny={:.2f} + {:.2f}x + {:.3f}x^2\nmeanx: {:.2f}\nin@mx: {:.2f}'.format('individual'
                        ,alpha.mean(),beta.mean(),gamma.mean(),x.mean(), yfit_at_xmean.mean()-x.mean())
        
        mu = yfit.mean(0)
        yerr_975 = np.percentile(yfit,97.5,axis=0)
        yerr_025 = np.percentile(yfit,2.5,axis=0)
        
        sp.plot(xfit, mu,linewidth=3, color=clrs['ind'][0], alpha=0.8)
        sp.fill_between(xfit, yerr_025, yerr_975, color=clrs['ind'][2],alpha=0.3)
        sp.annotate(note,xy=(1,0),xycoords='axes fraction',xytext=(-12,6),textcoords='offset points'
                ,color=clrs['ind'][1],weight='bold',size=12,ha='right',va='bottom')

        # plot regression: hierarchical
        if traces_hier is not None:    
            alpha = traces_hier['alpha'][burn_hier:,j]
            beta = traces_hier['beta'][burn_hier:,j]
            yfit = alpha[:, None] + beta[:, None] * xfit
            yfit_at_xmean = alpha[:, None] + beta[:, None] * x.mean()
            note = '{}\nslope:  {:.2f}\nincpt: {:.2f}\nmeanx: {:.2f}\nin@mx: {:.2f}'.format('hierarchical'
                                ,beta.mean(),alpha.mean(),x.mean(),yfit_at_xmean.mean()-x.mean())
            
#             if quad:
#                 gamma = traces_hier['gamma'][burn_hier:,j]
#                 yfit = alpha[:, None] + beta[:, None] * xfit + gamma[:, None] * xfit ** 2
#                 note = '{}\ny={:.2f} + {:.2f}x + {:.2f}x^2'.format('individual',alpha.mean(),beta.mean(),gamma.mean())
            
            mu = yfit.mean(0)
            yerr_975 = np.percentile(yfit,97.5,axis=0)
            yerr_025 = np.percentile(yfit,2.5,axis=0)

            sp.plot(xfit, mu,linewidth=3, color=clrs['hier'][0], alpha=0.8)
            sp.fill_between(xfit, yerr_025, yerr_975, color=clrs['hier'][2], alpha=0.3)
            sp.annotate(note, xy=(0,1),xycoords='axes fraction',xytext=(100,-6),textcoords='offset points'
                ,color=clrs['hier'][1],weight='bold',size=12,ha='right',va='top')
        
    plt.show()