def pathscan(scannables, path, detector, exposure, *args): #@UndefinedVariable ''' Scan a group of scannables following the specified path and collect data at each point from specified detector and time''' sg = ScannableGroup() for each in scannables: sg.addGroupMember(each) sg.setName("pathgroup") scan([sg, path, detector, exposure] + list(args))
def pathscan(*args): #@UndefinedVariable ''' Scan a group of scannables following the specified path and collect data at each point from scannables args ''' starttime = time.ctime() if PRINTTIME: print "=== Scan started: " + starttime newargs = [] i = 0 while i < len(args): arg = args[i] if type(arg) == TupleType: if allElementsAreScannable(arg): scannableGroup = ScannableGroup("pathgroup") for each in arg: scannableGroup.addGroupMember(each) newargs.append(scannableGroup) elif allElementsAreListOfNumber(arg): newargs.append(arg) else: raise TypeError, "Only tuple of scannables and tuple of list of numbers are supported." else: newargs.append(arg) i = i + 1 scan(newargs) if PRINTTIME: print("=== Scan ended: " + time.ctime() + ". Elapsed time: %.0f seconds" % (time.time() - starttime))
def pathscan(scannables, path, args=[]): #@UndefinedVariable ''' Scan a group of scannables following the specified path and collect data at each point from scannables args ''' sg = ScannableGroup() for each in scannables: sg.addGroupMember(each) sg.setName("pathgroup") scan([sg, path] + args)
def analyserpathscan(*args): ''' perform single/multiple regions analyser data collection at each point on the specified path, and produce a single scan file recording all scannables' poistions and metadata, along with analyser scan data under region's name as NXdetector node. implementation details: This function pre-process sequence file to set up analyser 'ew4000' ready for data collection. It creates scannable group to support point-to-point concurrent scan. ''' starttime = time.ctime() if PRINTTIME: print "=== Scan started: " + starttime newargs = [] i = 0 while i < len(args): arg = args[i] if type(arg) == TupleType: if allElementsAreScannable(arg): scannableGroup = ScannableGroup("pathgroup") for each in arg: scannableGroup.addGroupMember(each) newargs.append(scannableGroup) elif allElementsAreListOfNumber(arg): newargs.append(arg) else: raise TypeError, "Only tuple of scannables and tuple of list of numbers are supported." else: newargs.append(arg) i = i + 1 if isinstance(arg, EW4000): controller = Finder.find("SequenceFileObserver") xmldir = InterfaceProvider.getPathConstructor( ).createFromDefaultProperty() + "xml" + os.sep filename = xmldir + args[i] if (OsUtil.isWindows()): FilenameUtil.setPrefix("D:") filename = FilenameUtil.convertSeparator(filename) controller.update(controller, SequenceFileChangeEvent(filename)) sleep(2.0) jythonServerStatus = InterfaceProvider.getJythonServerStatusProvider( ).getJythonServerStatus() while (jythonServerStatus.isScriptOrScanPaused()): sleep(1.0) arg.setSequenceFilename(filename) sequence = arg.loadSequenceData(filename) if isinstance(arg.getCollectionStrategy(), EW4000CollectionStrategy): arg.getCollectionStrategy().setSequence(sequence) i = i + 1 scan(newargs) if PRINTTIME: print("=== Scan ended: " + time.ctime() + ". Elapsed time: %.0f seconds" % (time.time() - starttime))
def analyserscan(*args): ''' a more generalised scan that extends standard GDA scan syntax to support 1. scannable tuple (e.g. (s1,s2,...) argument) as scannable group and 2. its corresponding path tuple (e.g. tuple of position lists), if exist, and 3. EW4000 analyser detector that takes a reion sequence file name as input, if exist, and 4. syntax 'analyserscan ew4000 "user.seq ...' for analyser scan only It parses input parameters described above before delegating to the standard GDA scan to do the actual data collection. Thus it can be used anywhere the standard GDA 'scan' is used. ''' starttime = time.ctime() if PRINTTIME: print "=== Scan started: " + starttime newargs = [] i = 0 while i < len(args): arg = args[i] if i == 0 and isinstance(arg, EW4000): newargs.append(zeroScannable) newargs.append(0) newargs.append(0) newargs.append(1) newargs.append(arg) elif type(arg) == TupleType: if allElementsAreScannable(arg): #parsing (scannable1, scannable2,...) as scannable group scannableGroup = ScannableGroup() for each in arg: scannableGroup.addGroupMember(each) scannableGroup.setName("pathgroup") newargs.append(scannableGroup) elif allElementsAreListOfNumber(arg): #parsing scannable group's position lists newargs.append(arg) elif allElementsAreNumber(arg): #parsing scannable group's position lists newargs.append(arg) elif allElementsAreTuplesOfNumbers(arg): # This case is to fix BLIX-206 when using a scannable group with a tuple of tuples of positions newargs.append(arg) else: raise TypeError, "Only tuple of scannables, tuple of numbers, tuple of tuples of numbers, or list of numbers are supported." else: newargs.append(arg) i = i + 1 if isinstance(arg, EW4000): controller = Finder.find("SequenceFileObserver") xmldir = InterfaceProvider.getPathConstructor( ).getVisitSubdirectory('xml') + os.sep filename = xmldir + args[i] if (OsUtil.isWindows()): FilenameUtil.setPrefix("D:") filename = FilenameUtil.convertSeparator(filename) controller.update(controller, SequenceFileChangeEvent( filename)) #update client sequence view sleep(2.0) jythonServerStatus = InterfaceProvider.getJythonServerStatusProvider( ).getJythonServerStatus() while (jythonServerStatus.isScriptOrScanPaused()): sleep(1.0) # wait for user saving dirty file arg.setSequenceFilename(filename) sequence = arg.loadSequenceData(filename) if isinstance(arg.getCollectionStrategy(), EW4000CollectionStrategy): arg.getCollectionStrategy().setSequence(sequence) i = i + 1 scan(newargs) if ENABLEZEROSUPPLIES: zerosupplies() # @UndefinedVariable if PRINTTIME: print("=== Scan ended: " + time.ctime() + ". Elapsed time: %.0f seconds" % (time.time() - starttime))
clock = ShowClockClass('clock') print 'For time measuring, using "lineTime" and "pointTime" for the time spent on one line of a scan and each scan point, respectively' lineTime = LineTimeClass('lineTime') pointTime = PointTimeClass('pointTime') print "To control the speed of a scan, using 'waitTimer' for wait delay or 'scanTimer' or 'timer' as scannable" waitTimer = WaitTimerClass('waitTimer') #To scan against time. timer = ScanTimerClass('timer') scanTimer = ScanTimerClass('scanTimer') Timers = ScannableGroup() Timers.setName('Timers') Timers.addGroupMember(clock) Timers.addGroupMember(stopwatch) Timers.addGroupMember(timekeeper) Timers.addGroupMember(lineTime) Timers.addGroupMember(pointTime) Timers.addGroupMember(waitTimer) Timers.addGroupMember(timer) Timers.addGroupMember(scanTimer) dummyCounter = SoftCounterClass('dummyCounter') dummyCounter1 = SoftCounterClass('dummyCounter1') dummyCounter2 = SoftCounterClass('dummyCounter2') from Diamond.PseudoDevices.DummyShutter import DummyShutterClass dummyShutter = DummyShutterClass('dummyShutter', delayAfterOpening=0.5,
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
def miscan(*args): ''' a more generalised scan that extends standard GDA scan syntax to support 1. scannable tuple (e.g. (s1,s2,...) argument) as scannable group, 2. its corresponding path tuple (e.g. list of position tuples), if exist, and 3. area detector that takes 2 input numbers - 1st input is the number of images to be collected at each point, if omitted it default to 1, and 2nd input is detector exposure time which must be provided, 4. syntax 'miscan mpx 10 0.1 ...' is supported for collecting 10 images at a single point. It parses input parameters described above before delegating to the standard GDA scan to do the actual data collection. Thus it can be used anywhere the standard GDA 'scan' is used. ''' starttime = time.ctime() if PRINTTIME: print "=== Scan started: " + starttime newargs = [] i = 0 while i < len(args): arg = args[i] if i == 0 and isinstance(arg, NXDetector): newargs.append(zeroScannable) newargs.append(0) newargs.append(0) newargs.append(1) newargs.append(arg) elif type(arg) == TupleType: if allElementsAreScannable(arg): #parsing (scannable1, scannable2,...) as scannable group scannableGroup = ScannableGroup() for each in arg: scannableGroup.addGroupMember(each) scannableGroup.setName("pathgroup") newargs.append(scannableGroup) elif allElementsAreListOfNumber(arg): #parsing scannable group's position lists newargs.append(arg) elif allElementsAreNumber(arg): #parsing scannable group's position lists newargs.append(arg) elif allElementsAreTuplesOfNumbers(arg): # This case is to fix BLIX-206 when using a scannable group with a tuple of tuples of positions newargs.append(arg) elif allElementsAreString(arg): newargs.append(arg) else: raise TypeError, "Only tuple of scannables, tuple of numbers, tuple of tuples of numbers, list of numbers, or tuple of Strings are supported." else: newargs.append(arg) i = i + 1 if isinstance(arg, NXDetector): decoratee = arg.getCollectionStrategy().getDecoratee() if isinstance(decoratee, ImageModeDecorator): if i < len( args) - 1: # more than 2 arguments following detector if type(args[i]) == IntType and ( type(args[i + 1]) == IntType or type(args[i + 1]) == FloatType): #support the miscan command - first input after detector is number of images per data point decoratee.setNumberOfImagesPerCollection(args[i]) elif type(args[i]) == FloatType and ( type(args[i + 1]) == IntType or type(args[i + 1]) == FloatType): raise TypeError, "Number of images to collect per scan data point must be Int type." elif type(args[i]) == FloatType and not ( type(args[i + 1]) == IntType or type(args[i + 1]) == FloatType): decoratee.setNumberOfImagesPerCollection(1) elif i == len( args ) - 1: #followed by only one argument - must be exposure time decoratee.setNumberOfImagesPerCollection(1) else: #exposure time is the last one in the scan command newargs.append(args[i]) #single image per data point i = i + 1 scan([e for e in newargs]) if PRINTTIME: print("=== Scan ended: " + time.ctime() + ". Elapsed time: %.0f seconds" % (time.time() - starttime))
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
# 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
def miscan(*args): ''' a more generalised scan that extends standard GDA scan syntax to support 1. scannable tuple (e.g. (s1,s2,...) argument) as scannable group, 2. its corresponding path tuple (e.g. list of position tuples), if exist, and 3. area detector that takes 2 input numbers - 1st one is detector exposure time which must be provided, 2nd one is number of image to be collected at each point which if omitted default to 1 4. syntax 'miscan pixis_summed 0.1 10 ...' is supported for collecting multiple images at a single point without scanning any scannable. It parses input parameters described above before delegating to the standard GDA scan to do the actual data collection. Thus it can be used anywhere the standard GDA 'scan' is used. ''' starttime = time.ctime() if PRINTTIME: print "=== Scan started: " + starttime newargs = [] i = 0 while i < len(args): arg = args[i] if i == 0 and isinstance(arg, NXDetector): newargs.append(zeroScannable) newargs.append(0) newargs.append(0) newargs.append(1) newargs.append(arg) elif type(arg) == TupleType: if allElementsAreScannable(arg): #parsing (scannable1, scannable2,...) as scannable group scannableGroup = ScannableGroup() for each in arg: scannableGroup.addGroupMember(each) scannableGroup.setName("pathgroup") newargs.append(scannableGroup) elif allElementsAreListOfNumber(arg): #parsing scannable group's position lists newargs.append(arg) elif allElementsAreNumber(arg): #parsing scannable group's position lists newargs.append(arg) elif allElementsAreTuplesOfNumbers(arg): # This case is to fix BLIX-206 when using a scannable group with a tuple of tuples of positions newargs.append(arg) else: raise TypeError, "Only tuple of scannables, tuple of numbers, tuple of tuples of numbers, or list of numbers are supported." else: newargs.append(arg) i = i + 1 if isinstance(arg, NXDetector): decoratee = arg.getCollectionStrategy().getDecoratee() if isinstance(decoratee, AutoSummingProcessDecorator): #in dummy mode, AutoSummingProcessDecorator is 1st child decoratee.setAcquireTime(args[i]) elif isinstance(decoratee.getDecoratee(), AutoSummingProcessDecorator): #in live mode AutoSummingProcessDecorator is child's child decoratee.getDecoratee().setAcquireTime(args[i]) else: #exposure time is the last one in the scan command newargs.append(args[i]) #single image per data point if i < len(args) - 1: i = i + 1 # expecting number of images per data point if type(args[i]) == IntType: newargs.append(args[i - 1] * args[i]) elif type(args[i]) == FloatType: raise TypeError, "Number of image to collect per scan data point must be int type." i = i + 1 # scan(newargs) scan([e for e in newargs]) if PRINTTIME: print("=== Scan ended: " + time.ctime() + ". Elapsed time: %.0f seconds" % (time.time() - starttime))
alias("setVisit") def isgold(): return saz.getPosition() < -18 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"