Exemple #1
0
    def calibration(self, dYag=2):
        #pause to let user find second point
        requestInput("Use EPICS YAG motors to find the Beam spot, then press Enter...");
        xc1, yc1=self.cam1x.getPosition(), self.cam1y.getPosition();
        self.cam1.singleShot(1);
        [xz1, yz1, xsigma, ysigma, xysigma] = self.cam1.getCentroid();
        print "Point 1: (%f, %f) --> (%f, %f)" %(xz1, yz1, xc1, yc1);
        
        #Move to second point:
        self.cam1x.asynchronousMoveTo(xc1+dYag);
        self.cam1y.asynchronousMoveTo(yc1+dYag);
        while (self.cam1x.isBusy() or self.cam1y.isBusy()):
            sleep(1);

        sleep(5);
        xc2, yc2=self.cam1x.getPosition(), self.cam1y.getPosition();
        self.cam1.singleShot(1);
        [xz2, yz2, xsigma, ysigma, xysigma] = self.cam1.getCentroid();
        print "Point 2: (%f, %f) --> (%f, %f)" %(xz2, yz2, xc2, yc2);
        
        #To calculate the mapping parameters
        self.x0=(xc1*xz2-xc2*xz1)/(xz2-xz1);
        self.mx=(xc2-xc1)/(xz2-xz1);
    
        self.y0=(yc1*yz2-yc2*yz1)/(yz2-yz1);
        self. my=(yc2-yc1)/(yz2-yz1);

        #Restore to previous position:
        self.cam1x.asynchronousMoveTo(xc1);
        self.cam1y.asynchronousMoveTo(yc1);
        
        return [self.x0, self.y0, self.mx, self.my]
Exemple #2
0
    def calibrationOld(self, point1=[0, 0], point2=[2, 2]):
        xc1, yc1=point1;
        xc2, yc2=point2;

        #move to point 1
        self.cam1x.asynchronousMoveTo(xc1);
        self.cam1y.asynchronousMoveTo(yc1);
        while (self.cam1x.isBusy() or self.cam1y.isBusy()):
            sleep(1);
        self.cam1.singleShot(1);
        [xz1, yz1, xsigma, ysigma, xysigma] = self.cam1.getCentroid();
        print "Point 1: (%f, %f) --> (%f, %f)" %(xz1, yz1, xc1, yc1);
        

        #pause to let user find second point
        requestInput("Go back to EPICS YAG motors to move the Beam spot around, then press Enter...");
        #move to point 2
        self.cam1x.asynchronousMoveTo(xc2);
        self.cam1y.asynchronousMoveTo(yc2);
        while (self.cam1x.isBusy() or self.cam1y.isBusy()):
            sleep(1);
        self.cam1.singleShot(1);
        [xz2, yz2, xsigma, ysigma, xysigma] = self.cam1.getCentroid();
        print "Point 2: (%f, %f) --> (%f, %f)" %(xz2, yz2, xc2, yc2);
        
        #To calculate the mapping parameters
        self.x0=(xc1*xz2-xc2*xz1)/(xz2-xz1);
        self.mx=(xc2-xc1)/(xz2-xz1);
    
        self.y0=(yc1*yz2-yc2*yz1)/(yz2-yz1);
        self. my=(yc2-yc1)/(yz2-yz1);
        
        return [self.x0, self.y0, self.mx, self.my]
Exemple #3
0
def queryYesNo(question, default="yes"):
    """Ask a yes/no question via raw_input() and return their answer.
	
	"question" is a string that is presented to the user.
	"default" is the presumed answer if the user just hits <Enter>.
		It must be "yes" (the default), "no" or None (meaning
		an answer is required of the user).

	The "answer" return value is one of "yes" or "no".
	"""
    valid = {"yes": "yes", "y": "yes", "ye": "yes", "no": "no", "n": "no"}
    if default == None:
        prompt = " [y/n] "
    elif default == "yes":
        prompt = " [Y/n] "
    elif default == "no":
        prompt = " [y/N] "
    else:
        raise ValueError("invalid default answer: '%s'" % default)

    while True:
        choice = requestInput(question + prompt).lower()
        if default is not None and choice == '':
            return default
        elif choice in valid.keys():
            return valid[choice]
        else:
            print("Please respond with 'yes' or 'no' (or 'y' or 'n').\n")
