添加对python算法的支持
This commit is contained in:
@@ -0,0 +1,391 @@
|
||||
import numpy as np
|
||||
|
||||
|
||||
def xray2000_ana_m(normvideo, settings, errorin, ovrvwmem):
|
||||
from curvefit_analysis import (
|
||||
analy01, anajack2, ana_curvefit_tube, ana_curvefit_Uponor,
|
||||
ana_curvefit_cable, ana_curvefit_2l_tube
|
||||
)
|
||||
|
||||
conf_data = np.asarray(settings['confData'], dtype=np.float64).copy()
|
||||
conf20 = conf_data[19]
|
||||
|
||||
xL = np.zeros((1, 4))
|
||||
xR = np.zeros((1, 4))
|
||||
status = np.zeros((1, 4))
|
||||
statusL = np.zeros((1, 4))
|
||||
statusR = np.zeros((1, 4))
|
||||
attL = np.zeros(2)
|
||||
attR = np.zeros(2)
|
||||
errorlevel = np.zeros((2, 1))
|
||||
layeruse = np.zeros(5)
|
||||
IN = np.array([])
|
||||
detail = {
|
||||
'IN': np.nan, 'nominal': np.nan,
|
||||
'left': {
|
||||
'pos': {'result': np.nan, 'start': np.nan,
|
||||
'limit': {'left': np.nan, 'right': np.nan}},
|
||||
'att': {'outer': np.nan, 'inner': np.nan},
|
||||
'error': np.array([np.nan, np.nan])
|
||||
},
|
||||
'att': {'min': np.nan, 'max': np.nan},
|
||||
'contr': {'min': np.nan, 'max': np.nan, 'sign': np.nan},
|
||||
}
|
||||
detail['right'] = {k: (v.copy() if isinstance(v, dict) else v)
|
||||
for k, v in detail['left'].items()}
|
||||
|
||||
if ((30 <= conf20 <= 50) or conf20 == 53 or
|
||||
(62000000 <= conf20 < 63000000) or
|
||||
(151 <= conf20 < 160)):
|
||||
xL, xR, status, statusL, statusR, attL, attR, errorlevel, layeruse, ovrvwmem, IN = \
|
||||
anajack2(normvideo, conf_data, settings, ovrvwmem, errorin)
|
||||
elif 63000000 <= conf20 < 64000000:
|
||||
xL, xR, status, statusL, statusR, attL, attR, errorlevel, layeruse, ovrvwmem, IN = \
|
||||
anajack2(normvideo, conf_data, settings, ovrvwmem, errorin)
|
||||
elif 70 <= conf20 <= 90:
|
||||
xL, xR, status, statusL, statusR, attL, attR, errorlevel, layeruse, IN = \
|
||||
ana_curvefit_tube(normvideo, conf_data, errorin)
|
||||
elif 101 <= conf20 <= 104:
|
||||
xL, xR, status, statusL, statusR, attL, attR, errorlevel, layeruse, IN = \
|
||||
ana_curvefit_Uponor(normvideo, conf_data, errorin)
|
||||
elif 105 <= conf20 <= 110:
|
||||
xL, xR, status, statusL, statusR, attL, attR, errorlevel, layeruse, IN = \
|
||||
ana_curvefit_Uponor(normvideo, conf_data, errorin)
|
||||
elif 111 <= conf20 <= 130:
|
||||
if conf20 == 112:
|
||||
conf_data[19] = 111
|
||||
conf_data[2] = 0
|
||||
conf_data[3] = 0
|
||||
conf_data[4] = 0
|
||||
xL, xR, status, statusL, statusR, attL, attR, errorlevel, layeruse, IN, detail = \
|
||||
ana_curvefit_cable(normvideo, conf_data, errorin, settings)
|
||||
elif 131 <= conf20 <= 150:
|
||||
xL, xR, status, statusL, statusR, attL, attR, errorlevel, layeruse, ovrvwmem, IN = \
|
||||
ana_curvefit_2l_tube(normvideo, conf_data, errorin, ovrvwmem)
|
||||
else:
|
||||
if conf20 == 51:
|
||||
conf_data[19] = 1
|
||||
conf_data[2] = 0
|
||||
conf_data[3] = 0
|
||||
conf_data[4] = 0
|
||||
elif conf20 == 52:
|
||||
conf_data[19] = 2
|
||||
conf_data[2] = 0
|
||||
conf_data[3] = 0
|
||||
conf_data[4] = 0
|
||||
elif conf20 == 60 or conf20 == 62:
|
||||
conf_data[19] = 1
|
||||
conf_data[2] = 0
|
||||
conf_data[3] = 0
|
||||
conf_data[4] = 0
|
||||
elif conf20 == 61 or conf20 == 63:
|
||||
conf_data[19] = 2
|
||||
conf_data[2] = 0
|
||||
conf_data[3] = 0
|
||||
conf_data[4] = 0
|
||||
xL, xR, status, statusL, statusR, attL, attR, errorlevel, layeruse, IN = \
|
||||
analy01(normvideo, conf_data, errorin)
|
||||
|
||||
return xL, xR, status, statusL, statusR, attL, attR, errorlevel, layeruse, ovrvwmem, IN, detail
|
||||
|
||||
|
||||
def rotangle(settings, edges, results, status, avgmem):
|
||||
avw = np.zeros((3, 1))
|
||||
avw[1, 0] = 45
|
||||
x = np.zeros((3, 4))
|
||||
y = np.zeros((3, 4))
|
||||
return avw, avgmem, x, y
|
||||
|
||||
|
||||
def twist_compensation_sector(dk_x, dk_y, phi, xk, yk, x0_x, y0_y,
|
||||
b0, d0, r1, r2, maxTwist, orientation):
|
||||
b = np.array(dk_x).copy()
|
||||
d = np.array(dk_y).copy()
|
||||
return b, d
|
||||
|
||||
|
||||
def attprofile(IN_x, IN_y, dxZeile, edges, results, avgresults,
|
||||
attprofsett, avgdata, bRotateXDir, unit, att_avgmem):
|
||||
avgattcoeff = np.zeros(2)
|
||||
ringinfovek = np.zeros(10)
|
||||
return avgattcoeff, ringinfovek, att_avgmem
|
||||
|
||||
|
||||
def voiddetect(IN_x, IN_y, dxZeile, edges, results, voiddetectsett, unit, layeruse):
|
||||
return {}
|
||||
|
||||
|
||||
def startx2ana(rawvideo, rawdarkvideo, rawvideoDark_static, rawvideoDark_dynamic,
|
||||
rawbrightvideo, settings, errsettings, mem, init):
|
||||
from signal_utils import scan_norm
|
||||
from validation_utils import chksettings, plausi2000, plausi_layer, chk_tolchksettings
|
||||
from averaging_utils import avg_mval
|
||||
from detection_utils import AutoDetect
|
||||
from geometry_utils import xy_correct, modify_cable_position
|
||||
from layer_calibration_utils import layer_correct, uponor_alucorrect2
|
||||
|
||||
settings, err_meas_head = chksettings(settings, errsettings)
|
||||
|
||||
if errsettings is None:
|
||||
errsettings = np.zeros((2, 1))
|
||||
errsettings = np.atleast_2d(errsettings)
|
||||
if errsettings.shape[0] < 2:
|
||||
errsettings = np.zeros((2, 1))
|
||||
|
||||
gap = settings.get('gap', np.array([]))
|
||||
videoOffs = settings.get('videoOffs', 0)
|
||||
conf_data = np.asarray(settings['confData'], dtype=np.float64)
|
||||
|
||||
dxZeile = conf_data[91]
|
||||
video_req_time = conf_data[163] if len(conf_data) > 163 else 0.04
|
||||
|
||||
normvideo_x, mmPixel_x, errnorm, mem = scan_norm(
|
||||
rawvideo[0], rawbrightvideo[0], rawvideoDark_static[0], rawvideoDark_dynamic[0],
|
||||
dxZeile, gap, videoOffs, errsettings, mem, init, video_req_time
|
||||
)
|
||||
normvideo_y, mmPixel_y, errnorm, mem = scan_norm(
|
||||
rawvideo[1], rawbrightvideo[1], rawvideoDark_static[1], rawvideoDark_dynamic[1],
|
||||
dxZeile, gap, videoOffs, errsettings, mem, init, video_req_time
|
||||
)
|
||||
|
||||
normvideo = {'x': normvideo_x, 'y': normvideo_y}
|
||||
|
||||
settings['geometryData'] = settings.get('geometryData', {})
|
||||
settings['geometryData']['x_mmPixel'] = mmPixel_x
|
||||
settings['geometryData']['y_mmPixel'] = mmPixel_y
|
||||
|
||||
if 'StartX2Ana' not in mem:
|
||||
mem['StartX2Ana'] = {}
|
||||
if 'CableType' not in mem['StartX2Ana']:
|
||||
mem['StartX2Ana']['CableType'] = {}
|
||||
if 'ovrvwmem' not in mem['StartX2Ana']:
|
||||
mem['StartX2Ana']['ovrvwmem'] = {}
|
||||
if 'avgmem' not in mem['StartX2Ana']:
|
||||
mem['StartX2Ana']['avgmem'] = {}
|
||||
if 'att_avgmem' not in mem['StartX2Ana']:
|
||||
mem['StartX2Ana']['att_avgmem'] = {}
|
||||
if 'avgresults' not in mem['StartX2Ana']:
|
||||
mem['StartX2Ana']['avgresults'] = None
|
||||
|
||||
AutoDet = np.zeros(4)
|
||||
AutoDetHVon = conf_data[118] if len(conf_data) > 118 else 0
|
||||
|
||||
if AutoDetHVon == 0:
|
||||
if conf_data[19] == 0 and mem['StartX2Ana']['CableType'].get('BitInit', 0) == 0:
|
||||
mem['StartX2Ana']['CableType']['Number'] = np.zeros(25)
|
||||
mem['StartX2Ana']['CableType']['Counter'] = 0
|
||||
mem['StartX2Ana']['CableType']['Type'] = 0
|
||||
mem['StartX2Ana']['CableType']['NOMOSC'] = 0
|
||||
mem['StartX2Ana']['CableType']['NOMINS'] = 0
|
||||
mem['StartX2Ana']['CableType']['NOMISC'] = 0
|
||||
mem['StartX2Ana']['CableType']['BitInit'] = 1
|
||||
AutoDet = np.array([0, 0, 0, 0])
|
||||
elif conf_data[19] == 0 and mem['StartX2Ana']['CableType'].get('BitInit', 0) == 1:
|
||||
AutoDet = np.array([
|
||||
mem['StartX2Ana']['CableType'].get('Type', 0),
|
||||
mem['StartX2Ana']['CableType'].get('NOMOSC', 0),
|
||||
mem['StartX2Ana']['CableType'].get('NOMINS', 0),
|
||||
mem['StartX2Ana']['CableType'].get('NOMISC', 0),
|
||||
])
|
||||
elif conf_data[19] != 0 and mem['StartX2Ana']['CableType'].get('BitInit', 0) == 1:
|
||||
mem['StartX2Ana']['CableType']['BitInit'] = 0
|
||||
AutoDet = np.array([
|
||||
conf_data[19],
|
||||
mem['StartX2Ana']['CableType'].get('NOMOSC', 0),
|
||||
mem['StartX2Ana']['CableType'].get('NOMINS', 0),
|
||||
mem['StartX2Ana']['CableType'].get('NOMISC', 0),
|
||||
])
|
||||
elif conf_data[19] != 0 and mem['StartX2Ana']['CableType'].get('BitInit', 0) == 0:
|
||||
AutoDet = np.array([
|
||||
conf_data[19],
|
||||
mem['StartX2Ana']['CableType'].get('NOMOSC', 0),
|
||||
mem['StartX2Ana']['CableType'].get('NOMINS', 0),
|
||||
mem['StartX2Ana']['CableType'].get('NOMISC', 0),
|
||||
])
|
||||
|
||||
if mem['StartX2Ana']['CableType'].get('BitInit', 0) == 1:
|
||||
conf_data[92] = 1
|
||||
settings['confData'] = conf_data
|
||||
errnorm_in = np.asarray(errnorm).ravel()[:2]
|
||||
mem['StartX2Ana']['CableType'], errnorm_out = AutoDetect(
|
||||
normvideo['x'], conf_data, errnorm_in, mem['StartX2Ana']['CableType'])
|
||||
errnorm_flat = np.asarray(errnorm_out).ravel()
|
||||
errnorm[0, 0] = float(errnorm_flat[0])
|
||||
errnorm[1, 0] = float(errnorm_flat[1]) if len(errnorm_flat) > 1 else 0.0
|
||||
conf_data[92] = 0
|
||||
settings['confData'] = conf_data
|
||||
errnorm_in = np.asarray(errnorm).ravel()[:2]
|
||||
mem['StartX2Ana']['CableType'], errnorm_out = AutoDetect(
|
||||
normvideo['y'], conf_data, errnorm_in, mem['StartX2Ana']['CableType'])
|
||||
errnorm_flat = np.asarray(errnorm_out).ravel()
|
||||
errnorm[0, 0] = float(errnorm_flat[0])
|
||||
errnorm[1, 0] = float(errnorm_flat[1]) if len(errnorm_flat) > 1 else 0.0
|
||||
|
||||
if errnorm[0, 0] == 0:
|
||||
errnorm[0, 0] = 202
|
||||
|
||||
if mem['StartX2Ana']['CableType'].get('Type', 0) != 0:
|
||||
settings['CableType'] = mem['StartX2Ana']['CableType']['Type']
|
||||
settings['confData'][19] = mem['StartX2Ana']['CableType']['Type']
|
||||
AutoDet = np.array([
|
||||
mem['StartX2Ana']['CableType']['Type'],
|
||||
mem['StartX2Ana']['CableType'].get('NOMOSC', 0),
|
||||
mem['StartX2Ana']['CableType'].get('NOMINS', 0),
|
||||
mem['StartX2Ana']['CableType'].get('NOMISC', 0),
|
||||
])
|
||||
mem['StartX2Ana']['CableType']['BitInit'] = 0
|
||||
|
||||
conf_data[92] = 1
|
||||
settings['confData'] = conf_data
|
||||
(edgesL_x, edgesR_x, status_x, statusL_x, statusR_x, attL_x, attR_x, err_x,
|
||||
layeruse, mem['StartX2Ana']['ovrvwmem'], IN_x) = xray2000_ana_m(
|
||||
normvideo['x'], settings, errnorm, mem['StartX2Ana']['ovrvwmem'])[:11]
|
||||
|
||||
conf_data[92] = 0
|
||||
settings['confData'] = conf_data
|
||||
(edgesL_y, edgesR_y, status_y, statusL_y, statusR_y, attL_y, attR_y, err_y,
|
||||
layeruse, mem['StartX2Ana']['ovrvwmem'], IN_y) = xray2000_ana_m(
|
||||
normvideo['y'], settings, errnorm, mem['StartX2Ana']['ovrvwmem'])[:11]
|
||||
|
||||
edges = {
|
||||
'left': {'x': edgesL_x + settings['geometryData']['x_mmPixel'],
|
||||
'y': edgesL_y + settings['geometryData']['y_mmPixel']},
|
||||
'right': {'x': edgesR_x + settings['geometryData']['x_mmPixel'],
|
||||
'y': edgesR_y + settings['geometryData']['y_mmPixel']},
|
||||
}
|
||||
|
||||
geom_x = settings['geometryData'].get('x', {})
|
||||
geom_y = settings['geometryData'].get('y', {})
|
||||
|
||||
settings['correctionData'] = settings.get('correctionData', {})
|
||||
settings['correctionData']['delta_xk'] = 0
|
||||
settings['correctionData']['delta_yk'] = 0
|
||||
settings['correctionData']['x'] = settings['correctionData'].get('x', np.zeros(32))
|
||||
settings['correctionData']['y'] = settings['correctionData'].get('y', np.zeros(32))
|
||||
|
||||
(dmOut, oscL, oscR, isoL, isoR, iscL, iscR, coreDm, wthL, wthR, xk_res, yk_res) = xy_correct(
|
||||
edges['left']['x'], edges['right']['x'], edges['left']['y'], edges['right']['y'],
|
||||
geom_x.get('x0', 600), geom_x.get('y0', 600),
|
||||
geom_x.get('xCCD', 0), geom_x.get('yCCD', 0),
|
||||
geom_y.get('x0', 600), geom_y.get('y0', 600),
|
||||
geom_y.get('xCCD', 0), geom_y.get('yCCD', 0),
|
||||
geom_x.get('gamma', 90), geom_y.get('gamma', 90),
|
||||
status_x, status_y, statusL_x, statusR_x, statusL_y, statusR_y,
|
||||
settings['correctionData']['delta_xk'], settings['correctionData']['delta_yk'],
|
||||
settings['correctionData']['x'], settings['correctionData']['y'], 1, layeruse
|
||||
)
|
||||
|
||||
results = {
|
||||
'dmOut': dmOut,
|
||||
'left': {'osc': oscL, 'iso': isoL, 'isc': iscL, 'wth': wthL},
|
||||
'right': {'osc': oscR, 'iso': isoR, 'isc': iscR, 'wth': wthR},
|
||||
'coreDm': coreDm,
|
||||
'x': xk_res,
|
||||
'y': yk_res,
|
||||
'vw': np.zeros((3, 1)),
|
||||
}
|
||||
results['vw'][1, 0] = 45
|
||||
|
||||
cableType = conf_data[19]
|
||||
settings['cableData'] = settings.get('cableData', {})
|
||||
|
||||
if cableType in (51, 52, 53):
|
||||
if settings['cableData'].get('baseAngle', 0) > 0:
|
||||
orientation = settings['cableData'].get('orientation', 0)
|
||||
if orientation in (1, 3):
|
||||
settings['cableData']['height'] = dmOut[0, 0] * (dmOut[1, 0] == 0)
|
||||
else:
|
||||
settings['cableData']['height'] = dmOut[0, 1] * (dmOut[1, 1] == 0)
|
||||
|
||||
delta_xk, delta_yk = modify_cable_position(
|
||||
settings['cableData']['baseAngle'],
|
||||
orientation,
|
||||
settings['cableData']['height'])
|
||||
settings['correctionData']['delta_xk'] = delta_xk
|
||||
settings['correctionData']['delta_yk'] = delta_yk
|
||||
|
||||
(dmOut, oscL, oscR, isoL, isoR, iscL, iscR, coreDm, wthL, wthR, xk_res, yk_res) = xy_correct(
|
||||
edges['left']['x'], edges['right']['x'], edges['left']['y'], edges['right']['y'],
|
||||
geom_x.get('x0', 600), geom_x.get('y0', 600),
|
||||
geom_x.get('xCCD', 0), geom_x.get('yCCD', 0),
|
||||
geom_y.get('x0', 600), geom_y.get('y0', 600),
|
||||
geom_y.get('xCCD', 0), geom_y.get('yCCD', 0),
|
||||
geom_x.get('gamma', 90), geom_y.get('gamma', 90),
|
||||
status_x, status_y, statusL_x, statusR_x, statusL_y, statusR_y,
|
||||
settings['correctionData']['delta_xk'], settings['correctionData']['delta_yk'],
|
||||
settings['correctionData']['x'], settings['correctionData']['y'], 1, layeruse
|
||||
)
|
||||
results['dmOut'] = dmOut
|
||||
results['left']['osc'] = oscL
|
||||
results['right']['osc'] = oscR
|
||||
results['left']['iso'] = isoL
|
||||
results['right']['iso'] = isoR
|
||||
results['left']['isc'] = iscL
|
||||
results['right']['isc'] = iscR
|
||||
results['coreDm'] = coreDm
|
||||
results['left']['wth'] = wthL
|
||||
results['right']['wth'] = wthR
|
||||
results['x'] = xk_res
|
||||
results['y'] = yk_res
|
||||
|
||||
defaultval = np.array([[0, 0], [45, 45], [0, 0]])
|
||||
results['coreDm'] = defaultval.copy()
|
||||
results['left']['iso'] = defaultval.copy()
|
||||
results['left']['isc'] = defaultval.copy()
|
||||
results['right']['iso'] = defaultval.copy()
|
||||
results['right']['isc'] = defaultval.copy()
|
||||
if cableType in (51, 52):
|
||||
results['dmOut'] = defaultval.copy()
|
||||
|
||||
calib_struct = settings.get('calib_struct', {})
|
||||
_int = calib_struct.get('int')
|
||||
if _int is not None and (not isinstance(_int, np.ndarray) or _int.size > 0):
|
||||
results = layer_correct(results, calib_struct['int'], layeruse, cableType)
|
||||
else:
|
||||
defaultval = np.array([[0, 0], [191, 191], [0, 0]])
|
||||
results['dmOut'] = defaultval.copy()
|
||||
results['coreDm'] = defaultval.copy()
|
||||
results['left']['wth'] = defaultval.copy()
|
||||
results['left']['osc'] = defaultval.copy()
|
||||
results['left']['iso'] = defaultval.copy()
|
||||
results['left']['isc'] = defaultval.copy()
|
||||
results['right']['wth'] = defaultval.copy()
|
||||
results['right']['osc'] = defaultval.copy()
|
||||
results['right']['iso'] = defaultval.copy()
|
||||
results['right']['isc'] = defaultval.copy()
|
||||
|
||||
results = uponor_alucorrect2(results, cableType)
|
||||
|
||||
_ext = calib_struct.get('ext')
|
||||
if _ext is not None and (not isinstance(_ext, np.ndarray) or _ext.size > 0):
|
||||
results = layer_correct(results, calib_struct['ext'], layeruse, cableType)
|
||||
|
||||
tolchkactive = chk_tolchksettings(settings.get('tolchk', {}))
|
||||
if not tolchkactive:
|
||||
results = plausi2000(results, mem['StartX2Ana'].get('avgresults'), settings)
|
||||
|
||||
avgresults, mem['StartX2Ana']['avgmem'] = avg_mval(
|
||||
results, settings.get('avgData', {}), mem['StartX2Ana']['avgmem'])
|
||||
|
||||
if cableType == 53:
|
||||
avgresults['coreDm'][0, 0:2] = 0
|
||||
avgresults['coreDm'][1, 0:2] = 45
|
||||
avgresults['coreDm'][2, 0:2] = 0
|
||||
|
||||
avgresults = plausi_layer(avgresults, settings)
|
||||
mem['StartX2Ana']['avgresults'] = avgresults
|
||||
|
||||
attprofsett = settings.get('attprofsett', {})
|
||||
avgdata = settings.get('avgData', {})
|
||||
bRotateXDir = settings.get('bRotateXDir', 0)
|
||||
unit = settings.get('unit', 0)
|
||||
|
||||
AttCoeff, AttCoeffSt, mem['StartX2Ana']['att_avgmem'] = attprofile(
|
||||
IN_x, IN_y, conf_data[89], edges, results, avgresults,
|
||||
attprofsett, avgdata, bRotateXDir, unit, mem['StartX2Ana']['att_avgmem'])
|
||||
|
||||
voiddetectsett = settings.get('voiddetectsett', {})
|
||||
Void = voiddetect(IN_x, IN_y, conf_data[89], edges, results, voiddetectsett, unit, layeruse)
|
||||
|
||||
return avgresults, results, edges, status_x, status_y, attL_x, attR_x, attL_y, attR_y, \
|
||||
errnorm, AutoDet, mem, IN_x, IN_y, AttCoeff, AttCoeffSt, Void
|
||||
Reference in New Issue
Block a user