コード例 #1
0
ファイル: align.py プロジェクト: timrae/pylase
 def findFirstSignal(self,p0=None,res=FIRST_SIGNAL_RESOLUTION,span=None,profitFunction=None,threshold=None, softThreshold=None, plotFlag=False):
     """ Automatically look for the first sign of a signal by measuring across a grid, outwards from the center
     point, and stopping the measurement prematurely if the threshold is exceeded for profitFunction """
     if p0 is None: p0=self.ctrl.getCoordinates()
     if span is None: span=self.ctrl.GetMaxTravel()/2
     if profitFunction is None: 
         pm=PowerMeter()
         profitFunction=lambda : pm.readPowerAuto(tau=1)
     # If the current center point already has a signal then stop the search before it begins
     profit=profitFunction()
     if profit >threshold: return (self.ctrl.getCoordinates(),profit)
     # Create grid points evenly spaced according to span and resolution about p0
     x,y=self.gridPoints(span,res,p0)
     #x=x[logical_and(x>=0,x<=self.ctrl.GetMaxTravel())]
     #y=y[logical_and(y>=0,y<=self.ctrl.GetMaxTravel())]
     # Permute the x values so that they start at the center and move outwards
     xp,xip=self.permuteOutwards(x)
     #yp,yip=self.permuteOutwards(y) # This may significantly slow down the motor movement
     P=self.measureGrid(x,y,xip,profitFunction,threshold,softThreshold)
     # Optionally plot the grid
     if plotFlag:
         plt.imshow(P,extent=[min(x),max(x),max(y),min(y)])
         plt.show()
     # Extract the maximum value
     maxIdx=where(P==P.max())
     self.coordinates=(x[maxIdx[1][0]],y[maxIdx[0][0]])
     # Move to the position of max value
     self.moveTo(self.coordinates)
     # Measure the profit again
     finalProfit=profitFunction()
     return (self.coordinates,finalProfit)
コード例 #2
0
ファイル: align.py プロジェクト: timrae/pylase
 def autoalign(self,p0=None,res=1,span=None,profitFunction=None):
     """ Automatically align the piezo stage to get maximum value from profitFunction using a discrete search algorithm
     input arguments are starting position p0 (x,y) tuple in um
     grid resolution in um
     grid span (i.e. +/- how much to search over) in um
     a profitFunction method which gives the profit for optimization (e.g. the total power) """
     # Setup the input variables properly
     if p0 is None: p0=self.coordinates
     if span is None: span=self.ctrl.GetMaxTravel()/2
     if profitFunction is None: 
         pm=PowerMeter()
         profitFunction=lambda : pm.readPowerAuto()
     # Create a discrete grid with specified span and resolution centered at p0
     x,y=self.gridPoints(span,res,p0)
     #x,y=self.gridPoints(maxTravel/2,ROUGH_GRID_RES,(maxTravel/2,maxTravel/2))
     ix, iy = self.searchGrid(x,y,p0,profitFunction)
     self.coordinates = (x[ix], y[iy])
     self.moveTo(self.coordinates)
     finalProfit=profitFunction()
     # TO DO: send a pyqt signal when finished so it can be run in a separate thread
     return (self.coordinates,finalProfit)