def update_figure(self): global ImageDisplayed self.ax0.cla() self.axx.cla() self.axy.cla() self.ax0.imshow(ImageDisplayed, aspect='auto', cmap=beam_map, origin='lower') projx, projy = ImageDisplayed.sum(axis=0), ImageDisplayed.sum(axis=1) x = np.arange(len(projx)) y = np.arange(len(projy)) if FLAG_fit > 0: p2X = imgtl.FitProfile(projx, x) p2Y = imgtl.FitProfile(projy, y) # # top plot self.axx.plot(projx) if FLAG_fit > 0: self.axx.plot(x, imgtl.dg(x, p2X), 'r--', linewidth=3) self.axx.set_xlim(self.ax0.get_xlim()) # # Right plot self.axy.plot(projy, range(len(projy))) if FLAG_fit > 0: self.axy.plot(imgtl.dg(y, p2Y), y, 'r--', linewidth=3) self.axy.set_ylim(self.ax0.get_ylim()) # Remove tick labels nullfmt = ticker.NullFormatter() self.axx.xaxis.set_major_formatter(nullfmt) self.axx.yaxis.set_major_formatter(nullfmt) self.axy.xaxis.set_major_formatter(nullfmt) self.axy.yaxis.set_major_formatter(nullfmt) self.draw()
print("fitX: ", p2X) print("fitY: ", p2Y) plt.figure() disp=filenameIm.split('/') print(disp) print(len(disp)) plt.subplot (2,2,1) plt.title (disp[len(disp)-1]) plt.imshow(ndimage.gaussian_filter(IMGf, 10), extent=[min(x), max(x), min(y), max(y)], \ aspect='auto', cmap='coolwarm') plt.subplot (2,2,3) plt.plot (x, histx) plt.plot (x, imgtl.dg(x,p2X),'--',linewidth=3) plt.xlim(min(x), max(x)) plt.subplot (2,2,2) plt.plot (histy,y) plt.plot (imgtl.dg(y,p2Y),y,'--',linewidth=3) plt.ylim(min(y), max(y)) plt.subplot (2,2,4) plt.ylim(0,10) plt.xlim(0,10) text1='rms_x = '+str('{0:.2f}'.format((np.mean(stdx0[len(stdx0)-2:len(stdx0)+2])))) \ +'+/-'+str('{0:.2f}'.format(np.std(stdx0[len(stdx0)-2:len(stdx0)+2]))) text2='rms_y = '+str('{0:.2f}'.format((np.mean(stdy0[len(stdy0)-2:len(stdy0)+2])))) \ +'+/-'+str('{0:.2f}'.format(np.std(stdy0[len(stdy0)-2:len(stdy0)+2]))) text3='<xy>/(rms_x*rms_y) = '+str('{0:.2f}'.format((np.mean(correl0[len(correl0)-2:len(correl0)+2])))) \ +'+/-'+str('{0:.2f}'.format(np.std(correl0[len(correl0)-2:len(correl0)+2])))
axisX=np.arange(len(histX)) axisY=np.arange(len(histY)) # center the histogram and select a region of interest (ROI) around the peak window=1000. histXc, axisXc = imgtl.center_and_ROI(histX, axisX, window) histYc, axisYc = imgtl.center_and_ROI(histY, axisY, window) # remove background (there are many way of doing this) window = 10 histXc, axisXc = imgtl.removebackground(histXc, axisXc, window) histYc, axisYc = imgtl.removebackground(histYc, axisYc, window) p2X= imgtl.FitProfile(histXc, axisXc) p2Y= imgtl.FitProfile(histYc, axisYc) print "fitX: ", p2X print "fitY: ", p2Y plt.figure() plt.plot(axisXc, histXc,'ob',alpha=0.1) plt.plot(axisXc, imgtl.dg(axisXc,p2X),'--b',linewidth=3) plt.plot(axisYc, histYc,'or',alpha=0.1) plt.plot(axisYc, imgtl.dg(axisYc,p2Y),'--r',linewidth=3) plt.title("point number: "+str(i)) plt.show()
histY = np.loadtxt(filenameY) # create the horizontal coordinate axisX = np.arange(len(histX)) axisY = np.arange(len(histY)) # center the histogram and select a region of interest (ROI) around the peak window = 1000. histXc, axisXc = imgtl.center_and_ROI(histX, axisX, window) histYc, axisYc = imgtl.center_and_ROI(histY, axisY, window) # remove background (there are many way of doing this) window = 10 histXc, axisXc = imgtl.removebackground(histXc, axisXc, window) histYc, axisYc = imgtl.removebackground(histYc, axisYc, window) p2X = imgtl.FitProfile(histXc, axisXc) p2Y = imgtl.FitProfile(histYc, axisYc) print("fitX: ", p2X) print("fitY: ", p2Y) plt.figure() plt.plot(axisXc, histXc, 'ob', alpha=0.1) plt.plot(axisXc, imgtl.dg(axisXc, p2X), '--b', linewidth=3) plt.plot(axisYc, histYc, 'or', alpha=0.1) plt.plot(axisYc, imgtl.dg(axisYc, p2Y), '--r', linewidth=3) plt.title("point number: " + str(i)) plt.show()
y=y-y[np.argmax(histy)] p2X= imgtl.FitProfile(histx, x) p2Y= imgtl.FitProfile(histy, y) print 'RMS_x=',np.mean(stdx0[len(stdx0)-2:len(stdx0)+2]) print 'RMS_y=',np.mean(stdy0[len(stdy0)-2:len(stdy0)+2]) print "fitX: ", p2X print "fitY: ", p2Y plt.figure() plt.subplot (2,2,1) plt.imshow(ndimage.gaussian_filter(IMGf, 10), extent=[min(x), max(x), min(y), max(y)], \ aspect='auto', origin='lower', cmap='spectral') plt.subplot (2,2,3) plt.plot (x, histx) plt.plot (x, imgtl.dg(x,p2X),'--',linewidth=3) plt.xlim(min(x), max(x)) plt.subplot (2,2,2) plt.plot (histy,y) plt.plot (imgtl.dg(y,p2Y),y,'--',linewidth=3) plt.ylim(min(y), max(y)) plt.subplot (2,2,4) plt.ylim(0,10) plt.xlim(0,10) text1='rms_x = '+str('{0:.2f}'.format((np.mean(stdx0[len(stdx0)-2:len(stdx0)+2])))) \ +'+/-'+str('{0:.2f}'.format(np.std(stdx0[len(stdx0)-2:len(stdx0)+2]))) text2='rms_y = '+str('{0:.2f}'.format((np.mean(stdy0[len(stdy0)-2:len(stdy0)+2])))) \ +'+/-'+str('{0:.2f}'.format(np.std(stdy0[len(stdy0)-2:len(stdy0)+2]))) text3='<xy>/(rms_x*rms_y) = '+str('{0:.2f}'.format((np.mean(correl0[len(correl0)-2:len(correl0)+2])))) \ +'+/-'+str('{0:.2f}'.format(np.std(correl0[len(correl0)-2:len(correl0)+2])))