Files
CPY_AlgorithmGateway/algorithm/conv2dsp_utils.py
T
2026-07-30 18:46:32 +08:00

1150 lines
48 KiB
Python

import numpy as np
from thickness_utils import warnlogic, updateMinMaxWTH, updateMinMaxWTHall
def avgfunc(xL, sxL, xR, sxR, StOK, StWait, StNoteavg, reduceavgon):
xWt = 0.0
sxWt = 255.0
avgwarnxWt = 0.0
if sxL == StWait:
sxWt = sxL
xWt = xL
avgwarnxWt = 0
elif sxR == StWait:
sxWt = sxR
xWt = xR
avgwarnxWt = 0
elif (sxL == StOK) and (sxR != StOK):
if reduceavgon:
sxWt = 0
xWt = xL
avgwarnxWt = StNoteavg
else:
sxWt = sxR
xWt = 0
avgwarnxWt = 0
elif (sxL != StOK) and (sxR == StOK):
if reduceavgon:
sxWt = 0
xWt = xR
avgwarnxWt = StNoteavg
else:
sxWt = sxL
xWt = 0
avgwarnxWt = 0
elif (sxL != StOK) and (sxR != StOK):
sxWt = sxL
xWt = 0
avgwarnxWt = 0
else:
sxWt = sxL
xWt = (xL + xR) / 2
avgwarnxWt = 0
return xWt, sxWt, avgwarnxWt
def avgfuncDM(xL, sxL, xR, sxR, StOK, StWait, StNoteavg, reduceavgon):
xWt = 0.0
sxWt = 255.0
avgwarnxWt = 0.0
if (sxL == StWait) and (reduceavgon <= 1):
sxWt = sxL
xWt = xL
avgwarnxWt = 0
elif (sxR == StWait) and (reduceavgon <= 1):
sxWt = sxR
xWt = xR
avgwarnxWt = 0
elif (sxL == StOK) and (sxR != StOK):
if reduceavgon:
sxWt = 0
xWt = xL
avgwarnxWt = StNoteavg
else:
sxWt = sxR
xWt = 0
avgwarnxWt = 0
elif (sxL != StOK) and (sxR == StOK):
if reduceavgon:
sxWt = 0
xWt = xR
avgwarnxWt = StNoteavg
else:
sxWt = sxL
xWt = 0
avgwarnxWt = 0
elif (sxL != StOK) and (sxR != StOK):
sxWt = sxL
xWt = 0
avgwarnxWt = 0
else:
sxWt = sxL
xWt = (xL + xR) / 2
avgwarnxWt = 0
return xWt, sxWt, avgwarnxWt
def avg4func(xL, sxL, xR, sxR, yL, syL, yR, syR, StOK, StWait, StNoteavg, reduceavgon):
Wt = 0.0
sWt = 255.0
avgwarnWt = 0.0
values = np.array([xL, xR, yL, yR], dtype=np.float64)
status = np.array([sxL, sxR, syL, syR], dtype=np.float64)
waitind = np.where(status == StWait)[0]
okind = np.where(status == StOK)[0]
errind = np.where(status != StOK)[0]
if len(waitind) > 0 and (reduceavgon <= 1):
sWt = status[waitind[0]]
Wt = values[waitind[0]]
avgwarnWt = 0
elif len(okind) == 4:
sWt = 0
Wt = np.mean(values[okind])
avgwarnWt = 0
elif len(okind) > 0:
if reduceavgon:
sWt = 0
Wt = np.mean(values[okind])
avgwarnWt = StNoteavg
else:
sWt = status[errind[0]]
Wt = 0
avgwarnWt = 0
else:
sWt = status[errind[0]]
Wt = 0
avgwarnWt = 0
return Wt, sWt, avgwarnWt
def calc4modul(left, right, bRotateXDir, StOK, StWait, factMinWt, mm2inch,
calcecc, StNovalue, StNoteavg, reduceavgon, devicetype, cableType, NXT):
left = np.asarray(left, dtype=np.float64)
right = np.asarray(right, dtype=np.float64)
anzColWt = 2
MinMaxAng = np.zeros((3, anzColWt), dtype=np.float64)
MinMaxAng[1, :] = StNovalue
MinMaxAng[2, :] = 0
syL = left[1, 0]
if syL == StWait:
yL = left[0, 0]
else:
yL = left[0, 0] * mm2inch
sxL = left[1, 1]
if sxL == StWait:
xL = left[0, 1]
else:
xL = left[0, 1] * mm2inch
syR = right[1, 0]
if syR == StWait:
yR = right[0, 0]
else:
yR = right[0, 0] * mm2inch
sxR = right[1, 1]
if sxR == StWait:
xR = right[0, 1]
else:
xR = right[0, 1] * mm2inch
warnvek = np.array([left[2, 1], right[2, 1], left[2, 0], right[2, 0]], dtype=np.float64)
anzColWt = 13
Layer = np.zeros((3, anzColWt), dtype=np.float64)
Layer[1, :] = 255
Layer[2, :] = 0
if bRotateXDir > 0:
if ((devicetype == 8000) or (devicetype == 8100) or
((devicetype == 8001) and not NXT) or ((devicetype == 8101) and not NXT)):
h = xL; xL = yL; yL = h
h = sxL; sxL = syL; syL = h
h = xR; xR = yR; yR = h
h = sxR; sxR = syR; syR = h
warnvek = np.array([warnvek[1], warnvek[0], warnvek[3], warnvek[2]], dtype=np.float64)
elif ((devicetype == 8001) and NXT) or ((devicetype == 8101) and NXT):
h = yL; yL = yR; yR = h
h = syL; syL = syR; syR = h
warnvek = np.array([warnvek[1], warnvek[0], warnvek[2], warnvek[3]], dtype=np.float64)
else:
h = xL; xL = xR; xR = h
h = sxL; sxL = sxR; sxR = h
warnvek = np.array([warnvek[1], warnvek[0], warnvek[2], warnvek[3]], dtype=np.float64)
warnall, warnx, warny = warnlogic(warnvek)
xWt, sxWt, warnxWt = avgfunc(xL, sxL, xR, sxR, StOK, StWait, StNoteavg, reduceavgon)
yWt, syWt, warnyWt = avgfunc(yL, syL, yR, syR, StOK, StWait, StNoteavg, reduceavgon)
Wt, sWt, warnWt = avg4func(xL, sxL, xR, sxR, yL, syL, yR, syR, StOK, StWait, StNoteavg, reduceavgon)
if not warnWt:
warnWt = warnall
if not warnxWt:
warnxWt = warnx
if not warnyWt:
warnyWt = warny
xECC = 0.0
sxECC = StNovalue
yECC = 0.0
syECC = StNovalue
if calcecc:
if sxL != StOK:
xECC = 0
sxECC = sxL
elif sxR != StOK:
xECC = 0
sxECC = sxR
else:
xECC = (xL - xR) / 2
sxECC = 0
if syL != StOK:
yECC = 0
syECC = syL
elif syR != StOK:
yECC = 0
syECC = syR
else:
yECC = (yL - yR) / 2
syECC = 0
Ecc = 0.0
sEcc = 0.0
if sxECC != StOK:
sEcc = sxECC
elif syECC != StOK:
sEcc = syECC
Ang = 0.0
sAng = sEcc
if sEcc == StOK:
Ecc = np.sqrt(xECC * xECC + yECC * yECC)
Ang = np.arctan2(xECC, -yECC) * 180 / np.pi
if Ang < 0:
Ang = 360 + Ang
WtMin = 0.0
sWtMin = 255.0
status_arr = np.array([sxL, sxR, syL, syR], dtype=np.float64)
errind = np.where(status_arr != StOK)[0]
if len(errind) == 0:
vals = np.array([yL, xR, yR, xL], dtype=np.float64)
IndMin = np.argmin(vals)
WtMin = vals[IndMin]
MinMaxAng[0, 0] = 90 * IndMin
MinMaxAng[1, 0] = StOK
sWtMin = 0
else:
MinMaxAng[0, 0] = 0
MinMaxAng[1, 0] = StNovalue
sWtMin = status_arr[errind[0]]
WtMax = 0.0
sWtMax = 255.0
if len(errind) == 0:
vals = np.array([yL, xR, yR, xL], dtype=np.float64)
IndMax = np.argmax(vals)
WtMax = vals[IndMax]
MinMaxAng[0, 1] = 90 * IndMax
MinMaxAng[1, 1] = StOK
sWtMax = 0
else:
MinMaxAng[0, 1] = 0
MinMaxAng[1, 1] = StNovalue
sWtMax = status_arr[errind[0]]
MinMaxAng[2, :] = warnall
if cableType == 62 or cableType == 63:
if sWt == 249 and sxWt == 0:
Layer[0, 0] = xWt; Layer[1, 0] = sxWt; Layer[2, 0] = warnxWt
Layer[0, 1] = xWt; Layer[1, 1] = sxWt; Layer[2, 1] = warnxWt
Layer[0, 7] = xWt; Layer[1, 7] = sxWt; Layer[2, 7] = warnxWt
else:
Layer[0, 0] = Wt; Layer[1, 0] = sWt; Layer[2, 0] = warnWt
Layer[0, 1] = Wt; Layer[1, 1] = sWt; Layer[2, 1] = warnWt
Layer[0, 7] = Wt; Layer[1, 7] = sWt; Layer[2, 7] = warnWt
if sWt == 249 and syWt == 0:
Layer[0, 2] = yWt; Layer[1, 2] = syWt; Layer[2, 2] = warnyWt
Layer[0, 3] = yWt; Layer[1, 3] = syWt; Layer[2, 3] = warnyWt
Layer[0, 8] = yWt; Layer[1, 8] = syWt; Layer[2, 8] = warnyWt
else:
Layer[0, 2] = Wt; Layer[1, 2] = sWt; Layer[2, 2] = warnWt
Layer[0, 3] = Wt; Layer[1, 3] = sWt; Layer[2, 3] = warnWt
Layer[0, 8] = Wt; Layer[1, 8] = sWt; Layer[2, 8] = warnWt
Layer[0, 4] = Wt; Layer[1, 4] = sWt; Layer[2, 4] = warnWt
Layer[0, 5] = Wt; Layer[1, 5] = sWt; Layer[2, 5] = warnWt
Layer[0, 6] = Wt; Layer[1, 6] = sWt; Layer[2, 6] = warnWt
Layer[0, 9] = 0; Layer[1, 9] = sWt; Layer[2, 9] = warnWt
Layer[0, 10] = 0; Layer[1, 10] = sWt; Layer[2, 10] = warnWt
Layer[0, 11] = 0; Layer[1, 11] = sWt; Layer[2, 11] = warnWt
Layer[0, 12] = 0; Layer[1, 12] = sWt; Layer[2, 12] = warnWt
else:
Layer[0, 0] = xL; Layer[1, 0] = sxL; Layer[2, 0] = warnvek[0]
Layer[0, 1] = xR; Layer[1, 1] = sxR; Layer[2, 1] = warnvek[1]
Layer[0, 2] = yL; Layer[1, 2] = syL; Layer[2, 2] = warnvek[2]
Layer[0, 3] = yR; Layer[1, 3] = syR; Layer[2, 3] = warnvek[3]
Layer[0, 4] = Wt; Layer[1, 4] = sWt; Layer[2, 4] = warnWt
Layer[0, 5] = WtMin; Layer[1, 5] = sWtMin; Layer[2, 5] = warnall
Layer[0, 6] = WtMax; Layer[1, 6] = sWtMax; Layer[2, 6] = warnall
Layer[0, 7] = xWt; Layer[1, 7] = sxWt; Layer[2, 7] = warnxWt
Layer[0, 8] = yWt; Layer[1, 8] = syWt; Layer[2, 8] = warnyWt
Layer[0, 9] = Ecc; Layer[1, 9] = sEcc; Layer[2, 9] = warnall
Layer[0, 10] = Ang; Layer[1, 10] = sAng; Layer[2, 10] = warnall
Layer[0, 11] = xECC; Layer[1, 11] = sxECC; Layer[2, 11] = warnx
Layer[0, 12] = yECC; Layer[1, 12] = syECC; Layer[2, 12] = warny
if ((devicetype == 8000) and NXT) or ((devicetype == 8100) and NXT):
Layer[0, 10] = (Layer[0, 10] + 45) % 360
elif ((devicetype == 8001) and NXT) or ((devicetype == 8101) and NXT):
Layer[0, 10] = (Layer[0, 10] + 90) % 360
return Layer, MinMaxAng
def _safe_get(obj, *keys, default=None):
current = obj
for key in keys:
if isinstance(current, dict):
current = current.get(key)
else:
return default
if current is None:
return default
return current
def _safe_arr_get(arr, idx1, idx2, default=0.0):
try:
a = np.asarray(arr, dtype=np.float64)
if a.ndim >= 2:
return float(a[idx1, idx2])
elif a.ndim == 1:
return float(a[idx1])
except (IndexError, TypeError, ValueError):
pass
return float(default)
def calctwist2(avgresults, layeruse, angle):
TWIST_CALC_ERROR = 91
if isinstance(layeruse, np.ndarray):
layeruse = layeruse.ravel()
layeruse = np.asarray(layeruse, dtype=np.float64).ravel()
if len(layeruse) < 3:
layeruse = np.pad(layeruse, (0, 3 - len(layeruse)), mode='constant')
left_osc = np.asarray(avgresults['left']['osc'], dtype=np.float64).copy()
right_osc = np.asarray(avgresults['right']['osc'], dtype=np.float64).copy()
left_iso = np.asarray(avgresults['left']['iso'], dtype=np.float64).copy()
right_iso = np.asarray(avgresults['right']['iso'], dtype=np.float64).copy()
left_isc = np.asarray(avgresults['left']['isc'], dtype=np.float64).copy()
right_isc = np.asarray(avgresults['right']['isc'], dtype=np.float64).copy()
left_wth = np.asarray(avgresults['left']['wth'], dtype=np.float64).copy()
right_wth = np.asarray(avgresults['right']['wth'], dtype=np.float64).copy()
dmOut = np.asarray(avgresults['dmOut'], dtype=np.float64).copy()
coreDm = np.asarray(avgresults['coreDm'], dtype=np.float64).copy()
faillayer = np.zeros(3, dtype=bool)
faillayer[0] = not (layeruse[0] and (np.all(left_osc[1, :] == 0) and np.all(right_osc[1, :] == 0)))
faillayer[1] = not (layeruse[1] and (np.all(left_iso[1, :] == 0) and np.all(right_iso[1, :] == 0)))
faillayer[2] = not (layeruse[2] and (np.all(left_isc[1, :] == 0) and np.all(right_isc[1, :] == 0)))
all_ok = (np.all(dmOut[1, :] == 0) and np.all(coreDm[1, :] == 0) and
np.all(left_wth[1, :] == 0) and np.all(right_wth[1, :] == 0))
if all_ok:
xy0 = np.zeros((5, 2))
xy0[4, :] = np.diff(np.vstack([left_wth[0, :], right_wth[0, :]]), axis=0) / 2
xy0[3, :] = xy0[4, :]
xy0[2, :] = np.diff(np.vstack([left_wth[0, :] - left_isc[0, :], right_wth[0, :] - right_isc[0, :]]), axis=0) / 2
xy0[1, :] = np.diff(np.vstack([left_wth[0, :] - left_isc[0, :] - left_iso[0, :], right_wth[0, :] - right_isc[0, :] - right_iso[0, :]]), axis=0) / 2
xy0[0, :] = [0, 0]
xy0[:, 0] = -xy0[:, 0]
ab = np.zeros((5, 2))
ab[4, :] = coreDm[0, :] / 2
ab[3, :] = ab[4, :]
ab[2, :] = ab[3, :] + (left_isc[0, :] + right_isc[0, :]) / 2
ab[1, :] = ab[2, :] + (left_iso[0, :] + right_iso[0, :]) / 2
ab[0, :] = dmOut[0, :] / 2
with np.errstate(invalid='ignore', divide='ignore'):
t_n = np.arctan(np.sqrt((xy0[:, 0]**2 - ab[:, 0]**2) / (xy0[:, 1]**2 - ab[:, 1]**2)) * (xy0[:, 1] / ab[:, 0]))
ab_n = np.column_stack([ab[:, 0] / np.cos(t_n), xy0[:, 1] / np.sin(t_n)])
angle = 2 * np.pi - angle
phi = np.mod(angle + np.array([0, 3 * np.pi / 2]), 2 * np.pi)
for i in range(len(phi)):
t = np.arctan(ab[0, 0] / ab[0, 1] * np.tan(phi[i]))
xrl = np.array([[ab[0, 0] * np.cos(t), -ab[0, 0] * np.cos(t)]])
yrl = np.array([[ab[0, 1] * np.sin(t), -ab[0, 1] * np.sin(t)]])
p = xrl[0, 0] * (xrl[0, 0] * xy0[:, 0] * ab_n[:, 1]**2 + yrl[0, 0] * xy0[:, 1] * ab_n[:, 0]**2) / ((xrl[0, 0] * ab_n[:, 1])**2 + (yrl[0, 0] * ab_n[:, 0])**2)
q = xrl[0, 0]**2 * ((xy0[:, 0] * ab_n[:, 1])**2 + (xy0[:, 1] * ab_n[:, 0])**2 - (ab_n[:, 0] * ab_n[:, 1])**2) / ((xrl[0, 0] * ab_n[:, 1])**2 + (yrl[0, 0] * ab_n[:, 0])**2)
xi = np.column_stack([p + np.sqrt(p**2 - q), p - np.sqrt(p**2 - q)])
lu_mask = np.concatenate([[1], layeruse, [1]])
xi = xi * lu_mask[:, np.newaxis]
xrl = np.vstack([xrl, xi[1:, :]])
yi = yrl[0, 0] / xrl[0, 0] * xi
yrl = np.vstack([yrl, yi[1:, :]])
if (phi[i] > np.pi / 2) and (phi[i] <= 3 * np.pi / 2):
xrl = np.fliplr(xrl)
yrl = np.fliplr(yrl)
if np.allclose(layeruse, [1, 0, 0]):
pass
elif np.allclose(layeruse, [0, 1, 0]):
xrl[1, :] = xrl[0, :]
yrl[1, :] = yrl[0, :]
elif np.allclose(layeruse, [0, 0, 1]):
xrl[2, :] = xrl[0, :]
yrl[2, :] = yrl[0, :]
elif np.allclose(layeruse, [1, 1, 0]):
pass
elif np.allclose(layeruse, [0, 1, 1]):
xrl[1, :] = xrl[0, :]
yrl[1, :] = yrl[0, :]
elif np.allclose(layeruse, [1, 0, 1]):
xrl[2, :] = xrl[1, :]
yrl[2, :] = yrl[1, :]
elif np.allclose(layeruse, [1, 1, 1]):
pass
dmOut[0, i] = np.sqrt(xrl[0, 0]**2 + yrl[0, 0]**2) + np.sqrt(xrl[0, 1]**2 + yrl[0, 1]**2)
coreDm[0, i] = np.sqrt(xrl[4, 0]**2 + yrl[4, 0]**2) + np.sqrt(xrl[4, 1]**2 + yrl[4, 1]**2)
left_wth[0, i] = np.sqrt((xrl[0, 1] - xrl[4, 1])**2 + (yrl[0, 1] - yrl[4, 1])**2)
right_wth[0, i] = np.sqrt((xrl[0, 0] - xrl[4, 0])**2 + (yrl[0, 0] - yrl[4, 0])**2)
if not faillayer[0]:
left_osc[0, i] = np.sqrt((xrl[0, 1] - xrl[1, 1])**2 + (yrl[0, 1] - yrl[1, 1])**2) * layeruse[0]
right_osc[0, i] = np.sqrt((xrl[0, 0] - xrl[1, 0])**2 + (yrl[0, 0] - yrl[1, 0])**2) * layeruse[0]
else:
if left_osc[1, i] == 0:
left_osc[1, i] = TWIST_CALC_ERROR
if right_osc[1, i] == 0:
right_osc[1, i] = TWIST_CALC_ERROR
if not faillayer[1]:
left_iso[0, i] = np.sqrt((xrl[1, 1] - xrl[2, 1])**2 + (yrl[1, 1] - yrl[2, 1])**2) * layeruse[1]
right_iso[0, i] = np.sqrt((xrl[1, 0] - xrl[2, 0])**2 + (yrl[1, 0] - yrl[2, 0])**2) * layeruse[1]
else:
if left_iso[1, i] == 0:
left_iso[1, i] = TWIST_CALC_ERROR
if right_iso[1, i] == 0:
right_iso[1, i] = TWIST_CALC_ERROR
if not faillayer[2]:
left_isc[0, i] = np.sqrt((xrl[2, 1] - xrl[3, 1])**2 + (yrl[2, 1] - yrl[3, 1])**2) * layeruse[2]
right_isc[0, i] = np.sqrt((xrl[2, 0] - xrl[3, 0])**2 + (yrl[2, 0] - yrl[3, 0])**2) * layeruse[2]
else:
if left_isc[1, i] == 0:
left_isc[1, i] = TWIST_CALC_ERROR
if right_isc[1, i] == 0:
right_isc[1, i] = TWIST_CALC_ERROR
else:
dmOut[1, dmOut[1, :] == 0] = TWIST_CALC_ERROR
left_osc[1, left_osc[1, :] == 0] = TWIST_CALC_ERROR
right_osc[1, right_osc[1, :] == 0] = TWIST_CALC_ERROR
left_iso[1, left_iso[1, :] == 0] = TWIST_CALC_ERROR
right_iso[1, right_iso[1, :] == 0] = TWIST_CALC_ERROR
left_isc[1, left_isc[1, :] == 0] = TWIST_CALC_ERROR
right_isc[1, right_isc[1, :] == 0] = TWIST_CALC_ERROR
coreDm[1, coreDm[1, :] == 0] = TWIST_CALC_ERROR
left_wth[1, left_wth[1, :] == 0] = TWIST_CALC_ERROR
right_wth[1, right_wth[1, :] == 0] = TWIST_CALC_ERROR
result = {
'left': {
'osc': left_osc,
'iso': left_iso,
'isc': left_isc,
'wth': left_wth,
},
'right': {
'osc': right_osc,
'iso': right_iso,
'isc': right_isc,
'wth': right_wth,
},
'dmOut': dmOut,
'coreDm': coreDm,
}
return result
def conv2dsp(avgresults, bRotateXDir, factMinWt, unit, layeruse, cableType, eightpoint,
reduceavgon, angle, settings, devicetype, sectorAna, NXT):
StOK = 0
StWait = 249
StDefault = 255
StNovalue = 45
StNoteavg = 73
anzColDm = 3
if unit == 0:
mm2inch = 1
else:
mm2inch = 1 / 25.4
if (cableType in (51, 52, 53) or sectorAna or cableType in (62, 63)):
calcecc = 0
else:
calcecc = 1
if eightpoint is not None and not sectorAna:
EPFlag = eightpoint
else:
EPFlag = 0
if reduceavgon is None or (isinstance(reduceavgon, np.ndarray) and reduceavgon.size == 0):
reduceavgon = 0
elif isinstance(reduceavgon, (int, float)):
pass
else:
reduceavgon = float(np.asarray(reduceavgon).ravel()[0]) if np.asarray(reduceavgon).size > 0 else 0
anzColWt = 8
MinMaxAng = StDefault * np.ones((3, anzColWt), dtype=np.float64)
MinMaxAng[2, :] = 0
# 获取 avgresults 的嵌套结构
avgresults_left = _safe_get(avgresults, 'left', default={})
avgresults_right = _safe_get(avgresults, 'right', default={})
avgresults_coreDm = np.asarray(_safe_get(avgresults, 'coreDm', default=np.zeros((3, 2))), dtype=np.float64)
avgresults_dmOut = np.asarray(_safe_get(avgresults, 'dmOut', default=np.zeros((3, 2))), dtype=np.float64)
avgresults_eightPT = _safe_get(avgresults, 'eightPT', default={})
# eightPT 子结构
eightPT_left = _safe_get(avgresults_eightPT, 'left', default={})
eightPT_right = _safe_get(avgresults_eightPT, 'right', default={})
eightPT_coreDm = np.asarray(_safe_get(avgresults_eightPT, 'coreDm', default=np.zeros((3, 2))), dtype=np.float64)
eightPT_dmOut = np.asarray(_safe_get(avgresults_eightPT, 'dmOut', default=np.zeros((3, 2))), dtype=np.float64)
if isinstance(eightPT_left, dict):
if 'osc' in eightPT_left:
osc_arr = np.asarray(eightPT_left['osc'])
# 确保 layeruse 是正确的格式
if isinstance(layeruse, np.ndarray):
layeruse = layeruse.ravel()
elif isinstance(layeruse, (list, tuple)):
layeruse = np.asarray(layeruse, dtype=np.float64).ravel()
else:
layeruse = np.asarray([layeruse], dtype=np.float64).ravel()
if len(layeruse) < 3:
layeruse = np.pad(layeruse, (0, 3 - len(layeruse)), mode='constant')
# 调用 calc4modul 计算各层
OSC, MinMaxAng[:, 0:2] = calc4modul(
_safe_get(avgresults_left, 'osc', default=np.zeros((3, 2))),
_safe_get(avgresults_right, 'osc', default=np.zeros((3, 2))),
bRotateXDir, StOK, StWait, 1, mm2inch,
calcecc, StNovalue, StNoteavg, reduceavgon, devicetype, cableType, NXT
)
ISO, MinMaxAng[:, 2:4] = calc4modul(
_safe_get(avgresults_left, 'iso', default=np.zeros((3, 2))),
_safe_get(avgresults_right, 'iso', default=np.zeros((3, 2))),
bRotateXDir, StOK, StWait, 1, mm2inch,
calcecc, StNovalue, StNoteavg, reduceavgon, devicetype, cableType, NXT
)
ISC, MinMaxAng[:, 4:6] = calc4modul(
_safe_get(avgresults_left, 'isc', default=np.zeros((3, 2))),
_safe_get(avgresults_right, 'isc', default=np.zeros((3, 2))),
bRotateXDir, StOK, StWait, 1, mm2inch,
calcecc, StNovalue, StNoteavg, reduceavgon, devicetype, cableType, NXT
)
WTH, MinMaxAng[:, 6:8] = calc4modul(
_safe_get(avgresults_left, 'wth', default=np.zeros((3, 2))),
_safe_get(avgresults_right, 'wth', default=np.zeros((3, 2))),
bRotateXDir, StOK, StWait, factMinWt, mm2inch,
calcecc, StNovalue, StNoteavg, reduceavgon, devicetype, cableType, NXT
)
WTH_8pt, _ = calc4modul(
_safe_get(eightPT_left, 'wth', default=np.zeros((3, 2))),
_safe_get(eightPT_right, 'wth', default=np.zeros((3, 2))),
bRotateXDir, StOK, StWait, factMinWt, mm2inch,
calcecc, StNovalue, StNoteavg, reduceavgon, devicetype, cableType, NXT
)
# ==================== DMCore 计算 ====================
DMCore = StDefault * np.ones((3, anzColDm), dtype=np.float64)
DMCore[2, :] = 0
DMCore_8pt = StDefault * np.ones((3, anzColDm), dtype=np.float64)
DMCore_8pt[2, :] = 0
is_8k_device = ((devicetype == 8000) or (devicetype == 8100) or
((devicetype == 8001) and not NXT) or ((devicetype == 8101) and not NXT))
if is_8k_device:
if bRotateXDir == 1:
syDm = _safe_arr_get(avgresults_coreDm, 1, 1)
if syDm == StWait:
dmy = _safe_arr_get(avgresults_coreDm, 0, 1)
else:
dmy = _safe_arr_get(avgresults_coreDm, 0, 1) * mm2inch
sxDm = _safe_arr_get(avgresults_coreDm, 1, 0)
if sxDm == StWait:
dmx = _safe_arr_get(avgresults_coreDm, 0, 0)
else:
dmx = _safe_arr_get(avgresults_coreDm, 0, 0) * mm2inch
warnvek = np.array([_safe_arr_get(avgresults_coreDm, 2, 0), 0,
_safe_arr_get(avgresults_coreDm, 2, 1), 0], dtype=np.float64)
syDm_8pt = _safe_arr_get(eightPT_coreDm, 1, 1)
if syDm_8pt == StWait:
dmy_8pt = _safe_arr_get(eightPT_coreDm, 0, 1)
else:
dmy_8pt = _safe_arr_get(eightPT_coreDm, 0, 1) * mm2inch
sxDm_8pt = _safe_arr_get(eightPT_coreDm, 1, 0)
if sxDm_8pt == StWait:
dmx_8pt = _safe_arr_get(eightPT_coreDm, 0, 0)
else:
dmx_8pt = _safe_arr_get(eightPT_coreDm, 0, 0) * mm2inch
warnvek_8pt = np.array([_safe_arr_get(eightPT_coreDm, 2, 0), 0,
_safe_arr_get(eightPT_coreDm, 2, 1), 0], dtype=np.float64)
else:
syDm = _safe_arr_get(avgresults_coreDm, 1, 0)
if syDm == StWait:
dmy = _safe_arr_get(avgresults_coreDm, 0, 0)
else:
dmy = _safe_arr_get(avgresults_coreDm, 0, 0) * mm2inch
sxDm = _safe_arr_get(avgresults_coreDm, 1, 1)
if sxDm == StWait:
dmx = _safe_arr_get(avgresults_coreDm, 0, 1)
else:
dmx = _safe_arr_get(avgresults_coreDm, 0, 1) * mm2inch
warnvek = np.array([_safe_arr_get(avgresults_coreDm, 2, 1), 0,
_safe_arr_get(avgresults_coreDm, 2, 0), 0], dtype=np.float64)
syDm_8pt = _safe_arr_get(eightPT_coreDm, 1, 0)
if syDm_8pt == StWait:
dmy_8pt = _safe_arr_get(eightPT_coreDm, 0, 0)
else:
dmy_8pt = _safe_arr_get(eightPT_coreDm, 0, 0) * mm2inch
sxDm_8pt = _safe_arr_get(eightPT_coreDm, 1, 1)
if sxDm_8pt == StWait:
dmx_8pt = _safe_arr_get(eightPT_coreDm, 0, 1)
else:
dmx_8pt = _safe_arr_get(eightPT_coreDm, 0, 1) * mm2inch
warnvek_8pt = np.array([_safe_arr_get(eightPT_coreDm, 2, 1), 0,
_safe_arr_get(eightPT_coreDm, 2, 0), 0], dtype=np.float64)
else:
syDm = _safe_arr_get(avgresults_coreDm, 1, 0)
if syDm == StWait:
dmy = _safe_arr_get(avgresults_coreDm, 0, 0)
else:
dmy = _safe_arr_get(avgresults_coreDm, 0, 0) * mm2inch
sxDm = _safe_arr_get(avgresults_coreDm, 1, 1)
if sxDm == StWait:
dmx = _safe_arr_get(avgresults_coreDm, 0, 1)
else:
dmx = _safe_arr_get(avgresults_coreDm, 0, 1) * mm2inch
warnvek = np.array([_safe_arr_get(avgresults_coreDm, 2, 1), 0,
_safe_arr_get(avgresults_coreDm, 2, 0), 0], dtype=np.float64)
syDm_8pt = _safe_arr_get(eightPT_coreDm, 1, 0)
if syDm_8pt == StWait:
dmy_8pt = _safe_arr_get(eightPT_coreDm, 0, 0)
else:
dmy_8pt = _safe_arr_get(eightPT_coreDm, 0, 0) * mm2inch
sxDm_8pt = _safe_arr_get(eightPT_coreDm, 1, 1)
if sxDm_8pt == StWait:
dmx_8pt = _safe_arr_get(eightPT_coreDm, 0, 1)
else:
dmx_8pt = _safe_arr_get(eightPT_coreDm, 0, 1) * mm2inch
warnvek_8pt = np.array([_safe_arr_get(eightPT_coreDm, 2, 1), 0,
_safe_arr_get(eightPT_coreDm, 2, 0), 0], dtype=np.float64)
warnall, warnx, warny = warnlogic(warnvek)
warnall_8pt, warnx_8pt, warny_8pt = warnlogic(warnvek_8pt)
dm, sDm, warnavgdm = avgfuncDM(dmx, sxDm, dmy, syDm, StOK, StWait, StNoteavg, reduceavgon)
dm_8pt, sDm_8pt, warnavgdm_8pt = avgfuncDM(dmx_8pt, sxDm_8pt, dmy_8pt, syDm_8pt, StOK, StWait, StNoteavg, reduceavgon)
if not warnavgdm:
warnavgdm = warnall
if not warnavgdm_8pt:
warnavgdm_8pt = warnall_8pt
if cableType in (1, 2) and sectorAna:
DMCore[0, :] = 0
DMCore[1, :] = StNovalue
DMCore_8pt[0, :] = 0
DMCore_8pt[1, :] = StNovalue
else:
DMCore[0, 0] = dm; DMCore[1, 0] = sDm; DMCore[2, 0] = warnavgdm
DMCore[0, 1] = dmx; DMCore[1, 1] = sxDm; DMCore[2, 1] = warnx
DMCore[0, 2] = dmy; DMCore[1, 2] = syDm; DMCore[2, 2] = warny
DMCore_8pt[0, 0] = dm_8pt; DMCore_8pt[1, 0] = sDm_8pt; DMCore_8pt[2, 0] = warnavgdm_8pt
DMCore_8pt[0, 1] = dmx_8pt; DMCore_8pt[1, 1] = sxDm_8pt; DMCore_8pt[2, 1] = warnx_8pt
DMCore_8pt[0, 2] = dmy_8pt; DMCore_8pt[1, 2] = syDm_8pt; DMCore_8pt[2, 2] = warny_8pt
# ==================== DMTotal 计算 ====================
DMTotal = StDefault * np.ones((3, anzColDm), dtype=np.float64)
DMTotal[2, :] = 0
DMTotal_8pt = StDefault * np.ones((3, anzColDm), dtype=np.float64)
DMTotal_8pt[2, :] = 0
if is_8k_device:
if bRotateXDir == 1:
syDm = _safe_arr_get(avgresults_dmOut, 1, 1)
if syDm == StWait:
dmy = _safe_arr_get(avgresults_dmOut, 0, 1)
else:
dmy = _safe_arr_get(avgresults_dmOut, 0, 1) * mm2inch
sxDm = _safe_arr_get(avgresults_dmOut, 1, 0)
if sxDm == StWait:
dmx = _safe_arr_get(avgresults_dmOut, 0, 0)
else:
dmx = _safe_arr_get(avgresults_dmOut, 0, 0) * mm2inch
warnvek = np.array([_safe_arr_get(avgresults_dmOut, 2, 0), 0,
_safe_arr_get(avgresults_dmOut, 2, 1), 0], dtype=np.float64)
syDm_8pt = _safe_arr_get(eightPT_dmOut, 1, 1)
if syDm_8pt == StWait:
dmy_8pt = _safe_arr_get(eightPT_dmOut, 0, 1)
else:
dmy_8pt = _safe_arr_get(eightPT_dmOut, 0, 1) * mm2inch
sxDm_8pt = _safe_arr_get(eightPT_dmOut, 1, 0)
if sxDm_8pt == StWait:
dmx_8pt = _safe_arr_get(eightPT_dmOut, 0, 0)
else:
dmx_8pt = _safe_arr_get(eightPT_dmOut, 0, 0) * mm2inch
warnvek_8pt = np.array([_safe_arr_get(eightPT_dmOut, 2, 0), 0,
_safe_arr_get(eightPT_dmOut, 2, 1), 0], dtype=np.float64)
else:
syDm = _safe_arr_get(avgresults_dmOut, 1, 0)
if syDm == StWait:
dmy = _safe_arr_get(avgresults_dmOut, 0, 0)
else:
dmy = _safe_arr_get(avgresults_dmOut, 0, 0) * mm2inch
sxDm = _safe_arr_get(avgresults_dmOut, 1, 1)
if sxDm == StWait:
dmx = _safe_arr_get(avgresults_dmOut, 0, 1)
else:
dmx = _safe_arr_get(avgresults_dmOut, 0, 1) * mm2inch
warnvek = np.array([_safe_arr_get(avgresults_dmOut, 2, 1), 0,
_safe_arr_get(avgresults_dmOut, 2, 0), 0], dtype=np.float64)
syDm_8pt = _safe_arr_get(eightPT_dmOut, 1, 0)
if syDm_8pt == StWait:
dmy_8pt = _safe_arr_get(eightPT_dmOut, 0, 0)
else:
dmy_8pt = _safe_arr_get(eightPT_dmOut, 0, 0) * mm2inch
sxDm_8pt = _safe_arr_get(eightPT_dmOut, 1, 1)
if sxDm_8pt == StWait:
dmx_8pt = _safe_arr_get(eightPT_dmOut, 0, 1)
else:
dmx_8pt = _safe_arr_get(eightPT_dmOut, 0, 1) * mm2inch
warnvek_8pt = np.array([_safe_arr_get(eightPT_dmOut, 2, 1), 0,
_safe_arr_get(eightPT_dmOut, 2, 0), 0], dtype=np.float64)
else:
syDm = _safe_arr_get(avgresults_dmOut, 1, 0)
if syDm == StWait:
dmy = _safe_arr_get(avgresults_dmOut, 0, 0)
else:
dmy = _safe_arr_get(avgresults_dmOut, 0, 0) * mm2inch
sxDm = _safe_arr_get(avgresults_dmOut, 1, 1)
if sxDm == StWait:
dmx = _safe_arr_get(avgresults_dmOut, 0, 1)
else:
dmx = _safe_arr_get(avgresults_dmOut, 0, 1) * mm2inch
warnvek = np.array([_safe_arr_get(avgresults_dmOut, 2, 1), 0,
_safe_arr_get(avgresults_dmOut, 2, 0), 0], dtype=np.float64)
syDm_8pt = _safe_arr_get(eightPT_dmOut, 1, 0)
if syDm_8pt == StWait:
dmy_8pt = _safe_arr_get(eightPT_dmOut, 0, 0)
else:
dmy_8pt = _safe_arr_get(eightPT_dmOut, 0, 0) * mm2inch
sxDm_8pt = _safe_arr_get(eightPT_dmOut, 1, 1)
if sxDm_8pt == StWait:
dmx_8pt = _safe_arr_get(eightPT_dmOut, 0, 1)
else:
dmx_8pt = _safe_arr_get(eightPT_dmOut, 0, 1) * mm2inch
warnvek_8pt = np.array([_safe_arr_get(eightPT_dmOut, 2, 1), 0,
_safe_arr_get(eightPT_dmOut, 2, 0), 0], dtype=np.float64)
warnall, warnx, warny = warnlogic(warnvek)
warnall_8pt, warnx_8pt, warny_8pt = warnlogic(warnvek_8pt)
dm, sDm, warnavgdm = avgfuncDM(dmx, sxDm, dmy, syDm, StOK, StWait, StNoteavg, reduceavgon)
dm_8pt, sDm_8pt, warnavgdm_8pt = avgfuncDM(dmx_8pt, sxDm_8pt, dmy_8pt, syDm_8pt, StOK, StWait, StNoteavg, reduceavgon)
if (warnavgdm == 73) and (cableType == 53):
warnavgdm = 0
if (warnavgdm_8pt == 73) and (cableType == 53):
warnavgdm_8pt = 0
if not warnavgdm:
warnavgdm = warnall
if not warnavgdm_8pt:
warnavgdm_8pt = warnall_8pt
if cableType in (1, 2) and sectorAna:
DMTotal[0, :] = 0
DMTotal[1, :] = StNovalue
DMTotal_8pt[0, :] = 0
DMTotal_8pt[1, :] = StNovalue
else:
DMTotal[0, 0] = dm; DMTotal[1, 0] = sDm; DMTotal[2, 0] = warnavgdm
DMTotal[0, 1] = dmx; DMTotal[1, 1] = sxDm; DMTotal[2, 1] = warnx
DMTotal[0, 2] = dmy; DMTotal[1, 2] = syDm; DMTotal[2, 2] = warny
DMTotal_8pt[0, 0] = dm_8pt; DMTotal_8pt[1, 0] = sDm_8pt; DMTotal_8pt[2, 0] = warnavgdm_8pt
DMTotal_8pt[0, 1] = dmx_8pt; DMTotal_8pt[1, 1] = sxDm_8pt; DMTotal_8pt[2, 1] = warnx_8pt
DMTotal_8pt[0, 2] = dmy_8pt; DMTotal_8pt[1, 2] = syDm_8pt; DMTotal_8pt[2, 2] = warny_8pt
# ==================== DMISO 计算 ====================
DMISO = np.zeros((3, 3), dtype=np.float64)
DMISO[1, :] = StDefault
def _status_ok(s):
return s in (StOK, StWait)
if np.allclose(layeruse[:3], [0, 1, 0]) or np.allclose(layeruse[:3], [0, 1, 1]):
DMISO = DMTotal_8pt.copy()
elif np.allclose(layeruse[:3], [1, 1, 0]) or np.allclose(layeruse[:3], [1, 1, 1]):
if _status_ok(DMTotal_8pt[1, 1]) and _status_ok(OSC[1, 0]) and _status_ok(OSC[1, 1]):
DMISO[0, 1] = DMTotal_8pt[0, 1] - OSC[0, 0] - OSC[0, 1]
DMISO[1, 1] = 0
if _status_ok(DMTotal_8pt[1, 2]) and _status_ok(OSC[1, 2]) and _status_ok(OSC[1, 3]):
DMISO[0, 2] = DMTotal_8pt[0, 2] - OSC[0, 2] - OSC[0, 3]
DMISO[1, 2] = 0
if not (DMISO[1, 1] or DMISO[1, 2]):
DMISO[0, 0] = 0.5 * (DMISO[0, 1] + DMISO[0, 2])
DMISO[1, 0] = 0
elif not DMISO[1, 1] and (reduceavgon > 1):
DMISO[0, 0] = DMISO[0, 1]
DMISO[1, 0] = 0
DMISO[2, 0] = StNoteavg
elif not DMISO[1, 2] and (reduceavgon > 1):
DMISO[0, 0] = DMISO[0, 2]
DMISO[1, 0] = 0
DMISO[2, 0] = StNoteavg
warnvek = np.array([DMTotal_8pt[2, 1], OSC[2, 7], DMTotal_8pt[2, 2], OSC[2, 8]], dtype=np.float64)
warnall, warnx, warny = warnlogic(warnvek)
DMISO[2, 1] = warnx
DMISO[2, 2] = warny
DMISO[2, 0] = warnall
else:
DMISO[1, :] = StNovalue
# ==================== DMISC 计算 ====================
DMISC = np.zeros((3, 3), dtype=np.float64)
DMISC[1, :] = StDefault
if np.allclose(layeruse[:3], [0, 0, 1]):
DMISC = DMTotal_8pt.copy()
elif (np.allclose(layeruse[:3], [1, 0, 1]) or
np.allclose(layeruse[:3], [0, 1, 1]) or
np.allclose(layeruse[:3], [1, 1, 1])):
if _status_ok(DMCore_8pt[1, 1]) and _status_ok(ISC[1, 0]) and _status_ok(ISC[1, 1]):
DMISC[0, 1] = DMCore_8pt[0, 1] + ISC[0, 0] + ISC[0, 1]
DMISC[1, 1] = 0
if _status_ok(DMCore_8pt[1, 2]) and _status_ok(ISC[1, 2]) and _status_ok(ISC[1, 3]):
DMISC[0, 2] = DMCore_8pt[0, 2] + ISC[0, 2] + ISC[0, 3]
DMISC[1, 2] = 0
if not (DMISC[1, 1] or DMISC[1, 2]):
DMISC[0, 0] = 0.5 * (DMISC[0, 1] + DMISC[0, 2])
DMISC[1, 0] = 0
elif not DMISC[1, 1] and (reduceavgon > 1):
DMISC[0, 0] = DMISC[0, 1]
DMISC[1, 0] = 0
DMISC[2, 0] = StNoteavg
elif not DMISC[1, 2] and (reduceavgon > 1):
DMISC[0, 0] = DMISC[0, 2]
DMISC[1, 0] = 0
DMISC[2, 0] = StNoteavg
warnvek = np.array([DMCore_8pt[2, 1], ISC[2, 7], DMCore_8pt[2, 2], ISC[2, 8]], dtype=np.float64)
warnall, warnx, warny = warnlogic(warnvek)
DMISC[2, 1] = warnx
DMISC[2, 2] = warny
DMISC[2, 0] = warnall
else:
DMISC[1, :] = StNovalue
TAMode = 0
EPMode = 0
WTHMode = 0
# ==================== BisecWTH 计算 ====================
anzColWt = 16
BisecWTH = np.zeros((3, anzColWt), dtype=np.float64)
BisecWTH[1, :] = StDefault
BisecWTH[2, :] = 0
if EPFlag == 1:
if cableType not in (51, 52, 53, 62, 63):
if not TAMode:
Bisec_avgresults = calctwist2(avgresults_eightPT, layeruse, angle - np.pi / 4)
if bRotateXDir:
tmp = Bisec_avgresults
is_8k = (devicetype in (8000, 8100) or
(devicetype == 8001 and not NXT) or
(devicetype == 8101 and not NXT))
if is_8k:
for k in ('osc', 'iso', 'isc', 'wth'):
Bisec_avgresults['left'][k][:, 0] = tmp['right'][k][:, 0].copy()
Bisec_avgresults['right'][k][:, 0] = tmp['left'][k][:, 0].copy()
else:
for k in ('osc', 'iso', 'isc', 'wth'):
Bisec_avgresults['left'][k] = np.fliplr(tmp['right'][k]).copy()
Bisec_avgresults['right'][k] = np.fliplr(tmp['left'][k]).copy()
bl = Bisec_avgresults['left']
br = Bisec_avgresults['right']
BisecWTH[0, :] = np.concatenate([
[bl['osc'][0, 0]], np.fliplr(br['osc'][0:1, :])[0], [bl['osc'][0, 1]],
[bl['iso'][0, 0]], np.fliplr(br['iso'][0:1, :])[0], [bl['iso'][0, 1]],
[bl['isc'][0, 0]], np.fliplr(br['isc'][0:1, :])[0], [bl['isc'][0, 1]],
[bl['wth'][0, 0]], np.fliplr(br['wth'][0:1, :])[0], [bl['wth'][0, 1]],
]) * mm2inch
BisecWTH[1, :] = np.concatenate([
[bl['osc'][1, 0]], np.fliplr(br['osc'][1:2, :])[0], [bl['osc'][1, 1]],
[bl['iso'][1, 0]], np.fliplr(br['iso'][1:2, :])[0], [bl['iso'][1, 1]],
[bl['isc'][1, 0]], np.fliplr(br['isc'][1:2, :])[0], [bl['isc'][1, 1]],
[bl['wth'][1, 0]], np.fliplr(br['wth'][1:2, :])[0], [bl['wth'][1, 1]],
])
BisecWTH[2, :] = np.concatenate([
[bl['osc'][2, 0]], np.fliplr(br['osc'][2:3, :])[0], [bl['osc'][2, 1]],
[bl['iso'][2, 0]], np.fliplr(br['iso'][2:3, :])[0], [bl['iso'][2, 1]],
[bl['isc'][2, 0]], np.fliplr(br['isc'][2:3, :])[0], [bl['isc'][2, 1]],
[bl['wth'][2, 0]], np.fliplr(br['wth'][2:3, :])[0], [bl['wth'][2, 1]],
])
if np.allclose(layeruse[:3], [1, 0, 0]):
if EPMode:
pass
else:
OSC, BisecWTH[:, 0:4], MinMaxAng[:, 0:2] = updateMinMaxWTH(
OSC, DMTotal_8pt, DMCore_8pt, BisecWTH[:, 0:4], StOK, StDefault, StNovalue, reduceavgon
)
BisecWTH[0, 4:8] = 0; BisecWTH[1, 4:8] = StNovalue
BisecWTH[0, 8:12] = 0; BisecWTH[1, 8:12] = StNovalue
MinMaxAng[0, 2:4] = 0; MinMaxAng[1, 2:4] = StNovalue
MinMaxAng[0, 4:6] = 0; MinMaxAng[1, 4:6] = StNovalue
elif np.allclose(layeruse[:3], [0, 1, 0]):
if EPMode:
pass
else:
ISO, BisecWTH[:, 4:8], MinMaxAng[:, 2:4] = updateMinMaxWTH(
ISO, DMTotal_8pt, DMCore_8pt, BisecWTH[:, 4:8], StOK, StDefault, StNovalue, reduceavgon
)
BisecWTH[0, 0:4] = 0; BisecWTH[1, 0:4] = StNovalue
BisecWTH[0, 8:12] = 0; BisecWTH[1, 8:12] = StNovalue
MinMaxAng[0, 0:2] = 0; MinMaxAng[1, 0:2] = StNovalue
MinMaxAng[0, 4:6] = 0; MinMaxAng[1, 4:6] = StNovalue
elif np.allclose(layeruse[:3], [0, 0, 1]):
if EPMode:
pass
else:
ISC, BisecWTH[:, 8:12], MinMaxAng[:, 4:6] = updateMinMaxWTH(
ISC, DMTotal_8pt, DMCore_8pt, BisecWTH[:, 8:12], StOK, StDefault, StNovalue, reduceavgon
)
BisecWTH[0, 0:4] = 0; BisecWTH[1, 0:4] = StNovalue
BisecWTH[0, 4:8] = 0; BisecWTH[1, 4:8] = StNovalue
MinMaxAng[0, 0:2] = 0; MinMaxAng[1, 0:2] = StNovalue
MinMaxAng[0, 2:4] = 0; MinMaxAng[1, 2:4] = StNovalue
elif np.allclose(layeruse[:3], [1, 1, 0]):
if EPMode:
pass
else:
OSC, BisecWTH[:, 0:4], MinMaxAng[:, 0:2] = updateMinMaxWTH(
OSC, DMTotal_8pt, DMISO, BisecWTH[:, 0:4], StOK, StDefault, StNovalue, reduceavgon
)
ISO, BisecWTH[:, 4:8], MinMaxAng[:, 2:4] = updateMinMaxWTH(
ISO, DMISO, DMCore_8pt, BisecWTH[:, 4:8], StOK, StDefault, StNovalue, reduceavgon
)
BisecWTH[0, 8:12] = 0; BisecWTH[1, 8:12] = StNovalue
MinMaxAng[0, 4:6] = 0; MinMaxAng[1, 4:6] = StNovalue
elif np.allclose(layeruse[:3], [0, 1, 1]):
if EPMode:
pass
else:
ISO, BisecWTH[:, 4:8], MinMaxAng[:, 2:4] = updateMinMaxWTH(
ISO, DMTotal_8pt, DMISC, BisecWTH[:, 4:8], StOK, StDefault, StNovalue, reduceavgon
)
ISC, BisecWTH[:, 8:12], MinMaxAng[:, 4:6] = updateMinMaxWTH(
ISC, DMISC, DMCore_8pt, BisecWTH[:, 8:12], StOK, StDefault, StNovalue, reduceavgon
)
BisecWTH[0, 0:4] = 0; BisecWTH[1, 0:4] = StNovalue
MinMaxAng[0, 0:2] = 0; MinMaxAng[1, 0:2] = StNovalue
elif np.allclose(layeruse[:3], [1, 0, 1]):
if EPMode:
pass
else:
OSC, BisecWTH[:, 0:4], MinMaxAng[:, 0:2] = updateMinMaxWTH(
OSC, DMTotal_8pt, DMISO, BisecWTH[:, 0:4], StOK, StDefault, StNovalue, reduceavgon
)
ISC, BisecWTH[:, 8:12], MinMaxAng[:, 4:6] = updateMinMaxWTH(
ISC, DMISC, DMCore_8pt, BisecWTH[:, 8:12], StOK, StDefault, StNovalue, reduceavgon
)
BisecWTH[0, 4:8] = 0; BisecWTH[1, 4:8] = StNovalue
MinMaxAng[0, 2:4] = 0; MinMaxAng[1, 2:4] = StNovalue
elif np.allclose(layeruse[:3], [1, 1, 1]):
if EPMode:
pass
else:
OSC, BisecWTH[:, 0:4], MinMaxAng[:, 0:2] = updateMinMaxWTH(
OSC, DMTotal_8pt, DMISO, BisecWTH[:, 0:4], StOK, StDefault, StNovalue, reduceavgon
)
ISO, BisecWTH[:, 4:8], MinMaxAng[:, 2:4] = updateMinMaxWTH(
ISO, DMISO, DMISC, BisecWTH[:, 4:8], StOK, StDefault, StNovalue, reduceavgon
)
ISC, BisecWTH[:, 8:12], MinMaxAng[:, 4:6] = updateMinMaxWTH(
ISC, DMISC, DMCore_8pt, BisecWTH[:, 8:12], StOK, StDefault, StNovalue, reduceavgon
)
if EPMode:
pass
else:
WTH, BisecWTH[:, 12:16], MinMaxAng[:, 6:8] = updateMinMaxWTH(
WTH_8pt, DMTotal_8pt, DMCore_8pt, BisecWTH[:, 12:16], StOK, StDefault, StNovalue, reduceavgon
)
confData = np.asarray(settings.get('confData', np.array([])), dtype=np.float64) if isinstance(settings, dict) else np.array([])
WTHall = None
WTHallErr = None
addangle_arr = np.array([])
if not WTHMode:
if len(confData) > 197:
c198 = confData[197]
else:
c198 = 16
nangle = int(2 ** np.floor(np.log2(max(16, c198))))
dangle = 360.0 / nangle
addangle = np.arange(dangle, 89.999, dangle)
if EPFlag:
addangle = addangle[addangle % 45 != 0]
addangle_arr = addangle / 180 * np.pi
n_add = len(addangle_arr)
WTHall = np.zeros((n_add, 16), dtype=np.float64)
WTHallErr = np.zeros((n_add, 16), dtype=np.float64)
for i in range(n_add):
tmp = calctwist2(avgresults, layeruse, angle - addangle_arr[i])
if bRotateXDir:
for k in ('osc', 'iso', 'isc', 'wth'):
tmp['left'][k] = np.fliplr(tmp['left'][k])
tmp['right'][k] = np.fliplr(tmp['right'][k])
tl = tmp['left']
tr = tmp['right']
WTHall[i, :] = np.concatenate([
[tl['osc'][0, 0]], np.fliplr(tr['osc'][0:1, :])[0], [tl['osc'][0, 1]],
[tl['iso'][0, 0]], np.fliplr(tr['iso'][0:1, :])[0], [tl['iso'][0, 1]],
[tl['isc'][0, 0]], np.fliplr(tr['isc'][0:1, :])[0], [tl['isc'][0, 1]],
[tl['wth'][0, 0]], np.fliplr(tr['wth'][0:1, :])[0], [tl['wth'][0, 1]],
]) * mm2inch
WTHallErr[i, :] = np.concatenate([
[tl['osc'][1, 0]], np.fliplr(tr['osc'][1:2, :])[0], [tl['osc'][1, 1]],
[tl['iso'][1, 0]], np.fliplr(tr['iso'][1:2, :])[0], [tl['iso'][1, 1]],
[tl['isc'][1, 0]], np.fliplr(tr['isc'][1:2, :])[0], [tl['isc'][1, 1]],
[tl['wth'][1, 0]], np.fliplr(tr['wth'][1:2, :])[0], [tl['wth'][1, 1]],
])
if layeruse[0] and np.all(np.concatenate([OSC[1, 0:4], OSC[1, 10:13], DMTotal[1, 1:3], MinMaxAng[1, 0:2]]) == 0):
if not WTHMode and WTHall is not None:
OSC, MinMaxAng[0:2, 0:2] = updateMinMaxWTHall(
OSC, WTHall[:, 0:4], MinMaxAng[0:2, 0:2], confData, addangle_arr, WTHallErr[:, 0:4]
)
if layeruse[1] and np.all(np.concatenate([ISO[1, 0:4], ISO[1, 10:13], DMISO[1, 1:3], MinMaxAng[1, 2:4]]) == 0):
if not WTHMode and WTHall is not None:
ISO, MinMaxAng[0:2, 2:4] = updateMinMaxWTHall(
ISO, WTHall[:, 4:8], MinMaxAng[0:2, 2:4], confData, addangle_arr, WTHallErr[:, 4:8]
)
if layeruse[2] and np.all(np.concatenate([ISC[1, 0:4], ISC[1, 10:13], DMISC[1, 1:3], MinMaxAng[1, 4:6]]) == 0):
if not WTHMode and WTHall is not None:
ISC, MinMaxAng[0:2, 4:6] = updateMinMaxWTHall(
ISC, WTHall[:, 8:12], MinMaxAng[0:2, 4:6], confData, addangle_arr, WTHallErr[:, 8:12]
)
if np.all(np.concatenate([WTH[1, 0:4], WTH[1, 10:13], DMTotal[1, 1:3], MinMaxAng[1, 6:8]]) == 0):
if not WTHMode and WTHall is not None:
WTH, MinMaxAng[0:2, 6:8] = updateMinMaxWTHall(
WTH, WTHall[:, 12:16], MinMaxAng[0:2, 6:8], confData, addangle_arr, WTHallErr[:, 12:16]
)
# ==================== 后处理:NaN 和范围检查 ====================
def _post_process(arr):
a = arr.copy()
# NaN 检查
nan_mask = np.isnan(a[0, :])
a[1, nan_mask] = 255
# 范围检查 (仅前 9 列对于 Layer)
ncols = min(a.shape[1], 9)
if ncols > 0:
range_mask = (a[0, :ncols] < 0) | (a[0, :ncols] > 9999)
a[1, :ncols][range_mask] = 255
return a
OSC = _post_process(OSC)
ISO = _post_process(ISO)
ISC = _post_process(ISC)
WTH = _post_process(WTH)
# DMCore, DMTotal, DMISO, DMISC 范围检查
def _post_process_dm(arr):
a = arr.copy()
nan_mask = np.isnan(a[0, :])
a[1, nan_mask] = 255
range_mask = (a[0, :] < 0) | (a[0, :] > 9999)
a[1, range_mask] = 255
return a
DMTotal = _post_process_dm(DMTotal)
DMCore = _post_process_dm(DMCore)
DMISO = _post_process_dm(DMISO)
DMISC = _post_process_dm(DMISC)
# BisecWTH 和 MinMaxAng
def _post_process_other(arr):
a = arr.copy()
nan_mask = np.isnan(a[0, :])
a[1, nan_mask] = 255
range_mask = (a[0, :] < 0) | (a[0, :] > 9999)
a[1, range_mask] = 255
return a
BisecWTH = _post_process_other(BisecWTH)
MinMaxAng = _post_process_other(MinMaxAng)
return OSC, ISO, ISC, WTH, DMTotal, DMCore, DMISO, DMISC, BisecWTH, MinMaxAng