From 3a83f3cf341fc093b89359e5d3bcb926fd3feffc Mon Sep 17 00:00:00 2001 From: gobbo_a Date: Mon, 28 Nov 2022 12:30:31 +0100 Subject: [PATCH] Histogram automatically dialog closes when Renderer is not visible --- script/Regine.py | 126 +++++++++++++++++++++++++++++++++++++++++++++++ script/SIStem.py | 78 +++++++++++++++++++++++++++++ 2 files changed, 204 insertions(+) create mode 100644 script/Regine.py create mode 100644 script/SIStem.py diff --git a/script/Regine.py b/script/Regine.py new file mode 100644 index 0000000..0bc3e40 --- /dev/null +++ b/script/Regine.py @@ -0,0 +1,126 @@ +""" +Arguments: +DRY_RUN (BOOL) +CENTER_X, CENTER_Y (FLOAT) +STEPS_X, STEPS_Y (INT) +STEP_SIZE_X, STEP_SIZE_Y (FLOAT) +EXPOSURES (list or None) +SETTLING_TIME (double) +ZIGZAG (BOOLEAN) +COMPRESSION (BOOLEAN) +NOISE (FLOAT) +""" +import random + +position_plot = None if "POSITION_PLOT" not in globals() else POSITION_PLOT + +#Debugging +if (get_exec_pars().args is None) and (get_exec_pars().script=="Regine"): + DRY_RUN = True + CENTER_X = 0.0 + CENTER_Y = 0.0 + EXPOSURES = [0.1, 0.5, 1.0] + STEPS_X = 5 + STEPS_Y= 3 + STEP_SIZE_X = 0.1 + STEP_SIZE_Y = 0.2 + SETTLING_TIME = 1.0 + ZIGZAG = True + COMPRESSION = False + NOISE=0.10 + position_plot=None + + +if not position_plot: position_plot=plot(None, title="Motor Positions")[0] + +current=sin +ccd=scienta +dummy_x, dummy_y = motor, motor2 +sample_x, sample_y = motor, motor2 +after_readout= before_readout=None +def after_scan(): + pass + +#Scanning exposure +class exposure_index (Writable, Readable): + def __init__(self): + self.pos=0.0 + + def read(self): + return self.pos + + def write(self, value): + ccd.setExposure(EXPOSURES[int(value)]) + self.pos = value + +class exposure (Readable): + def read(self): + return ccd.exposure + + +#Constants +SENSORS = [current, ccd.dataMatrix] +POSITIONERS = [dummy_x, dummy_y] if DRY_RUN else [sample_x, sample_y] + +ENABLED_PLOTS = [current, ccd.dataMatrix] +CUSTOM_PLOT_TYPES = {ccd.dataMatrix:"ch.psi.pshell.plot.MatrixPlotRenderer"} + +RANGE_X=[CENTER_X - STEP_SIZE_X*STEPS_X, CENTER_X + STEP_SIZE_X*STEPS_X] +RANGE_Y=[CENTER_Y - STEP_SIZE_Y*STEPS_Y, CENTER_Y + STEP_SIZE_Y*STEPS_Y] + + +position_plot.clear() +position_plot.addSeries(LinePlotSeries("positions")) +position_plot.getAxis(AxisId.X).label = POSITIONERS[0].name +position_plot.getAxis(AxisId.X).setRange(RANGE_X[0]-STEP_SIZE_X, RANGE_X[1]+STEP_SIZE_X) +position_plot.getAxis(AxisId.Y).label = POSITIONERS[1].name +position_plot.getAxis(AxisId.Y).setRange(RANGE_Y[0]-STEP_SIZE_Y, RANGE_Y[1]+STEP_SIZE_Y) + + +def after_read(record, scan): + position_plot.getSeries(0).appendData(record[POSITIONERS[0]], record[POSITIONERS[1]]) + + +if EXPOSURES: + #ENABLED_PLOTS = [ccd.dataMatrix] #Cannot plot current in 3d vscan + POSITIONERS = POSITIONERS + [exposure_index()] + SENSORS = SENSORS + [exposure()] + RANGE_E=[0, len(EXPOSURES)-1] + + #set_exec_pars(manual_range=RANGE_E, manual_range_y=RANGE_Y) + + CUSTOM_PLOT_TYPES[sin]=1 + set_exec_pars(manual_range=RANGE_X) + #set_exec_pars(domain_axis="Index") + #set_exec_pars(auto_range=True) +else: + set_exec_pars(manual_range=RANGE_X, manual_range_y=RANGE_Y) + +def gen(): + x_index = y_index = e_index = 0 + for x_step in range(-STEPS_X, STEPS_X+1): + xpos = CENTER_X + x_step*STEP_SIZE_X + (random.random()-0.5)*NOISE*2*STEP_SIZE_X + range_y= range(STEPS_Y, -STEPS_Y-1, -1) if (ZIGZAG and(x_index%2 ==1)) else range(-STEPS_Y, STEPS_Y+1) + for y_step in range_y: + ypos = CENTER_Y + y_step*STEP_SIZE_Y + (random.random()-0.5)*NOISE*2*STEP_SIZE_Y + if EXPOSURES: + range_e= range(len(EXPOSURES)-1,-1, -1) if (ZIGZAG and(y_index%2 ==1)) else range(len(EXPOSURES)) + for e in range_e: + yield([xpos,ypos,e]) + else: + yield([xpos,ypos]) + y_index=y_index+1 + x_index=x_index+1 + + + +try: + r = vscan(POSITIONERS, SENSORS , gen(), False,\ + SETTLING_TIME, relative=False, zigzag = ZIGZAG, \ + before_read=before_readout, after_read = after_read, \ + compression = COMPRESSION, enabled_plots=ENABLED_PLOTS, \ + keep=False, check_positions=False, plot_types=CUSTOM_PLOT_TYPES) + set_return(r) +finally: + after_scan() + \ No newline at end of file diff --git a/script/SIStem.py b/script/SIStem.py new file mode 100644 index 0000000..242a6ac --- /dev/null +++ b/script/SIStem.py @@ -0,0 +1,78 @@ +#Debugging +if get_exec_pars().args is None: + """ + PRE_ACTIONS = {"motor2":0.1} + POSITIONERS = ["master", "motor"] + START = [0.0,0.0] + STOP = [1.0,1.0] + STEPS = [3, 5] + SENSORS = ["scienta.dataMatrix", "sin"] + SETTLING_TIME = 0.1 + PASSES = 1 + ZIGZAG = True + COMPRESSION = True + """ + NAME="Test" + print "Debug" + + +import json +def load_parameters(name): + filename = get_context().setup.expandPath("{home}/scans/" + name + ".json") + with open(filename) as config_file: + config = json.load(config_file) + for key in config.keys(): + globals()[key] = config[key] + print str(key), " = ", config[key] +if NAME: + load_parameters(NAME) + + + +#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) + + +#Execute pre-actions +for key in PRE_ACTIONS.keys(): + 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() + + +def after_read(rec, scan): + pass + #handle_diagnostics(rec) + +try: + ret= ascan(positioners, sensors, start, end, steps, \ + latency = latency, relative = False, passes = passes, zigzag = zigzag, \ + before_read = before_read, after_read = after_read, + snaps = diag_channels) +finally: + scienta.zeroSupplies() + +