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 |
Definition at line 64 of file matplotRender.py.
def matplotRender::matplotRender::__init__ | ( | self, | |
fig | |||
) |
Definition at line 65 of file matplotRender.py.
def matplotRender::matplotRender::drawHTTPstring | ( | self | ) |
Definition at line 762 of file matplotRender.py.
def matplotRender::matplotRender::drawInteractive | ( | self | ) |
Definition at line 773 of file matplotRender.py.
def matplotRender::matplotRender::drawPNG | ( | self, | |
filename | |||
) |
Definition at line 769 of file matplotRender.py.
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 685 of file matplotRender.py.
00686 : 00687 ''' 00688 Input: rawxdata [run,fill,starttime,stoptime,totalls,ncmsls] 00689 rawydata {label:[lumi]} 00690 ''' 00691 lslength=23.357 00692 lut=lumiTime.lumiTime() 00693 runnum=rawxdata[0] 00694 fill=rawxdata[1] 00695 starttime=lut.DatetimeToStr(rawxdata[2],customfm='%m/%d/%y %H:%M:%S') 00696 stoptime=lut.DatetimeToStr(rawxdata[3],customfm='%m/%d/%y %H:%M:%S') 00697 totalls=rawxdata[-2] 00698 ncmsls=rawxdata[-1] 00699 peakinst=max(rawydata['Delivered'])/lslength 00700 totaldelivered=sum(rawydata['Delivered']) 00701 totalrecorded=sum(rawydata['Recorded']) 00702 xpoints=range(1,totalls+1) 00703 #print len(xpoints) 00704 ypoints={} 00705 ymax={} 00706 for ylabel,yvalue in rawydata.items(): 00707 ypoints[ylabel]=[y/lslength for y in yvalue] 00708 ymax[ylabel]=max(yvalue)/lslength 00709 left=0.15 00710 width=0.7 00711 bottom=0.1 00712 height=0.65 00713 bottom_h=bottom+height 00714 rect_scatter=[left,bottom,width,height] 00715 rect_table=[left,bottom_h,width,0.25] 00716 00717 nullfmt=matplotlib.ticker.NullFormatter() 00718 nullloc=matplotlib.ticker.NullLocator() 00719 axtab=self.__fig.add_axes(rect_table,frameon=False) 00720 axtab.set_axis_off() 00721 axtab.xaxis.set_major_formatter(nullfmt) 00722 axtab.yaxis.set_major_formatter(nullfmt) 00723 axtab.xaxis.set_major_locator(nullloc) 00724 axtab.yaxis.set_major_locator(nullloc) 00725 00726 ax=self.__fig.add_axes(rect_scatter) 00727 00728 majorLoc=matplotlib.ticker.LinearLocator(numticks=nticks) 00729 minorLoc=matplotlib.ticker.LinearLocator(numticks=nticks*4) 00730 ax.set_xlabel(r'LS',position=(0.96,0)) 00731 ax.set_ylabel(r'L $\mu$b$^{-1}$s$^{-1}$',position=(0,0.9)) 00732 ax.xaxis.set_major_locator(majorLoc) 00733 ax.xaxis.set_minor_locator(minorLoc) 00734 ax.set_xbound(lower=xpoints[0],upper=xpoints[-1]) 00735 xticklabels=ax.get_xticklabels() 00736 for tx in xticklabels: 00737 tx.set_horizontalalignment('right') 00738 ax.grid(True) 00739 keylist=ypoints.keys() 00740 keylist.sort() 00741 legendlist=[] 00742 00743 for ylabel in keylist: 00744 cl='k' 00745 if self.colormap.has_key(ylabel): 00746 cl=self.colormap[ylabel] 00747 ax.plot(xpoints,ypoints[ylabel],'.',label=ylabel,color=cl) 00748 legendlist.append(ylabel) 00749 #ax.axhline(0,color='green',linewidth=0.2) 00750 ax.axvline(xpoints[ncmsls-1],color='green',linewidth=0.2) 00751 (unitstring,denomitor)=guessLumiUnit(totaldelivered) 00752 colLabels=('run','fill','max inst(/$\mu$b/s)','delivered('+unitstring+')','recorded('+unitstring+')') 00753 cellText=[[str(runnum),str(fill),'%.3f'%(peakinst),'%.3f'%(totaldelivered/denomitor),'%.3f'%(totalrecorded/denomitor)]] 00754 00755 sumtable=axtab.table(cellText=cellText,colLabels=colLabels,colWidths=[0.12,0.1,0.27,0.27,0.27],cellLoc='center',loc='center') 00756 trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes) 00757 axtab.add_table(sumtable) 00758 00759 ax.text(xpoints[0],1.02,starttime[0:17],transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white')) 00760 ax.text(xpoints[ncmsls-1],1.02,stoptime[0:17],transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white')) 00761 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 545 of file matplotRender.py.
00545 {},resultlines=[],minTime=None,maxTime=None,nticks=6,withannotation=False,yscale='linear',referenceLabel='Delivered',labels=['Delivered'],textoutput=None): 00546 ''' 00547 THIS PLOT IS DELIVERED ONLY 00548 Input: 00549 rawdata={'Delivered':[(day,run,ls,instlumi)]} 00550 resultlines=[[day,run,ls,maxinstlum],[]] 00551 minTime (python DateTime) : min *begin* time to draw: format %m/%d/%y %H:%M:%S 00552 maxTime (python DateTime): max *begin* time to draw %m/%d/%y %H:%M:%S 00553 withannotation: wheather the boundary points should be annotated 00554 referenceLabel: the one variable that decides the total unit and the plot x-axis range 00555 labels: labels of the variables to plot 00556 ''' 00557 xpoints=[] 00558 ypoints={} 00559 legendlist=[] 00560 maxinfo='' 00561 ymax={} 00562 lut=lumiTime.lumiTime() 00563 if not minTime: 00564 minTime='03/01/10 00:00:00' 00565 minTime=lut.StrToDatetime(minTime,customfm='%m/%d/%y %H:%M:%S') 00566 if not maxTime: 00567 maxTime=datetime.datetime.utcnow() 00568 else: 00569 maxTime=lut.StrToDatetime(maxTime,customfm='%m/%d/%y %H:%M:%S') 00570 for r in resultlines: 00571 day=int(r[0]) 00572 runnumber=int(r[1]) 00573 lsnum=int(r[2].split('.')[0]) 00574 if rawdata and day in [int(t[0]) for t in rawdata[referenceLabel]]:continue 00575 if day < minTime.date().toordinal():continue 00576 if day > maxTime.date().toordinal():continue 00577 for i,lab in enumerate(labels): 00578 v=float(r[-(len(labels)-i)]) 00579 rawdata.setdefault(lab,[]).append((day,runnumber,lsnum,v)) 00580 if not rawdata: 00581 print '[WARNING]: no data, do nothing' 00582 return 00583 maxlum=max([t[3] for t in rawdata[referenceLabel]]) 00584 minlum=min([t[3] for t in rawdata[referenceLabel] if t[3]>0]) #used only for log scale, fin the non-zero bottom 00585 (unitstring,denomitor)=guessLumiUnit(maxlum) 00586 csvreport=None 00587 rows=[] 00588 flat=[] 00589 alldays=[] 00590 for label,yvalues in rawdata.items(): 00591 yvalues.sort()#sort by day 00592 minday=yvalues[0][0] 00593 maxday=yvalues[-1][0] 00594 alldays=range(minday,maxday+1) 00595 ypoints[label]=[] 00596 dayvals=[t[0] for t in yvalues] 00597 lumivals=[t[3] for t in yvalues] 00598 flat.append(lumivals) 00599 for d in alldays: 00600 if not d in dayvals: 00601 ypoints[label].append(0.0) 00602 else: 00603 thisdaylumi=[t[3] for t in yvalues if t[0]==d][0] 00604 if yscale=='log': 00605 if thisdaylumi<minlum: 00606 thisdaylumi=minlum/denomitor 00607 else: 00608 thisdaylumi=thisdaylumi/denomitor 00609 else: 00610 thisdaylumi=thisdaylumi/denomitor 00611 ypoints[label].append(thisdaylumi) 00612 ymax[label]=max(lumivals)/denomitor 00613 xpoints=alldays 00614 if textoutput: 00615 csvreport=csvReporter.csvReporter(textoutput) 00616 head=['#day','run','lsnum','maxinstlumi'] 00617 csvreport.writeRow(head) 00618 flat.insert(0,[t[0] for t in yvalues]) 00619 allruns=[ t[1] for t in rawdata[referenceLabel]] 00620 allls=[ t[2] for t in rawdata[referenceLabel]] 00621 flat.insert(1,allruns) 00622 flat.insert(2,allls) 00623 rows=zip(*flat) 00624 csvreport.writeRows([list(t) for t in rows]) 00625 00626 yearStrMin=minTime.strftime('%Y') 00627 yearStrMax=maxTime.strftime('%Y') 00628 if yearStrMin==yearStrMax: 00629 dateFmt=matplotlib.dates.DateFormatter('%d/%m') 00630 else: 00631 dateFmt=matplotlib.dates.DateFormatter('%d/%m/%y') 00632 ax=self.__fig.add_subplot(111) 00633 if yscale=='linear': 00634 ax.set_yscale('linear') 00635 elif yscale=='log': 00636 ax.set_yscale('log') 00637 else: 00638 raise 'unsupported yscale ',yscale 00639 majorLoc=matplotlib.ticker.LinearLocator(numticks=nticks) 00640 minorLoc=matplotlib.ticker.LinearLocator(numticks=nticks*4) 00641 ax.xaxis.set_major_formatter(dateFmt) 00642 ax.set_xlabel(r'Date',position=(0.84,0)) 00643 ax.set_ylabel(r'L '+unitstring,position=(0,0.9)) 00644 ax.xaxis.set_major_locator(majorLoc) 00645 ax.xaxis.set_minor_locator(minorLoc) 00646 xticklabels=ax.get_xticklabels() 00647 for tx in xticklabels: 00648 tx.set_horizontalalignment('right') 00649 ax.grid(True) 00650 cl=self.colormap['Max Inst'] 00651 textsummaryhead=['#TotalDays'] 00652 textsummaryline=['#'+str(len(xpoints))] 00653 for ylabel in labels: 00654 cl='k' 00655 if self.colormap.has_key(ylabel): 00656 cl=self.colormap[ylabel] 00657 ax.plot(xpoints,ypoints[ylabel],label='Max Inst',color=cl,drawstyle='steps') 00658 legendlist.append('Max Inst %.3f'%(ymax[ylabel])+' '+unitstring) 00659 textsummaryhead.append('Max Inst'+ylabel) 00660 textsummaryline.append('%.3f'%(ymax[ylabel])+' '+unitstring) 00661 if textoutput: 00662 csvreport.writeRow(textsummaryhead) 00663 csvreport.writeRow(textsummaryline) 00664 ax.legend(tuple(legendlist),loc='upper left') 00665 ax.set_xbound(lower=matplotlib.dates.date2num(minTime),upper=matplotlib.dates.date2num(maxTime)) 00666 if withannotation: 00667 #annotations 00668 trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes) 00669 ax.text(xpoints[0],1.025,beginfo,transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white')) 00670 ax.text(xpoints[-1],1.025,endinfo,transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white')) 00671 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')) 00672 00673 firstday=datetime.date.fromordinal(rawdata[referenceLabel][0][0]) 00674 lastday=datetime.date.fromordinal(rawdata[referenceLabel][-1][0]) 00675 firstdayStr=firstday.strftime('%Y %b %d') 00676 lastdayStr=lastday.strftime('%Y %b %d') 00677 ax.set_title('CMS Peak Luminosity/Day ('+firstdayStr+' - '+lastdayStr+')',size='small') 00678 00679 #ax.autoscale(tight=True) 00680 ax.autoscale_view(tight=True,scalex=True,scaley=False) 00681 #ax.set_xmargin(0.015) 00682 self.__fig.autofmt_xdate(bottom=0.18,rotation=15,ha='right') 00683 self.__fig.subplots_adjust(bottom=0.2,left=0.15) 00684
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 402 of file matplotRender.py.
00402 {},resultlines=[],minTime=None,maxTime=None,nticks=6,yscale='linear',withannotation=False,referenceLabel='Delivered',labels=['Delivered','Recorded'],textoutput=None): 00403 ''' 00404 Input: 00405 rawdata={'Delivered':[(day,begrun:ls,endrun:ls,lumi)],'Recorded':[(dayofyear,begrun:ls,endrun:ls,lumi)]} 00406 resultlines=[[day,begrun:ls,endrun:ls,deliveredperday,recordedperday],[]] 00407 minTime (python DateTime) : min *begin* time to draw: format %m/%d/%y %H:%M:%S 00408 maxTime (python DateTime): max *begin* time to draw %m/%d/%y %H:%M:%S 00409 withannotation: wheather the boundary points should be annotated 00410 referenceLabel: the one variable that decides the total unit and the plot x-axis range 00411 labels: labels of the variables to plot 00412 ''' 00413 xpoints=[] 00414 ypoints={} 00415 ymax={} 00416 lut=lumiTime.lumiTime() 00417 if not minTime: 00418 minTime='03/01/10 00:00:00' 00419 minTime=lut.StrToDatetime(minTime,customfm='%m/%d/%y %H:%M:%S') 00420 if not maxTime: 00421 maxTime=datetime.datetime.utcnow() 00422 else: 00423 maxTime=lut.StrToDatetime(maxTime,customfm='%m/%d/%y %H:%M:%S') 00424 for r in resultlines: 00425 day=int(r[0]) 00426 begrunls=r[1] 00427 endrunls=r[2] 00428 #[begrun,begls]=[int(s) for s in r[1].split(':')] 00429 if rawdata and day in [t[0] for t in rawdata[referenceLabel]]:continue 00430 if day < minTime.date().toordinal():continue 00431 if day > maxTime.date().toordinal():continue 00432 for i,lab in enumerate(labels): 00433 v=float(r[-(len(labels)-i)]) 00434 rawdata.setdefault(lab,[]).append((day,begrunls,endrunls,v)) 00435 if not rawdata: 00436 print '[WARNING]: no data, do nothing' 00437 return 00438 maxlum=max([t[3] for t in rawdata[referenceLabel]]) 00439 minlum=min([t[3] for t in rawdata[referenceLabel] if t[3]>0]) #used only for log scale, fin the non-zero bottom 00440 (unitstring,denomitor)=guessLumiUnit(maxlum) 00441 csvreport=None 00442 rows=[] 00443 flat=[] 00444 for label,yvalues in rawdata.items(): 00445 yvalues.sort() 00446 flat.append([t[3] for t in yvalues]) 00447 minday=yvalues[0][0] 00448 #print 'minday ',minday 00449 maxday=yvalues[-1][0] 00450 #print 'maxday ',maxday 00451 alldays=range(minday,maxday+1) 00452 #print 'alldays ',alldays 00453 ypoints[label]=[] 00454 dayvals=[t[0] for t in yvalues] 00455 lumivals=[t[3] for t in yvalues] 00456 #print 'lumivals ',lumivals 00457 for d in alldays: 00458 if not d in dayvals: 00459 ypoints[label].append(0.0) 00460 else: 00461 thisdaylumi=[t[3] for t in yvalues if t[0]==d][0] 00462 if yscale=='log': 00463 if thisdaylumi<minlum: 00464 thisdaylumi=minlum/denomitor 00465 else: 00466 thisdaylumi=thisdaylumi/denomitor 00467 else: 00468 thisdaylumi=thisdaylumi/denomitor 00469 ypoints[label].append(thisdaylumi) 00470 ymax[label]=max(lumivals)/denomitor 00471 xpoints=alldays 00472 if textoutput: 00473 csvreport=csvReporter.csvReporter(textoutput) 00474 head=['#day','begrunls','endrunls','delivered','recorded'] 00475 csvreport.writeRow(head) 00476 flat.insert(0,alldays) 00477 allstarts=[ t[1] for t in rawdata[referenceLabel]] 00478 allstops=[ t[2] for t in rawdata[referenceLabel]] 00479 flat.insert(1,allstarts) 00480 flat.insert(2,allstops) 00481 rows=zip(*flat) 00482 csvreport.writeRows([list(t) for t in rows]) 00483 00484 yearStrMin=minTime.strftime('%Y') 00485 yearStrMax=maxTime.strftime('%Y') 00486 if yearStrMin==yearStrMax: 00487 dateFmt=matplotlib.dates.DateFormatter('%d/%m') 00488 else: 00489 dateFmt=matplotlib.dates.DateFormatter('%d/%m/%y') 00490 ax=self.__fig.add_subplot(111) 00491 if yscale=='linear': 00492 ax.set_yscale('linear') 00493 elif yscale=='log': 00494 ax.set_yscale('log') 00495 else: 00496 raise 'unsupported yscale ',yscale 00497 majorLoc=matplotlib.ticker.LinearLocator(numticks=nticks) 00498 minorLoc=matplotlib.ticker.LinearLocator(numticks=nticks*4) 00499 ax.xaxis.set_major_formatter(dateFmt) 00500 ax.set_xlabel(r'Date',position=(0.84,0)) 00501 ax.xaxis.set_major_locator(majorLoc) 00502 ax.xaxis.set_minor_locator(minorLoc) 00503 xticklabels=ax.get_xticklabels() 00504 for tx in xticklabels: 00505 tx.set_horizontalalignment('right') 00506 ax.grid(True) 00507 legendlist=[] 00508 ax.set_ylabel(r'L '+unitstring,position=(0,0.9)) 00509 textsummaryhead=['#TotalDays'] 00510 textsummaryline=['#'+str(len(xpoints))] 00511 for ylabel in labels: 00512 cl='k' 00513 if self.colormap.has_key(ylabel): 00514 cl=self.colormap[ylabel] 00515 ax.plot(xpoints,ypoints[ylabel],label=ylabel,color=cl,drawstyle='steps') 00516 legendlist.append(ylabel+' Max '+'%.3f'%(ymax[ylabel])+' '+unitstring) 00517 textsummaryhead.append('Max'+ylabel) 00518 textsummaryline.append('%.3f'%(ymax[ylabel])+' '+unitstring) 00519 if textoutput: 00520 csvreport.writeRow(textsummaryhead) 00521 csvreport.writeRow(textsummaryline) 00522 ax.legend(tuple(legendlist),loc='upper left') 00523 ax.set_xbound(lower=matplotlib.dates.date2num(minTime),upper=matplotlib.dates.date2num(maxTime)) 00524 #if withannotation: 00525 # begtime=boundaryInfo[0][0] 00526 # beginfo=boundaryInfo[0][1] 00527 # endtime=boundaryInfo[1][0] 00528 # endinfo=boundaryInfo[1][1] 00529 # #annotations 00530 # trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes) 00531 # ax.text(matplotlib.dates.date2num(begtime),1.025,beginfo,transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white')) 00532 # ax.text(matplotlib.dates.date2num(endtime),1.025,endinfo,transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white')) 00533 00534 firstday=datetime.date.fromordinal(rawdata[referenceLabel][0][0]) 00535 lastday=datetime.date.fromordinal(rawdata[referenceLabel][-1][0]) 00536 firstdayStr=firstday.strftime('%Y %b %d') 00537 lastdayStr=lastday.strftime('%Y %b %d') 00538 ax.set_title('CMS Integrated Luminosity/Day ('+firstdayStr+' - '+lastdayStr+')',size='small') 00539 #ax.autoscale(tight=True) 00540 ax.autoscale_view(tight=True,scalex=True,scaley=False) 00541 #ax.set_xmargin(0.015) 00542 self.__fig.autofmt_xdate(bottom=0.18,rotation=15,ha='right') 00543 self.__fig.subplots_adjust(bottom=0.2,left=0.15) 00544
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 173 of file matplotRender.py.
00173 {},resultlines=[],minFill=None,maxFill=None,nticks=6,yscale='linear',withannotation=False,referenceLabel='Delivered',labels=['Delivered','Recorded'],textoutput=None): 00174 ''' 00175 input: 00176 rawdata = {'Delivered':[(fill,runnumber,lumiperrun)],'Recorded':[(fill,runnumber,lumiperrun)]} 00177 resultlines = [[fillnumber,runnumber,dellumiperrun,reclumiperrun],[fillnumber,runnumber,dellumiperrun,reclumiperrun],] 00178 minFill : min fill to draw 00179 maxFill : max fill to draw 00180 yscale: linear,log or both 00181 withannotation: wheather the boundary points should be annotated 00182 textoutput: text output file name. 00183 ''' 00184 ytotal={} 00185 ypoints={} 00186 for r in resultlines: #parse old text data 00187 fillnum=int(r[0]) 00188 runnum=int(r[1]) 00189 if rawdata and (fillnum,runnum) in [(t[0],t[1]) for t in rawdata[referenceLabel]]:continue 00190 if minFill and fillnum<minFill:continue 00191 if maxFill and fillnum>maxFill:continue 00192 for i,lab in enumerate(labels) : 00193 v=float(r[-(len(labels)-i)])#the values to plot are always the last n fields 00194 rawdata.setdefault(lab,[]).append((fillnum,runnum,v)) 00195 #print 'fillrunDict ',fillrunDict 00196 if not rawdata: 00197 print '[WARNING]: no data, do nothing' 00198 return 00199 tot=sum([t[2] for t in rawdata[referenceLabel]]) 00200 beginfo='' 00201 endinfo='' 00202 (unitstring,denomitor)=guessLumiUnit(tot) 00203 csvreport=None 00204 rows=[] 00205 flat=[] 00206 for label,yvalues in rawdata.items(): 00207 yvalues.sort() 00208 flat.append([t[2] for t in yvalues]) 00209 ypoints[label]=[] 00210 ytotal[label]=0.0 00211 lumivals=[t[2] for t in yvalues] 00212 for i,val in enumerate(lumivals): 00213 ypoints[label].append(sum(lumivals[0:i+1])/denomitor) 00214 ytotal[label]=sum(lumivals)/denomitor 00215 xpoints=[t[0] for t in rawdata[referenceLabel]]#after sort 00216 ax=self.__fig.add_subplot(111) 00217 ax.set_xlabel(r'LHC Fill Number',position=(0.84,0)) 00218 ax.set_ylabel(r'L '+unitstring,position=(0,0.9)) 00219 ax.set_xbound(lower=xpoints[0],upper=xpoints[-1]) 00220 if yscale=='linear': 00221 ax.set_yscale('linear') 00222 elif yscale=='log': 00223 ax.set_yscale('log') 00224 else: 00225 raise 'unsupported yscale ',yscale 00226 xticklabels=ax.get_xticklabels() 00227 majorLocator=matplotlib.ticker.LinearLocator( nticks ) 00228 majorFormatter=matplotlib.ticker.FormatStrFormatter('%d') 00229 #minorLocator=matplotlib.ticker.MultipleLocator(sampleinterval) 00230 ax.xaxis.set_major_locator(majorLocator) 00231 ax.xaxis.set_major_formatter(majorFormatter) 00232 #ax.xaxis.set_minor_locator(minorLocator) 00233 ax.grid(True) 00234 keylist=ypoints.keys() 00235 keylist.sort() 00236 keylist.insert(0,keylist.pop(keylist.index(referenceLabel)))#move refereceLabel to front from now on 00237 legendlist=[] 00238 head=['#fill','run'] 00239 textsummaryhead=['#TotalFill'] 00240 textsummaryline=['#'+str(len(xpoints))] 00241 for ylabel in keylist: 00242 cl='k' 00243 if self.colormap.has_key(ylabel): 00244 cl=self.colormap[ylabel] 00245 ax.plot(xpoints,ypoints[ylabel],label=ylabel,color=cl,drawstyle='steps') 00246 legendlist.append(ylabel+' '+'%.3f'%(ytotal[ylabel])+' '+unitstring) 00247 textsummaryhead.append('Total'+ylabel) 00248 textsummaryline.append('%.3f'%(ytotal[ylabel])+' '+unitstring) 00249 head.append(ylabel) 00250 if textoutput: 00251 csvreport=csvReporter.csvReporter(textoutput) 00252 allfills=[int(t[0]) for t in rawdata[referenceLabel]] 00253 allruns=[int(t[1]) for t in rawdata[referenceLabel]] 00254 flat.insert(0,allfills) 00255 flat.insert(1,allruns) 00256 rows=zip(*flat) 00257 csvreport.writeRow(head) 00258 csvreport.writeRows([list(t) for t in rows]) 00259 csvreport.writeRow(textsummaryhead) 00260 csvreport.writeRow(textsummaryline) 00261 #font=FontProperties(size='medium',weight='demibold') 00262 #annotations 00263 if withannotation: 00264 trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes) 00265 ax.text(xpoints[0],1.025,beginfo,transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white')) 00266 ax.text(xpoints[-1],1.025,endinfo,transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white')) 00267 #legend 00268 ax.legend(tuple(legendlist),loc='upper left') 00269 #adjust 00270 self.__fig.subplots_adjust(bottom=0.1,left=0.1) 00271
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 74 of file matplotRender.py.
00074 {},resultlines=[],minRun=None,maxRun=None,nticks=6,yscale='linear',withannotation=False,referenceLabel='Delivered',labels=['Delivered','Recorded'],textoutput=None): 00075 ''' 00076 input: 00077 rawdata = {'Delivered':[(runnumber,lumiperrun),..],'Recorded':[(runnumber,lumiperrun),..]} 00078 resultlines = [[runnumber,dellumiperrun,reclumiperrun],[runnumber,dellumiperrun,reclumiperrun],] 00079 minRun : minimal runnumber required 00080 maxRun : max runnumber required 00081 yscale: linear,log or both 00082 withannotation: wheather the boundary points should be annotated 00083 referenceLabel: the one variable that decides the total unit and the plot x-axis range 00084 labels: labels of the variables to plot 00085 textoutput: text output file name. 00086 ''' 00087 ypoints={} 00088 ytotal={} 00089 for r in resultlines:#parse old text data 00090 runnumber=int(r[0]) 00091 if rawdata and runnumber in [t[0] for t in rawdata[referenceLabel]]:continue#use text input only if not in selected data 00092 if minRun and runnumber<minRun: continue 00093 if maxRun and runnumber>maxRun: continue 00094 for i,lab in enumerate(labels) : 00095 v=float(r[-(len(labels)-i)])#the values to plot are always the last n fields 00096 rawdata.setdefault(lab,[]).append((runnumber,v)) 00097 if not rawdata: 00098 print '[WARNING]: no data to plot , exit' 00099 return 00100 00101 tot=sum([t[1] for t in rawdata[referenceLabel]]) 00102 (unitstring,denomitor)=guessLumiUnit(tot) 00103 csvreport=None 00104 rows=[] 00105 flat=[] 00106 for label,yvalues in rawdata.items(): 00107 yvalues.sort() 00108 flat.append([t[1] for t in yvalues]) 00109 ypoints[label]=[] 00110 ytotal[label]=0.0 00111 lumivals=[t[1] for t in yvalues] 00112 for i,val in enumerate(lumivals): 00113 ypoints[label].append(sum(lumivals[0:i+1])/denomitor)#integrated lumi 00114 ytotal[label]=sum(lumivals)/denomitor 00115 xpoints=[t[0] for t in rawdata[referenceLabel]] 00116 ax=self.__fig.add_subplot(111) 00117 if yscale=='linear': 00118 ax.set_yscale('linear') 00119 elif yscale=='log': 00120 ax.set_yscale('log') 00121 else: 00122 raise 'unsupported yscale ',yscale 00123 ax.set_xlabel(r'Run',position=(0.95,0)) 00124 ax.set_ylabel(r'L '+unitstring,position=(0,0.9)) 00125 xticklabels=ax.get_xticklabels() 00126 for tx in xticklabels: 00127 tx.set_rotation(30) 00128 majorLocator=matplotlib.ticker.LinearLocator( nticks ) 00129 majorFormatter=matplotlib.ticker.FormatStrFormatter('%d') 00130 minorLocator=matplotlib.ticker.LinearLocator(numticks=4*nticks) 00131 ax.xaxis.set_major_locator(majorLocator) 00132 ax.xaxis.set_major_formatter(majorFormatter) 00133 ax.xaxis.set_minor_locator(minorLocator) 00134 ax.set_xbound(lower=xpoints[0],upper=xpoints[-1]) 00135 ax.grid(True) 00136 keylist=ypoints.keys() 00137 keylist.sort() 00138 keylist.insert(0,keylist.pop(keylist.index(referenceLabel)))#move refereceLabel to front from now on 00139 legendlist=[] 00140 head=['#Run'] 00141 textsummaryhead=['#TotalRun'] 00142 textsummaryline=['#'+str(len(xpoints))] 00143 for ylabel in keylist: 00144 cl='k' 00145 if self.colormap.has_key(ylabel): 00146 cl=self.colormap[ylabel] 00147 ax.plot(xpoints,ypoints[ylabel],label=ylabel,color=cl,drawstyle='steps') 00148 legendlist.append(ylabel+' '+'%.3f'%(ytotal[ylabel])+' '+unitstring) 00149 textsummaryhead.append('Total'+ylabel) 00150 textsummaryline.append('%.3f'%(ytotal[ylabel])+' '+unitstring) 00151 head.append(ylabel) 00152 if textoutput: 00153 csvreport=csvReporter.csvReporter(textoutput) 00154 csvreport.writeRow(head) 00155 allruns=[int(t[0]) for t in rawdata[referenceLabel]] 00156 flat.insert(0,allruns) 00157 rows=zip(*flat) 00158 csvreport.writeRows([list(t) for t in rows]) 00159 csvreport.writeRow(textsummaryhead) 00160 csvreport.writeRow(textsummaryline) 00161 #font=FontProperties(size='medium',weight='demibold') 00162 #legend 00163 ax.legend(tuple(legendlist),loc='upper left') 00164 #adjust 00165 self.__fig.subplots_adjust(bottom=0.18,left=0.1) 00166 #annotations 00167 if withannotation: 00168 trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes) 00169 ax.text(xpoints[0],1.025,str(xpoints[0]),transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white')) 00170 ax.text(xpoints[-1],1.025,str(xpoints[-1]),transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white')) 00171 00172
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 272 of file matplotRender.py.
00272 {},resultlines=[],minTime=None,maxTime=None,nticks=6,yscale='linear',withannotation=False,referenceLabel='Delivered',labels=['Delivered','Recorded'],textoutput=None): 00273 ''' 00274 input: 00275 rawdata = {'Delivered':[(runnumber,starttimestamp,stoptimestamp,lumiperrun)],'Recorded':[(runnumber,starttimestamp,stoptimestamp,lumiperrun)]} 00276 resultlines = [[runnumber,starttimestampStr,stoptimestampStr,dellumiperrun,reclumiperrun],[runnumber,starttimestampStr,stoptimestampStr,dellumiperrun,reclumiperrun],] 00277 minTime (python DateTime) : min *begin* time to draw: format %m/%d/%y %H:%M:%S 00278 maxTime (python DateTime): max *begin* time to draw %m/%d/%y %H:%M:%S 00279 yscale: linear,log or both 00280 withannotation: wheather the boundary points should be annotated 00281 referenceLabel: the one variable that decides the total unit and the plot x-axis range 00282 labels: labels of the variables to plot 00283 ''' 00284 xpoints=[] 00285 ypoints={} 00286 ytotal={} 00287 lut=lumiTime.lumiTime() 00288 if not minTime: 00289 minTime='03/01/10 00:00:00' 00290 minTime=lut.StrToDatetime(minTime,customfm='%m/%d/%y %H:%M:%S') 00291 if not maxTime: 00292 maxTime=datetime.datetime.utcnow() 00293 else: 00294 maxTime=lut.StrToDatetime(maxTime,customfm='%m/%d/%y %H:%M:%S') 00295 for r in resultlines: 00296 runnumber=int(r[0]) 00297 starttimeStr=r[1].split('.')[0] 00298 starttime=lut.StrToDatetime(starttimeStr,customfm='%Y-%m-%d %H:%M:%S') 00299 stoptimeStr=r[2].split('.')[0] 00300 stoptime=lut.StrToDatetime(stoptimeStr,customfm='%Y-%m-%d %H:%M:%S') 00301 if rawdata and runnumber in [t[0] for t in rawdata[referenceLabel]]:continue 00302 if starttime<minTime:continue 00303 if starttime>maxTime:continue 00304 00305 for i,lab in enumerate(labels): 00306 v=float(r[-(len(labels)-i)]) 00307 rawdata.setdefault(lab,[]).append((runnumber,starttime,stoptime,v)) 00308 if not rawdata: 00309 print '[WARNING]: no data, do nothing' 00310 return 00311 tot=sum([t[3] for t in rawdata[referenceLabel]]) 00312 (unitstring,denomitor)=guessLumiUnit(tot) 00313 csvreport=None 00314 rows=[] 00315 flat=[] 00316 for label,yvalues in rawdata.items(): 00317 yvalues.sort() 00318 flat.append([t[3] for t in yvalues]) 00319 if label==referenceLabel: 00320 minTime=yvalues[0][1] 00321 maxTime=yvalues[-1][1] 00322 ypoints[label]=[] 00323 lumivals=[t[3] for t in yvalues] 00324 for i,val in enumerate(lumivals): 00325 ypoints[label].append(sum(lumivals[0:i+1])/denomitor) 00326 ytotal[label]=sum(lumivals)/denomitor 00327 xpoints=[matplotlib.dates.date2num(t[1]) for t in rawdata[referenceLabel]] 00328 ax=self.__fig.add_subplot(111) 00329 ax.set_yscale(yscale) 00330 yearStrMin=minTime.strftime('%Y') 00331 yearStrMax=maxTime.strftime('%Y') 00332 if yearStrMin==yearStrMax: 00333 dateFmt=matplotlib.dates.DateFormatter('%d/%m') 00334 else: 00335 dateFmt=matplotlib.dates.DateFormatter('%d/%m/%y') 00336 majorLoc=matplotlib.ticker.LinearLocator(numticks=nticks) 00337 ax.xaxis.set_major_locator(majorLoc) 00338 minorLoc=matplotlib.ticker.LinearLocator(numticks=nticks*4) 00339 ax.xaxis.set_major_formatter(dateFmt) 00340 ax.set_xlabel(r'Date',position=(0.84,0)) 00341 ax.set_ylabel(r'L '+unitstring,position=(0,0.9)) 00342 ax.xaxis.set_minor_locator(minorLoc) 00343 ax.set_xbound(lower=xpoints[0],upper=xpoints[-1]) 00344 xticklabels=ax.get_xticklabels() 00345 for tx in xticklabels: 00346 tx.set_horizontalalignment('left') 00347 ax.grid(True) 00348 keylist=ypoints.keys() 00349 keylist.sort() 00350 keylist.insert(0,keylist.pop(keylist.index(referenceLabel)))#move refereceLabel to front from now on 00351 legendlist=[] 00352 head=['#Run','StartTime','StopTime'] 00353 textsummaryhead=['#TotalRun'] 00354 textsummaryline=['#'+str(len(xpoints))] 00355 for ylabel in keylist: 00356 cl='k' 00357 if self.colormap.has_key(ylabel): 00358 cl=self.colormap[ylabel] 00359 ax.plot(xpoints,ypoints[ylabel],label=ylabel,color=cl,drawstyle='steps') 00360 legendlist.append(ylabel+' '+'%.3f'%(ytotal[ylabel])+' '+unitstring) 00361 textsummaryhead.append('Total'+ylabel) 00362 textsummaryline.append('%.3f'%(ytotal[ylabel])+' '+unitstring) 00363 head.append(ylabel) 00364 if textoutput: 00365 csvreport=csvReporter.csvReporter(textoutput) 00366 csvreport.writeRow(head) 00367 allruns=[int(t[0]) for t in rawdata[referenceLabel]] 00368 allstarts=[ t[1] for t in rawdata[referenceLabel]] 00369 allstops=[ t[2] for t in rawdata[referenceLabel]] 00370 flat.insert(0,allruns) 00371 flat.insert(1,allstarts) 00372 flat.insert(2,allstops) 00373 rows=zip(*flat) 00374 csvreport.writeRows([list(t) for t in rows]) 00375 csvreport.writeRow(textsummaryhead) 00376 csvreport.writeRow(textsummaryline) 00377 #annotations 00378 trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes) 00379 #print 'run boundary ',runs[0],runs[-1] 00380 #print 'xpoints boundary ',xpoints[0],xpoints[-1] 00381 #annotation 00382 if withannotation: 00383 runs=[t[0] for t in rawdata[referenceLabel]] 00384 ax.text(xpoints[0],1.025,str(runs[0]),transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white')) 00385 ax.text(xpoints[-1],1.025,str(runs[-1]),transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white')) 00386 00387 if yearStrMin==yearStrMax: 00388 firsttimeStr=rawdata[referenceLabel][1][1].strftime('%b %d %H:%M') #time range(start) in the title is the first run beg time 00389 lasttimeStr=rawdata[referenceLabel][-1][2].strftime('%b %d %H:%M') #time range(stop) in the tile is the last run stop time 00390 #firstimeStr=minTime.strftime('%b %d %H:%M') 00391 #lasttimeStr=maxTime.strftime('%b %d %H:%M') 00392 #ax.set_title('CMS Total Integrated Luminosity '+yearStrMin+' ('+firstimeStr+' - '+lasttimeStr+' UTC)',size='small',family='fantasy') 00393 ax.set_title('CMS Total Integrated Luminosity '+yearStrMin+' ('+firsttimeStr+' - '+lasttimeStr+' UTC)',size='small') 00394 else: 00395 #ax.set_title('CMS Total Integrated Luminosity '+yearStrMin+'-'+yearStrMax,size='small',family='fantasy') 00396 ax.set_title('CMS Total Integrated Luminosity '+yearStrMin+'-'+yearStrMax,size='small') 00397 ax.legend(tuple(legendlist),loc='upper left') 00398 ax.autoscale_view(tight=True,scalex=True,scaley=False) 00399 self.__fig.autofmt_xdate(bottom=0.18,rotation=15,ha='right') 00400 self.__fig.subplots_adjust(bottom=0.2,left=0.15) 00401
matplotRender::matplotRender::__canvas [private] |
Definition at line 65 of file matplotRender.py.
matplotRender::matplotRender::__fig [private] |
Definition at line 65 of file matplotRender.py.
Definition at line 65 of file matplotRender.py.