Package reflectometry :: Package reduction :: Module polcorplot

Source Code for Module reflectometry.reduction.polcorplot

  1  # This program is public domain 
  2  """ 
  3  Plot the data associated with the polarization efficiency correction. 
  4   
  5  This is a pair of plots locked together, one plot showing the intensity 
  6  scans for the individual cross-sections, and the estimated 2*beta, the 
  7  other showing the efficiencies of the front/back polarizers and flippers. 
  8  """ 
  9   
 10  import numpy 
 11  import wx 
 12  import matplotlib as mpl 
 13  mpl.interactive(False) 
 14  mpl.use('WXAgg') 
 15  import matplotlib.pyplot 
 16  #from canvas import FigureCanvas as Canvas 
 17  from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas 
 18   
 19   
20 -class Plotter(wx.Panel):
21 - def __init__(self, parent, id = -1, dpi = None, **kwargs):
22 wx.Panel.__init__(self, parent, id=id, **kwargs) 23 self.figure = mpl.figure.Figure(dpi=dpi, figsize=(2,2)) 24 self.canvas = Canvas(self, -1, self.figure) 25 sizer = wx.BoxSizer(wx.VERTICAL) 26 sizer.Add(self.canvas,1,wx.EXPAND) 27 self.SetSizer(sizer) 28 29 self.intensity = self.figure.add_subplot(211) 30 mpl.pyplot.setp(self.intensity.get_xticklabels(), visible=False) 31 self.efficiency = self.figure.add_subplot(212, sharex=self.intensity) 32 33 self.raw = None 34 self.smooth = None
35
36 - def update_intensity(self):
37 ax = self.intensity 38 ax.clear() 39 ax.set_ylabel("Counts") 40 if self.raw is not None: 41 eff = self.raw 42 for data,label,color in zip([eff.beam.pp, eff.beam.pm, 43 eff.beam.mp, eff.beam.mm], 44 ['$I++$','$I+-$','$I-+$','$I--$'], 45 ['r','g','b','m']): 46 self.intensity.errorbar(data.x,data.v,yerr=data.dv, 47 fmt='x'+color,label=label) 48 self.intensity.plot(eff.beam.pp.x,eff.Ic,'xc',label='$I_c$') 49 if self.smooth is not None: 50 eff = self.smooth 51 for data,color in zip([eff.beam.pp, eff.beam.pm, 52 eff.beam.mp, eff.beam.mm], 53 ['r','g','b','m']): 54 self.intensity.errorbar(data.x,data.v,data.dv,fmt='-'+color) 55 self.intensity.semilogy(eff.beam.pp.x,eff.Ic,'-c') 56 ax.legend() 57 ax.set_yscale('log') 58 self.canvas.draw_idle()
59
60 - def update_efficiency(self):
61 ax = self.efficiency 62 ax.clear() 63 ax.set_ylabel("Efficiency (%)") 64 # Draw rectangle above 1.0 showing invalid efficiencies. 65 if self.raw is not None: 66 eff = self.raw 67 ax.set_xlabel("%s (%s)"%(eff.beam.xlabel, eff.beam.xunits)) 68 for y,lab,color in zip([eff.fp, eff.ff, eff.rf, eff.rp], 69 ['F pol','F flip','R pol','R flip'], 70 ['r','g','b','m']): 71 self.efficiency.plot(eff.beam.pp.x, 100*y,'x'+color,label=lab) 72 if self.smooth is not None: 73 eff = self.smooth 74 ax.set_xlabel("%s (%s)"%(eff.beam.xlabel, eff.beam.xunits)) 75 for y,color in zip([eff.fp, eff.ff, eff.rf, eff.rp], 76 ['r','g','b','m']): 77 self.efficiency.plot(eff.beam.pp.x, 100*y,'-'+color) 78 ax.set_ylim(ymax=105) 79 ax.axhspan(100,1000,facecolor='0.8',alpha=0.5) 80 ax.legend() 81 self.canvas.draw_idle()
82
83 - def plot(self, raw=None, smooth=None):
84 self.raw = raw 85 self.smooth = smooth 86 self.update_efficiency() 87 self.update_intensity()
88
89 -def demo():
90 from examples import e3a12 as data 91 from polcor import PolarizationEfficiency 92 from smooth import Smooth 93 94 # Get a slit scan and compute the raw efficiency 95 beam = data.slits() 96 eff = PolarizationEfficiency(beam=beam, FRbalance=0.6, clip=False) 97 # Smooth it and comput the smoothed efficiency 98 beam.apply(Smooth(degree=2,span=13)) 99 effsmooth = PolarizationEfficiency(beam=beam, FRbalance=0.6, clip=True) 100 101 # Make a frame to show it 102 app = wx.PySimpleApp() 103 frame = wx.Frame(None,-1,'Plottables') 104 plotter = Plotter(frame) 105 frame.Show() 106 107 # render the graph to the pylab plotter 108 plotter.plot(eff, effsmooth) 109 110 app.MainLoop() 111 pass
112 113 if __name__ == "__main__": demo() 114