Files
2026-07-30 18:46:32 +08:00

934 lines
34 KiB
Python

import numpy as np
from thickness_utils import warnlogic
def strng2(x, left_edge, right_edge, flag=1):
"""
计算 X 射线穿过圆形/圆柱形截面物体时,在每个像素位置处的材料路径长度(厚度)。
对应 Matlab 的 strng2 函数。
参数:
x: numpy.ndarray - 像素位置坐标数组
left_edge: float - 物体左边缘位置
right_edge: float - 物体右边缘位置
flag: int - 计算模式标志 (默认1: 标准圆形截面路径长度)
返回:
numpy.ndarray: 与 x 同长度的数组,每个位置处的材料厚度
物体外的位置返回 0
"""
x = np.asarray(x, dtype=np.float64)
if right_edge <= left_edge:
return np.zeros_like(x)
center = (left_edge + right_edge) / 2.0
radius = (right_edge - left_edge) / 2.0
dx = x - center
inside = np.abs(dx) <= radius
s = np.zeros_like(x)
s[inside] = 2.0 * np.sqrt(radius**2 - dx[inside]**2)
return s
def strngellips(x, left_edge, right_edge, other_axis_diameter, flag=1):
"""
计算 X 射线穿过椭圆形截面物体时,在每个像素位置处的材料路径长度(厚度)。
对应 Matlab 的 strngellips 函数。
参数:
x: numpy.ndarray - 像素位置坐标数组(沿当前扫描轴)
left_edge: float - 椭圆在当前扫描轴上的左边缘
right_edge: float - 椭圆在当前扫描轴上的右边缘
other_axis_diameter: float - 椭圆另一个正交轴的直径
flag: int - 计算模式标志 (默认1: 标准椭圆截面路径长度)
返回:
numpy.ndarray: 与 x 同长度的数组,每个位置处的材料厚度
物体外的位置返回 0
"""
x = np.asarray(x, dtype=np.float64)
if right_edge <= left_edge or other_axis_diameter <= 0:
return np.zeros_like(x)
a = (right_edge - left_edge) / 2.0
b = other_axis_diameter / 2.0
center = (left_edge + right_edge) / 2.0
dx = x - center
inside = np.abs(dx) <= a
s = np.zeros_like(x)
ratio = (dx[inside] / a) ** 2
ratio = np.clip(ratio, 0.0, 1.0)
s[inside] = 2.0 * b * np.sqrt(1.0 - ratio)
return s
def xy_correct(xL_x, xR_x, xL_y, xR_y, x0_x, y0_x, xCCD_x, yCCD_x,
x0_y, y0_y, xCCD_y, yCCD_y, gamma_x, gamma_y,
status_x, status_y, statusL_x, statusR_x, statusL_y, statusR_y,
delta_xk, delta_yk, kx, ky, mode, layeruse):
xL_x = np.atleast_2d(np.asarray(xL_x, dtype=np.float64))
xR_x = np.atleast_2d(np.asarray(xR_x, dtype=np.float64))
xL_y = np.atleast_2d(np.asarray(xL_y, dtype=np.float64))
xR_y = np.atleast_2d(np.asarray(xR_y, dtype=np.float64))
status_x = np.atleast_2d(np.asarray(status_x, dtype=np.float64))
status_y = np.atleast_2d(np.asarray(status_y, dtype=np.float64))
statusL_x = np.atleast_2d(np.asarray(statusL_x, dtype=np.float64))
statusR_x = np.atleast_2d(np.asarray(statusR_x, dtype=np.float64))
statusL_y = np.atleast_2d(np.asarray(statusL_y, dtype=np.float64))
statusR_y = np.atleast_2d(np.asarray(statusR_y, dtype=np.float64))
if kx is None or len(kx) == 0:
kx = np.zeros(32)
kx[27] = 1.0
ky = np.zeros(32)
ky[27] = 1.0
else:
kx = np.asarray(kx, dtype=np.float64).flatten()
ky = np.asarray(ky, dtype=np.float64).flatten()
if len(kx) == 40:
kx = kx[:32]
ky = ky[:32]
if gamma_x is None:
gamma_x = 90.0
gamma_y = 90.0
VALID = 0
LOW_LEVEL_ERR = 1
XL00_DETECT_ERR = 2
XR00_DETECT_ERR = 3
XL11_DETECT_ERR = 4
XR11_DETECT_ERR = 5
NO_CABLE_ERR = 6
LOW_RADIATION_ERR = 9
DOUBLE_ERR = 10
OUTER_DM_ERR = 14
CORE_DM_ERR = 15
OSC_ERR = 16
ISC_ERR = 17
SCANNER_DATA_ERR = 18
CONF_DATA_ERR = 19
CHKSPEED_ERR = 24
WINDOW_DIRTY_ERR = 25
LAYER_NOT_REQUESTED = 45
CAM_SYSERR = 251
GV_OFF_SYSERR = 252
HV_OFF_SYSERR = 253
globalfailure = np.array([LOW_LEVEL_ERR, XL00_DETECT_ERR, XR00_DETECT_ERR,
XL11_DETECT_ERR, XR11_DETECT_ERR, NO_CABLE_ERR,
LOW_RADIATION_ERR, DOUBLE_ERR, SCANNER_DATA_ERR,
CONF_DATA_ERR, CHKSPEED_ERR, WINDOW_DIRTY_ERR,
CAM_SYSERR, GV_OFF_SYSERR, HV_OFF_SYSERR] + list(range(180, 221)))
dmOut = np.zeros((3, 2))
dmOut[1, :] = 255
oscL = np.zeros((3, 2))
oscR = np.zeros((3, 2))
oscL[1, :] = 255
oscR[1, :] = 255
isoL = np.zeros((3, 2))
isoR = np.zeros((3, 2))
isoL[1, :] = 255
isoR[1, :] = 255
iscL = np.zeros((3, 2))
iscR = np.zeros((3, 2))
iscL[1, :] = 255
iscR[1, :] = 255
coreDm = np.zeros((3, 2))
coreDm[1, :] = 255
wthL = np.zeros((3, 2))
wthR = np.zeros((3, 2))
wthL[1, :] = 255
wthR[1, :] = 255
xk = np.zeros((3, 4))
yk = np.zeros((3, 4))
xk[1, :] = 255
yk[1, :] = 255
gamma_x = gamma_x * np.pi / 180.0
gamma_y = gamma_y * np.pi / 180.0
beta_x = np.zeros(4)
beta_y = np.zeros(4)
tgBeta_x = np.zeros(4)
tgBeta_y = np.zeros(4)
rL_x = np.zeros(4)
rL_y = np.zeros(4)
rR_x = np.zeros(4)
rR_y = np.zeros(4)
for n in range(4):
if mode == 1:
denomLx = x0_x - xCCD_x - xL_x[0, n] * np.cos(gamma_x)
denomRx = x0_x - xCCD_x - xR_x[0, n] * np.cos(gamma_x)
if abs(denomLx) < 1e-15:
denomLx = 1e-15
if abs(denomRx) < 1e-15:
denomRx = 1e-15
beta_x[n] = 0.5 * (
np.arctan((xL_x[0, n] * np.sin(gamma_x) - y0_x + yCCD_x) / denomLx) +
np.arctan((xR_x[0, n] * np.sin(gamma_x) - y0_x + yCCD_x) / denomRx)
)
tgBeta_x[n] = np.tan(beta_x[n])
denomLy = y0_y - yCCD_y - xL_y[0, n] * np.cos(gamma_y)
denomRy = y0_y - yCCD_y - xR_y[0, n] * np.cos(gamma_y)
if abs(denomLy) < 1e-15:
denomLy = 1e-15
if abs(denomRy) < 1e-15:
denomRy = 1e-15
beta_y[n] = 0.5 * (
np.arctan((xL_y[0, n] * np.sin(gamma_y) - x0_y + xCCD_y) / denomLy) +
np.arctan((xR_y[0, n] * np.sin(gamma_y) - x0_y + xCCD_y) / denomRy)
)
tgBeta_y[n] = np.tan(beta_y[n])
else:
tgBeta_x[n] = ((xL_x[0, n] + xR_x[0, n]) / 2.0 - y0_x + yCCD_x) / (x0_x - xCCD_x)
beta_x[n] = tgBeta_x[n]
tgBeta_y[n] = ((xL_y[0, n] + xR_y[0, n]) / 2.0 - x0_y + xCCD_y) / (y0_y - yCCD_y)
beta_y[n] = tgBeta_y[n]
if abs(tgBeta_y[n]) > 1e-15:
xk[0, n] = (tgBeta_x[n] * x0_x + y0_x - 1.0 / tgBeta_y[n] * x0_y - y0_y) / (tgBeta_x[n] - 1.0 / tgBeta_y[n])
else:
xk[0, n] = x0_y
yk[0, n] = -(xk[0, n] - x0_x) * tgBeta_x[n] + y0_x
xk[0, n] = xk[0, n] + delta_xk
yk[0, n] = yk[0, n] + delta_yk
if (not statusL_x[0, n]) and (not statusR_x[0, n]) and (not statusL_y[0, n]) and (not statusR_y[0, n]):
xk[1, n] = VALID
yk[1, n] = VALID
if statusL_x[0, 1] or statusR_x[0, 1] or statusL_y[0, 1] or statusR_y[0, 1]:
xk[0, 1] = xk[0, 0]
yk[0, 1] = yk[0, 0]
beta_x[1] = beta_x[0]
beta_y[1] = beta_y[0]
tgBeta_x[1] = tgBeta_x[0]
tgBeta_y[1] = tgBeta_y[0]
if statusL_x[0, 3] or statusR_x[0, 3] or statusL_y[0, 3] or statusR_y[0, 3]:
xk[0, 3] = xk[0, 0]
yk[0, 3] = yk[0, 0]
beta_x[3] = beta_x[0]
beta_y[3] = beta_y[0]
tgBeta_x[3] = tgBeta_x[0]
tgBeta_y[3] = tgBeta_y[0]
if statusL_x[0, 2] or statusR_x[0, 2] or statusL_y[0, 2] or statusR_y[0, 2]:
xk[0, 2] = xk[0, 3]
yk[0, 2] = yk[0, 3]
beta_x[2] = beta_x[3]
beta_y[2] = beta_y[3]
tgBeta_x[2] = tgBeta_x[3]
tgBeta_y[2] = tgBeta_y[3]
for n in range(4):
ek_x = np.sqrt((x0_x - xk[0, n])**2 + (y0_x - yk[0, n])**2)
ek_y = np.sqrt((x0_y - xk[0, n])**2 + (y0_y - yk[0, n])**2)
if mode == 1:
denomLx = x0_x - xCCD_x - xL_x[0, n] * np.cos(gamma_x)
denomRx = x0_x - xCCD_x - xR_x[0, n] * np.cos(gamma_x)
if abs(denomLx) < 1e-15:
denomLx = 1e-15
if abs(denomRx) < 1e-15:
denomRx = 1e-15
alphaL_x = np.arctan((xL_x[0, n] * np.sin(gamma_x) - y0_x + yCCD_x) / denomLx) - beta_x[n]
alphaR_x = np.arctan((xR_x[0, n] * np.sin(gamma_x) - y0_x + yCCD_x) / denomRx) - beta_x[n]
denomLy = y0_y - yCCD_y - xL_y[0, n] * np.cos(gamma_y)
denomRy = y0_y - yCCD_y - xR_y[0, n] * np.cos(gamma_y)
if abs(denomLy) < 1e-15:
denomLy = 1e-15
if abs(denomRy) < 1e-15:
denomRy = 1e-15
alphaL_y = np.arctan((xL_y[0, n] * np.sin(gamma_y) - x0_y + xCCD_y) / denomLy) - beta_y[n]
alphaR_y = np.arctan((xR_y[0, n] * np.sin(gamma_y) - x0_y + xCCD_y) / denomRy) - beta_y[n]
else:
alphaL_x = ((xL_x[0, n] - y0_x + yCCD_x) / (x0_x - xCCD_x)) - tgBeta_x[n]
alphaR_x = ((xR_x[0, n] - y0_x + yCCD_x) / (x0_x - xCCD_x)) - tgBeta_x[n]
alphaL_y = ((xL_y[0, n] - x0_y + xCCD_y) / (y0_y - yCCD_y)) - tgBeta_y[n]
alphaR_y = ((xR_y[0, n] - x0_y + xCCD_y) / (y0_y - yCCD_y)) - tgBeta_y[n]
if mode == 1:
rL_x[n] = abs(ek_x * np.sin(alphaL_x))
rR_x[n] = abs(ek_x * np.sin(alphaR_x))
rL_y[n] = abs(ek_y * np.sin(alphaL_y))
rR_y[n] = abs(ek_y * np.sin(alphaR_y))
else:
rL_x[n] = abs(ek_x * alphaL_x)
rR_x[n] = abs(ek_x * alphaR_x)
rL_y[n] = abs(ek_y * alphaL_y)
rR_y[n] = abs(ek_y * alphaR_y)
if len(kx) == 30:
poly_terms = lambda xv, yv, rv: np.array([
1, xv, xv*yv, xv*yv*(2*rv), xv*yv*(2*rv)**2,
xv*yv**2, xv*yv**2*(2*rv), xv*yv**2*(2*rv)**2,
xv*(2*rv), xv*(2*rv)**2, xv**2, xv**2*yv,
xv**2*yv*(2*rv), xv**2*yv*(2*rv)**2, xv**2*yv**2,
xv**2*yv**2*(2*rv), xv**2*yv**2*(2*rv)**2,
xv**2*(2*rv), xv**2*(2*rv)**2, xv**3, yv,
yv*(2*rv), yv*(2*rv)**2, yv**2, yv**2*(2*rv),
yv**2*(2*rv)**2, yv**3, (2*rv), (2*rv)**2, (2*rv)**3
])
rL_x[n] = 0.5 * np.dot(poly_terms(xk[0, n], yk[0, n], rL_x[n]), kx[:30])
rR_x[n] = 0.5 * np.dot(poly_terms(xk[0, n], yk[0, n], rR_x[n]), kx[:30])
rL_y[n] = 0.5 * np.dot(poly_terms(xk[0, n], yk[0, n], rL_y[n]), ky[:30])
rR_y[n] = 0.5 * np.dot(poly_terms(xk[0, n], yk[0, n], rR_y[n]), ky[:30])
elif len(kx) == 32:
poly_terms = lambda xv, yv, rv: np.array([
1, xv, xv*yv, xv*yv*(2*rv), xv*yv*(2*rv)**2,
xv*yv**2, xv*yv**2*(2*rv), xv*yv**2*(2*rv)**2,
xv*(2*rv), xv*(2*rv)**2, xv**2, xv**2*yv,
xv**2*yv*(2*rv), xv**2*yv*(2*rv)**2, xv**2*yv**2,
xv**2*yv**2*(2*rv), xv**2*yv**2*(2*rv)**2,
xv**2*(2*rv), xv**2*(2*rv)**2, xv**3, yv,
yv*(2*rv), yv*(2*rv)**2, yv**2, yv**2*(2*rv),
yv**2*(2*rv)**2, yv**3, (2*rv), (2*rv)**2, (2*rv)**3,
xv**4, yv**4
])
rL_x[n] = 0.5 * np.dot(poly_terms(xk[0, n], yk[0, n], rL_x[n]), kx)
rR_x[n] = 0.5 * np.dot(poly_terms(xk[0, n], yk[0, n], rR_x[n]), kx)
rL_y[n] = 0.5 * np.dot(poly_terms(xk[0, n], yk[0, n], rL_y[n]), ky)
rR_y[n] = 0.5 * np.dot(poly_terms(xk[0, n], yk[0, n], rR_y[n]), ky)
if (not statusL_x[0, 0]) and (not statusR_x[0, 0]) and (not statusL_y[0, 0]) and (not statusR_y[0, 0]):
dmOut[0, 0] = rL_x[0] + rR_x[0]
dmOut[0, 1] = rL_y[0] + rR_y[0]
dmOut[1, :] = VALID
if not statusL_x[0, 1]:
oscL[0, 0] = rL_x[0] - rL_x[1] + (yk[0, 1] - yk[0, 0])
oscL[1, 0] = VALID
else:
oscL[1, 0] = statusL_x[0, 1]
if not statusR_x[0, 1]:
oscR[0, 0] = rR_x[0] - rR_x[1] - (yk[0, 1] - yk[0, 0])
oscR[1, 0] = VALID
else:
oscR[1, 0] = statusR_x[0, 1]
if not statusL_y[0, 1]:
oscL[0, 1] = rL_y[0] - rL_y[1] + (xk[0, 1] - xk[0, 0])
oscL[1, 1] = VALID
else:
oscL[1, 1] = statusL_y[0, 1]
if not statusR_y[0, 1]:
oscR[0, 1] = rR_y[0] - rR_y[1] - (xk[0, 1] - xk[0, 0])
oscR[1, 1] = VALID
else:
oscR[1, 1] = statusR_y[0, 1]
if not statusL_x[0, 3]:
wthL[0, 0] = rL_x[0] - rL_x[3] + (yk[0, 3] - yk[0, 0])
wthL[1, 0] = VALID
else:
wthL[1, 0] = statusL_x[0, 3]
if not statusR_x[0, 3]:
wthR[0, 0] = rR_x[0] - rR_x[3] - (yk[0, 3] - yk[0, 0])
wthR[1, 0] = VALID
else:
wthR[1, 0] = statusR_x[0, 3]
if not statusL_y[0, 3]:
wthL[0, 1] = rL_y[0] - rL_y[3] + (xk[0, 3] - xk[0, 0])
wthL[1, 1] = VALID
else:
wthL[1, 1] = statusL_y[0, 3]
if not statusR_y[0, 3]:
wthR[0, 1] = rR_y[0] - rR_y[3] - (xk[0, 3] - xk[0, 0])
wthR[1, 1] = VALID
else:
wthR[1, 1] = statusR_y[0, 3]
else:
if np.any(np.isin(status_x[0, 0], globalfailure)):
dmOut[1, 0] = status_x[0, 0]
oscL[1, 0] = status_x[0, 0]
oscR[1, 0] = status_x[0, 0]
coreDm[1, 0] = status_x[0, 0]
wthL[1, 0] = status_x[0, 0]
wthR[1, 0] = status_x[0, 0]
iscL[1, 0] = status_x[0, 0]
iscR[1, 0] = status_x[0, 0]
isoL[1, 0] = status_x[0, 0]
isoR[1, 0] = status_x[0, 0]
else:
if statusL_x[0, 0]:
dmOut[1, 0] = statusL_x[0, 0]
elif statusR_x[0, 0]:
dmOut[1, 0] = statusR_x[0, 0]
else:
dmOut[1, 0] = OUTER_DM_ERR
if statusL_x[0, 1]:
oscL[1, 0] = statusL_x[0, 1]
else:
oscL[1, 0] = OUTER_DM_ERR
if statusR_x[0, 1]:
oscR[1, 0] = statusR_x[0, 1]
else:
oscR[1, 0] = OUTER_DM_ERR
if statusL_x[0, 2]:
iscL[1, 0] = statusL_x[0, 2]
else:
iscL[1, 0] = OUTER_DM_ERR
if statusR_x[0, 2]:
iscR[1, 0] = statusR_x[0, 2]
else:
iscR[1, 0] = OUTER_DM_ERR
if statusL_x[0, 3]:
coreDm[1, 0] = statusL_x[0, 3]
elif statusR_x[0, 3]:
coreDm[1, 0] = statusR_x[0, 3]
else:
coreDm[1, 0] = OUTER_DM_ERR
wthL[1, 0] = OUTER_DM_ERR
wthR[1, 0] = OUTER_DM_ERR
isoL[1, 0] = OUTER_DM_ERR
isoR[1, 0] = OUTER_DM_ERR
if np.any(np.isin(status_y[0, 0], globalfailure)):
dmOut[1, 1] = status_y[0, 0]
oscL[1, 1] = status_y[0, 0]
oscR[1, 1] = status_y[0, 0]
coreDm[1, 1] = status_y[0, 0]
wthL[1, 1] = status_y[0, 0]
wthR[1, 1] = status_y[0, 0]
iscL[1, 1] = status_y[0, 0]
iscR[1, 1] = status_y[0, 0]
isoL[1, 1] = status_y[0, 0]
isoR[1, 1] = status_y[0, 0]
else:
if statusL_y[0, 0]:
dmOut[1, 1] = statusL_y[0, 0]
elif statusR_y[0, 0]:
dmOut[1, 1] = statusR_y[0, 0]
else:
dmOut[1, 1] = OUTER_DM_ERR
if statusL_y[0, 1]:
oscL[1, 1] = statusL_y[0, 1]
else:
oscL[1, 1] = OUTER_DM_ERR
if statusR_y[0, 1]:
oscR[1, 1] = statusR_y[0, 1]
else:
oscR[1, 1] = OUTER_DM_ERR
if statusL_y[0, 2]:
iscL[1, 1] = statusL_y[0, 2]
else:
iscL[1, 1] = OUTER_DM_ERR
if statusR_y[0, 2]:
iscR[1, 1] = statusR_y[0, 2]
else:
iscR[1, 1] = OUTER_DM_ERR
if statusL_y[0, 3]:
coreDm[1, 1] = statusL_y[0, 3]
elif statusR_y[0, 3]:
coreDm[1, 1] = statusR_y[0, 3]
else:
coreDm[1, 1] = OUTER_DM_ERR
wthL[1, 1] = OUTER_DM_ERR
wthR[1, 1] = OUTER_DM_ERR
iscL[1, 1] = OUTER_DM_ERR
iscR[1, 1] = OUTER_DM_ERR
isoL[1, 1] = OUTER_DM_ERR
isoR[1, 1] = OUTER_DM_ERR
if ((not statusL_x[0, 3] and not statusR_x[0, 3] and not statusL_y[0, 3] and not statusR_y[0, 3]) or
(not statusL_x[0, 0] and not statusR_x[0, 0] and not statusL_y[0, 0] and not statusR_y[0, 0])):
if not statusL_x[0, 3] and not statusR_x[0, 3]:
coreDm[0, 0] = rL_x[3] + rR_x[3]
coreDm[1, 0] = VALID
elif statusL_x[0, 3]:
coreDm[1, 0] = statusL_x[0, 3]
elif statusR_x[0, 3]:
coreDm[1, 0] = statusR_x[0, 3]
if not statusL_y[0, 3] and not statusR_y[0, 3]:
coreDm[0, 1] = rL_y[3] + rR_y[3]
coreDm[1, 1] = VALID
elif statusL_y[0, 3]:
coreDm[1, 1] = statusL_y[0, 3]
elif statusR_y[0, 3]:
coreDm[1, 1] = statusR_y[0, 3]
if not statusL_x[0, 2] and not statusL_x[0, 3]:
iscL[0, 0] = rL_x[2] - rL_x[3] + (yk[0, 3] - yk[0, 2])
iscL[1, 0] = VALID
else:
if statusL_x[0, 2]:
iscL[1, 0] = statusL_x[0, 2]
else:
iscL[1, 0] = statusL_x[0, 3]
if not statusR_x[0, 2] and not statusR_x[0, 3]:
iscR[0, 0] = rR_x[2] - rR_x[3] - (yk[0, 3] - yk[0, 2])
iscR[1, 0] = VALID
else:
if statusR_x[0, 2]:
iscR[1, 0] = statusR_x[0, 2]
else:
iscR[1, 0] = statusR_x[0, 3]
if not statusL_y[0, 2] and not statusL_y[0, 3]:
iscL[0, 1] = rL_y[2] - rL_y[3] + (xk[0, 3] - xk[0, 2])
iscL[1, 1] = VALID
else:
if statusL_y[0, 2]:
iscL[1, 1] = statusL_y[0, 2]
else:
iscL[1, 1] = statusL_y[0, 3]
if not statusR_y[0, 2] and not statusR_y[0, 3]:
iscR[0, 1] = rR_y[2] - rR_y[3] - (xk[0, 3] - xk[0, 2])
iscR[1, 1] = VALID
else:
if statusR_y[0, 2]:
iscR[1, 1] = statusR_y[0, 2]
else:
iscR[1, 1] = statusR_y[0, 3]
if (not wthL[1, 0]) and ((not oscL[1, 0]) or oscL[1, 0] == LAYER_NOT_REQUESTED) and ((not iscL[1, 0]) or iscL[1, 0] == LAYER_NOT_REQUESTED):
isoL[0, 0] = wthL[0, 0] - oscL[0, 0] - iscL[0, 0]
isoL[1, 0] = VALID
elif wthL[1, 0]:
isoL[1, 0] = wthL[1, 0]
elif oscL[1, 0]:
isoL[1, 0] = oscL[1, 0]
elif iscL[1, 0]:
isoL[1, 0] = iscL[1, 0]
if (not wthL[1, 1]) and ((not oscL[1, 1]) or oscL[1, 1] == LAYER_NOT_REQUESTED) and ((not iscL[1, 1]) or iscL[1, 1] == LAYER_NOT_REQUESTED):
isoL[0, 1] = wthL[0, 1] - oscL[0, 1] - iscL[0, 1]
isoL[1, 1] = VALID
elif wthL[1, 1]:
isoL[1, 1] = wthL[1, 1]
elif oscL[1, 1]:
isoL[1, 1] = oscL[1, 1]
elif iscL[1, 1]:
isoL[1, 1] = iscL[1, 1]
if (not wthR[1, 0]) and ((not oscR[1, 0]) or oscR[1, 0] == LAYER_NOT_REQUESTED) and ((not iscR[1, 0]) or iscR[1, 0] == LAYER_NOT_REQUESTED):
isoR[0, 0] = wthR[0, 0] - oscR[0, 0] - iscR[0, 0]
isoR[1, 0] = VALID
elif wthR[1, 0]:
isoR[1, 0] = wthR[1, 0]
elif oscR[1, 0]:
isoR[1, 0] = oscR[1, 0]
elif iscR[1, 0]:
isoR[1, 0] = iscR[1, 0]
if (not wthR[1, 1]) and ((not oscR[1, 1]) or oscR[1, 1] == LAYER_NOT_REQUESTED) and ((not iscR[1, 1]) or iscR[1, 1] == LAYER_NOT_REQUESTED):
isoR[0, 1] = wthR[0, 1] - oscR[0, 1] - iscR[0, 1]
isoR[1, 1] = wthR[1, 1]
elif wthR[1, 1]:
isoR[1, 1] = wthR[1, 1]
elif oscR[1, 1]:
isoR[1, 1] = oscR[1, 1]
elif iscR[1, 1]:
isoR[1, 1] = iscR[1, 1]
return dmOut, oscL, oscR, isoL, isoR, iscL, iscR, coreDm, wthL, wthR, xk, yk
def modify_cable_position(baseAngle, orientation, height):
delta_xk = 0.0
delta_yk = 0.0
if baseAngle == 0:
slope = 0.0
orientation = 0
elif baseAngle == 1:
slope = 0.43
elif baseAngle == 2:
slope = 0.35
elif baseAngle == 3:
slope = 0.37
elif baseAngle == 4:
slope = 0.225
else:
slope = 0.0
a = slope * height
if orientation == 0:
delta_xk = 0.0
delta_yk = 0.0
elif orientation == 1:
delta_xk = 0.0
delta_yk = (height / 2.0 - a)
elif orientation == 2:
delta_xk = -(height / 2.0 - a)
delta_yk = 0.0
elif orientation == 3:
delta_xk = 0.0
delta_yk = -(height / 2.0 - a)
elif orientation == 4:
delta_xk = (height / 2.0 - a)
delta_yk = 0.0
else:
delta_xk = 0.0
delta_yk = 0.0
return delta_xk, delta_yk
def axis_result(xL_x, xR_x, status_x, statusL_x, statusR_x, mode, layeruse):
xL_x = np.atleast_2d(np.asarray(xL_x, dtype=np.float64))
xR_x = np.atleast_2d(np.asarray(xR_x, dtype=np.float64))
status_x = np.atleast_2d(np.asarray(status_x, dtype=np.float64))
statusL_x = np.atleast_2d(np.asarray(statusL_x, dtype=np.float64))
statusR_x = np.atleast_2d(np.asarray(statusR_x, dtype=np.float64))
# Ensure at least 2 rows (row 0=error code, row 1=warning code)
if status_x.shape[0] < 2:
status_x = np.vstack([status_x, np.zeros((2 - status_x.shape[0], status_x.shape[1]))])
if statusL_x.shape[0] < 2:
statusL_x = np.vstack([statusL_x, np.zeros((2 - statusL_x.shape[0], statusL_x.shape[1]))])
if statusR_x.shape[0] < 2:
statusR_x = np.vstack([statusR_x, np.zeros((2 - statusR_x.shape[0], statusR_x.shape[1]))])
layeruse = np.asarray(layeruse, dtype=np.float64).ravel()
VALID = 0
LOW_LEVEL_ERR = 1
XL00_DETECT_ERR = 2
XR00_DETECT_ERR = 3
XL11_DETECT_ERR = 4
XR11_DETECT_ERR = 5
NO_CABLE_ERR = 6
LOW_RADIATION_ERR = 9
DOUBLE_ERR = 10
OUTER_DM_ERR = 14
CORE_DM_ERR = 15
OSC_ERR = 16
ISC_ERR = 17
SCANNER_DATA_ERR = 18
CONF_DATA_ERR = 19
CHKSPEED_ERR = 24
WINDOW_DIRTY_ERR = 25
LAYER_NOT_REQUESTED = 45
RIFFLE_MATCH_CONFLICT = 90
NO_SCAN_DATA_ERR = 240
SCANNER_1_TOO_COLD = 241
SCANNER_2_TOO_COLD = 242
SCANNER_1_TOO_HOT = 243
SCANNER_2_TOO_HOT = 244
CAM_SYSERR = 251
GV_OFF_SYSERR = 252
HV_OFF_SYSERR = 253
globalfailure = np.array([
LOW_LEVEL_ERR, XL00_DETECT_ERR, XR00_DETECT_ERR,
XL11_DETECT_ERR, XR11_DETECT_ERR, NO_CABLE_ERR,
LOW_RADIATION_ERR, DOUBLE_ERR, SCANNER_DATA_ERR,
CONF_DATA_ERR, CHKSPEED_ERR, WINDOW_DIRTY_ERR,
CAM_SYSERR, GV_OFF_SYSERR, HV_OFF_SYSERR,
NO_SCAN_DATA_ERR, SCANNER_1_TOO_COLD, SCANNER_2_TOO_COLD,
SCANNER_1_TOO_HOT, SCANNER_2_TOO_HOT
] + list(range(180, 221)) + [RIFFLE_MATCH_CONFLICT])
dmOut = np.zeros((3, 1))
dmOut[1, 0] = 255
oscL = np.zeros((3, 1))
oscL[1, 0] = 255
oscR = np.zeros((3, 1))
oscR[1, 0] = 255
isoL = np.zeros((3, 1))
isoL[1, 0] = 255
isoR = np.zeros((3, 1))
isoR[1, 0] = 255
iscL = np.zeros((3, 1))
iscL[1, 0] = 255
iscR = np.zeros((3, 1))
iscR[1, 0] = 255
coreDm = np.zeros((3, 1))
coreDm[1, 0] = 255
wthL = np.zeros((3, 1))
wthL[1, 0] = 255
wthR = np.zeros((3, 1))
wthR[1, 0] = 255
xk = np.zeros((3, 4))
xk[1, :] = 255
rL_x = np.zeros(4)
rR_x = np.zeros(4)
for n in range(4):
xk[0, n] = (xL_x[0, n] + xR_x[0, n]) / 2.0
if (not statusL_x[0, n]) and (not statusR_x[0, n]):
xk[1, n] = VALID
if statusL_x[0, 1] or statusR_x[0, 1]:
xk[0, 1] = xk[0, 0]
if statusL_x[0, 3] or statusR_x[0, 3]:
xk[0, 3] = xk[0, 0]
if statusL_x[0, 2] or statusR_x[0, 2]:
xk[0, 2] = xk[0, 3]
for n in range(4):
rL_x[n] = abs(xL_x[0, n] - xk[0, n])
rR_x[n] = abs(xR_x[0, n] - xk[0, n])
if (not statusL_x[0, 0]) and (not statusR_x[0, 0]):
dmOut[0, 0] = rL_x[0] + rR_x[0]
dmOut[1, 0] = VALID
if not statusL_x[0, 1]:
oscL[0, 0] = rL_x[0] - rL_x[1] + (xk[0, 1] - xk[0, 0])
oscL[1, 0] = VALID
else:
oscL[1, 0] = statusL_x[0, 1]
if not statusR_x[0, 1]:
oscR[0, 0] = rR_x[0] - rR_x[1] - (xk[0, 1] - xk[0, 0])
oscR[1, 0] = VALID
else:
oscR[1, 0] = statusR_x[0, 1]
if not statusL_x[0, 3]:
wthL[0, 0] = rL_x[0] - rL_x[3] + (xk[0, 3] - xk[0, 0])
wthL[1, 0] = VALID
else:
wthL[1, 0] = statusL_x[0, 3]
if not statusR_x[0, 3]:
wthR[0, 0] = rR_x[0] - rR_x[3] - (xk[0, 3] - xk[0, 0])
wthR[1, 0] = VALID
else:
wthR[1, 0] = statusR_x[0, 3]
else:
if np.any(np.isin(status_x[0, 0], globalfailure)):
dmOut[1, 0] = status_x[0, 0]
oscL[1, 0] = status_x[0, 0]
oscR[1, 0] = status_x[0, 0]
coreDm[1, 0] = status_x[0, 0]
wthL[1, 0] = status_x[0, 0]
wthR[1, 0] = status_x[0, 0]
iscL[1, 0] = status_x[0, 0]
iscR[1, 0] = status_x[0, 0]
isoL[1, 0] = status_x[0, 0]
isoR[1, 0] = status_x[0, 0]
else:
if statusL_x[0, 0]:
dmOut[1, 0] = statusL_x[0, 0]
elif statusR_x[0, 0]:
dmOut[1, 0] = statusR_x[0, 0]
else:
dmOut[1, 0] = OUTER_DM_ERR
if statusL_x[0, 1]:
oscL[1, 0] = statusL_x[0, 1]
else:
oscL[1, 0] = OUTER_DM_ERR
if statusR_x[0, 1]:
oscR[1, 0] = statusR_x[0, 1]
else:
oscR[1, 0] = OUTER_DM_ERR
if statusL_x[0, 2]:
iscL[1, 0] = statusL_x[0, 2]
else:
iscL[1, 0] = OUTER_DM_ERR
if statusR_x[0, 2]:
iscR[1, 0] = statusR_x[0, 2]
else:
iscR[1, 0] = OUTER_DM_ERR
if statusL_x[0, 3]:
coreDm[1, 0] = statusL_x[0, 3]
elif statusR_x[0, 3]:
coreDm[1, 0] = statusR_x[0, 3]
else:
coreDm[1, 0] = OUTER_DM_ERR
wthL[1, 0] = OUTER_DM_ERR
wthR[1, 0] = OUTER_DM_ERR
isoL[1, 0] = OUTER_DM_ERR
isoR[1, 0] = OUTER_DM_ERR
if ((not statusL_x[0, 3] and not statusR_x[0, 3]) or
(not statusL_x[0, 0] and not statusR_x[0, 0])):
if not statusL_x[0, 3] and not statusR_x[0, 3]:
coreDm[0, 0] = rL_x[3] + rR_x[3]
coreDm[1, 0] = VALID
elif statusL_x[0, 3]:
coreDm[1, 0] = statusL_x[0, 3]
elif statusR_x[0, 3]:
coreDm[1, 0] = statusR_x[0, 3]
if not statusL_x[0, 2] and not statusL_x[0, 3]:
iscL[0, 0] = rL_x[2] - rL_x[3] + (xk[0, 3] - xk[0, 2])
iscL[1, 0] = VALID
else:
if statusL_x[0, 2]:
iscL[1, 0] = statusL_x[0, 2]
else:
iscL[1, 0] = statusL_x[0, 3]
if not statusR_x[0, 2] and not statusR_x[0, 3]:
iscR[0, 0] = rR_x[2] - rR_x[3] - (xk[0, 3] - xk[0, 2])
iscR[1, 0] = VALID
else:
if statusR_x[0, 2]:
iscR[1, 0] = statusR_x[0, 2]
else:
iscR[1, 0] = statusR_x[0, 3]
if (not wthL[1, 0] and ((not oscL[1, 0]) or oscL[1, 0] == LAYER_NOT_REQUESTED)
and ((not iscL[1, 0]) or iscL[1, 0] == LAYER_NOT_REQUESTED)):
isoL[0, 0] = wthL[0, 0] - oscL[0, 0] - iscL[0, 0]
isoL[1, 0] = VALID
elif wthL[1, 0]:
isoL[1, 0] = wthL[1, 0]
elif oscL[1, 0] and (layeruse[0] == 1):
isoL[1, 0] = oscL[1, 0]
elif iscL[1, 0] and (layeruse[2] == 1):
isoL[1, 0] = iscL[1, 0]
if (not wthR[1, 0] and ((not oscR[1, 0]) or oscR[1, 0] == LAYER_NOT_REQUESTED)
and ((not iscR[1, 0]) or iscR[1, 0] == LAYER_NOT_REQUESTED)):
isoR[0, 0] = wthR[0, 0] - oscR[0, 0] - iscR[0, 0]
isoR[1, 0] = VALID
elif wthR[1, 0]:
isoR[1, 0] = wthR[1, 0]
elif oscR[1, 0] and (layeruse[0] == 1):
isoR[1, 0] = oscR[1, 0]
elif iscR[1, 0] and (layeruse[2] == 1):
isoR[1, 0] = iscR[1, 0]
warnvek = np.array([statusL_x[1, 0], statusR_x[1, 0], 0, 0])
warnall, warnx, dummy = warnlogic(warnvek)
dmOut[2, 0] = warnx
warncore = np.zeros(1)
warnvek = np.array([statusL_x[1, 3], statusR_x[1, 3], 0, 0])
warnall, warncore[0], dummy = warnlogic(warnvek)
warnwth = np.zeros(2)
warnvek = np.array([statusL_x[1, 0], statusL_x[1, 3], statusR_x[1, 0], statusR_x[1, 3]])
warnall, warnwth[0], warnwth[1] = warnlogic(warnvek)
warnosc = np.zeros(2)
warnvek = np.array([statusL_x[1, 0], statusL_x[1, 1], statusR_x[1, 0], statusR_x[1, 1]])
warnall, warnosc[0], warnosc[1] = warnlogic(warnvek)
warnisc = np.zeros(2)
warnvek = np.array([statusL_x[1, 2], statusL_x[1, 3], statusR_x[1, 2], statusR_x[1, 3]])
warnall, warnisc[0], warnisc[1] = warnlogic(warnvek)
warniso = np.zeros(2)
warnvek = np.array([warnwth[0], warnosc[0], warnisc[0], warnwth[1], warnosc[1], warnisc[1]])
warnall, warniso[0], warniso[1] = warnlogic(warnvek)
if np.array_equal(layeruse, np.array([0, 0, 0])):
wthL[0, :] = 0
wthR[0, :] = 0
wthL[1, :] = LAYER_NOT_REQUESTED
wthR[1, :] = LAYER_NOT_REQUESTED
oscL[0, :] = 0
oscR[0, :] = 0
oscL[1, :] = LAYER_NOT_REQUESTED
oscR[1, :] = LAYER_NOT_REQUESTED
isoL[0, :] = 0
isoR[0, :] = 0
isoL[1, :] = LAYER_NOT_REQUESTED
isoR[1, :] = LAYER_NOT_REQUESTED
iscL[0, :] = 0
iscR[0, :] = 0
iscL[1, :] = LAYER_NOT_REQUESTED
iscR[1, :] = LAYER_NOT_REQUESTED
coreDm[0, :] = 0
coreDm[1, :] = LAYER_NOT_REQUESTED
elif np.array_equal(layeruse, np.array([0, 0, 1])):
wthL[2, :] = warnwth[[0, 1]]
wthR[2, :] = warnwth[1]
oscL[0, :] = 0
oscR[0, :] = 0
oscL[1, :] = LAYER_NOT_REQUESTED
oscR[1, :] = LAYER_NOT_REQUESTED
isoL[0, :] = 0
isoR[0, :] = 0
isoL[1, :] = LAYER_NOT_REQUESTED
isoR[1, :] = LAYER_NOT_REQUESTED
iscL[2, :] = warnisc[0]
iscR[2, :] = warnisc[1]
coreDm[2, :] = warncore
elif np.array_equal(layeruse, np.array([0, 1, 0])):
wthL[2, :] = warnwth[0]
wthR[2, :] = warnwth[1]
oscL[0, :] = 0
oscR[0, :] = 0
oscL[1, :] = LAYER_NOT_REQUESTED
oscR[1, :] = LAYER_NOT_REQUESTED
isoL[2, :] = warniso[0]
isoR[2, :] = warniso[1]
iscL[0, :] = 0
iscR[0, :] = 0
iscL[1, :] = LAYER_NOT_REQUESTED
iscR[1, :] = LAYER_NOT_REQUESTED
coreDm[2, :] = warncore
elif np.array_equal(layeruse, np.array([0, 1, 1])):
wthL[2, :] = warnwth[0]
wthR[2, :] = warnwth[1]
oscL[0, :] = 0
oscR[0, :] = 0
oscL[1, :] = LAYER_NOT_REQUESTED
oscR[1, :] = LAYER_NOT_REQUESTED
isoL[2, :] = warniso[0]
isoR[2, :] = warniso[1]
iscL[2, :] = warnisc[0]
iscR[2, :] = warnisc[1]
coreDm[2, :] = warncore
elif np.array_equal(layeruse, np.array([1, 0, 0])):
wthL[2, :] = warnwth[0]
wthR[2, :] = warnwth[1]
oscL[2, :] = warnosc[0]
oscR[2, :] = warnosc[1]
isoL[0, :] = 0
isoR[0, :] = 0
isoL[1, :] = LAYER_NOT_REQUESTED
isoR[1, :] = LAYER_NOT_REQUESTED
iscL[0, :] = 0
iscR[0, :] = 0
iscL[1, :] = LAYER_NOT_REQUESTED
iscR[1, :] = LAYER_NOT_REQUESTED
coreDm[2, :] = warncore
elif np.array_equal(layeruse, np.array([1, 0, 1])):
wthL[2, :] = warnwth[0]
wthR[2, :] = warnwth[1]
oscL[2, :] = warnosc[0]
oscR[2, :] = warnosc[1]
isoL[0, :] = 0
isoR[0, :] = 0
isoL[1, :] = LAYER_NOT_REQUESTED
isoR[1, :] = LAYER_NOT_REQUESTED
iscL[2, :] = warnisc[0]
iscR[2, :] = warnisc[1]
coreDm[2, :] = warncore
elif np.array_equal(layeruse, np.array([1, 1, 0])):
wthL[2, :] = warnwth[0]
wthR[2, :] = warnwth[1]
oscL[2, :] = warnosc[0]
oscR[2, :] = warnosc[1]
isoL[2, :] = warniso[0]
isoR[2, :] = warniso[1]
iscL[0, :] = 0
iscR[0, :] = 0
iscL[1, :] = LAYER_NOT_REQUESTED
iscR[1, :] = LAYER_NOT_REQUESTED
coreDm[2, :] = warncore
elif np.array_equal(layeruse, np.array([1, 1, 1])):
wthL[2, :] = warnwth[0]
wthR[2, :] = warnwth[1]
oscL[2, :] = warnosc[0]
oscR[2, :] = warnosc[1]
isoL[2, :] = warniso[0]
isoR[2, :] = warniso[1]
iscL[2, :] = warnisc[0]
iscR[2, :] = warnisc[1]
coreDm[2, :] = warncore
return dmOut, oscL, oscR, isoL, isoR, iscL, iscR, coreDm, wthL, wthR, xk