from collections import OrderedDict time.sleep(2.0) 1/0 #Debugging if get_exec_pars().args is None: PRE_ACTIONS = {z:0.1} POSITIONERS = ["x", "y"] START = [0.0,0.0] STOP = [1.0,1.0] STEPS = [3, 5] SENSORS = [scienta.dataMatrix, current] SETTLING_TIME = 0.1 PASSES = 1 ZIGZAG = True COMPRESSION = True DIAGS = [] SNAPS = diag_channels MONITORS = [] NAME=None import json def load_parameters(name): print "Scan Name: ", name filename = get_context().setup.expandPath("{script}/scans/" + name + ".json") with open(filename) as config_file: config = json.load(config_file, object_pairs_hook=OrderedDict) #Read ordered dictionaries for key in config.keys(): globals()[key] = config[key] print str(key), " = ", config[key] if NAME: load_parameters(NAME) reinit(None) #Enforece parameter types positioners = string_to_obj(POSITIONERS) sensors = string_to_obj(SENSORS) start = list(to_array(START, 'd')) end = list(to_array(STOP, 'd')) steps = list(to_array(STEPS, 'i')) latency = SETTLING_TIME passes = int(PASSES) zigzag = bool(ZIGZAG) #Change photon parameters _id_mode=_grating=None if "id_mode" in PRE_ACTIONS.keys(): _id_mode=PRE_ACTIONS.pop("id_mode") if "grating" in PRE_ACTIONS.keys(): _grating=PRE_ACTIONS.pop("grating") if (_id_mode is not None) or (_grating is not None): print _id_mode, _grating change_photon_pars(_id_mode=_id_mode, _grating=_grating) #Execute pre-actions for key in PRE_ACTIONS.keys(): if key=="eval": log("Eval " + str(PRE_ACTIONS[key])) eval(str(PRE_ACTIONS[key])) else: dev = string_to_obj(key) if isinstance(dev, Writable): log("Setting " + dev.name + " to: " + str(PRE_ACTIONS[key])) dev.write(PRE_ACTIONS[key]) for key in PRE_ACTIONS.keys(): dev = string_to_obj(key) if isinstance(dev, Device): log("Waiting " + dev.name) dev.waitReady(-1) #Run scan if COMPRESSION: set_exec_pars(compression=[scienta.dataMatrix]) def before_read(pos, scan): trigger_scienta() data_3d = (scienta.dataMatrix in sensors) and (str(scienta.getAcquisitionMode())=="Swept_Energy_ThetaY") def after_read(rec, scan): global data_3d #handle_diagnostics(rec) #data_3d = (scienta.dataMatrix in sensors) and (scienta.arraySize2.read()>1) if data_3d: try: path = get_exec_pars().scanPath + ("/3d_images/%04d" % rec.index) data = scienta.takeStack() save_dataset(path, data) except: log(sys.exc_info()[1]) try: if len(positioners)==0: ret= tscan (sensors, 1,0, passes=passes, \ before_read=before_read, after_read=after_read, \ snaps=SNAPS, diags=DIAGS, monitors=MONITORS) else: ret= ascan (positioners, sensors, start, end, steps, \ latency= latency, relative=False, passes=passes, zigzag=zigzag, \ before_read=before_read, after_read=after_read, \ snaps=SNAPS, diags=DIAGS, monitors=MONITORS) finally: scienta.zeroSupplies()