def create_group_and_tuples(self): """Function to create a scannable group from scannables passed in""" # If scan_group has already been defined in the namespace, remove scannables global scan_group if "scan_group" not in globals(): scan_group = ScannableGroup() self.insert_into_namespace("scan_group", scan_group) else: group_member_names = scan_group.getGroupMemberNames() for name in group_member_names: scan_group.removeGroupMemberByScannable(scan_group.getGroupMember(name)) # Add the primary scannable to the group self.add_scannable_to_group(self.scannable_func_list[0]) # Add the other list members to the group and append their function values to tuple list for scannable, func, scannable_start_val in self.scannable_func_list[1:]: self.add_scannable_to_group(scannable) self.append_function_values(func, scannable_start_val) # Configure the scan_group scan_group.setName("scan_group") scan_group.configure() tuples = tuple(self.tuple_list) self.insert_into_namespace("scan_points", tuples) return tuples
class TestDiffractometerScannableGroup(unittest.TestCase): def setUp(self): self.a = MockMotor() self.b = MockMotor() self.c = MockMotor() self.d = MockMotor() self.e = MockMotor() self.f = MockMotor() self.grp = ScannableGroup( 'grp', [self.a, self.b, self.c, self.d, self.e, self.f]) self.grp.configure() self.sg = DiffractometerScannableGroup( 'sixc', MockDiffcalc(6), self.grp) def testInit(self): self.assertEqual(list(self.sg.getPosition()), [0., 0., 0., 0., 0., 0.]) def testAsynchronousMoveTo(self): self.sg.asynchronousMoveTo([1, 2.0, 3, 4, 5, 6]) self.assertEqual(list(self.sg.getPosition()), [1., 2., 3., 4., 5., 6.]) def testAsynchronousMoveToWithNones(self): self.sg.asynchronousMoveTo([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]) self.sg.asynchronousMoveTo([None, None, 3.2, None, 5.2, None]) self.assertEqual(list(self.sg.getPosition()), [1., 2., 3.2, 4., 5.2, 6.]) def testGetPosition(self): #implicitely tested above pass def testWhereMoveTo(self): # just check for exceptions print self.sg.simulateMoveTo((1.23, 2, 3, 4, 5, 6)) def testIsBusy(self): self.assertEqual(self.sg.isBusy(), False) self.sg.asynchronousMoveTo([1.0, 2.0, 3.0, 4, 5, 6]) self.assertEqual(self.sg.isBusy(), True) self.b.makeNotBusy() self.assertEqual(self.sg.isBusy(), True) self.a.makeNotBusy() self.c.makeNotBusy() self.d.makeNotBusy() self.e.makeNotBusy() self.f.makeNotBusy() self.assertEqual(self.sg.isBusy(), False) def testRepr(self): print self.sg.__repr__()
def make_tomoScanDevice( tomography_theta, tomography_shutter, tomography_translation, tomography_optimizer, image_key, tomography_imageIndex ): tomoScanDevice = ScannableGroup() tomoScanDevice.addGroupMember(tomography_theta) tomoScanDevice.addGroupMember(EnumPositionerDelegateScannable("tomography_shutter", tomography_shutter)) tomoScanDevice.addGroupMember(tomography_translation) tomoScanDevice.addGroupMember(tomography_optimizer) tomoScanDevice.addGroupMember(image_key) tomoScanDevice.addGroupMember(tomography_imageIndex) tomoScanDevice.setName("tomoScanDevice") tomoScanDevice.configure() return tomoScanDevice
class TestDiffractometerScannableGroup(object): def setup_method(self): self.a = MockMotor() self.b = MockMotor() self.c = MockMotor() self.d = MockMotor() self.e = MockMotor() self.f = MockMotor() self.grp = ScannableGroup( 'grp', [self.a, self.b, self.c, self.d, self.e, self.f]) self.grp.configure() self.sg = DiffractometerScannableGroup('sixc', MockDiffcalc(6), self.grp) def testInit(self): assert list(self.sg.getPosition()) == [0., 0., 0., 0., 0., 0.] def testAsynchronousMoveTo(self): self.sg.asynchronousMoveTo([1, 2.0, 3, 4, 5, 6]) assert list(self.sg.getPosition()) == [1., 2., 3., 4., 5., 6.] def testAsynchronousMoveToWithNones(self): self.sg.asynchronousMoveTo([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]) self.sg.asynchronousMoveTo([None, None, 3.2, None, 5.2, None]) assert list(self.sg.getPosition()) == [1., 2., 3.2, 4., 5.2, 6.] def testGetPosition(self): #implicitely tested above pass def testWhereMoveTo(self): # just check for exceptions print self.sg.simulateMoveTo((1.23, 2, 3, 4, 5, 6)) def testIsBusy(self): assert not self.sg.isBusy() self.sg.asynchronousMoveTo([1.0, 2.0, 3.0, 4, 5, 6]) assert self.sg.isBusy() self.b.makeNotBusy() assert self.sg.isBusy() self.a.makeNotBusy() self.c.makeNotBusy() self.d.makeNotBusy() self.e.makeNotBusy() self.f.makeNotBusy() assert not self.sg.isBusy() def testRepr(self): print self.sg.__repr__()
def make_tomoScanDevice(tomography_theta, tomography_shutter, tomography_translation, tomography_optimizer, image_key, tomography_imageIndex): tomoScanDevice = ScannableGroup() tomoScanDevice.addGroupMember(tomography_theta) tomoScanDevice.addGroupMember( EnumPositionerDelegateScannable("tomography_shutter", tomography_shutter)) tomoScanDevice.addGroupMember(tomography_translation) tomoScanDevice.addGroupMember(tomography_optimizer) tomoScanDevice.addGroupMember(image_key) tomoScanDevice.addGroupMember(tomography_imageIndex) tomoScanDevice.setName("tomoScanDevice") tomoScanDevice.configure() return tomoScanDevice
class TestDiffractometerScannableGroupWithFailingAngleCalculator(object): def setup_method(self): class BadMockAngleCalculator: def angles_to_hkl(self, pos): raise Exception("Problem") dummy = createDummyAxes(['alpha', 'delta', 'gamma', 'omega', 'chi', 'phi']) self.group = ScannableGroup('grp', dummy) self.group.configure() self.sg = DiffractometerScannableGroup( 'sixc', BadMockAngleCalculator(), self.group) def testGetPosition(self): self.sg.getPosition() def testSimulateMoveTo(self): assert (self.sg.simulateMoveTo([1., 2., 3., 4., 5., 6.]) == "Error: Problem")
class TestDiffractometerScannableGroupWithFailingAngleCalculator(object): def setup_method(self): class BadMockAngleCalculator: def angles_to_hkl(self, pos): raise Exception("Problem") dummy = createDummyAxes( ['alpha', 'delta', 'gamma', 'omega', 'chi', 'phi']) self.group = ScannableGroup('grp', dummy) self.group.configure() self.sg = DiffractometerScannableGroup('sixc', BadMockAngleCalculator(), self.group) def testGetPosition(self): self.sg.getPosition() def testSimulateMoveTo(self): assert (self.sg.simulateMoveTo([1., 2., 3., 4., 5., 6.]) == "Error: Problem")
print " (change threshold with checkrc.minumumThreshold=12345)" print " 2. 'checktopup_time', - avoid topup period, pause 5 seconds before topup starts, 5s wait after topup finished." print " 3. 'checkfe', - check Front end shutter, pause when shutter closed, resume 60s after shutter opened." print " 4. 'checkbeam', - composite scannable of above 3 scannables" print " Checking is done every second!" from gdascripts.scannable.beamokay import WaitWhileScannableBelowThreshold, WaitForScannableState from gda.device.scannable.scannablegroup import ScannableGroup checkrc = WaitWhileScannableBelowThreshold('checkrc', ringcurrent, 190, secondsBetweenChecks=1, secondsToWaitAfterBeamBackUp=5) checktopup_time = WaitWhileScannableBelowThreshold( 'checktopup_time', topup_time, 5, secondsBetweenChecks=1, secondsToWaitAfterBeamBackUp=5) checkfe = WaitForScannableState('checkfe', fepb, secondsBetweenChecks=1, secondsToWaitAfterBeamBackUp=60) checkbeam = ScannableGroup('checkbeam', [checkrc, checkfe, checktopup_time]) checkbeam.configure() except: localStation_exception(sys.exc_info(), "creating checkbeam objects")
class PathScan(): def __init__(self, name, detectorToUse=edxd):#@UndefinedVariable self.name=name self.sg = ScannableGroup() self.pointid=[] self.path=[] self.startline=1 self.lastline=10 self.scannablelist=[] self.scannableunitlist=[] self.detector=detectorToUse self.detectorunit="s" self.exposuretime=[] def read_scan_path(self,filename): f = open(filename, "r") lines = f.readlines() f.close() lines = map(string.split, map(string.strip, lines)) self.pointid=[] self.path=[] self.scannablelist=[] self.scannableunitlist=[] self.exposuretime=[] # parsing the input data for line in lines: print line if line[0].startswith("#"): #ignore comment continue elif line[0].startswith("First"): self.startline=line[-1] elif line[0].startswith("Last"): self.lastline=line[-1] elif line[0].startswith("ScannableNames"): self.scannablelist=[globals()[x] for x in line[1:]] # get all motors self.sg.setName("pathscangroup") self.sg.setGroupMembers(self.scannablelist) self.sg.configure() elif line[0].startswith("ScannableUnits"): self.scannableunitlist=[x for x in line[1:]] else: #real data go here if int(line[0])>= self.startline or int(line[0]) <= self.lastline: self.pointid.append(int(line[0])) self.path.append([float(x) for x in line[1:]]) def setStartPoint(self, start): self.startline=start def getStartPoint(self): return self.startline def setStopPoint(self, stop): self.lastline=stop def getStopPoint(self): return self.lastline def setDetector(self, det): self.detector=det def getDetector(self): return self.detector def getPath(self): return self.path def setPath(self, path): self.path=path def getPointIDs(self): return self.pointid def setPointIDs(self, points): self.pointid=points def start(self,filename, exposureTime): ''' kept for backward compatibility''' self.read_scan_path(filename) print self.pointid print self.path print self.exposuretime pathPositions=tuple(self.path) print pathPositions scan([self.sg, pathPositions, self.detector, exposureTime]) def startScan(self,filename, exposureTime): print self.pointid print self.exposuretime pathPositions=tuple(self.path) print pathPositions scan([self.sg, pathPositions, self.detector, exposureTime]) def setName(self, name): self.name=name def getName(self): return self.name
# make an index scannable from gda.device.scannable import SimpleScannable ix = SimpleScannable() ix.name = "ix" pos ix 0 #make scannablegroup for driving sample stage from gda.device.scannable.scannablegroup import ScannableGroup idd_pos_neg = ScannableGroup() #idd_pos_neg.addGroupMember(idd_pos_neg_switchable) idd_pos_neg.addGroupMember(idd_pos_neg_switcher) idd_pos_neg.addGroupMember(idd_pos_neg_switchable) idd_pos_neg.addGroupMember(ix) idd_pos_neg.setName("idd_pos_neg") idd_pos_neg.configure() #make ScanPointProvider def readfile(filepath): """ reads a 2 column csv file returns a list of tuple """ values=[] f = open( filepath ) lines = f.readlines() f.close() lineno=0 for l in lines: lineno +=1
sample_name=metadatatweaks.SampleNameScannable("sample_name","samplename",isgoldpost=isgold) # Setting Analyser slices to 1000 #try: # analyser.setSlices(1000) #except: # print "There was a problem setting the analyser slices to 1000, please check detector parameters." #centre_energy=analyser.getCentreEnergyScannable() #centre_energy.setName("centre_energy") #centre_energy.setInputNames(["centre_energy"]) energy_group = ScannableGroup() # Make a new ScannableGroup energy_group.addGroupMember(energy) # Add members #energy_group.addGroupMember(centre_energy) energy_group.setName('energy_group') # Set the group name energy_group.configure() # Configure the group, once all the members are added print "Scannable group 'energy_group' created containing 'energy'"; print "Loading Photon and Centre Energy Scan calculator... " print "Usage: calculate_hv_scan_values(hv_start, hv_end, hv_step, start_centre_energy, centre_energy_hv_function_name)" execfile(gdaScriptDir + "photonCentreEnergyScan.py") print "Loading Secondary Scannable Group Creator Script... " print "Usage: scan_creator = ScanCreator(start, stop, step, input_list)" print "scan_creator.create_group_and_tuples()" execfile(gdaScriptDir + "scan_creator.py") print "-" *20 print "Adding PGM backlash scannables pgm_gtrans_bl and pgm_mtrans_bl" execfile(gdaScriptDir + "/beamline/pgm_with_backlash.py") print "\nLoading Work Function calculator... "
from gda.device.scannable import SimpleScannable from gda.device.scannable.scannablegroup import ScannableGroup from BeamlineI06.Mainline.xmcd import XMCDScanPositionProvider imagenum = SimpleScannable() imagenum.name = "imagenum" imagenum.moveTo(0) print "Creating energy scannable groups...\n" print " dxmcd uses iddpol & denergy" dxmcd = ScannableGroup("dxmcd", (imagenum, iddpol, denergy)) dxmcd.configure() print " uxmcd uses idupol & uenergy" uxmcd = ScannableGroup("uxmcd", (imagenum, idupol, uenergy)) uxmcd.configure() print " xxmcd uses xpol & xenergy" xxmcd = ScannableGroup("xxmcd", (imagenum, xpol, xenergy)) xxmcd.configure() print "\nCreating xmcd_positions...\n" xmcd_positions = XMCDScanPositionProvider(name='xmcd_positions', numberOfImages=10, pols=('PosCirc', 'NegCirc'), energies=(706.7, 702.3)) print " xmcd_positions.numberOfImages = %r" % xmcd_positions.numberOfImages print " xmcd_positions.pols = %r" % (xmcd_positions.pols,) print " xmcd_positions.energies = %r" % (xmcd_positions.energies,) print "\nExamples\n"