from collections import OrderedDict #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] with open(filename) as config_file: save_dataset("scripts/config.json", config_file.read(), type = 's') set_attribute("scripts", "config", filename) 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) #Setuop Scienta scienta.setGrabMode(Camera.GrabMode.Single) #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): if scienta.dataMatrix in sensors: trigger_scienta() data_3d = (scienta.dataMatrix in sensors) and ("thetay" in scienta.acquisitionMode.lower()) if data_3d: print "3D dataset" def after_read(rec, scan): global data_3d #handle_diagnostics(rec) if data_3d: try: #path = get_exec_pars().scanPath + ("/3d_images/%04d" % rec.index) #data = scienta.takeStack() #save_dataset(path, data) path = get_exec_pars().scanPath + "/images" if rec.index==0: size=scienta.getImageSize() if len(size)<3: raise Exception("Data is not 3D") num_images = scan.getNumberOfRecords() * size[2] create_dataset(path, scienta.dataArray, None, (num_images, size[1], size[0]), {"layout":"contiguous", "compression":True}) for img in scienta.takeStack(): append_dataset(path, img) 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, keep=True) #if (scienta.dataMatrix in sensors) and not data_3d: # save_dataset("/image", ret[scienta.dataMatrix][0], type = 'i', features={"compression":True}) 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) set_device_channel_names(ret.scan, sensors, SNAPS, DIAGS, MONITORS ) finally: scienta.stop() scienta.zeroSupplies() print ret