157 lines
5.2 KiB
Python
157 lines
5.2 KiB
Python
#TODO:
|
|
# currently 2 settings/configs are used
|
|
# QSettings -> cat ~/.config/Paul\ Scherrer\ Institut/SwissMX.conf
|
|
# yaml -> swissmx.yaml
|
|
# QSettings are changed by program
|
|
# #yaml is fixed and not altened by program
|
|
|
|
import logging
|
|
_log = logging.getLogger(__name__)
|
|
|
|
from PyQt5.QtCore import QSettings
|
|
import os, json, yaml
|
|
|
|
class AppCfg(QSettings):
|
|
|
|
GEO_OPT_CTR='geometry/opt_ctr'
|
|
GEO_PIX2POS='geometry/pix2pos'
|
|
|
|
GEO_BEAM_SZ="geometry/beam_size"
|
|
GEO_BEAM_POS="geometry/beam_pos"
|
|
|
|
|
|
WINDOW_GEOMETRY="window/geometry"
|
|
WINDOW_SPLITTER="window/splitter"
|
|
WINDOW_STATE= "window/state"
|
|
|
|
# ---------- OBSOLETE ??? ----------
|
|
#ZOOM_BUTTONS="sample_viewing/zoom_buttons"
|
|
|
|
SKIP_ESCAPE_TRANSITIONS_IF_SAFE="escape/skip_transitions_if_safe"
|
|
|
|
CRYOJET_MOTION_ENABLED="cryojet/motion_enabled"
|
|
CRYOJET_NOZZLE_OUT="cryojet/nozzle_out"
|
|
CRYOJET_NOZZLE_IN="cryojet/nozzle_in"
|
|
|
|
DELTATAU_HOST="deltatau/host"
|
|
DELTATAU_SHOW_PLOTS="deltatau/show_plots"
|
|
DELTATAU_OMEGACOS="deltatau/omegacos"
|
|
DELTATAU_SORT_POINTS="deltatau/sort_points"
|
|
DELTATAU_VELOCITY_SCALE="deltatau/velocity_scale"
|
|
|
|
CAMERA_TRANSFORMATIONS="camera/transformations"
|
|
CAMERA_ZOOM_TO_PPM="camera/zoom_to_ppm"
|
|
|
|
EXPERIMENT_PGROUP="experiment/pgroup"
|
|
EXPERIMENT_UID="experiment/uid"
|
|
|
|
ACTIVATE_PULSE_PICKER="scanning/activate_pulse_picker"
|
|
|
|
def __init__(self):
|
|
super(AppCfg, self).__init__("PSI", "SwissMX")
|
|
keys = self.allKeys()
|
|
# Dump config to debug
|
|
#for k in keys:
|
|
# print(k, self.value(k))
|
|
|
|
#set default keys if not existing
|
|
if AppCfg.GEO_BEAM_SZ not in keys:
|
|
_log.warning(f'{AppCfg.GEO_BEAM_SZ} not defined. set default')
|
|
self.setValue(AppCfg.GEO_BEAM_SZ, [30.2, 25.6]) #([40, 20) -> tuples are not supported natively
|
|
|
|
if AppCfg.GEO_BEAM_POS not in keys:
|
|
_log.warning(f'{AppCfg.GEO_BEAM_POS} not defined. set default')
|
|
self.setValue(AppCfg.GEO_BEAM_POS, [23.4, -54.2]) # beam position relativ to optical center in mm
|
|
|
|
if AppCfg.GEO_PIX2POS not in keys:
|
|
_log.warning(f'{AppCfg.GEO_OPT_CTR} not defined. use default')
|
|
import numpy as np
|
|
lut_pix2pos=(np.array([1., 200., 400., 600., 800., 1000.]),
|
|
np.array([[[ 2.42827273e-03, -9.22117396e-05],
|
|
[-1.10489804e-04, -2.42592492e-03]],
|
|
[[ 1.64346103e-03, -7.52341417e-05],
|
|
[-6.60711165e-05, -1.64190224e-03]],
|
|
[[ 9.91307639e-04, -4.02008751e-05],
|
|
[-4.23878232e-05, -9.91563507e-04]],
|
|
[[ 5.98443038e-04, -2.54046255e-05],
|
|
[-2.76831563e-05, -6.02738142e-04]],
|
|
[[ 3.64418977e-04, -1.41389267e-05],
|
|
[-1.55708176e-05, -3.66233567e-04]],
|
|
[[ 2.16526433e-04, -8.23070130e-06],
|
|
[-9.29894004e-06, -2.16842976e-04]]]))
|
|
self.setValue(AppCfg.GEO_PIX2POS, lut_pix2pos)
|
|
|
|
if AppCfg.GEO_OPT_CTR not in keys:
|
|
_log.warning(f'{AppCfg.GEO_OPT_CTR} not defined. use default')
|
|
import numpy as np
|
|
opt_ctr=np.array([603.28688025, 520.01112846])
|
|
self.setValue(AppCfg.GEO_OPT_CTR, opt_ctr)
|
|
|
|
#if AppCfg.ACTIVATE_PULSE_PICKER not in keys:
|
|
# self.setValue(AppCfg.ACTIVATE_PULSE_PICKER, False)
|
|
|
|
#if AppCfg.SKIP_ESCAPE_TRANSITIONS_IF_SAFE not in keys:
|
|
# self.setValue(AppCfg.SKIP_ESCAPE_TRANSITIONS_IF_SAFE, False)
|
|
|
|
def sync(self):
|
|
super(AppCfg, self).sync()
|
|
#import numpy as np
|
|
#a=np.array(((1,2,3),(4,5,6)))
|
|
#self._yamlFn=fn=os.path.expanduser('~/.config/PSI/SwissMX.yaml')
|
|
#_yaml = [{'name': 'John Doe', 'occupation': 'gardener'},
|
|
# {'name': 'Lucy Black', 'occupation': 'teacher'}]
|
|
#_yaml = {'name': 'John Doe', 'occupation': 'gardener','A':(1,2,3),'B':{1,2,3},'C': {1:(1,2,3),2:'df',3:'dddd'},4:a }
|
|
#with open(self._yamlFn, 'w') as f:
|
|
# data = yaml.dump(_yaml, f)
|
|
# print(data)
|
|
|
|
def setValue(self, key: str, val): #overload to debug
|
|
return super(AppCfg, self).setValue(key,val)
|
|
|
|
def value(self,key,*vargs): #overload to debug
|
|
val=super(AppCfg, self).value(key,*vargs)
|
|
return val
|
|
#@property
|
|
#def value(self):
|
|
# return super(AppCfg, self).value
|
|
|
|
def option(self,key: str) -> bool:
|
|
try:
|
|
return self.value(key, type=bool)
|
|
except:
|
|
_log.error(f"option {key} not known")
|
|
return False
|
|
|
|
def toggle_option(self,key: str):
|
|
v = self.value(key, type=bool)
|
|
self.setValue(key, not v)
|
|
self.sync()
|
|
|
|
|
|
#inst_folder = Path(__file__).absolute().parent
|
|
#config_file = inst_folder / "swissmx.yaml"
|
|
#configs = yaml.load(config_file.read_text(),Loader=yaml.FullLoader)
|
|
#endstation = configs["configure_for"]
|
|
#appsconf = configs[endstation]
|
|
#simulated = appsconf.get("simulate", False)
|
|
#logger.info(f"configuring for endstation: {endstation.upper()}")
|
|
|
|
#if simulated:
|
|
# logger.warning("SIMULATION is ACTIVE")
|
|
#css_file = inst_folder / "swissmx.css"
|
|
|
|
|
|
|
|
#def font(name: str) -> str:
|
|
# p = Path(__file__).absolute().parent / "fonts" / name
|
|
# return str(p)
|
|
|
|
|
|
#def logo(size: int = 0) -> str:
|
|
# p = Path(__file__).absolute().parent / "logos" / "logo.png"
|
|
# if size:
|
|
# p = Path(__file__).absolute().parent / "logos" / f"tell_logo_{size}x{size}.png"
|
|
# return str(p)
|
|
|
|
|