Example #1
0
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))
Example #2
0
    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
Example #3
0
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)
Example #4
0
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
Example #5
0
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
Example #6
0
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))
Example #7
0
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
Example #8
0
timekeeper.autoReset = False
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',
Example #9
0
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))
Example #10
0
    def __init__(self, name):
        self.name = name
        self.inputNames = ['epoch']
        self.extraNames = []
        self.outputFormat = ['%.3f']
        self.level = 9
        self.target_time = None

    def asynchronousMoveTo(self, time):
        self.target_time = time
        
    def isBusy(self):
        if self.target_time is None:
            return False
        return time.time() <= self.target_time
    
    def getPosition(self):
        return time.time()
       

t = TimeSinceScanStart('t')
dt = TimeSinceLastGetPosition("dt")
w = Wait("w")
clock = TimeOfDay('clock')
epoch = TimeSinceEpoch('epoch')

timerelated = ScannableGroup()
timerelated.setName("timerelated")
timerelated.setGroupMembers([t, dt, w, clock, epoch])
Example #11
0
# 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
Example #12
0
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))
Example #13
0
   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"
execfile(gdaScriptDir + "/beamline/pgm_with_backlash.py")