CMS 3D CMS Logo

Public Member Functions | Public Attributes | Private Attributes

matplotRender::matplotRender Class Reference

List of all members.

Public Member Functions

def __init__
def drawHTTPstring
def drawInteractive
def drawPNG
def plotInst_RunLS
def plotPeakPerday_Time
def plotPerdayX_Time
def plotSumX_Fill
def plotSumX_Run
def plotSumX_Time

Public Attributes

 colormap

Private Attributes

 __canvas
 __fig

Detailed Description

Definition at line 94 of file matplotRender.py.


Constructor & Destructor Documentation

def matplotRender::matplotRender::__init__ (   self,
  fig 
)

Definition at line 95 of file matplotRender.py.

00096                           :
00097         self.__fig=fig
00098         self.__canvas=''
00099         self.colormap={}
00100         self.colormap['Delivered']='r'
00101         self.colormap['Recorded']='b'
00102         self.colormap['Effective']='g'
00103         self.colormap['Max Inst']='r'


Member Function Documentation

def matplotRender::matplotRender::drawHTTPstring (   self)

Definition at line 796 of file matplotRender.py.

00797                             :
00798         self.__canvas=CanvasBackend(self.__fig)    
00799         cherrypy.response.headers['Content-Type']='image/png'
00800         buf=StringIO()
00801         self.__canvas.print_png(buf)
00802         return buf.getvalue()
    
def matplotRender::matplotRender::drawInteractive (   self)

Definition at line 807 of file matplotRender.py.

00808                              :
00809         if batchonly:
00810             print 'interactive mode is not available for your setup, exit'
00811             sys.exit()
00812         aw=lumiQTWidget.ApplicationWindow(fig=self.__fig)
00813         aw.show()
00814         aw.destroy()
        
def matplotRender::matplotRender::drawPNG (   self,
  filename 
)

Definition at line 803 of file matplotRender.py.

00804                               :
00805         self.__canvas=CanvasBackend(self.__fig)    
00806         self.__canvas.print_figure(filename)
    
def matplotRender::matplotRender::plotInst_RunLS (   self,
  rawxdata,
  rawydata,
  nticks = 6,
  textoutput = None 
)
Input: rawxdata [run,fill,starttime,stoptime,totalls,ncmsls]
       rawydata {label:[lumi]}

Definition at line 719 of file matplotRender.py.

00720                                                                        :
00721         '''
00722         Input: rawxdata [run,fill,starttime,stoptime,totalls,ncmsls]
00723                rawydata {label:[lumi]}
00724         '''
00725         lslength=23.357
00726         lut=lumiTime.lumiTime()
00727         runnum=rawxdata[0]
00728         fill=rawxdata[1]
00729         starttime=lut.DatetimeToStr(rawxdata[2],customfm='%m/%d/%y %H:%M:%S')
00730         stoptime=lut.DatetimeToStr(rawxdata[3],customfm='%m/%d/%y %H:%M:%S')
00731         totalls=rawxdata[-2]
00732         ncmsls=rawxdata[-1]
00733         peakinst=max(rawydata['Delivered'])/lslength
00734         totaldelivered=sum(rawydata['Delivered'])
00735         totalrecorded=sum(rawydata['Recorded'])
00736         xpoints=range(1,totalls+1)        
00737         #print len(xpoints)
00738         ypoints={}
00739         ymax={}
00740         for ylabel,yvalue in rawydata.items():
00741             ypoints[ylabel]=[y/lslength for y in yvalue]
00742             ymax[ylabel]=max(yvalue)/lslength
00743         left=0.15
00744         width=0.7
00745         bottom=0.1
00746         height=0.65
00747         bottom_h=bottom+height
00748         rect_scatter=[left,bottom,width,height]
00749         rect_table=[left,bottom_h,width,0.25]
00750         
00751         nullfmt=matplotlib.ticker.NullFormatter()
00752         nullloc=matplotlib.ticker.NullLocator()
00753         axtab=self.__fig.add_axes(rect_table,frameon=False)
00754         axtab.set_axis_off()
00755         axtab.xaxis.set_major_formatter(nullfmt)
00756         axtab.yaxis.set_major_formatter(nullfmt)
00757         axtab.xaxis.set_major_locator(nullloc)
00758         axtab.yaxis.set_major_locator(nullloc)
00759 
00760         ax=self.__fig.add_axes(rect_scatter)
00761         
00762         majorLoc=matplotlib.ticker.LinearLocator(numticks=nticks)
00763         minorLoc=matplotlib.ticker.LinearLocator(numticks=nticks*4)
00764         ax.set_xlabel(r'LS',position=(0.96,0))
00765         ax.set_ylabel(r'L $\mu$b$^{-1}$s$^{-1}$',position=(0,0.9))
00766         ax.xaxis.set_major_locator(majorLoc)
00767         ax.xaxis.set_minor_locator(minorLoc)
00768         ax.set_xbound(lower=xpoints[0],upper=xpoints[-1])
00769         xticklabels=ax.get_xticklabels()
00770         for tx in xticklabels:
00771             tx.set_horizontalalignment('right')
00772         ax.grid(True)
00773         keylist=ypoints.keys()
00774         keylist.sort()
00775         legendlist=[]
00776 
00777         for ylabel in keylist:
00778             cl='k'
00779             if self.colormap.has_key(ylabel):
00780                 cl=self.colormap[ylabel]
00781             ax.plot(xpoints,ypoints[ylabel],'.',label=ylabel,color=cl)
00782             legendlist.append(ylabel)      
00783         #ax.axhline(0,color='green',linewidth=0.2)
00784         ax.axvline(xpoints[ncmsls-1],color='green',linewidth=0.2)
00785         (unitstring,denomitor)=guessLumiUnit(totaldelivered)
00786         colLabels=('run','fill','max inst(/$\mu$b/s)','delivered('+unitstring+')','recorded('+unitstring+')')
00787         cellText=[[str(runnum),str(fill),'%.3f'%(peakinst),'%.3f'%(totaldelivered/denomitor),'%.3f'%(totalrecorded/denomitor)]]
00788        
00789         sumtable=axtab.table(cellText=cellText,colLabels=colLabels,colWidths=[0.12,0.1,0.27,0.27,0.27],cellLoc='center',loc='center')
00790         trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes)        
00791         axtab.add_table(sumtable)
00792         
00793         ax.text(xpoints[0],1.02,starttime[0:17],transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))   
00794         ax.text(xpoints[ncmsls-1],1.02,stoptime[0:17],transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))        
00795         ax.legend(tuple(legendlist),loc='upper right',numpoints=1)

