def updateRoi(): selected = roi.getArrayRegion(self.ImageArray.T, self.img) p2.plot(selected.sum(axis=1), clear=True) datahor = selected.sum(axis=1) FittedParamsHor = MatTools.FitGaussian(datahor)[0] xhor = np.arange(datahor.size) p2.plot(MatTools.gaussian(xhor,*FittedParamsHor), pen=(0,255,0)) p3.plot(selected.sum(axis=0), clear=True).rotate(-90) datavert = selected.sum(axis=0) FittedParamsVert = MatTools.FitGaussian(datavert)[0] xvert = np.arange(datavert.size) p3.plot(MatTools.gaussian(xvert,*FittedParamsVert), pen=(0,255,0)).rotate(-90) hLine.setPos(FittedParamsVert[2]+roi.pos()[1]) vLine.setPos(FittedParamsHor[2]+roi.pos()[0]) pos = np.array([[(FittedParamsHor[2]+roi.pos()[0]),(FittedParamsVert[2]+roi.pos()[1])]]) peak.setData(pos=pos,symbol=symbol,size=25, symbolPen='g', symbolBrush='g')
def updateRoi(): ''' In this method the Roi data is updated. It is called when the Roi position and/or shape changes and when the image is updated. The ROI data is summed up in vertical and horizontal directions and plotted in the according diagrams. The total sum of the ROI is seen as Amplitude and displayed in the plot. A gaussian is fitted to the sums in horizontal and vertical direction. The fit results are used to plot the peak position and contour. The beam properties are stored in a buffer and can be plotted in the time evolution plot. ''' global ImageArray, img, databuffer # Get ROI data selected = roi.getArrayRegion(ImageArray.T, img) # Calculate amplitude amplitude = selected.sum() # Shift buffer one step forward and store amplitude and time stamp databuffer[1:,:-1] = databuffer[1:,1:] actualtime = time.time() databuffer[1,-1] = actualtime - starttime databuffer[2,-1] = amplitude # Plot sum in horizontal direction and fit gaussian datahor = selected.sum(axis=1) p2.plot(datahor, clear=True) FittedParamsHor = MatTools.FitGaussian(datahor)[0] xhor = np.arange(datahor.size) if ui.fitCheck.isChecked(): p2.plot(MatTools.gaussian(xhor,*FittedParamsHor), pen=(0,255,0)) # Plot amplitude xamp = np.array([1.,2.]) yamp = np.array([amplitude]) amphist.plot(xamp, yamp, stepMode=True, clear=True, fillLevel=0, brush=(0,0,255,150)) # Plot sum in vertical direction and fit gaussian, save fit results in buffer and show in text box datavert = selected.sum(axis=0) p3.plot(datavert, clear=True).rotate(90) FittedParamsVert = MatTools.FitGaussian(datavert)[0] xvert = np.arange(datavert.size) if ui.fitCheck.isChecked(): p3.plot(MatTools.gaussian(xvert,*FittedParamsVert), pen=(0,255,0)).rotate(90) poshor = FittedParamsHor[2]+roi.pos()[0] posvert = FittedParamsVert[2]+roi.pos()[1] waistx = FittedParamsHor[1] waisty = FittedParamsVert[1] databuffer[3,-1] = poshor databuffer[4,-1] = posvert databuffer[5,-1] = waistx databuffer[6,-1] = waisty updatetext(amplitude,poshor,posvert,waistx,waisty) if ui.trackCheck.isChecked(): # Adjust cross hair hLine.setPos(FittedParamsVert[2]+roi.pos()[1]) vLine.setPos(FittedParamsHor[2]+roi.pos()[0]) vLine.show() hLine.show() # Plot peak pos = np.array([[(FittedParamsHor[2]+roi.pos()[0]),(FittedParamsVert[2]+roi.pos()[1])]]) peak.setData(pos,clear=True) # Plot contour x = np.linspace(-(FittedParamsHor[1]),(FittedParamsHor[1]),1000) sigmax = FittedParamsHor[1] sigmay = FittedParamsVert[1] y = ellipse(x,sigmax,sigmay) x = np.append(x,-x) y = np.append(y,-y) x += FittedParamsHor[2]+roi.pos()[0] y += FittedParamsVert[2]+roi.pos()[1] # X,Y = np.meshgrid(x,y) # contour.clear() contour.setData(x,y,clear=True) else: # view.removeItem(hLine) # view.removeItem(vLine) # Hide cross hair, peak and contour if 'Track beam' is not checked vLine.hide() hLine.hide() contour.clear() peak.clear() #When checked, the reference beam peak and contour is plotted if ui.refCheck.isChecked(): peakposition = np.array([[ui.x0Spin.value(),ui.y0Spin.value()]]) peakpos.setData(peakposition,clear=True) sigmax = ui.sigmaxSpin.value() sigmay = ui.sigmaySpin.value() x = np.linspace(-(sigmax),(sigmax),1000) y = ellipse(x,sigmax,sigmay) x = np.append(x,-x) y = np.append(y,-y) x += ui.x0Spin.value() y += ui.y0Spin.value() # X,Y = np.meshgrid(x,y) # contour.clear() refcontour.setData(x,y,clear=True) else: peakpos.clear() refcontour.clear() # Update the time evolution plot updatetimescrolling()
def beamProfilerAnalysis(): ''' In this method the Roi data is updated. It is called when the Roi position and/or shape changes and when the image is updated. The centroid of the roi is determined two cuts (x and y through the roi are fit by gaussians and both the data and the fit is shown. Peak amplitude is shown and the localtion of the centroid ''' global ImageArray, img, databuffer # Get ROI data selected = roi.getArrayRegion(ImageArray.T, img) # Calculate amplitude amplitude = np.nansum(selected) # Shift buffer one step forward and store amplitude and time stamp databuffer[1:,:-1] = databuffer[1:,1:] actualtime = time.time() databuffer[1,-1] = actualtime - starttime databuffer[2,-1] = amplitude #find centroid # xs,ys = selected.shape # X,Y=np.meshgrid(np.arange(ys),np.arange(xs)) # ss = selected-np.nanmin(selected) # s = np.nansum(ss) # my = int(np.nansum(X*ss)/s) # mx = int(np.nansum(Y*ss)/s) #find max mx,my = np.where(selected==np.nanmax(selected)) mx, my = mx[0],my[0] # Plot sum in horizontal direction and fit gaussian datahor = selected[:,my] p2.plot(datahor, clear=True) FittedParamsHor = MatTools.FitGaussian(datahor)[0] xhor = np.arange(datahor.size) if ui.fitCheck.isChecked(): p2.plot(MatTools.gaussian(xhor,*FittedParamsHor), pen=(0,255,0)) # Plot amplitude xamp = np.array([1.,2.]) yamp = np.array([amplitude]) amphist.plot(xamp, yamp, stepMode=True, clear=True, fillLevel=0, brush=(0,0,255,150)) # Plot sum in vertical direction and fit gaussian, save fit results in buffer and show in text box datavert = selected[mx] p3.plot(datavert, clear=True).rotate(90) FittedParamsVert = MatTools.FitGaussian(datavert)[0] xvert = np.arange(datavert.size) if ui.fitCheck.isChecked(): p3.plot(MatTools.gaussian(xvert,*FittedParamsVert), pen=(0,255,0)).rotate(90) poshor = FittedParamsHor[2]+roi.pos()[0] posvert = FittedParamsVert[2]+roi.pos()[1] waistx = FittedParamsHor[1] waisty = FittedParamsVert[1] databuffer[3,-1] = poshor databuffer[4,-1] = posvert databuffer[5,-1] = waistx databuffer[6,-1] = waisty updatetext(amplitude,poshor,posvert,waistx,waisty) if ui.trackCheck.isChecked(): # Adjust cross hair # hLine.setPos(FittedParamsVert[2]+roi.pos()[1]) # vLine.setPos(FittedParamsHor[2]+roi.pos()[0]) hLine.setPos(my+roi.pos()[1]) vLine.setPos(mx+roi.pos()[0]) vLine.show() hLine.show() # Plot peak pos = np.array([[(FittedParamsHor[2]+roi.pos()[0]),(FittedParamsVert[2]+roi.pos()[1])]]) peak.setData(pos,clear=True) # Plot contour x = np.linspace(-(FittedParamsHor[1]),(FittedParamsHor[1]),1000) sigmax = FittedParamsHor[1] sigmay = FittedParamsVert[1] y = ellipse(x,sigmax,sigmay) x = np.append(x,-x) y = np.append(y,-y) x += FittedParamsHor[2]+roi.pos()[0] y += FittedParamsVert[2]+roi.pos()[1] # X,Y = np.meshgrid(x,y) # contour.clear() contour.setData(x,y,clear=True) else: # view.removeItem(hLine) # view.removeItem(vLine) # Hide cross hair, peak and contour if 'Track beam' is not checked vLine.hide() hLine.hide() contour.clear() peak.clear() # Update the time evolution plot updatetimescrolling()