Exemple #4
0
 def prepareForCollection(self):
     if self.scanType == ScanType.DARK_FIELD:
         str = requestInput(
             "Waiting for dark field setup  ... When finished press a key")
     elif self.scanType == ScanType.FLAT_FIELD:
         str = requestInput(
             "Waiting for flat field setup  ... When finished press a key")
     FlatFieldAndDarkFielPluginExists = False
     for item in self.andor.getAdditionalPluginList()[:]:
         if isinstance(item, FlatAndDarkFieldPlugin):
             item.setScanType(self.scanType)
             self.scanargs = [
                 self.scannable, 0, 0, 1, self.andor, self.exposureTime
             ]
             FlatFieldAndDarkFielPluginExists = True
             break
     if FlatFieldAndDarkFielPluginExists != True:
         raise Exception(
             'Flat and Dark Field plugin is not in the andor plugin list')
     return FlatFieldAndDarkFielPluginExists
 def startDetector(self, frequency, scanNumber, collectionNumber):
     print "\ncollecting %d frames, %d gates per frame, Scan number %d, Collection number %d" % (self.numFrames*self.numDefinedSequency, self.numGates, scanNumber, collectionNumber)
     if frequency <= self.boundaryFrequency:
         Thread(target=self.gateDetector, name="MythenGatedCollection", args=(self.numFrames, self.numGates, scanNumber, collectionNumber), kwargs={}).start()
         sleep(1)
     else:
         print "\nPlease start PSD collection from Mythen QT client ..."
         print "set 'Acquisition time' to %d, 'Repetitions' to %d" % (self.numGates, self.numFrames * self.numDefinedSequency)
         print "set 'Output Directory' to %s, 'File name root' to %d, 'Start index' to %d" % (self.directory, self.scanNumber, 0)
         target = requestInput("Is PSD ready, Yes or No?")
         print str(target)
         if str(target)!="Yes":
             sys.exit()
 def pescan(self, frequency=0.1,exposure=0.5,amplitude=5.0,numPoints=40, function=2, bncycle=1):
     self.directory=PathConstructor.createFromDefaultProperty()
     self.scanNumber=scanNumTracker.incrementNumber()
     self.filename=self.directory+(str(self.scanNumber))
     print self.filename
     if self.adc.getMode()=="Gate":
         self.setupADC2()
     elif self.adc.getMode()=="Trigger":
         self.configADC(200, self.adcClockRate(frequency))
     self.calculateExperimentParameters(frequency, exposure, numPoints)
     self.setupFG(freq=frequency,amp=amplitude,bncycle=self.numGates, func=function)
     # must in following order
     if self.isSampleConditioning():
         self.sampleConditioning(func=6, bncycle=1)
     self.configTFG(frequency)
     self.setupDataCapturer(self.filename, self.numGates)
     print "open fast shutter %d" % time()
     self.fastshutter.moveTo("OPEN")
     try:
         if frequency <= self.boundaryFrequency:
             for i in range(self.numCycles):
                 GeneralCommands.pause()
                 self.pedata.reset()
                 self.pedata.setCollectionNumber(i)
                 print "\ncollecting %d frames, %d gates per frame, Scan number %d, Collection number %d" % (self.numFrames*self.numDefinedSequency, self.numGates, self.scanNumber, i)
                 Thread(target=self.gateDetector, name="MythenGatedCollection", args=(self.numFrames, self.numGates, self.scanNumber, i), kwargs={}).start()
                 sleep(1)
                 #self.startDetector(frequency, self.scanNumber, i)
                 if self.adc.getMode()=="Trigger":
                     print "enable adc sampling"
                     self.adc.enable()
                 #elif self.adc.getMode()=="Continuous":
                 self.startPEDataStreamer(self.filename+"_pe_"+str(i)+".h5", 1/frequency+TIME_FUDGE_FACTOR_IN_SECONDS)
                 self.tfg.start()
                 sleep(1/frequency+GDAPROCESSTIME)
         else:
             finder=Finder.getInstance()
             print "\nPlease start PSD collection from Mythen QT client ..."
             print "    1. select 'Gated' option in the 'Runs' box first"
             print "    2. then set 'Acquisition time' to %d, 'Repetitions' to %d" % (self.numGates, self.numFrames * self.numDefinedSequency*self.numCycles)
             print "    3. set 'Output Directory' to subdirector %s under 'processing' directory, 'File name root' to %d, 'Start index' to %d" % (finder.find("GDAMetadata").getMetadataValue("subdirectory"), self.scanNumber, 0)
             target = requestInput("Is PSD ready, Yes or No?")
             print str(target)
             if str(target)!="Yes":
                 raise "Exiting program"
             for j in range(self.startCycleNumber,self.numCycles):
                 self.pedata.reset()
                 self.pedata.setCollectionNumber(j)
                 #self.startDetector(frequency, self.scanNumber, j)
                 for i in range(self.startSeqNumber, self.numDefinedSequency):
                     GeneralCommands.pause()
                     sleep(4.0)
                     self.tfg.config_cycle_for_seq(i, self.numGates, 1)
                     sleep(4.0)
                     if self.adc.getMode()=="Trigger":
                         print "enable adc sampling"
                         self.adc.enable()
                     #elif self.adc.getMode()=="Continuous":
                     self.startPEDataStreamer(self.filename+"_pe_"+str(i)+".h5", 1/frequency*self.numGates+TIME_FUDGE_FACTOR_IN_SECONDS)
                     self.tfg.start()
                     sleep(1/frequency*self.numGates+GDAPROCESSTIME)
     except:
         self.stop()
         raise
     finally:
         print "close fast shutter %d" % time()
         self.fastshutter.moveTo("CLOSE")
         self.pedata.removeMonitors()
         print "collection completed at %d" % time()
dnp.plot.image(res)

print "Calculting coms"

points = []
for i in range(res.shape[1]):
    a = res[:,i:i+1].mean(1)
    points.append(dnp.centroid(a))

coms = dnp.array(points)
coms.squeeze()
dnp.plot.line(coms)

p = dnp.fit.polyfit(dnp.arange(coms.shape[0]), coms, 1, full=True)

p[1].plot()

rotation = math.degrees(math.atan2(p[0][0],1.))

responce = requestInput("Would you like to rotate the camera stage by %f" % (rotation))

if responce == 'y' :
    print "Moving cam1.roll"
    pos cam1.roll
    inc cam1.roll rotation
    pos cam1.roll
    print "In position."