def matplotRender::matplotRender::plotPeakPerday_Time (   self,
  rawdata = {},
  resultlines = [],
  minTime = None,
  maxTime = None,
  nticks = 6,
  withannotation = False,
  yscale = 'linear',
  referenceLabel = 'Delivered',
  labels = ['Delivered'],
  textoutput = None 
)
THIS PLOT IS DELIVERED ONLY
Input:
rawdata={'Delivered':[(day,run,ls,instlumi)]}
resultlines=[[day,run,ls,maxinstlum],[]]
minTime (python DateTime) : min *begin* time to draw: format %m/%d/%y %H:%M:%S
maxTime (python DateTime): max *begin* time to draw %m/%d/%y %H:%M:%S
withannotation: wheather the boundary points should be annotated
referenceLabel: the one variable that decides the total unit and the plot x-axis range
labels: labels of the variables to plot

Definition at line 575 of file matplotRender.py.

00575                                          {},resultlines=[],minTime=None,maxTime=None,nticks=6,withannotation=False,yscale='linear',referenceLabel='Delivered',labels=['Delivered'],textoutput=None):
00576         '''
00577         THIS PLOT IS DELIVERED ONLY
00578         Input:
00579         rawdata={'Delivered':[(day,run,ls,instlumi)]}
00580         resultlines=[[day,run,ls,maxinstlum],[]]
00581         minTime (python DateTime) : min *begin* time to draw: format %m/%d/%y %H:%M:%S
00582         maxTime (python DateTime): max *begin* time to draw %m/%d/%y %H:%M:%S
00583         withannotation: wheather the boundary points should be annotated
00584         referenceLabel: the one variable that decides the total unit and the plot x-axis range
00585         labels: labels of the variables to plot
00586         '''
00587         xpoints=[]
00588         ypoints={}
00589         legendlist=[]
00590         maxinfo=''
00591         ymax={}
00592         lut=lumiTime.lumiTime()
00593         if not minTime:
00594             minTime='03/01/10 00:00:00'
00595         minTime=lut.StrToDatetime(minTime,customfm='%m/%d/%y %H:%M:%S')
00596         if not maxTime:
00597             maxTime=datetime.datetime.utcnow()
00598         else:
00599             maxTime=lut.StrToDatetime(maxTime,customfm='%m/%d/%y %H:%M:%S')
00600         for r in resultlines:
00601             day=int(r[0])
00602             runnumber=int(r[1])
00603             lsnum=int(r[2].split('.')[0])
00604             if rawdata and day in [int(t[0]) for t in rawdata[referenceLabel]]:continue
00605             if day < minTime.date().toordinal():continue
00606             if day > maxTime.date().toordinal():continue
00607             for i,lab in enumerate(labels):
00608                 v=float(r[-(len(labels)-i)-1])
00609                 rawdata.setdefault(lab,[]).append((day,runnumber,lsnum,v))
00610         if not rawdata:
00611             print '[WARNING]: no data, do nothing'
00612             return
00613         maxlum=max([t[3] for t in rawdata[referenceLabel]])
00614         minlum=min([t[3] for t in rawdata[referenceLabel] if t[3]>0]) #used only for log scale, fin the non-zero bottom
00615         (unitstring,denomitor)=guessInstLumiUnit(maxlum)
00616         
00617         csvreport=None
00618         rows=[]
00619         flat=[]
00620         MinDay=minTime.date().toordinal()
00621         MaxDay=maxTime.date().toordinal()
00622         fulldays=range(MinDay,MaxDay+1)
00623         for label in rawdata.keys():
00624             yvalues=rawdata[label]
00625             yvalues.sort()#sort by day
00626             alldays=[t[0] for t in yvalues]
00627             alldates=[str(datetime.date.fromordinal(t)) for t in alldays]
00628             ypoints[label]=[]
00629             lumivals=[t[3] for t in yvalues]
00630             flat.append(lumivals)
00631             for d in fulldays:
00632                 if not d in alldays:
00633                     ypoints[label].append(0.0)
00634                 else:
00635                     thisdaylumi=[t[3] for t in yvalues if t[0]==d][0]
00636                     if yscale=='log':
00637                         if thisdaylumi<minlum:
00638                             thisdaylumi=minlum/denomitor
00639                         else:
00640                             thisdaylumi=thisdaylumi/denomitor
00641                     else:
00642                         thisdaylumi=thisdaylumi/denomitor
00643                     ypoints[label].append(thisdaylumi)
00644             ymax[label]=max(lumivals)/denomitor
00645             'ymax ',max(lumivals)
00646         xpoints=fulldays
00647         if textoutput:
00648             csvreport=csvReporter.csvReporter(textoutput)
00649             head=['#day','run','lsnum','maxinstlumi','date']
00650             csvreport.writeRow(head)
00651             flat.insert(0,alldays)
00652             allruns=[ t[1] for t in rawdata[referenceLabel]]
00653             allls=[ t[2] for t in rawdata[referenceLabel]]
00654             flat.insert(1,allruns)
00655             flat.insert(2,allls)
00656             flat.append(alldates)
00657             rows=zip(*flat)
00658             csvreport.writeRows([list(t) for t in rows])
00659             
00660         yearStrMin=minTime.strftime('%Y')
00661         yearStrMax=maxTime.strftime('%Y')
00662         if yearStrMin==yearStrMax:
00663             dateFmt=matplotlib.dates.DateFormatter('%d/%m')
00664         else:
00665             dateFmt=matplotlib.dates.DateFormatter('%d/%m/%y')
00666         ax=self.__fig.add_subplot(111)
00667         if yscale=='linear':
00668             ax.set_yscale('linear')
00669         elif yscale=='log':
00670             ax.set_yscale('log')
00671         else:
00672             raise 'unsupported yscale ',yscale
00673         majorLoc=matplotlib.ticker.LinearLocator(numticks=nticks)
00674         minorLoc=matplotlib.ticker.LinearLocator(numticks=nticks*4)
00675         ax.xaxis.set_major_formatter(dateFmt)
00676         ax.set_xlabel(r'Date',position=(0.84,0))
00677         ax.set_ylabel(r'L '+unitstring,position=(0,0.9))
00678         ax.xaxis.set_major_locator(majorLoc)
00679         ax.xaxis.set_minor_locator(minorLoc)
00680         xticklabels=ax.get_xticklabels()
00681         for tx in xticklabels:
00682             tx.set_horizontalalignment('right')
00683         ax.grid(True)
00684         cl=self.colormap['Max Inst']
00685         textsummaryhead=['#TotalRunningDays']
00686         textsummaryline=['#'+str(len(alldays))]
00687         for ylabel in labels:
00688             cl='k'
00689             if self.colormap.has_key(ylabel):
00690                 cl=self.colormap[ylabel]
00691             ax.plot(xpoints,ypoints[ylabel],label='Max Inst',color=cl,drawstyle='steps')
00692             legendlist.append('Max Inst %.3f'%(ymax[ylabel])+' '+unitstring)
00693             textsummaryhead.append('Max Inst'+ylabel)
00694             textsummaryline.append('%.3f'%(ymax[ylabel])+' '+unitstring)
00695         if textoutput:
00696             csvreport.writeRow(textsummaryhead)
00697             csvreport.writeRow(textsummaryline)
00698         ax.legend(tuple(legendlist),loc='upper left')
00699         ax.set_xbound(lower=matplotlib.dates.date2num(minTime),upper=matplotlib.dates.date2num(maxTime))
00700         if withannotation:
00701            #annotations
00702            trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes)
00703            ax.text(xpoints[0],1.025,beginfo,transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
00704            ax.text(xpoints[-1],1.025,endinfo,transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
00705            ax.annotate(maxinfo,xy=(xmax,ymax),xycoords='data',xytext=(0,13),textcoords='offset points',arrowprops=dict(facecolor='green',shrink=0.05),size='x-small',horizontalalignment='center',color='green',bbox=dict(facecolor='white'))
00706            
00707         firstday=datetime.date.fromordinal(rawdata[referenceLabel][0][0])
00708         lastday=datetime.date.fromordinal(rawdata[referenceLabel][-1][0])
00709         firstdayStr=firstday.strftime('%Y %b %d')
00710         lastdayStr=lastday.strftime('%Y %b %d')
00711         ax.set_title('CMS Peak Luminosity/Day ('+firstdayStr+' - '+lastdayStr+')',size='small')
00712 
00713         #ax.autoscale(tight=True)
00714         ax.autoscale_view(tight=True,scalex=True,scaley=False)        
00715         #ax.set_xmargin(0.015)
00716         self.__fig.autofmt_xdate(bottom=0.18,rotation=15,ha='right')
00717         self.__fig.subplots_adjust(bottom=0.2,left=0.15)
00718 
def matplotRender::matplotRender::plotPerdayX_Time (   self,
  rawdata = {},
  resultlines = [],
  minTime = None,
  maxTime = None,
  nticks = 6,
  yscale = 'linear',
  withannotation = False,
  referenceLabel = 'Delivered',
  labels = ['Delivered',
  Recorded,
  textoutput = None 
)
Input:
rawdata={'Delivered':[(day,begrun:ls,endrun:ls,lumi)],'Recorded':[(dayofyear,begrun:ls,endrun:ls,lumi)]}
resultlines=[[day,begrun:ls,endrun:ls,deliveredperday,recordedperday],[]]
minTime (python DateTime) : min *begin* time to draw: format %m/%d/%y %H:%M:%S
maxTime (python DateTime): max *begin* time to draw %m/%d/%y %H:%M:%S
withannotation: wheather the boundary points should be annotated
referenceLabel: the one variable that decides the total unit and the plot x-axis range
labels: labels of the variables to plot

Definition at line 432 of file matplotRender.py.

00432                                       {},resultlines=[],minTime=None,maxTime=None,nticks=6,yscale='linear',withannotation=False,referenceLabel='Delivered',labels=['Delivered','Recorded'],textoutput=None):
00433         '''
00434         Input:
00435         rawdata={'Delivered':[(day,begrun:ls,endrun:ls,lumi)],'Recorded':[(dayofyear,begrun:ls,endrun:ls,lumi)]}
00436         resultlines=[[day,begrun:ls,endrun:ls,deliveredperday,recordedperday],[]]
00437         minTime (python DateTime) : min *begin* time to draw: format %m/%d/%y %H:%M:%S
00438         maxTime (python DateTime): max *begin* time to draw %m/%d/%y %H:%M:%S
00439         withannotation: wheather the boundary points should be annotated
00440         referenceLabel: the one variable that decides the total unit and the plot x-axis range
00441         labels: labels of the variables to plot
00442         '''
00443         xpoints=[]
00444         ypoints={}
00445         ymax={}
00446         lut=lumiTime.lumiTime()
00447         if not minTime:
00448             minTime='03/01/10 00:00:00'
00449         minTime=lut.StrToDatetime(minTime,customfm='%m/%d/%y %H:%M:%S')
00450         if not maxTime:
00451             maxTime=datetime.datetime.utcnow()
00452         else:
00453             maxTime=lut.StrToDatetime(maxTime,customfm='%m/%d/%y %H:%M:%S')
00454         for r in resultlines:
00455             day=int(r[0])
00456             begrunls=r[1]
00457             endrunls=r[2]
00458             #[begrun,begls]=[int(s) for s in r[1].split(':')]
00459             if rawdata and day in [t[0] for t in rawdata[referenceLabel]]:continue
00460             if day < minTime.date().toordinal():continue
00461             if day > maxTime.date().toordinal():continue
00462             for i,lab in enumerate(labels):
00463                 v=float(r[-(len(labels)-i)-1])
00464                 rawdata.setdefault(lab,[]).append((day,begrunls,endrunls,v))
00465         if not rawdata:
00466             print '[WARNING]: no data, do nothing'
00467             return
00468         maxlum=max([t[3] for t in rawdata[referenceLabel]])
00469         minlum=min([t[3] for t in rawdata[referenceLabel] if t[3]>0]) #used only for log scale, fin the non-zero bottom
00470         (unitstring,denomitor)=guessLumiUnit(maxlum)
00471         csvreport=None
00472         rows=[]
00473         flat=[]
00474         MinDay=minTime.date().toordinal()
00475         MaxDay=maxTime.date().toordinal()
00476         fulldays=range(MinDay,MaxDay+1)
00477         allstarts=[]
00478         allstops=[]
00479         for label,yvalues in rawdata.items():
00480             yvalues.sort()
00481             flat.append([t[3] for t in yvalues])
00482             alldays=[t[0] for t in yvalues]
00483             alldates=[str(datetime.date.fromordinal(t)) for t in alldays]
00484             ypoints[label]=[]
00485             lumivals=[t[3] for t in yvalues]
00486             for d in fulldays:
00487                 if not d in alldays:
00488                     ypoints[label].append(0.0)
00489                 else:
00490                     thisdaylumi=[t[3] for t in yvalues if t[0]==d][0]
00491                     if yscale=='log':
00492                         if thisdaylumi<minlum:
00493                             thisdaylumi=minlum/denomitor
00494                         else:
00495                             thisdaylumi=thisdaylumi/denomitor
00496                     else:
00497                          thisdaylumi=thisdaylumi/denomitor
00498                     ypoints[label].append(thisdaylumi)
00499                 ymax[label]=max(lumivals)/denomitor
00500         xpoints=fulldays
00501         if textoutput:
00502             csvreport=csvReporter.csvReporter(textoutput)
00503             head=['#day','begrunls','endrunls','delivered','recorded','date']
00504             csvreport.writeRow(head)
00505             flat.insert(0,alldays)
00506             allstarts=[ t[1] for t in rawdata[referenceLabel]]
00507             allstops=[ t[2] for t in rawdata[referenceLabel]]
00508             #print 'allstarts ',allstarts
00509             flat.insert(1,allstarts)
00510             flat.insert(2,allstops)
00511             flat.append(alldates)
00512             rows=zip(*flat)
00513             csvreport.writeRows([list(t) for t in rows])
00514         yearStrMin=minTime.strftime('%Y')
00515         yearStrMax=maxTime.strftime('%Y')
00516         if yearStrMin==yearStrMax:
00517             dateFmt=matplotlib.dates.DateFormatter('%d/%m')
00518         else:
00519             dateFmt=matplotlib.dates.DateFormatter('%d/%m/%y')
00520         ax=self.__fig.add_subplot(111)     
00521         if yscale=='linear':
00522             ax.set_yscale('linear')
00523         elif yscale=='log':
00524             ax.set_yscale('log')
00525         else:
00526             raise 'unsupported yscale ',yscale        
00527         majorLoc=matplotlib.ticker.LinearLocator(numticks=nticks)
00528         minorLoc=matplotlib.ticker.LinearLocator(numticks=nticks*4)
00529         ax.xaxis.set_major_formatter(dateFmt)
00530         ax.set_xlabel(r'Date',position=(0.84,0))
00531         ax.xaxis.set_major_locator(majorLoc)
00532         ax.xaxis.set_minor_locator(minorLoc)
00533         xticklabels=ax.get_xticklabels()
00534         for tx in xticklabels:
00535             tx.set_horizontalalignment('right')
00536         ax.grid(True)
00537         legendlist=[]
00538         ax.set_ylabel(r'L '+unitstring,position=(0,0.9))
00539         textsummaryhead=['#TotalRunningDays']
00540         textsummaryline=['#'+str(len(alldays))]
00541         for ylabel in labels:
00542             cl='k'
00543             if self.colormap.has_key(ylabel):
00544                 cl=self.colormap[ylabel]
00545             ax.plot(xpoints,ypoints[ylabel],label=ylabel,color=cl,drawstyle='steps')
00546             legendlist.append(ylabel+' Max '+'%.3f'%(ymax[ylabel])+' '+unitstring)
00547             textsummaryhead.append('Max'+ylabel)
00548             textsummaryline.append('%.3f'%(ymax[ylabel])+' '+unitstring)
00549         if textoutput:
00550             csvreport.writeRow(textsummaryhead)
00551             csvreport.writeRow(textsummaryline)
00552         ax.legend(tuple(legendlist),loc='upper left')
00553         ax.set_xbound(lower=matplotlib.dates.date2num(minTime),upper=matplotlib.dates.date2num(maxTime))
00554         #if withannotation:
00555         #        begtime=boundaryInfo[0][0]
00556         #        beginfo=boundaryInfo[0][1]
00557         #        endtime=boundaryInfo[1][0]
00558         #        endinfo=boundaryInfo[1][1]
00559         #        #annotations
00560         #        trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes)
00561         #        ax.text(matplotlib.dates.date2num(begtime),1.025,beginfo,transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))        
00562         #        ax.text(matplotlib.dates.date2num(endtime),1.025,endinfo,transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
00563         
00564         firstday=datetime.date.fromordinal(rawdata[referenceLabel][0][0])
00565         lastday=datetime.date.fromordinal(rawdata[referenceLabel][-1][0])
00566         firstdayStr=firstday.strftime('%Y %b %d')
00567         lastdayStr=lastday.strftime('%Y %b %d')
00568         ax.set_title('CMS Integrated Luminosity/Day ('+firstdayStr+' - '+lastdayStr+')',size='small')
00569         #ax.autoscale(tight=True)
00570         ax.autoscale_view(tight=True,scalex=True,scaley=False)
00571         #ax.set_xmargin(0.015)
00572         self.__fig.autofmt_xdate(bottom=0.18,rotation=15,ha='right')
00573         self.__fig.subplots_adjust(bottom=0.2,left=0.15)
00574 
def matplotRender::matplotRender::plotSumX_Fill (   self,
  rawdata = {},
  resultlines = [],
  minFill = None,
  maxFill = None,
  nticks = 6,
  yscale = 'linear',
  withannotation = False,
  referenceLabel = 'Delivered',
  labels = ['Delivered',
  Recorded,
  textoutput = None 
)
input:
rawdata = {'Delivered':[(fill,runnumber,lumiperrun)],'Recorded':[(fill,runnumber,lumiperrun)]}
resultlines = [[fillnumber,runnumber,dellumiperrun,reclumiperrun],[fillnumber,runnumber,dellumiperrun,reclumiperrun],]
minFill : min fill to draw
maxFill : max fill to draw
yscale: linear,log or both
withannotation: wheather the boundary points should be annotated
textoutput: text output file name. 

Definition at line 203 of file matplotRender.py.

00203                                    {},resultlines=[],minFill=None,maxFill=None,nticks=6,yscale='linear',withannotation=False,referenceLabel='Delivered',labels=['Delivered','Recorded'],textoutput=None):
00204         '''
00205         input:
00206         rawdata = {'Delivered':[(fill,runnumber,lumiperrun)],'Recorded':[(fill,runnumber,lumiperrun)]}
00207         resultlines = [[fillnumber,runnumber,dellumiperrun,reclumiperrun],[fillnumber,runnumber,dellumiperrun,reclumiperrun],]
00208         minFill : min fill to draw
00209         maxFill : max fill to draw
00210         yscale: linear,log or both
00211         withannotation: wheather the boundary points should be annotated
00212         textoutput: text output file name. 
00213         '''
00214         ytotal={}
00215         ypoints={}
00216         for r in resultlines: #parse old text data
00217             fillnum=int(r[0])
00218             runnum=int(r[1])
00219             if rawdata and (fillnum,runnum) in [(t[0],t[1]) for t in rawdata[referenceLabel]]:continue
00220             if minFill and fillnum<minFill:continue
00221             if maxFill and fillnum>maxFill:continue
00222             for i,lab in enumerate(labels) :
00223                 v=float(r[-(len(labels)-i)])#the values to plot are always the last n fields
00224                 rawdata.setdefault(lab,[]).append((fillnum,runnum,v))
00225         #print 'fillrunDict ',fillrunDict
00226         if not rawdata:
00227             print '[WARNING]: no data, do nothing'
00228             return
00229         tot=sum([t[2] for t in rawdata[referenceLabel]])
00230         beginfo=''
00231         endinfo=''
00232         (unitstring,denomitor)=guessLumiUnit(tot)
00233         csvreport=None
00234         rows=[]
00235         flat=[]
00236         for label,yvalues in rawdata.items():
00237             yvalues.sort()
00238             flat.append([t[2] for t in yvalues])
00239             ypoints[label]=[]
00240             ytotal[label]=0.0
00241             lumivals=[t[2] for t in yvalues]
00242             for i,val in enumerate(lumivals):
00243                 ypoints[label].append(sum(lumivals[0:i+1])/denomitor)
00244             ytotal[label]=sum(lumivals)/denomitor
00245         xpoints=[t[0] for t in rawdata[referenceLabel]]#after sort
00246         ax=self.__fig.add_subplot(111)
00247         ax.set_xlabel(r'LHC Fill Number',position=(0.84,0))
00248         ax.set_ylabel(r'L '+unitstring,position=(0,0.9))
00249         ax.set_xbound(lower=xpoints[0],upper=xpoints[-1])
00250         if yscale=='linear':
00251             ax.set_yscale('linear')
00252         elif yscale=='log':
00253             ax.set_yscale('log')
00254         else:
00255             raise 'unsupported yscale ',yscale
00256         xticklabels=ax.get_xticklabels()
00257         majorLocator=matplotlib.ticker.LinearLocator( nticks )
00258         majorFormatter=matplotlib.ticker.FormatStrFormatter('%d')
00259         #minorLocator=matplotlib.ticker.MultipleLocator(sampleinterval)
00260         ax.xaxis.set_major_locator(majorLocator)
00261         ax.xaxis.set_major_formatter(majorFormatter)
00262         #ax.xaxis.set_minor_locator(minorLocator)
00263         ax.grid(True)
00264         keylist=ypoints.keys()
00265         keylist.sort()
00266         keylist.insert(0,keylist.pop(keylist.index(referenceLabel)))#move refereceLabel to front from now on
00267         legendlist=[]
00268         head=['#fill','run']        
00269         textsummaryhead=['#TotalFill']
00270         textsummaryline=['#'+str(len(xpoints))]
00271         for ylabel in keylist:
00272             cl='k'
00273             if self.colormap.has_key(ylabel):
00274                 cl=self.colormap[ylabel]
00275             ax.plot(xpoints,ypoints[ylabel],label=ylabel,color=cl,drawstyle='steps')
00276             legendlist.append(ylabel+' '+'%.3f'%(ytotal[ylabel])+' '+unitstring)
00277             textsummaryhead.append('Total'+ylabel)
00278             textsummaryline.append('%.3f'%(ytotal[ylabel])+' '+unitstring)
00279             head.append(ylabel)
00280         if textoutput:
00281             csvreport=csvReporter.csvReporter(textoutput)
00282             allfills=[int(t[0]) for t in rawdata[referenceLabel]]
00283             allruns=[int(t[1]) for t in rawdata[referenceLabel]]
00284             flat.insert(0,allfills)
00285             flat.insert(1,allruns)
00286             rows=zip(*flat)
00287             csvreport.writeRow(head)
00288             csvreport.writeRows([list(t) for t in rows])
00289             csvreport.writeRow(textsummaryhead)
00290             csvreport.writeRow(textsummaryline)
00291         #font=FontProperties(size='medium',weight='demibold')
00292         #annotations
00293         if withannotation:
00294             trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes)
00295             ax.text(xpoints[0],1.025,beginfo,transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
00296             ax.text(xpoints[-1],1.025,endinfo,transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
00297         #legend
00298         ax.legend(tuple(legendlist),loc='upper left')
00299         #adjust
00300         self.__fig.subplots_adjust(bottom=0.1,left=0.1)
00301         
def matplotRender::matplotRender::plotSumX_Run (   self,
  rawdata = {},
  resultlines = [],
  minRun = None,
  maxRun = None,
  nticks = 6,
  yscale = 'linear',
  withannotation = False,
  referenceLabel = 'Delivered',
  labels = ['Delivered',
  Recorded,
  textoutput = None 
)
input:
  rawdata = {'Delivered':[(runnumber,lumiperrun),..],'Recorded':[(runnumber,lumiperrun),..]}
  resultlines = [[runnumber,dellumiperrun,reclumiperrun],[runnumber,dellumiperrun,reclumiperrun],]
  minRun : minimal runnumber required
  maxRun : max runnumber required
  yscale: linear,log or both
  withannotation: wheather the boundary points should be annotated
  referenceLabel: the one variable that decides the total unit and the plot x-axis range
  labels: labels of the variables to plot
  textoutput: text output file name. 

Definition at line 104 of file matplotRender.py.

00104                                   {},resultlines=[],minRun=None,maxRun=None,nticks=6,yscale='linear',withannotation=False,referenceLabel='Delivered',labels=['Delivered','Recorded'],textoutput=None):
00105         '''
00106         input:
00107           rawdata = {'Delivered':[(runnumber,lumiperrun),..],'Recorded':[(runnumber,lumiperrun),..]}
00108           resultlines = [[runnumber,dellumiperrun,reclumiperrun],[runnumber,dellumiperrun,reclumiperrun],]
00109           minRun : minimal runnumber required
00110           maxRun : max runnumber required
00111           yscale: linear,log or both
00112           withannotation: wheather the boundary points should be annotated
00113           referenceLabel: the one variable that decides the total unit and the plot x-axis range
00114           labels: labels of the variables to plot
00115           textoutput: text output file name. 
00116         '''
00117         ypoints={}
00118         ytotal={}
00119         for r in resultlines:#parse old text data
00120             runnumber=int(r[0])
00121             if rawdata and runnumber in [t[0] for t in rawdata[referenceLabel]]:continue#use text input only if not in selected data
00122             if minRun and runnumber<minRun: continue
00123             if maxRun and runnumber>maxRun: continue
00124             for i,lab in enumerate(labels) :
00125                 v=float(r[-(len(labels)-i)-1])#the values to plot are always the last n fields
00126                 rawdata.setdefault(lab,[]).append((runnumber,v))
00127         if not rawdata:
00128             print '[WARNING]: no data to plot , exit'
00129             return
00130       
00131         tot=sum([t[1] for t in rawdata[referenceLabel]])
00132         (unitstring,denomitor)=guessLumiUnit(tot)
00133         csvreport=None
00134         rows=[]
00135         flat=[]
00136         for label,yvalues in rawdata.items():
00137             yvalues.sort()
00138             flat.append([t[1] for t in yvalues])
00139             ypoints[label]=[]
00140             ytotal[label]=0.0
00141             lumivals=[t[1] for t in yvalues]
00142             for i,val in enumerate(lumivals):
00143                 ypoints[label].append(sum(lumivals[0:i+1])/denomitor)#integrated lumi
00144             ytotal[label]=sum(lumivals)/denomitor
00145         xpoints=[t[0] for t in rawdata[referenceLabel]]
00146         ax=self.__fig.add_subplot(111)
00147         if yscale=='linear':
00148             ax.set_yscale('linear')
00149         elif yscale=='log':
00150             ax.set_yscale('log')
00151         else:
00152             raise 'unsupported yscale ',yscale
00153         ax.set_xlabel(r'Run',position=(0.95,0))
00154         ax.set_ylabel(r'L '+unitstring,position=(0,0.9))
00155         xticklabels=ax.get_xticklabels()
00156         for tx in xticklabels:
00157             tx.set_rotation(30)
00158         majorLocator=matplotlib.ticker.LinearLocator( nticks )
00159         majorFormatter=matplotlib.ticker.FormatStrFormatter('%d')
00160         minorLocator=matplotlib.ticker.LinearLocator(numticks=4*nticks)
00161         ax.xaxis.set_major_locator(majorLocator)
00162         ax.xaxis.set_major_formatter(majorFormatter)
00163         ax.xaxis.set_minor_locator(minorLocator)
00164         ax.set_xbound(lower=xpoints[0],upper=xpoints[-1])
00165         ax.grid(True)
00166         keylist=ypoints.keys()
00167         keylist.sort()
00168         keylist.insert(0,keylist.pop(keylist.index(referenceLabel)))#move refereceLabel to front from now on
00169         legendlist=[]
00170         head=['#Run']
00171         textsummaryhead=['#TotalRun']
00172         textsummaryline=['#'+str(len(xpoints))]
00173         for ylabel in keylist:
00174             cl='k'
00175             if self.colormap.has_key(ylabel):
00176                 cl=self.colormap[ylabel]
00177             ax.plot(xpoints,ypoints[ylabel],label=ylabel,color=cl,drawstyle='steps')
00178             legendlist.append(ylabel+' '+'%.3f'%(ytotal[ylabel])+' '+unitstring)
00179             textsummaryhead.append('Total'+ylabel)
00180             textsummaryline.append('%.3f'%(ytotal[ylabel])+' '+unitstring)
00181             head.append(ylabel)
00182         if textoutput:
00183             csvreport=csvReporter.csvReporter(textoutput)
00184             csvreport.writeRow(head)
00185             allruns=[int(t[0]) for t in rawdata[referenceLabel]]
00186             flat.insert(0,allruns)
00187             rows=zip(*flat)
00188             csvreport.writeRows([list(t) for t in rows])
00189             csvreport.writeRow(textsummaryhead)
00190             csvreport.writeRow(textsummaryline)
00191         #font=FontProperties(size='medium',weight='demibold')
00192         #legend
00193         ax.legend(tuple(legendlist),loc='upper left')
00194         #adjust
00195         self.__fig.subplots_adjust(bottom=0.18,left=0.1)
00196         #annotations
00197         if withannotation:
00198             trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes)
00199             ax.text(xpoints[0],1.025,str(xpoints[0]),transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
00200             ax.text(xpoints[-1],1.025,str(xpoints[-1]),transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
00201         
00202     
def matplotRender::matplotRender::plotSumX_Time (   self,
  rawdata = {},
  resultlines = [],
  minTime = None,
  maxTime = None,
  nticks = 6,
  yscale = 'linear',
  withannotation = False,
  referenceLabel = 'Delivered',
  labels = ['Delivered',
  Recorded,
  textoutput = None 
)
input:
rawdata = {'Delivered':[(runnumber,starttimestamp,stoptimestamp,lumiperrun)],'Recorded':[(runnumber,starttimestamp,stoptimestamp,lumiperrun)]}
resultlines = [[runnumber,starttimestampStr,stoptimestampStr,dellumiperrun,reclumiperrun],[runnumber,starttimestampStr,stoptimestampStr,dellumiperrun,reclumiperrun],]
minTime (python DateTime) : min *begin* time to draw: format %m/%d/%y %H:%M:%S
maxTime (python DateTime): max *begin* time to draw %m/%d/%y %H:%M:%S
yscale: linear,log or both
withannotation: wheather the boundary points should be annotated
referenceLabel: the one variable that decides the total unit and the plot x-axis range
labels: labels of the variables to plot

Definition at line 302 of file matplotRender.py.

00302                                    {},resultlines=[],minTime=None,maxTime=None,nticks=6,yscale='linear',withannotation=False,referenceLabel='Delivered',labels=['Delivered','Recorded'],textoutput=None):
00303         '''
00304         input:
00305         rawdata = {'Delivered':[(runnumber,starttimestamp,stoptimestamp,lumiperrun)],'Recorded':[(runnumber,starttimestamp,stoptimestamp,lumiperrun)]}
00306         resultlines = [[runnumber,starttimestampStr,stoptimestampStr,dellumiperrun,reclumiperrun],[runnumber,starttimestampStr,stoptimestampStr,dellumiperrun,reclumiperrun],]
00307         minTime (python DateTime) : min *begin* time to draw: format %m/%d/%y %H:%M:%S
00308         maxTime (python DateTime): max *begin* time to draw %m/%d/%y %H:%M:%S
00309         yscale: linear,log or both
00310         withannotation: wheather the boundary points should be annotated
00311         referenceLabel: the one variable that decides the total unit and the plot x-axis range
00312         labels: labels of the variables to plot
00313         '''
00314         xpoints=[]
00315         ypoints={}
00316         ytotal={}
00317         lut=lumiTime.lumiTime()
00318         if not minTime:
00319             minTime='03/01/10 00:00:00'
00320         minTime=lut.StrToDatetime(minTime,customfm='%m/%d/%y %H:%M:%S')
00321         if not maxTime:
00322             maxTime=datetime.datetime.utcnow()
00323         else:
00324             maxTime=lut.StrToDatetime(maxTime,customfm='%m/%d/%y %H:%M:%S')
00325         for r in resultlines:
00326             runnumber=int(r[0])
00327             starttimeStr=r[1].split('.')[0]
00328             starttime=lut.StrToDatetime(starttimeStr,customfm='%Y-%m-%d %H:%M:%S')
00329             stoptimeStr=r[2].split('.')[0]
00330             stoptime=lut.StrToDatetime(stoptimeStr,customfm='%Y-%m-%d %H:%M:%S')
00331             if rawdata and runnumber in [t[0] for t in rawdata[referenceLabel]]:continue
00332             if starttime<minTime:continue
00333             if starttime>maxTime:continue
00334                 
00335             for i,lab in enumerate(labels):
00336                 v=float(r[-(len(labels)-i)])
00337                 rawdata.setdefault(lab,[]).append((runnumber,starttime,stoptime,v))        
00338         if not rawdata:
00339             print '[WARNING]: no data, do nothing'
00340             return
00341         tot=sum([t[3] for t in rawdata[referenceLabel]])
00342         (unitstring,denomitor)=guessLumiUnit(tot)
00343         csvreport=None
00344         rows=[]
00345         flat=[]
00346         for label,yvalues in rawdata.items():
00347             yvalues.sort()
00348             flat.append([t[3] for t in yvalues])
00349             if label==referenceLabel:
00350                 minTime=yvalues[0][1]
00351                 maxTime=yvalues[-1][1]
00352             ypoints[label]=[]
00353             lumivals=[t[3] for t in yvalues]
00354             for i,val in enumerate(lumivals):
00355                 ypoints[label].append(sum(lumivals[0:i+1])/denomitor)
00356             ytotal[label]=sum(lumivals)/denomitor
00357         xpoints=[matplotlib.dates.date2num(t[1]) for t in rawdata[referenceLabel]]
00358         ax=self.__fig.add_subplot(111)
00359         ax.set_yscale(yscale)
00360         yearStrMin=minTime.strftime('%Y')
00361         yearStrMax=maxTime.strftime('%Y')
00362         if yearStrMin==yearStrMax:
00363             dateFmt=matplotlib.dates.DateFormatter('%d/%m')
00364         else:
00365             dateFmt=matplotlib.dates.DateFormatter('%d/%m/%y')
00366         majorLoc=matplotlib.ticker.LinearLocator(numticks=nticks)
00367         ax.xaxis.set_major_locator(majorLoc)
00368         minorLoc=matplotlib.ticker.LinearLocator(numticks=nticks*4)
00369         ax.xaxis.set_major_formatter(dateFmt)
00370         ax.set_xlabel(r'Date',position=(0.84,0))
00371         ax.set_ylabel(r'L '+unitstring,position=(0,0.9))
00372         ax.xaxis.set_minor_locator(minorLoc)
00373         ax.set_xbound(lower=xpoints[0],upper=xpoints[-1])
00374         xticklabels=ax.get_xticklabels()
00375         for tx in xticklabels:
00376             tx.set_horizontalalignment('left')
00377         ax.grid(True)
00378         keylist=ypoints.keys()
00379         keylist.sort()
00380         keylist.insert(0,keylist.pop(keylist.index(referenceLabel)))#move refereceLabel to front from now on
00381         legendlist=[]
00382         head=['#Run','StartTime','StopTime']
00383         textsummaryhead=['#TotalRun']
00384         textsummaryline=['#'+str(len(xpoints))]
00385         for ylabel in keylist:
00386             cl='k'
00387             if self.colormap.has_key(ylabel):
00388                 cl=self.colormap[ylabel]
00389             ax.plot(xpoints,ypoints[ylabel],label=ylabel,color=cl,drawstyle='steps')
00390             legendlist.append(ylabel+' '+'%.3f'%(ytotal[ylabel])+' '+unitstring)
00391             textsummaryhead.append('Total'+ylabel)
00392             textsummaryline.append('%.3f'%(ytotal[ylabel])+' '+unitstring)
00393             head.append(ylabel)
00394         if textoutput:
00395             csvreport=csvReporter.csvReporter(textoutput)
00396             csvreport.writeRow(head)
00397             allruns=[int(t[0]) for t in rawdata[referenceLabel]]
00398             allstarts=[ lut.DatetimeToStr(t[1],customfm='%Y-%m-%d %H:%M:%S') for t in rawdata[referenceLabel] ]
00399             allstops=[ lut.DatetimeToStr(t[2],customfm='%Y-%m-%d %H:%M:%S') for t in rawdata[referenceLabel] ]
00400             flat.insert(0,allruns)
00401             flat.insert(1,allstarts)
00402             flat.insert(2,allstops)
00403             rows=zip(*flat)
00404             csvreport.writeRows([list(t) for t in rows])
00405             csvreport.writeRow(textsummaryhead)
00406             csvreport.writeRow(textsummaryline)
00407         #annotations
00408         trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes)
00409         #print 'run boundary ',runs[0],runs[-1]
00410         #print 'xpoints boundary ',xpoints[0],xpoints[-1]
00411         #annotation
00412         if withannotation:
00413             runs=[t[0] for t in rawdata[referenceLabel]]
00414             ax.text(xpoints[0],1.025,str(runs[0]),transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))        
00415             ax.text(xpoints[-1],1.025,str(runs[-1]),transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
00416         
00417         if yearStrMin==yearStrMax:
00418             firsttimeStr=rawdata[referenceLabel][1][1].strftime('%b %d %H:%M') #time range(start) in the title is the first run beg time 
00419             lasttimeStr=rawdata[referenceLabel][-1][2].strftime('%b %d %H:%M') #time range(stop) in the tile is the last run stop time
00420             #firstimeStr=minTime.strftime('%b %d %H:%M')
00421             #lasttimeStr=maxTime.strftime('%b %d %H:%M')
00422             #ax.set_title('CMS Total Integrated Luminosity '+yearStrMin+' ('+firstimeStr+' - '+lasttimeStr+' UTC)',size='small',family='fantasy')
00423             ax.set_title('CMS Total Integrated Luminosity '+yearStrMin+' ('+firsttimeStr+' - '+lasttimeStr+' UTC)',size='small')
00424         else:
00425             #ax.set_title('CMS Total Integrated Luminosity '+yearStrMin+'-'+yearStrMax,size='small',family='fantasy')
00426             ax.set_title('CMS Total Integrated Luminosity '+yearStrMin+'-'+yearStrMax,size='small')
00427         ax.legend(tuple(legendlist),loc='upper left')
00428         ax.autoscale_view(tight=True,scalex=True,scaley=False)
00429         self.__fig.autofmt_xdate(bottom=0.18,rotation=15,ha='right')
00430         self.__fig.subplots_adjust(bottom=0.2,left=0.15)
00431         

Member Data Documentation

Definition at line 95 of file matplotRender.py.

Definition at line 95 of file matplotRender.py.

Definition at line 95 of file matplotRender.py.