GenericDialog.py for Application Config

This commit is contained in:
2022-08-22 13:02:31 +02:00
parent 0f16af5810
commit 28c94dd297
4 changed files with 539 additions and 405 deletions

View File

@@ -42,7 +42,7 @@ class timestamp():
print(txt+f'{t-self.t:6.3g}')
self.t=t
ts=timestamp()
ts.log('Import part 1/7:')
ts.log('Import part 1/8:')
import sys, os, time
import json, re
import random, signal
@@ -68,7 +68,7 @@ TASK_GRID = "grid"
TASK_PRELOCATED = "prelocated"
TASK_HELICAL = "helical"
TASK_EMBL = "embl"
ts.log('Import part 2/7:')
ts.log('Import part 2/8:')
import PrelocatedCoordinatesModel # ZAC: orig. code
from EmblModule import EmblWidget #ZAC: orig. code
from HelicalTable import HelicalTableWidget #ZAC: orig. code
@@ -78,7 +78,7 @@ from HelicalTable import HelicalTableWidget #ZAC: orig. code
#import mx_swissfel #ZAC: orig. code
#swissfel = mx_swissfel.SwissFELMachine() #ZAC: orig. code
#from bernina_pulse_picker import pulsePicker #ZAC: orig. code
ts.log('Import part 3/7:')
ts.log('Import part 3/8:')
import qtawesome
import qutilities
from PyQt5 import QtCore, QtGui
@@ -89,32 +89,38 @@ from PyQt5.QtWidgets import (
QMessageBox, QPlainTextEdit, QProgressBar, QProgressDialog, QPushButton, QShortcut, QSizePolicy, QSpinBox,
QSplashScreen, QTextBrowser, QToolBox, QVBoxLayout, QWidget,)
from PyQt5.uic import loadUiType
ts.log('Import part 4/7:')
ts.log('Import part 4/8:')
import CustomROI as CstROI
import pyqtUsrObj as UsrGO
#from CustomROI import BeamMark, Grid, CrystalCircle #ZAC: orig. code
import GenericDialog
#from GenericDialog import GenericDialog #ZAC: orig. code
#from dialogs.PreferencesDialog import PreferencesDialog #ZAC: orig. code
#from epics_widgets import zoom #ZAC: orig. code
from epics_widgets.MotorTweak import MotorTweak
from epics_widgets.SmaractMotorTweak import SmaractMotorTweak
from epics_widgets.SimMotorTweak import SimMotorTweak
ts.log('Import part 5/7:')
ts.log('Import part 5/8:')
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import pyqtgraph as pg
import pyqtgraph.exporters
# use antialias for draw lines, interpret image data as row-major instead of col-major
pg.setConfigOptions(antialias=True,imageAxisOrder='row-major')
ts.log('Import part 6/7:')
ts.log('Import part 6/8:')
import app_utils
from app_config import AppCfg #settings, option, toggle_option
import epics
from epics.ca import pend_event
import camera,backlight,zoom,illumination,geometry
ts.log('Import part 7/7:')
ts.log('Import part 7/8:')
import deltatau
import detector
ts.log('Import part 8/8:')
#_URL = "http://PC12288:8080"
@@ -2231,28 +2237,17 @@ class Main(QMainWindow, Ui_MainWindow):
try:
dt=app._deltatau
except AttributeError:
import matplotlib.pyplot as plt
import deltatau
app._deltatau=dt=deltatau.Deltatau()
try:
jf=app._jungfrau
except AttributeError:
import detector
app._jungfrau=jf=detector.Jungfrau()
dt=app._deltatau
sp=dt._shapepath
sp.gen_grid_points(w=15, h=15, pitch=3, rnd=0, ofs=(0, +2000));
sp.sort_points(False, 15);
sp.meta['pt2pt_time']=10
gtMaxLn=116508
ovhdTime=100
acq_per=int(np.ceil((sp.meta['pt2pt_time']*sp.points.shape[0]+ovhdTime)/(gtMaxLn*sp.meta['srv_per'])))
sp.setup_gather(acq_per=acq_per)
sp.setup_gather()
sp.setup_sync(verbose=verbose&32, timeOfs=0.05)
sp.setup_coord_trf() # reset to shape path system
# sp.meta['pt2pt_time']=10 #put between setup_sync and setup_motion to have more motion points than FEL syncs
@@ -2268,11 +2263,11 @@ class Main(QMainWindow, Ui_MainWindow):
print('progress %d/%d'%(p, sp.points.shape[0]));
time.sleep(.1)
sp.gather_upload(fnRec=fn+'.npz')
dp=deltatau.shapepath.DebugPlot(sp);
dp=deltatau.shapepath.DebugPlot(sp)
dp.plot_gather(mode=11)
print('done')
plt.show(block=False)
#plt.show(block=False)
plt.show(block=True)
return
@@ -3072,168 +3067,108 @@ class Main(QMainWindow, Ui_MainWindow):
fy_motor.move_motor_to_position(y)
def set_beam_size_marker_dialog(self):
w, h = settings.value(BEAM_SIZE)
d = GenericDialog(
title="Beamsize",
SPN=GenericDialog.Spinner
app=QApplication.instance()
cfg=app._cfg
w, h = map(float,cfg.value(AppCfg.GEO_BEAM_SZ))
d = GenericDialog.GenericDialog(
title="geometry",
message="Enter the size of the beam in microns",
inputs={
"width": (
"Width",
int(w),
Spinner(int(w), min=1, max=200, suffix=" \u00B5m"),
),
"height": (
"Height",
int(h),
Spinner(int(h), min=1, max=200, suffix=" \u00B5m"),
),
"bw": ("beam width um" ,w,SPN(w, min=1, max=200, suffix=" \u00B5m"),),
"bh": ("beam height um",h,SPN(h, min=1, max=200, suffix=" \u00B5m"),),
},
)
if d.exec():
results = d.results
_log.info("Updating beamsize to {}".format(results))
w, h = results["width"], results["height"]
bm_sz= (results["bw"], results["bh"])
_log.debug("types {}".format(type(w)))
settings.setValue(BEAM_SIZE, (w, h))
self._beammark.set_beam_size((w, h))
settings.sync()
cfg.setValue(AppCfg.GEO_BEAM_SZ, bm_sz)
bm=self._goBeamMarker
bm.setSize(bm_sz)
#self._beammark.set_beam_size((w, h))
cfg.sync()
def set_posttube_references_dialog(self):
x_up = settings.value("post_sample_tube/x_up", 0.0)
y_up = settings.value("post_sample_tube/y_up", 0.0)
x_down = settings.value("post_sample_tube/x_down", 0.0)
y_down = settings.value("post_sample_tube/y_down", 0.0)
dx = settings.value("post_sample_tube/dx", 0.0)
dy = settings.value("post_sample_tube/dy", 0.0)
tz_in = settings.value("post_sample_tube/z_in", 0.0)
tz_out = settings.value("post_sample_tube/z_out", 0.0)
SPN=GenericDialog.Spinner
app=QApplication.instance()
cfg=app._cfg
x_up = cfg.value(AppCfg.PST_X_UP , 0.0,type=float)
y_up = cfg.value(AppCfg.PST_Y_UP , 0.0,type=float)
x_down = cfg.value(AppCfg.PST_X_DOWN, 0.0,type=float)
y_down = cfg.value(AppCfg.PST_Y_DOWN, 0.0,type=float)
dx = cfg.value(AppCfg.PST_DX , 0.0,type=float)
dy = cfg.value(AppCfg.PST_DY , 0.0,type=float)
tz_in = cfg.value(AppCfg.PST_TZ_IN , 0.0,type=float)
tz_out = cfg.value(AppCfg.PST_TZ_OUT, 0.0,type=float)
d = GenericDialog(
d = GenericDialog.GenericDialog(
title="Post Sample Tube Configuration",
message="Enter the relative displacements for X and Y to move the post sample tube either in or out.",
inputs={
"post_sample_tube/x_up": (
"Up X",
float(x_up),
Spinner(float(x_up), decimals=3, min=-45.0, max=15.0, suffix=" mm"),
),
"post_sample_tube/y_up": (
"Up Y",
float(y_up),
Spinner(float(y_up), decimals=3, min=-45.0, max=15.0, suffix=" mm"),
),
"post_sample_tube/x_down": (
"Down X",
float(x_down),
Spinner(
float(x_down), decimals=3, min=-45.0, max=15.0, suffix=" mm"
),
),
"post_sample_tube/y_down": (
"Down Y",
float(y_down),
Spinner(
float(y_down), decimals=3, min=-45.0, max=15.0, suffix=" mm"
),
),
"post_sample_tube/dx": (
"out delta X",
float(dx),
Spinner(float(dx), decimals=3, min=-32.0, max=32.0, suffix=" mm"),
),
"post_sample_tube/dy": (
"out delta Y",
float(dy),
Spinner(float(dy), decimals=3, min=-32.0, max=32.0, suffix=" mm"),
),
"post_sample_tube/z_in": (
"tube Z in position",
float(tz_in),
Spinner(float(tz_in), decimals=3, min=-8.0, max=1.0, suffix=" mm"),
),
"post_sample_tube/z_out": (
"tube Z OUT position",
float(tz_out),
Spinner(float(tz_out), decimals=3, min=-8.0, max=1.0, suffix=" mm"),
),
AppCfg.PST_X_UP : ("Up X" , x_up , SPN(x_up , decimals=3, min=-45.0, max=15.0, suffix=" mm"), ),
AppCfg.PST_Y_UP : ("Up Y" , y_up , SPN(y_up , decimals=3, min=-45.0, max=15.0, suffix=" mm"), ),
AppCfg.PST_X_DOWN: ("Down X" , x_down, SPN(x_down, decimals=3, min=-45.0, max=15.0, suffix=" mm"), ),
AppCfg.PST_Y_DOWN: ("Down Y" , y_down, SPN(y_down, decimals=3, min=-45.0, max=15.0, suffix=" mm"), ),
AppCfg.PST_DX : ("out delta X" , dx , SPN(dx , decimals=3, min=-32.0, max=32.0, suffix=" mm"), ),
AppCfg.PST_DY : ("out delta Y" , dy , SPN(dy , decimals=3, min=-32.0, max=32.0, suffix=" mm"), ),
AppCfg.PST_TZ_IN : ("tube Z in position" , tz_in , SPN(tz_in , decimals=3, min=-8.0 , max=1.0 , suffix=" mm"), ),
AppCfg.PST_TZ_OUT: ("tube Z OUT position", tz_out, SPN(tz_out, decimals=3, min=-8.0 , max=1.0 , suffix=" mm"), ),
},
)
if d.exec():
results = d.results
_log.info("setting post-sample-tube displacements {}".format(results))
for k, v in results.items():
settings.setValue(k, v)
settings.sync()
cfg.setValue(k, v)
cfg.sync()
def set_collimator_reference_positions(self):
x_out = float(settings.value("collimator/dx", 0.0))
y_out = float(settings.value("collimator/dy", 0.0))
x_in = float(settings.value("collimator/x_in", 0.0))
y_in = float(settings.value("collimator/y_in", 0.0))
d = GenericDialog(
SPN=GenericDialog.Spinner
app=QApplication.instance()
cfg=app._cfg
x_out = cfg.value(AppCfg.COL_DX , 0.0,type=float)
y_out = cfg.value(AppCfg.COL_DY , 0.0,type=float)
x_in = cfg.value(AppCfg.COL_X_IN, 0.0,type=float)
y_in = cfg.value(AppCfg.COL_Y_IN, 0.0,type=float)
d = GenericDialog.GenericDialog(
title="Collimator configuration",
message="Enter reference positions for the collimator",
inputs={
"collimator/dx": (
"Collimator out deltaX",
x_out,
Spinner(x_out, decimals=3, min=-15.9, max=15.9, suffix=" mm"),
),
"collimator/dy": (
"Collimator out deltaY",
y_out,
Spinner(y_out, decimals=3, min=-15.9, max=15.9, suffix=" mm"),
),
"collimator/x_in": (
"Collimator in X",
x_in,
Spinner(x_in, decimals=3, min=-15.9, max=15.9, suffix=" mm"),
),
"collimator/y_in": (
"Collimator in Y",
y_in,
Spinner(y_in, decimals=3, min=-15.9, max=15.9, suffix=" mm"),
),
AppCfg.COL_DX: ("Collimator out deltaX", x_out, SPN(x_out, decimals=3, min=-15.9, max=15.9, suffix=" mm"),),
AppCfg.COL_DY: ("Collimator out deltaY", y_out, SPN(y_out, decimals=3, min=-15.9, max=15.9, suffix=" mm"),),
AppCfg.COL_X_IN: ("Collimator in X", x_in, SPN(x_in, decimals=3, min=-15.9, max=15.9, suffix=" mm"),),
AppCfg.COL_Y_IN: ("Collimator in Y", y_in, SPN(y_in, decimals=3, min=-15.9, max=15.9, suffix=" mm"),),
},
)
if d.exec():
results = d.results
_log.info("setting collimator reference positions {}".format(results))
for k, v in results.items():
settings.setValue(k, v)
settings.sync()
cfg.setValue(k, v)
cfg.sync()
def set_backlight_positions_dialog(self):
p_in = int(settings.value("backlight/in"))
p_out = int(settings.value("backlight/out"))
p_diode = int(settings.value("backlight/diode"))
d = GenericDialog(
SPN=GenericDialog.Spinner
app=QApplication.instance()
cfg=app._cfg
p_in = cfg.value(AppCfg.BKLGT_IN,0,type=int)
p_out = cfg.value(AppCfg.BKLGT_OUT,0,type=int)
d = GenericDialog.GenericDialog(
title="Back Light configuration",
message="Enter reference positions for the backlight",
inputs={
"backlight/in": (
"In position",
p_in,
Spinner(p_in, min=-30000, max=10),
),
"backlight/out": (
"Out position",
p_out,
Spinner(p_out, min=-1000, max=10),
),
"backlight/diode": (
"Diode position",
p_diode,
Spinner(p_diode, min=-40000, max=-20000),
),
AppCfg.BKLGT_IN: ("In position" , p_in , SPN(p_in, min=-30000, max=10), ),
AppCfg.BKLGT_OUT: ("Out position", p_out, SPN(p_out, min=-1000, max=10), ),
},
)
if d.exec():
results = d.results
_log.info("setting back light reference positions {}".format(results))
for k, v in results.items():
settings.setValue(k, v)
settings.sync()
cfg.setValue(k, v)
cfg.sync()
def set_cryojet_positions_dialog(self):
p_in = settings.value(CRYOJET_NOZZLE_IN, type=float)
@@ -3256,31 +3191,31 @@ class Main(QMainWindow, Ui_MainWindow):
settings.sync()
def set_deltatau_parameters(self):
a = settings.value(DELTATAU_VELOCITY_SCALE, 1, type=float)
b = option(DELTATAU_SORT_POINTS)
c = option(DELTATAU_OMEGACOS)
d = option(DELTATAU_SHOW_PLOTS)
SPN=GenericDialog.Spinner
CB=GenericDialog.Checkbox
app=QApplication.instance()
cfg=app._cfg
#dt1 = cfg.value(AppCfg.DT_HOST,'SAR-CPPM-EXPMX1')
dt1 = cfg.value(AppCfg.DT_HOST,'localhost:10001:10002')
dt2 = cfg.value(AppCfg.DT_VEL_SCL, 1, type=float)
dt3 = cfg.option(AppCfg.DT_SHOW_PLOTS)
d = GenericDialog(
d = GenericDialog.GenericDialog(
title="Delta Tau Parameters",
message="These parameters affect the data collection.",
inputs={
DELTATAU_VELOCITY_SCALE: ("Velocity Scale (1=optimal, 0=zero vel at target)", a,
Spinner(a, min=0, max=1, suffix=""),),
DELTATAU_SORT_POINTS: ("Sort pointshoot/prelocated coords", b,
Checkbox(b, "sort points"),),
DELTATAU_SHOW_PLOTS: ("show plots after collection", d,
Checkbox(d, "correct"),),
DELTATAU_OMEGACOS: ( "preloc. correct omega tilt", c,
Checkbox(c, "correct"),),
AppCfg.DT_HOST:("host name (host[:port:port_gather])", dt1, QLineEdit(),),
AppCfg.DT_VEL_SCL: ("Velocity Scale (1=optimal, 0=zero vel at target)", dt2,SPN(dt2, min=0, max=1, suffix=""),),
AppCfg.DT_SHOW_PLOTS: ("show plots after collection", dt3,CB(dt3, "active"),),
#DELTATAU_SORT_POINTS: ("Sort pointshoot/prelocated coords", b,CB(b, "sort points"),),
},
)
if d.exec():
results = d.results
_log.info("setting delta tau parameters {}".format(results))
for k, v in results.items():
settings.setValue(k, v)
settings.sync()
cfg.setValue(k, v)
cfg.sync()
def set_tell_mount_positions(self):
AUTODRY_ENABLED = "tell/autodry_enabled"
@@ -3293,7 +3228,7 @@ class Main(QMainWindow, Ui_MainWindow):
maxtime = settings.value(AUTODRY_MAXTIME, type=float) / SECS_HOURS
maxmounts = settings.value(AUTODRY_MAXMOUNTS, type=int)
d = GenericDialog(
d = GenericDialog.GenericDialog(
title="TELL Settings",
message="These control some features of the TELL sample changer",
inputs={