192 lines
7.0 KiB
Python
192 lines
7.0 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_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, [40, 20]) #([40, 20) -> tuples are not supported natively
|
|
|
|
if AppCfg.GEO_PIX2POS not in keys:
|
|
_log.warning(f'{AppCfg.GEO_OPT_CTR} not defined. calc default')
|
|
import geometry
|
|
geo=geometry.geometry()
|
|
pix2pos_measure={
|
|
1:[(-3.0, -7.6, 116.99110193046, 632.5463827525),
|
|
(-2.0, -7.6, 934.07501517856, 600.7926167715),
|
|
(-2.0, -7.1, 916.54131238102, 191.0366615002),
|
|
(-3.0, -7.1, 103.74668003329, 226.2150231456)],
|
|
200:[(-3.1, -7.3, 113.66321353086, 824.9041423107),
|
|
(-2.3, -7.3, 1065.97386092697, 792.2851118419),
|
|
(-2.3, -6.7, 1033.68452410347, 74.0336610693),
|
|
(-3.1, -6.7, 84.62681572700, 116.6832971512)],
|
|
400:[(-3.4, -6.7, 155.00053674203, 601.3838942136),
|
|
(-3.0, -6.7, 957.95919656052, 573.0827012272),
|
|
(-3.2, -6.5, 541.08684037200, 187.9171307943),
|
|
(-3.2, -6.8, 564.32152887203, 789.1146957326)],
|
|
600:[(-3.3, -6.8, 328.27244399903, 509.5061192017),
|
|
(-3.1, -6.8, 992.78996735279, 488.0323963092),
|
|
(-3.2, -6.9, 672.03111567934, 832.4122409755),
|
|
(-3.2, -6.7, 645.70960116180, 164.2534779331)],
|
|
800:[(-3.2, -6.7, 639.52253576449, 53.4455632943),
|
|
(-3.2, -6.85, 671.47023245203, 882.6335091391),
|
|
(-3.3, -6.75, 105.12470026379, 361.3051859197),
|
|
(-3.1, -6.75, 1195.96864609255, 313.1068618673)],
|
|
1000:[(-3.25, -6.75, 195.05641095116, 353.3492286375),
|
|
(-3.15, -6.75, 1117.27204644084, 314.9636405871),
|
|
(-3.2, -6.8, 675.10991143017, 790.3040145281),
|
|
(-3.2, -6.72, 638.98580653116, 59.3803912957)]}
|
|
geo.update_pix2pos(pix2pos_measure)
|
|
self.setValue(AppCfg.GEO_PIX2POS, geo._lut_pix2pos)
|
|
|
|
if AppCfg.GEO_OPT_CTR not in keys:
|
|
_log.warning(f'{AppCfg.GEO_OPT_CTR} not defined. calc default')
|
|
import geometry
|
|
geo=geometry.geometry()
|
|
opt_ctr_meas={ # x,y = 0.02, -4.89
|
|
1000:[(1057.4251530483375, 116.10122290395591),
|
|
(117.84916300310408, 190.27827474963223),
|
|
(184.2181041281829, 963.2812360887852),
|
|
(1092.5616512910262, 899.514998537239)],
|
|
800:[(888.2494207687248, 203.2917926172947),
|
|
(329.96950424600305, 248.83910515411347),
|
|
(372.9141132092893, 708.2162858826),
|
|
(906.4683457834523, 675.6824912134438)],
|
|
600:[(781.5385742538922, 251.44180872764602),
|
|
(447.09116505496564, 264.4553265953085),
|
|
(471.81684900352445, 554.6567750441825),
|
|
(798.4561474818535, 535.1364982426887)],
|
|
400:[(722.9777438494109, 286.5783069703348),
|
|
(525.1722722609408, 295.68776947769857),
|
|
(535.5830865550707, 462.26079818377866),
|
|
(729.4845027832422, 450.5486321028824)],
|
|
200:[(689.1425973934884, 308.70128734536104),
|
|
(565.5141776506945, 307.39993555859473),
|
|
(574.6236401580583, 406.30267135282986),
|
|
(693.0466527537872, 399.79591241899857)],
|
|
1:[(673.5263759522934, 307.39993555859473),
|
|
(591.5412133860195, 308.70128734536104),
|
|
(595.4452687463182, 376.3715802572061),
|
|
(672.2250241655271, 373.7688766836736)]}
|
|
geo.update_optical_center(opt_ctr_meas)
|
|
self.setValue(AppCfg.GEO_OPT_CTR, geo._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)
|
|
|
|
|