def testStartStop(self): print("\n=== Start/stop at each step ===") table_scan = TableScan( ("X", "Y", "Wait For", "Value"), [ ["1", "2", "counter", "10"], ["3", "4", "counter", "10"], ], pre=Set('shutter', 1), post=Set('shutter', 0), start=[ Set('counter:reset', 1, completion=True), Set('counter:enable', 1, completion=True), Set('daq:enable', 1, completion=True) ], stop=[ Set('daq:enable', 0, completion=True), Set('counter:enable', 0, completion=True) ], ) cmds = handle(table_scan) self.assertEqual( str(cmds), "[Set('shutter', 1), Set('X', 1.0), Set('Y', 2.0), Set('counter:reset', 1, completion=True), Set('counter:enable', 1, completion=True), Set('daq:enable', 1, completion=True), Wait('counter', 10.0, comparison='>=', tolerance=0.1), Log('X', 'Y', 'counter'), Set('daq:enable', 0, completion=True), Set('counter:enable', 0, completion=True), Set('X', 3.0), Set('Y', 4.0), Set('counter:reset', 1, completion=True), Set('counter:enable', 1, completion=True), Set('daq:enable', 1, completion=True), Wait('counter', 10.0, comparison='>=', tolerance=0.1), Log('X', 'Y', 'counter'), Set('daq:enable', 0, completion=True), Set('counter:enable', 0, completion=True), Set('shutter', 0)]" )
def testBasics(self): align = AlignmentScan("motor_x", 0, 10, 0.5, "seconds", 0.5, "signal", pre=Set("motor_y", 3), find_command="FindPeak") cmds = align.createScan() print CommandSequence(cmds) self.assertEqual( str(cmds), "[Set('Demo:CS:Scan:Fit:Height', 0), Set('motor_y', 3), Loop('motor_x', 0, 10, 0.5, [ Delay(0.5), Log('signal', 'motor_x'), Script('WriteDataToPV', 'motor_x', 'Demo:CS:Scan:Fit:Data:X'), Script('WriteDataToPV', 'signal', 'Demo:CS:Scan:Fit:Data:Y', '-', '1') ]), Script('FindPeak', 'motor_x', 'signal', '-', '1', 'Demo:CS:Scan:Fit:Pos', 'Demo:CS:Scan:Fit:Height', 'Demo:CS:Scan:Fit:Width')]" )
Created on Apr 17, 2015 @author: shen ''' from scan.client.scanclient import ScanClient from scan.commands import Set, Loop, Delay, Log, Comment from scan.client.logdata import createTable if __name__ == '__main__': orig_motor_x = 0 orig_motor_y = 0 try: cmds = [ Comment("Example"), Set('motor_x', 1, completion=True), Loop('motor_x', 1, 5, 1, [ Loop('motor_y', 1, 3, 1, [ Loop('loc://i(0)', 1, 2, 1, [Delay(1), Log('motor_x', 'motor_y', 'neutrons')]), ]), ]), Set('motor_x', orig_motor_x, completion=True), Set('motor_y', orig_motor_y, completion=True) ] for cmd in cmds: print cmd exit() client = ScanClient('localhost', 4810) scid = client.submit(cmds, name="2D scan example")
@author: shen ''' from scan.client.scanclient import ScanClient from scan import createNDimScan as ndim from scan.commands import Comment, Delay, Set from scan.client.logdata import createTable if __name__ == '__main__': orig_motor_x = 0 orig_motor_y = 0 cmds = ndim(Comment("Example"), Set('motor_x', 1), ('motor_x', 1, 5, 1), ('motor_y', 1, 3, 1), ('loc://i(0)', 1, 2, 1), Set('neutrons', 0, completion=True, readback=False), Delay(1), 'neutrons', 'setpoint') for cmd in cmds: print cmd exit() try: client = ScanClient('localhost', 4810) scid = client.submit(cmds, name="2D ndim scan example") client.waitUntilDone(scid) print "Number of log calls: %d" % client.lastSerial(scid) # get raw data back as a Python dict data = client.getData(scid) print data
''' from scan.client.scanclient import ScanClient from scan import createNDimScan as ndim from scan.commands import Comment, Delay, Set from scan.client.logdata import createTable if __name__ == '__main__': orig_motor_x = 0 orig_motor_y = 0 cmds = ndim(Comment("Example"), Set('motor_x', 1), ('motor_x', 1, 5, 1), ('motor_y', 1, 3, 1), Set('neutrons', 0, completion=True, readback=False), Delay(1), 'neutrons', 'setpoint') try: client = ScanClient('localhost', 4810) scid = client.submit(cmds, name="2D ndim scan example") client.waitUntilDone(scid) print "Number of log calls: %d" % client.lastSerial(scid) # get raw data back as a Python dict data = client.getData(scid) print data # Create table for motor_x, motor_y and neutrons
def scan2d(self, device1, device2, meas_dev, **kwds): """ Perform a 2-D alignment scan, it checks the readback within given tolerance, or waits callback completion if readback is `False`, for each setting. If original setting is provided, it will restore to this point after scan finished. If there is any error, it will try again, then abort. acceptable kwds key words: - title: job title for a scan, "phyutil 1D Scan" by default - orig1: original settings for `device`, default None. - readback1: `False` to not check any readback, `True` to wait for readback from the 'device', or name of specific device to check for readback. - tolerance1:Tolerance when checking numeric `readback`, 0 by default. - orig2: original settings for `device`, default None. - readback2: `False` to not check any readback, `True` to wait for readback from the 'device', or name of specific device to check for readback. - tolerance2:Tolerance when checking numeric `readback`, 0 by default. - timeout: Timeout in seconds, used for `completion` and `readback` check, 5.0 by default. - ramping: ramping `device` to start at beginning, and ramp back to original after finish. If orig is not given, then ignore since not know where to go. False by default. `False` to directly jump to start for the 'device', `True` to ramp to start with same step for the 'device', - delay: delay in seconds, 5.0 by default. - wait: whether wait until done, `True` by default - samples: how many point taken for each measurement device, 1 by default - compress: how to compress data if multiple samples are taken, None by default. Has to be: `None`: no compress, and keep all data as it is; `average`: take an average. :param device1: first dimension information with format [Device name, start, stop, step] :param device2: second dimension information with format [Device name, start, stop, step] :param meas_dev: Device to measure :return: a table with column following the device order: device, meas_dev :raise: """ if not isinstance(device1, (list, tuple)) or len(device1) != 4 or \ not isinstance(device2, (list, tuple)) or len(device2) != 4: raise RuntimeError("Scan parameters are not sufficient.") if not isinstance(device1[0], str): raise Exception("Expecting device1 name, got '%s'" % str(device1[0])) else: # Ensure device is NOT unicode object until # it is supported by PyScanClient library. device1[0] = str(device1[0]) if not isinstance(device2[0], str): raise Exception("Expecting device2 name, got '%s'" % str(device2[0])) else: # Ensure device is NOT unicode object until # it is supported by PyScanClient library. device2[0] = str(device2[0]) comments = kwds.get("title", "phyutil 2D Scan") orig1 = kwds.get("orig1", None) readback1 = kwds.get("readback1", False) tolerance1 = kwds.get("tolerance1", 0.0) orig2 = kwds.get("orig2", None) readback2 = kwds.get("readback2", False) tolerance2 = kwds.get("tolerance2", 0.0) timeout = kwds.get("timeout", 5.0) ramping = kwds.get("ramping", False) delay = kwds.get("delay", 5.0) samples = int(kwds.get("samples", 1)) wait = kwds.get('wait', True) compress = kwds.get("compress", None) completion = kwds.get("completion", False) errhandler = kwds.get('errhandler', None) if compress is not None: # TODO add support to compress multiple samples and compress.lower not in ["average"]: raise RuntimeError("Compress algorithm is not support yet.") scan_cmds = [] # prepare scan comments scan_cmds.append(Comment(comments)) # ramp to start point if needed if orig1 is not None and ramping: # slow ramping to the start point for scan if orig1 < device1[1]: scan_cmds.append( Loop(device1[0], orig1, device1[1], abs(device1[3]), [Delay(delay)], completion=completion, readback=readback1, tolerance=tolerance1, timeout=timeout, errhandler=errhandler)) else: scan_cmds.append( Loop(device1[0], orig1, device1[1], -abs(device1[3]), [Delay(delay)], completion=completion, readback=readback1, tolerance=tolerance1, timeout=timeout, errhandler=errhandler)) # ramp to start point if needed if orig2 is not None and ramping: # slow ramping to the start point for scan if orig2 < device2[1]: scan_cmds.append( Loop(device2[0], orig2, device2[1], abs(device2[3]), [Delay(delay)], completion=completion, readback=readback2, tolerance=tolerance2, timeout=timeout, errhandler=errhandler)) else: scan_cmds.append( Loop(device2[0], orig2, device2[1], -abs(device2[3]), [Delay(delay)], completion=completion, readback=readback2, tolerance=tolerance2, timeout=timeout, errhandler=errhandler)) # confirm start point scan_cmds.append( Set(device1[0], device1[1], completion=completion, readback=readback1, tolerance=tolerance1, timeout=timeout, errhandler=errhandler)) scan_cmds.append( Set(device2[0], device2[1], completion=completion, readback=readback2, tolerance=tolerance2, timeout=timeout, errhandler=errhandler)) # real scan if samples == 1: scan_cmds.append( Loop(device1[0], device1[1], device1[2], device1[3], [ Loop( device2[0], device2[1], device2[2], device2[3], [ Delay(delay), Log([device1[0], device2[0]] + list(meas_dev)) ], completion=completion, readback=readback2, tolerance=tolerance2, ), ], completion=completion, readback=readback1, tolerance=tolerance1, timeout=timeout, errhandler=errhandler)) else: scan_cmds.append( Loop(device1[0], device1[1], device1[2], device1[3], [ Loop( device2[0], device2[1], device2[2], device2[3], [ Loop('loc://i(0)', 1, samples, 1, [ Delay(delay), Log([device1[0], device2[0]] + list(meas_dev)) ]) ], completion=completion, readback=readback2, tolerance=tolerance2, ), ], completion=completion, readback=readback1, tolerance=tolerance1, timeout=timeout, errhandler=errhandler)) # ramp back to original setting if orig1 is not None and ramping: # slow ramping to the start point for scan if device1[2] < orig1: scan_cmds.append( Loop(device1[0], device1[2], orig1, abs(device1[3]), [Delay(delay)], completion=completion, readback=readback1, tolerance=tolerance1, timeout=timeout, errhandler=errhandler)) else: scan_cmds.append( Loop(device1[0], device1[2], orig1, -abs(device1[3]), [Delay(delay)], completion=completion, readback=readback1, tolerance=tolerance1, timeout=timeout, errhandler=errhandler)) # ramp back to original setting if orig2 is not None and ramping: # slow ramping to the start point for scan if device2[2] < orig2: scan_cmds.append( Loop(device2[0], device2[2], orig2, abs(device2[3]), [Delay(delay)], completion=completion, readback=readback2, tolerance=tolerance2, timeout=timeout, errhandler=errhandler)) else: scan_cmds.append( Loop(device2[0], device2[2], orig2, -abs(device2[3]), [Delay(delay)], completion=completion, readback=readback2, tolerance=tolerance2, timeout=timeout, errhandler=errhandler)) # confirm original setting if orig1 is not None: scan_cmds.append( Set(device1[0], orig1, completion=completion, readback=readback1, tolerance=tolerance1, timeout=timeout, errhandler=errhandler)) if orig2 is not None: scan_cmds.append( Set(device2[0], orig2, completion=completion, readback=readback2, tolerance=tolerance2, timeout=timeout, errhandler=errhandler)) if self.scanclient is None: self._connectscanserver() scid = self.scanclient.submit(scan_cmds, name=comments) if wait: self.scanclient.waitUntilDone(scid) return scid