saving document, plane and fiducal fitter
This commit is contained in:
@@ -10,9 +10,25 @@ _log = logging.getLogger(__name__)
|
||||
|
||||
from PyQt5.QtCore import QSettings
|
||||
from PyQt5.QtWidgets import QApplication, QLineEdit
|
||||
import os, json, yaml
|
||||
import json
|
||||
import numpy as np
|
||||
import GenericDialog
|
||||
|
||||
|
||||
class MyJsonEncoder(json.JSONEncoder):
|
||||
""" Special json encoder for numpy types """
|
||||
def default(self, obj):
|
||||
if isinstance(obj, np.integer):
|
||||
return int(obj)
|
||||
elif isinstance(obj, np.floating):
|
||||
return float(obj)
|
||||
elif isinstance(obj, np.ndarray):
|
||||
return obj.tolist()
|
||||
elif type(obj) not in (dict,list,str,int):
|
||||
_log.error('dont know how to json')
|
||||
return repr(obj)
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
class AppCfg(QSettings):
|
||||
|
||||
GEO_OPT_CTR='geometry/opt_ctr'
|
||||
@@ -87,8 +103,7 @@ class AppCfg(QSettings):
|
||||
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
|
||||
_log.warning(f'{AppCfg.GEO_PIX2POS} not defined. use default')
|
||||
lut_pix2pos=(np.array([1., 200., 400., 600., 800., 1000.]),
|
||||
np.array([[[ 2.42827273e-03, -9.22117396e-05],
|
||||
[-1.10489804e-04, -2.42592492e-03]],
|
||||
@@ -106,7 +121,6 @@ class AppCfg(QSettings):
|
||||
|
||||
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)
|
||||
|
||||
@@ -129,10 +143,25 @@ class AppCfg(QSettings):
|
||||
# print(data)
|
||||
|
||||
def setValue(self, key: str, val): #overload to debug
|
||||
# only simple lists, str, int, float can not be serialized nicely
|
||||
t=type(val)
|
||||
if key in (AppCfg.GEO_PIX2POS):
|
||||
val=json.dumps(val, cls=MyJsonEncoder)
|
||||
elif key in (AppCfg.GEO_OPT_CTR,AppCfg.GEO_BEAM_SZ,AppCfg.GEO_BEAM_POS,):
|
||||
val=val.tolist()
|
||||
elif type(val)==tuple:
|
||||
val=list(val)
|
||||
return super(AppCfg, self).setValue(key,val)
|
||||
|
||||
def value(self,key,*vargs,**kwargs): #overload to debug
|
||||
val=super(AppCfg, self).value(key,*vargs,**kwargs)
|
||||
if key in (AppCfg.GEO_PIX2POS):
|
||||
val=json.loads(val)#, object_hook=MyJsonDecoder)
|
||||
val=(np.array(val[0]),np.array(val[1]))
|
||||
elif key in (AppCfg.GEO_BEAM_SZ,AppCfg.GEO_BEAM_POS,):
|
||||
val=np.array(tuple(map(float, val)))/1000
|
||||
elif key in (AppCfg.GEO_OPT_CTR):
|
||||
val=np.array(tuple(map(float, val)))
|
||||
return val
|
||||
#@property
|
||||
#def value(self):
|
||||
|
||||
Reference in New Issue
Block a user