def getscandata(self, scanid, devicelist, dtype="table"): """Get scan results :param scanid: scan id number :param devicelist: a list of all wished device, which is used for table format :param dtype: returned data format, either "table" or "dict" """ if self.scanclient is None: self._connectscanserver() data = self.scanclient.getData(scanid) if dtype == "table": # Create table return createTable(data, *devicelist) elif dtype == "dict": # return dictionary return data else: raise Exception("Unsupported return data type")
if __name__ == '__main__': orig_motor = 0 try: client = ScanClient('localhost', 4810) cmds = [Comment("Example"), Set('motor_x', 1, completion=True), Loop('motor_x', 1, 10, 1, [ Delay(1.0), Log("motor_x","neutrons") ], completion=True), Set('motor_x', orig_motor, completion=True) ] scid = client.submit(cmds, name="1D scan example") client.waitUntilDone(scid) data = client.getData(scid) # Create table for motor_x and neutrons table = createTable(data, 'motor_x', 'neutrons') print "Positions: ", table[0] print "Counts : ", table[1] # Remove specific scan task client.delete(scid) # or Remove information for all completed scans client.clear() except: raise
pre=Set('motor_x', 1, completion=True), post=[ Set('motor_x', orig_motor_x, completion=True), Set('motor_y', orig_motor_y, completion=True), ], log_always=('neutrons', 'setpoint')) cmds = table.createScan() try: client = ScanClient('localhost', 4810) scid = client.submit(cmds, name="2D table 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 table = createTable(data, 'motor_x', 'motor_y', 'neutrons', 'setpoint') print "Position X: ", table[0] print "Position Y: ", table[1] print "Counts : ", table[2] print "Setpoint : ", table[3] # Remove specific scan task client.delete(scid) # or Remove information for all completed scans client.clear() except: raise
<time>1427913271459</time> <value>3.0</value> </sample> <sample id="14"> <time>1427913271559</time> <value>4.0</value> </sample> </samples> </device> </data> """ # client.getData(id) calls this to turn the XML data into a data dict: data = parseXMLData(xml_text) print(data) # Direct access to data dict print("Times: ", [str(getDatetime(time)) for time in data['motor_x']['time']]) print("Values: ", data['motor_x']['value']) # Demo of sample iterator for s in iterateSamples(data, 'motor_x'): print("%s (%2d): %s" % (str(getDatetime(s[1])), s[0], str(s[2]))) # Create table, i.e. align samples for different devices by sample ID: table = createTable(data, 'motor_x', 'motor_y') print(table[0]) print(table[1]) # With numpy/scipy: plot(table[0], table[1]) etc.
[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") client.waitUntilDone(scid) print "Number of log calls: %d" % client.lastSerial(scid) # get raw data back as a Python dict data = client.getData(scid) # Create table for motor_x, motor_y and neutrons table = createTable(data, 'motor_x', 'motor_y', 'neutrons') print "Position X: ", table[0] print "Position Y: ", table[1] print "Counts : ", table[2] # Remove specific scan task client.delete(scid) # or Remove information for all completed scans client.clear() except: raise
post=[Set('motor_x', orig_motor_x, completion=True), Set('motor_y', orig_motor_y, completion=True),], start=Set("neutrons", 0, completion=True, timeout=10), log_always=('neutrons', 'setpoint') ) cmds = table.createScan() try: client = ScanClient('localhost', 4810) scid = client.submit(cmds, name="2D table 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 table = createTable(data, 'motor_x', 'motor_y', 'neutrons', 'setpoint') print "Position X: ", table[0] print "Position Y: ", table[1] print "Counts : ", table[2] print "Setpoint : ", table[3] # Remove specific scan task client.delete(scid) # or Remove information for all completed scans client.clear() except: raise
<time>1427913271459</time> <value>3.0</value> </sample> <sample id="14"> <time>1427913271559</time> <value>4.0</value> </sample> </samples> </device> </data> """ # client.getData(id) calls this to turn the XML data into a data dict: data = parseXMLData(xml_text) print data # Direct access to data dict print "Times: ", [ str(getDatetime(time)) for time in data['motor_x']['time'] ] print "Values: ", data['motor_x']['value'] # Demo of sample iterator for s in iterateSamples(data, 'motor_x'): print "%s (%2d): %s" % (str(getDatetime(s[1])), s[0], str(s[2])) # Create table, i.e. align samples for different devices by sample ID: table = createTable(data, 'motor_x', 'motor_y') print table[0] print table[1] # With numpy/scipy: plot(table[0], table[1]) etc.
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, [Delay(1), Log("motor_x", "motor_y", "neutrons")])]), Set("motor_x", orig_motor_x, completion=True), Set("motor_y", orig_motor_y, completion=True), ] client = ScanClient("localhost", 4810) scid = client.submit(cmds, name="2D 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) # Create table for motor_x, motor_y and neutrons table = createTable(data, "motor_x", "motor_y", "neutrons") print "Position X: ", table[0] print "Position Y: ", table[1] print "Counts : ", table[2] # Remove specific scan task client.delete(scid) # or Remove information for all completed scans client.clear() except: raise