1231 lines
54 KiB
Python
1231 lines
54 KiB
Python
import numpy as np
|
|
|
|
try:
|
|
from .math_utils import ind
|
|
from .extremum_utils import minmax, minmax2, findmaxima, lowlimit
|
|
from .signal_utils import filter2k3
|
|
from .geometry_utils import strng2
|
|
except ImportError:
|
|
from math_utils import ind
|
|
from extremum_utils import minmax, minmax2, findmaxima, lowlimit
|
|
from signal_utils import filter2k3
|
|
from geometry_utils import strng2
|
|
|
|
|
|
def i0detect(I, DistI0, dx, Lowrad, errorin):
|
|
I0 = 1.0
|
|
errorlevel = np.zeros(2, dtype=np.float64)
|
|
|
|
dx = float(dx) if dx is not None else 0.048
|
|
if dx == 0:
|
|
dx = 0.048
|
|
|
|
if len(I) == 0:
|
|
errorin[0] = 9
|
|
|
|
errorlevel[0] = errorin[0] if len(errorin) > 0 else 0
|
|
errorlevel[1] = errorin[1] if len(errorin) > 1 else 0
|
|
|
|
count = len(I)
|
|
Imax = np.max(I)
|
|
limitfak1 = 0.95
|
|
limitfak2 = 0.90
|
|
midcount = int(np.round(DistI0 / dx))
|
|
|
|
run = 1
|
|
i = 1
|
|
startind = 0
|
|
while run:
|
|
if I[i] > limitfak1 * Imax:
|
|
startind = i
|
|
run = 0
|
|
elif i == count - 1:
|
|
run = 0
|
|
else:
|
|
i = i + 1
|
|
|
|
if startind > 0:
|
|
run = 1
|
|
else:
|
|
run = 0
|
|
i = startind
|
|
stopind = 0
|
|
while run:
|
|
if (I[i] < limitfak2 * Imax) or (i > (startind + 2 * midcount)):
|
|
stopind = i
|
|
run = 0
|
|
elif i == count - 1:
|
|
run = 0
|
|
else:
|
|
i = i + 1
|
|
|
|
Il = 1.0
|
|
if (startind > 0) and (stopind > 0) and ((stopind - startind) > midcount):
|
|
Anz = stopind - startind + 1
|
|
Il = 1.0 + np.sum(I[startind:stopind + 1])
|
|
Il = Il / Anz
|
|
|
|
run = 1
|
|
i = count - 2
|
|
startind = 0
|
|
while run:
|
|
if I[i] > limitfak1 * Imax:
|
|
startind = i
|
|
run = 0
|
|
elif i == 0:
|
|
run = 0
|
|
else:
|
|
i = i - 1
|
|
|
|
if startind > 0:
|
|
run = 1
|
|
else:
|
|
run = 0
|
|
i = startind
|
|
stopind = 0
|
|
while run:
|
|
if (I[i] < limitfak2 * Imax) or (i < (startind - 2 * midcount)):
|
|
stopind = i
|
|
run = 0
|
|
elif i == 0:
|
|
run = 0
|
|
else:
|
|
i = i - 1
|
|
|
|
Ir = 1.0
|
|
if (startind > 0) and (stopind > 0) and ((startind - stopind) > midcount):
|
|
Anz = startind - stopind + 1
|
|
Ir = 1.0 + np.sum(I[stopind:startind + 1])
|
|
Ir = Ir / Anz
|
|
|
|
if ((Il / Ir) > 0.985) and ((Il / Ir) < 1.015):
|
|
I0 = (Il + Ir) / 2.0
|
|
else:
|
|
if Il > Ir:
|
|
I0 = Il
|
|
else:
|
|
I0 = Ir
|
|
|
|
if Imax > 1.1 * I0:
|
|
I0 = Imax
|
|
errorlevel[0] = 1
|
|
|
|
if I0 < Lowrad and Lowrad >= 1000:
|
|
errorlevel[1] = 9
|
|
if I0 < 2250:
|
|
errorlevel[0] = 112
|
|
errorlevel[1] = 0
|
|
|
|
if errorin[1] != 0:
|
|
errorlevel[1] = errorin[1]
|
|
|
|
return I0, errorlevel
|
|
|
|
|
|
def i0det2(I, xl11, xr11, conf, errin=None):
|
|
if errin is not None and len(errin) >= 2:
|
|
errorlevel = np.array(errin[:2], dtype=np.float64)
|
|
else:
|
|
errorlevel = np.zeros(2, dtype=np.float64)
|
|
|
|
if errorlevel[0] != 0:
|
|
return 1.0, errorlevel
|
|
|
|
I0 = 1.0
|
|
dx = conf[91] if len(conf) > 91 else 0.1
|
|
dx = float(dx) if dx is not None else 0.1
|
|
if dx == 0:
|
|
dx = 0.1
|
|
count = len(I)
|
|
I0diff = conf[33] / 100.0 if len(conf) > 33 else 0.015
|
|
DistI0 = conf[34] if len(conf) > 34 else 3.0
|
|
Dist01 = 0.1
|
|
|
|
Indl = ind(xl11 - Dist01 - DistI0, dx, 0, count)
|
|
Indr = ind(xl11 - Dist01, dx, 0, count)
|
|
Indl = int(Indl)
|
|
Indr = int(Indr)
|
|
Anz = Indr - Indl + 1
|
|
if Anz < 20:
|
|
errorlevel[0] = 25
|
|
return I0, errorlevel
|
|
Il = np.sum(I[Indl - 1:Indr])
|
|
Il = Il / Anz
|
|
|
|
Indl = int(ind(xr11 + Dist01, dx, 0, count))
|
|
if Indl > count:
|
|
Indl = count
|
|
Indr = int(ind(xr11 + Dist01 + DistI0, dx, 0, count))
|
|
if Indr > count:
|
|
Indr = count
|
|
Anz = Indr - Indl + 1
|
|
if Anz < 20:
|
|
errorlevel[0] = 25
|
|
return I0, errorlevel
|
|
Ir = np.sum(I[Indl - 1:Indr])
|
|
Ir = Ir / Anz
|
|
|
|
if ((Il / Ir) > (1 - I0diff)) and ((Il / Ir) < (1 + I0diff)):
|
|
I0 = (Il + Ir) / 2.0
|
|
else:
|
|
errorlevel[0] = 25
|
|
if Il > Ir:
|
|
I0 = Il
|
|
else:
|
|
I0 = Ir
|
|
|
|
return I0, errorlevel
|
|
|
|
|
|
def x41det2(x, IN, conf):
|
|
xl11 = conf[0]
|
|
xr11 = conf[1]
|
|
Dist41 = conf[2]
|
|
I0 = conf[3]
|
|
Offpegel41 = conf[4]
|
|
Off41 = conf[5]
|
|
Minpegel41 = conf[7] if len(conf) > 7 else 0
|
|
Minidiff = conf[8] if len(conf) > 8 else 0
|
|
Ber = conf[9] if len(conf) > 9 else 0
|
|
Anzpara = conf[10] if len(conf) > 10 else 0
|
|
dx = conf[11] if len(conf) > 11 else 0.1
|
|
Maximumc = conf[12] if len(conf) > 12 else 0
|
|
CableType = conf[13] if len(conf) > 13 else 0
|
|
xr41det = conf[14] if len(conf) > 14 else 0
|
|
alpha0 = None
|
|
if len(conf) > 15:
|
|
alpha0 = conf[15]
|
|
level = 0
|
|
if len(conf) > 16:
|
|
level = conf[16]
|
|
|
|
if CableType == 22:
|
|
if (xr11 - xl11) < 40:
|
|
Filtertyp = 2
|
|
else:
|
|
Filtertyp = 3
|
|
elif CableType == 7:
|
|
if alpha0 is None:
|
|
alpha0 = 0.01
|
|
IN_bp, _ = lowlimit(IN, np.exp(-alpha0 * (xr11 - xl11)))
|
|
IN = IN_bp
|
|
Offpegel41 = 0
|
|
Off41 = 0
|
|
Filtertyp = 4
|
|
elif (CableType == 2) or (CableType == 63500000):
|
|
alpha0 = 0.2
|
|
maxsehne = (xr11 - xl11)
|
|
bp = np.exp(-alpha0 * maxsehne)
|
|
mindetlevel = 0.01
|
|
if bp < mindetlevel:
|
|
bp = mindetlevel
|
|
IN_bp, _ = lowlimit(IN, bp)
|
|
IN = IN_bp
|
|
Offpegel41 = 0
|
|
Off41 = 0
|
|
Filtertyp = 1
|
|
else:
|
|
Filtertyp = 1
|
|
|
|
if Filtertyp == 1:
|
|
lengthref1 = 0.09
|
|
lengthref2 = 0.06
|
|
shiftlength = 0.15
|
|
gain = 4.75
|
|
fpara1 = np.ones(int(np.round(lengthref1 / dx)) + 1)
|
|
fpara1 = (1.0 / len(fpara1)) * fpara1
|
|
fpara2 = np.zeros(int(np.round(lengthref2 / dx)) + 1)
|
|
filtpara = np.concatenate([-fpara1, fpara2, fpara1]) * gain
|
|
shiftind = int(np.round(shiftlength / dx)) + 1
|
|
elif Filtertyp == 2:
|
|
lengthref1 = 0.09
|
|
lengthref2 = 0.78
|
|
shiftlength = 0.45
|
|
gain = 2.1492
|
|
fpara1 = -1 * np.ones(int(np.round(lengthref1 / dx)) + 1)
|
|
fpara1 = (1.0 / len(fpara1)) * fpara1
|
|
fpara2 = np.ones(int(np.round(lengthref2 / dx)) + 1)
|
|
fpara2 = (1.0 / len(fpara2)) * fpara2
|
|
filtpara = np.concatenate([fpara1, fpara2]) * gain
|
|
shiftind = int(np.round(shiftlength / dx)) + 1
|
|
elif Filtertyp == 3:
|
|
lengthref1 = 0.09
|
|
lengthref2 = 1.74
|
|
shiftlength = 0.9
|
|
gain = 1.056
|
|
fpara1 = -1 * np.ones(int(np.round(lengthref1 / dx)) + 1)
|
|
fpara1 = (1.0 / len(fpara1)) * fpara1
|
|
fpara2 = np.ones(int(np.round(lengthref2 / dx)) + 1)
|
|
fpara2 = (1.0 / len(fpara2)) * fpara2
|
|
filtpara = np.concatenate([fpara1, fpara2]) * gain
|
|
shiftind = int(np.round(shiftlength / dx)) + 1
|
|
elif Filtertyp == 4:
|
|
lengthref1 = 0.09
|
|
lengthref2 = 0.12
|
|
shiftlength = 0.09
|
|
gain = 2.1492
|
|
fpara1 = -1 * np.ones(int(np.round(lengthref1 / dx)) + 1)
|
|
fpara1 = (1.0 / len(fpara1)) * fpara1
|
|
fpara2 = np.ones(int(np.round(lengthref2 / dx)) + 1)
|
|
fpara2 = (1.0 / len(fpara2)) * fpara2
|
|
filtpara = np.concatenate([fpara1, fpara2]) * gain
|
|
shiftind = int(np.round(shiftlength / dx)) + 1
|
|
else:
|
|
filtpara = np.array([1.0])
|
|
shiftind = 1
|
|
|
|
errorlevel = np.zeros(2, dtype=np.float64)
|
|
|
|
if xr41det:
|
|
filtpara = filtpara[::-1]
|
|
|
|
NN = len(IN)
|
|
if Dist41 < dx:
|
|
Dist41 = dx
|
|
if xr41det:
|
|
ll = int(ind(xl11 + (xr11 - xl11) / 2, dx, 0, NN))
|
|
rr = int(ind(xr11 - Dist41, dx, 0, NN))
|
|
else:
|
|
ll = int(ind(xl11 + Dist41, dx, 0, NN))
|
|
rr = int(ind(xl11 + (xr11 - xl11) / 2, dx, 0, NN))
|
|
|
|
Offset = Offpegel41 + Off41 / I0
|
|
|
|
x41 = 0.0
|
|
if (x[ll - 1] > xl11) and (x[rr - 1] < xr11) and (ll < rr):
|
|
s1 = strng2(x[ll - 1:rr], xl11, xr11)
|
|
k1 = -(np.log((IN[ll - 1:rr] + Offset) / (1 + Offset))) / s1
|
|
k1 = np.nan_to_num(k1, nan=0.0, posinf=0.0, neginf=0.0)
|
|
|
|
Idiff, N2 = filter2k3(filtpara, k1, 2)
|
|
|
|
if CableType == 63500000:
|
|
x41_idx = findmaxima(Idiff, 0.6, not xr41det)
|
|
Minidiffv = Idiff[int(x41_idx) - 1] if int(x41_idx) > 0 else 0
|
|
elif CableType == 118:
|
|
Minidiffv, x41_idx = minmax2(Idiff, Maximumc, xr41det, level)
|
|
x41_idx = np.round(x41_idx)
|
|
else:
|
|
Minidiffv, x41_idx = minmax(Idiff, Maximumc)
|
|
x41_idx = np.round(x41_idx)
|
|
|
|
if xr41det:
|
|
x41_idx = x41_idx + (ll - 1) + shiftind
|
|
else:
|
|
x41_idx = x41_idx + (ll - 1) - shiftind
|
|
|
|
x41_idx = int(np.clip(x41_idx, 1, NN))
|
|
Relpegelx41 = IN[x41_idx - 1]
|
|
if (IN[x41_idx - 1] * I0 < Minpegel41):
|
|
errorlevel[0] = 7
|
|
|
|
x41 = (x41_idx - 1) * dx
|
|
if abs(Minidiffv) < Minidiff:
|
|
errorlevel[0] = 7
|
|
else:
|
|
x41 = 0.0
|
|
errorlevel[0] = 7
|
|
|
|
return x41, errorlevel
|
|
|
|
|
|
def DaeMinMaxDet(DaeKurve, LR, Tube, StartInd, DeltaMinMax):
|
|
Grenze = 6
|
|
|
|
MaxAnz = 0
|
|
MinAnz = 0
|
|
IndMax = np.array([], dtype=np.float64)
|
|
IndMin = np.array([], dtype=np.float64)
|
|
Maximum = np.zeros((2, 1), dtype=np.float64)
|
|
Minimum = np.zeros((2, 1), dtype=np.float64)
|
|
l = 0
|
|
k = 0
|
|
m = 0
|
|
BitMax = 0
|
|
BitMin = 0
|
|
|
|
DaeKurve = np.asarray(DaeKurve, dtype=np.float64).copy()
|
|
|
|
if len(DaeKurve) == 0:
|
|
return MaxAnz, MinAnz, IndMax, IndMin
|
|
|
|
IndGrenze = 0
|
|
if LR == 0:
|
|
k = 0
|
|
for i in range(len(DaeKurve)):
|
|
if np.isinf(DaeKurve[i]) or np.isnan(DaeKurve[i]):
|
|
DaeKurve[i] = 0
|
|
elif k < Grenze:
|
|
DaeKurve[i] = 0
|
|
k = k + 1
|
|
IndGrenze = i + 1
|
|
k = 0
|
|
elif LR == 1:
|
|
k = 0
|
|
for i in range(len(DaeKurve) - 1, -1, -1):
|
|
if np.isinf(DaeKurve[i]) or np.isnan(DaeKurve[i]):
|
|
DaeKurve[i] = 0
|
|
elif k < Grenze:
|
|
DaeKurve[i] = 0
|
|
k = k + 1
|
|
IndGrenze = i - 1
|
|
k = 0
|
|
|
|
for i in range(1, len(DaeKurve) - 1):
|
|
if DaeKurve[i] != 0:
|
|
if (DaeKurve[i - 1] < DaeKurve[i]) and (DaeKurve[i] > DaeKurve[i + 1]):
|
|
if (Maximum[0, l] == 0) and (i != IndGrenze):
|
|
Maximum[0, l] = DaeKurve[i]
|
|
Maximum[1, l] = i
|
|
BitMax = 1
|
|
|
|
if (DaeKurve[i] > Maximum[0, l]) and (Maximum[0, l] != 0):
|
|
if DaeKurve[i] <= Maximum[0, l] + DeltaMinMax:
|
|
Maximum[0, l] = DaeKurve[i]
|
|
Maximum[1, l] = i
|
|
BitMax = 1
|
|
else:
|
|
if (Minimum.shape[1] > 1) and (Maximum.shape[1] == 1):
|
|
Maximum[0, l] = DaeKurve[i]
|
|
Maximum[1, l] = i
|
|
BitMax = 1
|
|
else:
|
|
Minimum = np.column_stack([Minimum, np.zeros(2)])
|
|
Minimum[0, m] = Maximum[0, l]
|
|
Minimum[1, m] = Maximum[1, 0]
|
|
Maximum[0, l] = DaeKurve[i]
|
|
Maximum[1, l] = i
|
|
BitMax = 1
|
|
m = m + 1
|
|
|
|
if (DaeKurve[i - 1] > DaeKurve[i]) and (DaeKurve[i] < DaeKurve[i + 1]):
|
|
if Minimum[0, m] == 0:
|
|
Minimum[0, m] = DaeKurve[i]
|
|
Minimum[1, m] = i
|
|
BitMin = 1
|
|
|
|
if DaeKurve[i] < Minimum[0, m]:
|
|
if DaeKurve[i] >= Minimum[0, m] - DeltaMinMax:
|
|
Minimum[0, m] = DaeKurve[i]
|
|
Minimum[1, m] = i
|
|
BitMin = 1
|
|
else:
|
|
if (Maximum.shape[1] > 1) and (Minimum.shape[1] == 1):
|
|
Minimum[0, m] = DaeKurve[i]
|
|
Minimum[1, m] = i
|
|
BitMin = 1
|
|
else:
|
|
Maximum = np.column_stack([Maximum, np.zeros(2)])
|
|
Maximum[0, l] = Minimum[0, m]
|
|
Maximum[1, l] = Minimum[1, m]
|
|
Minimum[0, m] = DaeKurve[i]
|
|
Minimum[1, m] = i
|
|
BitMin = 1
|
|
l = l + 1
|
|
|
|
if BitMin == 1:
|
|
MaxValue = 0
|
|
if Maximum[0, l] != 0:
|
|
MaxValue = Maximum[0, l]
|
|
elif Maximum.shape[1] > 1:
|
|
MaxValue = Maximum[0, l - 1]
|
|
|
|
if MaxValue != 0:
|
|
if Minimum[0, m] <= MaxValue - DeltaMinMax:
|
|
if Minimum[0, l if l < m else m] != 0:
|
|
pass
|
|
if Maximum[0, l] != 0:
|
|
l = l + 1
|
|
Maximum = np.column_stack([Maximum, np.zeros(2)])
|
|
Maximum[0, l] = 0
|
|
Maximum[1, l] = 0
|
|
else:
|
|
Minimum[0, m] = 0
|
|
Minimum[1, m] = 0
|
|
|
|
BitMin = 0
|
|
|
|
if BitMax == 1:
|
|
MinValue = 0
|
|
if Minimum[0, m] != 0:
|
|
MinValue = Minimum[0, m]
|
|
elif Minimum.shape[1] > 1:
|
|
MinValue = Minimum[0, m - 1]
|
|
|
|
if MinValue != 0:
|
|
if Maximum[0, l] > MinValue + DeltaMinMax:
|
|
if Minimum[0, m] != 0:
|
|
m = m + 1
|
|
Minimum = np.column_stack([Minimum, np.zeros(2)])
|
|
Minimum[0, m] = 0
|
|
Minimum[1, m] = 0
|
|
else:
|
|
Maximum[0, l] = 0
|
|
Maximum[1, l] = 0
|
|
|
|
BitMax = 0
|
|
|
|
temp = np.where(Maximum[0, :] != 0)[0]
|
|
if len(temp) > 0:
|
|
MaxAnz = len(temp)
|
|
IndMax = Maximum[1, temp] + StartInd
|
|
temp = np.where(Minimum[0, :] != 0)[0]
|
|
if len(temp) > 0:
|
|
MinAnz = len(temp)
|
|
IndMin = Minimum[1, temp] + StartInd
|
|
|
|
return MaxAnz, MinAnz, IndMax, IndMin
|
|
|
|
|
|
def GradMinMaxDet(grad, LR, DaeGrad, MinMax, Tube, Indxlr11):
|
|
if Tube == 0:
|
|
if (LR == 0) and (DaeGrad == 1) and (MinMax == 1):
|
|
ThrAttGrad = 5e-4
|
|
elif (LR == 0) and (DaeGrad == 1) and (MinMax == 0):
|
|
ThrAttGrad = 2.5e-3
|
|
elif (LR == 1) and (DaeGrad == 1) and (MinMax == 0):
|
|
ThrAttGrad = 5e-4
|
|
elif (LR == 1) and (DaeGrad == 1) and (MinMax == 1):
|
|
ThrAttGrad = 2.5e-3
|
|
else:
|
|
ThrAttGrad = 1e-3
|
|
else:
|
|
if (LR == 0) and (DaeGrad == 1) and (MinMax == 1):
|
|
ThrAttGrad = 5e-4
|
|
elif (LR == 0) and (DaeGrad == 1) and (MinMax == 0):
|
|
ThrAttGrad = 1.5e-3
|
|
elif (LR == 1) and (DaeGrad == 1) and (MinMax == 0):
|
|
ThrAttGrad = 5e-4
|
|
elif (LR == 1) and (DaeGrad == 1) and (MinMax == 1):
|
|
ThrAttGrad = 1.5e-3
|
|
else:
|
|
ThrAttGrad = 1e-3
|
|
|
|
if (Tube == 0) or (Tube == 1):
|
|
if (LR == 0) and (DaeGrad == 2) and (MinMax == 1):
|
|
ThrAttGrad = 5e-4
|
|
elif (LR == 0) and (DaeGrad == 2) and (MinMax == 0):
|
|
ThrAttGrad = 1.5e-3
|
|
elif (LR == 1) and (DaeGrad == 2) and (MinMax == 0):
|
|
ThrAttGrad = 5e-4
|
|
elif (LR == 1) and (DaeGrad == 2) and (MinMax == 1):
|
|
ThrAttGrad = 1.5e-3
|
|
|
|
if Tube == 0:
|
|
IndexGrenze = 5
|
|
else:
|
|
IndexGrenze = 7
|
|
if DaeGrad == 2:
|
|
IndexGrenze = 100
|
|
|
|
if Tube == 0:
|
|
ThrNoiseGrad = 0.5
|
|
else:
|
|
ThrNoiseGrad = 0.4
|
|
|
|
if DaeGrad == 1:
|
|
ThrNoiseDae = 0.5
|
|
elif DaeGrad == 2:
|
|
ThrNoiseDae = 0.2
|
|
else:
|
|
ThrNoiseDae = 0.5
|
|
|
|
j = 0
|
|
k = 0
|
|
MinAnz = 0
|
|
MaxAnz = 0
|
|
IndMinGrad = np.array([], dtype=np.float64)
|
|
IndMaxGrad = np.array([], dtype=np.float64)
|
|
Minimum = np.zeros((2, 0), dtype=np.float64)
|
|
Maximum = np.zeros((2, 0), dtype=np.float64)
|
|
|
|
grad = np.asarray(grad, dtype=np.float64)
|
|
|
|
for i in range(1, len(grad) - 1):
|
|
if (grad[i] < grad[i - 1]) and (grad[i] < grad[i + 1]):
|
|
Minimum = np.column_stack([Minimum, np.array([grad[i], i])])
|
|
j = j + 1
|
|
|
|
for i in range(1, len(grad) - 1):
|
|
if (grad[i] > grad[i - 1]) and (grad[i] > grad[i + 1]):
|
|
Maximum = np.column_stack([Maximum, np.array([grad[i], i])])
|
|
k = k + 1
|
|
|
|
if LR == 0:
|
|
if DaeGrad == 0:
|
|
if Minimum.shape[1] > 0:
|
|
Ind = np.where(Minimum[0, :])[0]
|
|
if len(Ind) > 0:
|
|
MinimumMean = np.mean(Minimum[0, Ind])
|
|
else:
|
|
MinimumMean = 0
|
|
for j_idx in range(Minimum.shape[1]):
|
|
if Minimum[0, j_idx] > MinimumMean:
|
|
Minimum[0, j_idx] = 0
|
|
Minimum[1, j_idx] = 0
|
|
|
|
IndMinAnz = np.where(Minimum[0, :] != 0)[0]
|
|
if len(IndMinAnz) > 1:
|
|
for i in range(len(IndMinAnz) - 1):
|
|
Index = Minimum[1, IndMinAnz[i]]
|
|
Value = Minimum[0, IndMinAnz[i]]
|
|
IndexNext = Minimum[1, IndMinAnz[i + 1]]
|
|
ValueNext = Minimum[0, IndMinAnz[i + 1]]
|
|
if (IndexNext - Index) <= IndexGrenze:
|
|
if abs(Value) < abs(ValueNext):
|
|
Minimum[0, IndMinAnz[i]] = 0
|
|
Minimum[1, IndMinAnz[i]] = 0
|
|
elif abs(Value) > abs(ValueNext):
|
|
if i < (len(IndMinAnz) - 1):
|
|
IndexNext2 = Minimum[1, IndMinAnz[i + 2]]
|
|
ValueNext2 = Minimum[0, IndMinAnz[i + 2]]
|
|
if (IndexNext2 - IndexNext) <= IndexGrenze:
|
|
if abs(Value) < abs(ValueNext2):
|
|
Minimum[0, IndMinAnz[i]] = 0
|
|
Minimum[1, IndMinAnz[i]] = 0
|
|
Minimum[0, IndMinAnz[i + 1]] = 0
|
|
Minimum[1, IndMinAnz[i + 1]] = 0
|
|
elif abs(Value) > abs(ValueNext2):
|
|
Minimum[0, IndMinAnz[i + 1]] = 0
|
|
Minimum[1, IndMinAnz[i + 1]] = 0
|
|
Minimum[0, IndMinAnz[i + 2]] = 0
|
|
Minimum[1, IndMinAnz[i + 2]] = 0
|
|
else:
|
|
Minimum[0, IndMinAnz[i + 1]] = 0
|
|
Minimum[1, IndMinAnz[i + 1]] = 0
|
|
else:
|
|
Minimum[0, IndMinAnz[i + 1]] = 0
|
|
Minimum[1, IndMinAnz[i + 1]] = 0
|
|
|
|
IndMinAnz = np.where(Minimum[0, :] != 0)[0]
|
|
MinValue = np.min(Minimum[0, :]) if len(Minimum[0, :]) > 0 else 0
|
|
if len(IndMinAnz) > 1:
|
|
for i in range(len(IndMinAnz)):
|
|
Value = Minimum[0, IndMinAnz[i]]
|
|
if MinValue != 0 and abs(Value / MinValue) < ThrNoiseGrad:
|
|
Minimum[0, IndMinAnz[i]] = 0
|
|
Minimum[1, IndMinAnz[i]] = 0
|
|
|
|
IndMinAnz = np.where(Minimum[0, :] != 0)[0]
|
|
if len(IndMinAnz) > 0:
|
|
MinAnz = len(IndMinAnz)
|
|
IndMinGrad = Minimum[1, IndMinAnz]
|
|
|
|
elif DaeGrad == 1:
|
|
if MinMax == 1:
|
|
if Maximum.shape[1] > 0:
|
|
Ind = np.where(Maximum[0, :])[0]
|
|
if len(Ind) > 0:
|
|
MaximumMean = np.mean(Maximum[0, Ind])
|
|
else:
|
|
MaximumMean = 0
|
|
for i in range(Maximum.shape[1]):
|
|
if Maximum[0, i] < MaximumMean:
|
|
Maximum[0, i] = 0
|
|
Maximum[1, i] = 0
|
|
|
|
IndMaxAnz = np.where(Maximum[0, :] != 0)[0]
|
|
if len(IndMaxAnz) > 1:
|
|
for i in range(len(IndMaxAnz) - 1):
|
|
Index = Maximum[1, IndMaxAnz[i]]
|
|
Value = Maximum[0, IndMaxAnz[i]]
|
|
IndexNext = Maximum[1, IndMaxAnz[i + 1]]
|
|
ValueNext = Maximum[0, IndMaxAnz[i + 1]]
|
|
if (IndexNext - Index) <= IndexGrenze:
|
|
if abs(Value) < abs(ValueNext):
|
|
Maximum[0, IndMaxAnz[i]] = 0
|
|
Maximum[1, IndMaxAnz[i]] = 0
|
|
elif abs(Value) > abs(ValueNext):
|
|
if i < (len(IndMaxAnz) - 1):
|
|
IndexNext2 = Maximum[1, IndMaxAnz[i + 2]]
|
|
ValueNext2 = Maximum[0, IndMaxAnz[i + 2]]
|
|
if (IndexNext2 - IndexNext) <= IndexGrenze:
|
|
if abs(Value) < abs(ValueNext2):
|
|
Maximum[0, IndMaxAnz[i]] = 0
|
|
Maximum[1, IndMaxAnz[i]] = 0
|
|
Maximum[0, IndMaxAnz[i + 1]] = 0
|
|
Maximum[1, IndMaxAnz[i + 1]] = 0
|
|
elif abs(Value) > abs(ValueNext2):
|
|
Maximum[0, IndMaxAnz[i + 1]] = 0
|
|
Maximum[1, IndMaxAnz[i + 1]] = 0
|
|
Maximum[0, IndMaxAnz[i + 2]] = 0
|
|
Maximum[1, IndMaxAnz[i + 2]] = 0
|
|
else:
|
|
Maximum[0, IndMaxAnz[i + 1]] = 0
|
|
Maximum[1, IndMaxAnz[i + 1]] = 0
|
|
else:
|
|
Maximum[0, IndMaxAnz[i + 1]] = 0
|
|
Maximum[1, IndMaxAnz[i + 1]] = 0
|
|
|
|
IndMaxAnz = np.where(Maximum[0, :] != 0)[0]
|
|
MaxValue = np.max(Maximum[0, :]) if len(Maximum[0, :]) > 0 else 0
|
|
if len(IndMaxAnz) > 1:
|
|
for i in range(len(IndMaxAnz)):
|
|
Value = Maximum[0, IndMaxAnz[i]]
|
|
if MaxValue != 0 and abs(Value / MaxValue) < ThrNoiseDae:
|
|
Maximum[0, IndMaxAnz[i]] = 0
|
|
Maximum[1, IndMaxAnz[i]] = 0
|
|
|
|
IndMaxAnz = np.where(Maximum[0, :] != 0)[0]
|
|
for i in range(len(IndMaxAnz)):
|
|
Value = Maximum[0, IndMaxAnz[i]]
|
|
if abs(Value) < ThrAttGrad:
|
|
Maximum[0, IndMaxAnz[i]] = 0
|
|
Maximum[1, IndMaxAnz[i]] = 0
|
|
|
|
IndMaxAnz = np.where(Maximum[0, :] != 0)[0]
|
|
if len(IndMaxAnz) > 0:
|
|
if abs(Maximum[1, IndMaxAnz[0]] - Indxlr11) < 15:
|
|
Maximum[0, IndMaxAnz[0]] = 0
|
|
Maximum[1, IndMaxAnz[0]] = 0
|
|
|
|
IndMaxAnz = np.where(Maximum[0, :] != 0)[0]
|
|
if len(IndMaxAnz) > 0:
|
|
MaxAnz = len(IndMaxAnz)
|
|
IndMaxGrad = Maximum[1, IndMaxAnz]
|
|
|
|
elif MinMax == 0:
|
|
if Minimum.shape[1] > 0:
|
|
Ind = np.where(Minimum[0, :])[0]
|
|
if len(Ind) > 0:
|
|
MinimumMean = np.mean(Minimum[0, Ind])
|
|
else:
|
|
MinimumMean = 0
|
|
for j_idx in range(Minimum.shape[1]):
|
|
if Minimum[0, j_idx] > MinimumMean:
|
|
Minimum[0, j_idx] = 0
|
|
Minimum[1, j_idx] = 0
|
|
|
|
IndMinAnz = np.where(Minimum[0, :] != 0)[0]
|
|
if len(IndMinAnz) > 1:
|
|
for i in range(len(IndMinAnz) - 1):
|
|
Index = Minimum[1, IndMinAnz[i]]
|
|
Value = Minimum[0, IndMinAnz[i]]
|
|
IndexNext = Minimum[1, IndMinAnz[i + 1]]
|
|
ValueNext = Minimum[0, IndMinAnz[i + 1]]
|
|
if (IndexNext - Index) <= IndexGrenze:
|
|
if abs(Value) < abs(ValueNext):
|
|
Minimum[0, IndMinAnz[i]] = 0
|
|
Minimum[1, IndMinAnz[i]] = 0
|
|
elif abs(Value) > abs(ValueNext):
|
|
if i < (len(IndMinAnz) - 1):
|
|
IndexNext2 = Minimum[1, IndMinAnz[i + 2]]
|
|
ValueNext2 = Minimum[0, IndMinAnz[i + 2]]
|
|
if (IndexNext2 - IndexNext) <= IndexGrenze:
|
|
if abs(Value) < abs(ValueNext2):
|
|
Minimum[0, IndMinAnz[i]] = 0
|
|
Minimum[1, IndMinAnz[i]] = 0
|
|
Minimum[0, IndMinAnz[i + 1]] = 0
|
|
Minimum[1, IndMinAnz[i + 1]] = 0
|
|
elif abs(Value) > abs(ValueNext2):
|
|
Minimum[0, IndMinAnz[i + 1]] = 0
|
|
Minimum[1, IndMinAnz[i + 1]] = 0
|
|
Minimum[0, IndMinAnz[i + 2]] = 0
|
|
Minimum[1, IndMinAnz[i + 2]] = 0
|
|
else:
|
|
Minimum[0, IndMinAnz[i + 1]] = 0
|
|
Minimum[1, IndMinAnz[i + 1]] = 0
|
|
else:
|
|
Minimum[0, IndMinAnz[i + 1]] = 0
|
|
Minimum[1, IndMinAnz[i + 1]] = 0
|
|
|
|
IndMinAnz = np.where(Minimum[0, :] != 0)[0]
|
|
MinValue = np.min(Minimum[0, :]) if len(Minimum[0, :]) > 0 else 0
|
|
if len(IndMinAnz) > 1:
|
|
for i in range(len(IndMinAnz)):
|
|
Value = Minimum[0, IndMinAnz[i]]
|
|
if MinValue != 0 and abs(Value / MinValue) < ThrNoiseDae:
|
|
Minimum[0, IndMinAnz[i]] = 0
|
|
Minimum[1, IndMinAnz[i]] = 0
|
|
|
|
IndMinAnz = np.where(Minimum[0, :] != 0)[0]
|
|
for i in range(len(IndMinAnz)):
|
|
Value = Minimum[0, IndMinAnz[i]]
|
|
if abs(Value) < ThrAttGrad:
|
|
Minimum[0, IndMinAnz[i]] = 0
|
|
Minimum[1, IndMinAnz[i]] = 0
|
|
|
|
IndMinAnz = np.where(Minimum[0, :] != 0)[0]
|
|
if len(IndMinAnz) > 0:
|
|
if abs(Minimum[1, IndMinAnz[-1]] - Indxlr11) < 15:
|
|
Minimum[0, IndMinAnz[-1]] = 0
|
|
Minimum[1, IndMinAnz[-1]] = 0
|
|
|
|
IndMinAnz = np.where(Minimum[0, :] != 0)[0]
|
|
if len(IndMinAnz) > 0:
|
|
MinAnz = len(IndMinAnz)
|
|
IndMinGrad = Minimum[1, IndMinAnz]
|
|
|
|
elif DaeGrad == 2:
|
|
if MinMax == 1:
|
|
if Maximum.shape[1] > 0:
|
|
Ind = np.where(Maximum[0, :])[0]
|
|
if len(Ind) > 0:
|
|
MaximumMean = np.mean(Maximum[0, Ind])
|
|
else:
|
|
MaximumMean = 0
|
|
for i in range(Maximum.shape[1]):
|
|
if Maximum[0, i] < MaximumMean:
|
|
Maximum[0, i] = 0
|
|
Maximum[1, i] = 0
|
|
|
|
IndMaxAnz = np.where(Maximum[0, :] != 0)[0]
|
|
if len(IndMaxAnz) > 1:
|
|
for i in range(len(IndMaxAnz) - 1):
|
|
Index = Maximum[1, IndMaxAnz[i]]
|
|
Value = Maximum[0, IndMaxAnz[i]]
|
|
IndexNext = Maximum[1, IndMaxAnz[i + 1]]
|
|
ValueNext = Maximum[0, IndMaxAnz[i + 1]]
|
|
if (IndexNext - Index) <= IndexGrenze:
|
|
if abs(Value) < abs(ValueNext):
|
|
Maximum[0, IndMaxAnz[i]] = 0
|
|
Maximum[1, IndMaxAnz[i]] = 0
|
|
elif abs(Value) > abs(ValueNext):
|
|
if i < (len(IndMaxAnz) - 1):
|
|
IndexNext2 = Maximum[1, IndMaxAnz[i + 2]]
|
|
ValueNext2 = Maximum[0, IndMaxAnz[i + 2]]
|
|
if (IndexNext2 - IndexNext) <= IndexGrenze:
|
|
if abs(Value) < abs(ValueNext2):
|
|
Maximum[0, IndMaxAnz[i]] = 0
|
|
Maximum[1, IndMaxAnz[i]] = 0
|
|
Maximum[0, IndMaxAnz[i + 1]] = 0
|
|
Maximum[1, IndMaxAnz[i + 1]] = 0
|
|
elif abs(Value) > abs(ValueNext2):
|
|
Maximum[0, IndMaxAnz[i + 1]] = 0
|
|
Maximum[1, IndMaxAnz[i + 1]] = 0
|
|
Maximum[0, IndMaxAnz[i + 2]] = 0
|
|
Maximum[1, IndMaxAnz[i + 2]] = 0
|
|
else:
|
|
Maximum[0, IndMaxAnz[i + 1]] = 0
|
|
Maximum[1, IndMaxAnz[i + 1]] = 0
|
|
else:
|
|
Maximum[0, IndMaxAnz[i + 1]] = 0
|
|
Maximum[1, IndMaxAnz[i + 1]] = 0
|
|
|
|
IndMaxAnz = np.where(Maximum[0, :] != 0)[0]
|
|
MaxValue = np.max(Maximum[0, :]) if len(Maximum[0, :]) > 0 else 0
|
|
if len(IndMaxAnz) > 1:
|
|
for i in range(len(IndMaxAnz)):
|
|
Value = Maximum[0, IndMaxAnz[i]]
|
|
if MaxValue != 0 and abs(Value / MaxValue) < ThrNoiseDae:
|
|
Maximum[0, IndMaxAnz[i]] = 0
|
|
Maximum[1, IndMaxAnz[i]] = 0
|
|
|
|
IndMaxAnz = np.where(Maximum[0, :] != 0)[0]
|
|
for i in range(len(IndMaxAnz)):
|
|
Value = Maximum[0, IndMaxAnz[i]]
|
|
if abs(Value) < ThrAttGrad:
|
|
Maximum[0, IndMaxAnz[i]] = 0
|
|
Maximum[1, IndMaxAnz[i]] = 0
|
|
|
|
IndMaxAnz = np.where(Maximum[0, :] != 0)[0]
|
|
if len(IndMaxAnz) > 0:
|
|
MaxAnz = len(IndMaxAnz)
|
|
IndMaxGrad = Maximum[1, IndMaxAnz]
|
|
|
|
elif MinMax == 0:
|
|
if Minimum.shape[1] > 0:
|
|
Ind = np.where(Minimum[0, :])[0]
|
|
if len(Ind) > 0:
|
|
MinimumMean = np.mean(Minimum[0, Ind])
|
|
else:
|
|
MinimumMean = 0
|
|
for j_idx in range(Minimum.shape[1]):
|
|
if Minimum[0, j_idx] > MinimumMean:
|
|
Minimum[0, j_idx] = 0
|
|
Minimum[1, j_idx] = 0
|
|
|
|
IndMinAnz = np.where(Minimum[0, :] != 0)[0]
|
|
if len(IndMinAnz) > 1:
|
|
for i in range(len(IndMinAnz) - 1):
|
|
Index = Minimum[1, IndMinAnz[i]]
|
|
Value = Minimum[0, IndMinAnz[i]]
|
|
IndexNext = Minimum[1, IndMinAnz[i + 1]]
|
|
ValueNext = Minimum[0, IndMinAnz[i + 1]]
|
|
if (IndexNext - Index) <= IndexGrenze:
|
|
if abs(Value) < abs(ValueNext):
|
|
Minimum[0, IndMinAnz[i]] = 0
|
|
Minimum[1, IndMinAnz[i]] = 0
|
|
elif abs(Value) > abs(ValueNext):
|
|
if i < (len(IndMinAnz) - 1):
|
|
IndexNext2 = Minimum[1, IndMinAnz[i + 2]]
|
|
ValueNext2 = Minimum[0, IndMinAnz[i + 2]]
|
|
if (IndexNext2 - IndexNext) <= IndexGrenze:
|
|
if abs(Value) < abs(ValueNext2):
|
|
Minimum[0, IndMinAnz[i]] = 0
|
|
Minimum[1, IndMinAnz[i]] = 0
|
|
Minimum[0, IndMinAnz[i + 1]] = 0
|
|
Minimum[1, IndMinAnz[i + 1]] = 0
|
|
elif abs(Value) > abs(ValueNext2):
|
|
Minimum[0, IndMinAnz[i + 1]] = 0
|
|
Minimum[1, IndMinAnz[i + 1]] = 0
|
|
Minimum[0, IndMinAnz[i + 2]] = 0
|
|
Minimum[1, IndMinAnz[i + 2]] = 0
|
|
else:
|
|
Minimum[0, IndMinAnz[i + 1]] = 0
|
|
Minimum[1, IndMinAnz[i + 1]] = 0
|
|
else:
|
|
Minimum[0, IndMinAnz[i + 1]] = 0
|
|
Minimum[1, IndMinAnz[i + 1]] = 0
|
|
|
|
IndMinAnz = np.where(Minimum[0, :] != 0)[0]
|
|
MinValue = np.min(Minimum[0, :]) if len(Minimum[0, :]) > 0 else 0
|
|
if len(IndMinAnz) > 1:
|
|
for i in range(len(IndMinAnz)):
|
|
Value = Minimum[0, IndMinAnz[i]]
|
|
if MinValue != 0 and abs(Value / MinValue) < ThrNoiseDae:
|
|
Minimum[0, IndMinAnz[i]] = 0
|
|
Minimum[1, IndMinAnz[i]] = 0
|
|
|
|
IndMinAnz = np.where(Minimum[0, :] != 0)[0]
|
|
for i in range(len(IndMinAnz)):
|
|
Value = Minimum[0, IndMinAnz[i]]
|
|
if abs(Value) < ThrAttGrad:
|
|
Minimum[0, IndMinAnz[i]] = 0
|
|
Minimum[1, IndMinAnz[i]] = 0
|
|
|
|
IndMinAnz = np.where(Minimum[0, :] != 0)[0]
|
|
if len(IndMinAnz) > 0:
|
|
MinAnz = len(IndMinAnz)
|
|
IndMinGrad = Minimum[1, IndMinAnz]
|
|
|
|
elif LR == 1:
|
|
if DaeGrad == 0:
|
|
if Maximum.shape[1] > 0:
|
|
Ind = np.where(Maximum[0, :])[0]
|
|
if len(Ind) > 0:
|
|
MaximumMean = np.mean(Maximum[0, Ind])
|
|
else:
|
|
MaximumMean = 0
|
|
for i in range(Maximum.shape[1]):
|
|
if Maximum[0, i] < MaximumMean:
|
|
Maximum[0, i] = 0
|
|
Maximum[1, i] = 0
|
|
|
|
IndMaxAnz = np.where(Maximum[0, :] != 0)[0]
|
|
if len(IndMaxAnz) > 1:
|
|
for i in range(len(IndMaxAnz) - 1):
|
|
Index = Maximum[1, IndMaxAnz[i]]
|
|
Value = Maximum[0, IndMaxAnz[i]]
|
|
IndexNext = Maximum[1, IndMaxAnz[i + 1]]
|
|
ValueNext = Maximum[0, IndMaxAnz[i + 1]]
|
|
if (IndexNext - Index) <= IndexGrenze:
|
|
if abs(Value) < abs(ValueNext):
|
|
Maximum[0, IndMaxAnz[i]] = 0
|
|
Maximum[1, IndMaxAnz[i]] = 0
|
|
elif abs(Value) > abs(ValueNext):
|
|
if i < (len(IndMaxAnz) - 1):
|
|
IndexNext2 = Maximum[1, IndMaxAnz[i + 2]]
|
|
ValueNext2 = Maximum[0, IndMaxAnz[i + 2]]
|
|
if (IndexNext2 - IndexNext) <= IndexGrenze:
|
|
if abs(Value) < abs(ValueNext2):
|
|
Maximum[0, IndMaxAnz[i]] = 0
|
|
Maximum[1, IndMaxAnz[i]] = 0
|
|
Maximum[0, IndMaxAnz[i + 1]] = 0
|
|
Maximum[1, IndMaxAnz[i + 1]] = 0
|
|
elif abs(Value) > abs(ValueNext2):
|
|
Maximum[0, IndMaxAnz[i + 1]] = 0
|
|
Maximum[1, IndMaxAnz[i + 1]] = 0
|
|
Maximum[0, IndMaxAnz[i + 2]] = 0
|
|
Maximum[1, IndMaxAnz[i + 2]] = 0
|
|
else:
|
|
Maximum[0, IndMaxAnz[i + 1]] = 0
|
|
Maximum[1, IndMaxAnz[i + 1]] = 0
|
|
else:
|
|
Maximum[0, IndMaxAnz[i + 1]] = 0
|
|
Maximum[1, IndMaxAnz[i + 1]] = 0
|
|
|
|
IndMaxAnz = np.where(Maximum[0, :] != 0)[0]
|
|
MaxValue = np.max(Maximum[0, :]) if len(Maximum[0, :]) > 0 else 0
|
|
if len(IndMaxAnz) > 1:
|
|
for i in range(len(IndMaxAnz)):
|
|
Value = Maximum[0, IndMaxAnz[i]]
|
|
if MaxValue != 0 and abs(Value / MaxValue) < ThrNoiseGrad:
|
|
Maximum[0, IndMaxAnz[i]] = 0
|
|
Maximum[1, IndMaxAnz[i]] = 0
|
|
|
|
IndMaxAnz = np.where(Maximum[0, :] != 0)[0]
|
|
if len(IndMaxAnz) > 0:
|
|
MaxAnz = len(IndMaxAnz)
|
|
IndMaxGrad = Maximum[1, IndMaxAnz]
|
|
|
|
elif DaeGrad == 1:
|
|
if MinMax == 0:
|
|
if Minimum.shape[1] > 0:
|
|
Ind = np.where(Minimum[0, :])[0]
|
|
if len(Ind) > 0:
|
|
MinimumMean = np.mean(Minimum[0, Ind])
|
|
else:
|
|
MinimumMean = 0
|
|
for j_idx in range(Minimum.shape[1]):
|
|
if Minimum[0, j_idx] > MinimumMean:
|
|
Minimum[0, j_idx] = 0
|
|
Minimum[1, j_idx] = 0
|
|
|
|
IndMinAnz = np.where(Minimum[0, :] != 0)[0]
|
|
if len(IndMinAnz) > 1:
|
|
for i in range(len(IndMinAnz) - 1):
|
|
Index = Minimum[1, IndMinAnz[i]]
|
|
Value = Minimum[0, IndMinAnz[i]]
|
|
IndexNext = Minimum[1, IndMinAnz[i + 1]]
|
|
ValueNext = Minimum[0, IndMinAnz[i + 1]]
|
|
if (IndexNext - Index) <= IndexGrenze:
|
|
if abs(Value) < abs(ValueNext):
|
|
Minimum[0, IndMinAnz[i]] = 0
|
|
Minimum[1, IndMinAnz[i]] = 0
|
|
elif abs(Value) > abs(ValueNext):
|
|
if i < (len(IndMinAnz) - 1):
|
|
IndexNext2 = Minimum[1, IndMinAnz[i + 2]]
|
|
ValueNext2 = Minimum[0, IndMinAnz[i + 2]]
|
|
if (IndexNext2 - IndexNext) <= IndexGrenze:
|
|
if abs(Value) < abs(ValueNext2):
|
|
Minimum[0, IndMinAnz[i]] = 0
|
|
Minimum[1, IndMinAnz[i]] = 0
|
|
Minimum[0, IndMinAnz[i + 1]] = 0
|
|
Minimum[1, IndMinAnz[i + 1]] = 0
|
|
elif abs(Value) > abs(ValueNext2):
|
|
Minimum[0, IndMinAnz[i + 1]] = 0
|
|
Minimum[1, IndMinAnz[i + 1]] = 0
|
|
Minimum[0, IndMinAnz[i + 2]] = 0
|
|
Minimum[1, IndMinAnz[i + 2]] = 0
|
|
else:
|
|
Minimum[0, IndMinAnz[i + 1]] = 0
|
|
Minimum[1, IndMinAnz[i + 1]] = 0
|
|
else:
|
|
Minimum[0, IndMinAnz[i + 1]] = 0
|
|
Minimum[1, IndMinAnz[i + 1]] = 0
|
|
|
|
IndMinAnz = np.where(Minimum[0, :] != 0)[0]
|
|
MinValue = np.min(Minimum[0, :]) if len(Minimum[0, :]) > 0 else 0
|
|
if len(IndMinAnz) > 1:
|
|
for i in range(len(IndMinAnz)):
|
|
Value = Minimum[0, IndMinAnz[i]]
|
|
if MinValue != 0 and abs(Value / MinValue) < ThrNoiseDae:
|
|
Minimum[0, IndMinAnz[i]] = 0
|
|
Minimum[1, IndMinAnz[i]] = 0
|
|
|
|
IndMinAnz = np.where(Minimum[0, :] != 0)[0]
|
|
for i in range(len(IndMinAnz)):
|
|
Value = Minimum[0, IndMinAnz[i]]
|
|
if abs(Value) < ThrAttGrad:
|
|
Minimum[0, IndMinAnz[i]] = 0
|
|
Minimum[1, IndMinAnz[i]] = 0
|
|
|
|
IndMinAnz = np.where(Minimum[0, :] != 0)[0]
|
|
if len(IndMinAnz) > 0:
|
|
if abs(Minimum[1, IndMinAnz[-1]] - Indxlr11) < 15:
|
|
Minimum[0, IndMinAnz[-1]] = 0
|
|
Minimum[1, IndMinAnz[-1]] = 0
|
|
|
|
IndMinAnz = np.where(Minimum[0, :] != 0)[0]
|
|
if len(IndMinAnz) > 0:
|
|
MinAnz = len(IndMinAnz)
|
|
IndMinGrad = Minimum[1, IndMinAnz]
|
|
|
|
elif MinMax == 1:
|
|
if Maximum.shape[1] > 0:
|
|
Ind = np.where(Maximum[0, :])[0]
|
|
if len(Ind) > 0:
|
|
MaximumMean = np.mean(Maximum[0, Ind])
|
|
else:
|
|
MaximumMean = 0
|
|
for i in range(Maximum.shape[1]):
|
|
if Maximum[0, i] < MaximumMean:
|
|
Maximum[0, i] = 0
|
|
Maximum[1, i] = 0
|
|
|
|
IndMaxAnz = np.where(Maximum[0, :] != 0)[0]
|
|
if len(IndMaxAnz) > 1:
|
|
for i in range(len(IndMaxAnz) - 1):
|
|
Index = Maximum[1, IndMaxAnz[i]]
|
|
Value = Maximum[0, IndMaxAnz[i]]
|
|
IndexNext = Maximum[1, IndMaxAnz[i + 1]]
|
|
ValueNext = Maximum[0, IndMaxAnz[i + 1]]
|
|
if (IndexNext - Index) <= IndexGrenze:
|
|
if abs(Value) < abs(ValueNext):
|
|
Maximum[0, IndMaxAnz[i]] = 0
|
|
Maximum[1, IndMaxAnz[i]] = 0
|
|
elif abs(Value) > abs(ValueNext):
|
|
if i < (len(IndMaxAnz) - 1):
|
|
IndexNext2 = Maximum[1, IndMaxAnz[i + 2]]
|
|
ValueNext2 = Maximum[0, IndMaxAnz[i + 2]]
|
|
if (IndexNext2 - IndexNext) <= IndexGrenze:
|
|
if abs(Value) < abs(ValueNext2):
|
|
Maximum[0, IndMaxAnz[i]] = 0
|
|
Maximum[1, IndMaxAnz[i]] = 0
|
|
Maximum[0, IndMaxAnz[i + 1]] = 0
|
|
Maximum[1, IndMaxAnz[i + 1]] = 0
|
|
elif abs(Value) > abs(ValueNext2):
|
|
Maximum[0, IndMaxAnz[i + 1]] = 0
|
|
Maximum[1, IndMaxAnz[i + 1]] = 0
|
|
Maximum[0, IndMaxAnz[i + 2]] = 0
|
|
Maximum[1, IndMaxAnz[i + 2]] = 0
|
|
else:
|
|
Maximum[0, IndMaxAnz[i + 1]] = 0
|
|
Maximum[1, IndMaxAnz[i + 1]] = 0
|
|
else:
|
|
Maximum[0, IndMaxAnz[i + 1]] = 0
|
|
Maximum[1, IndMaxAnz[i + 1]] = 0
|
|
|
|
IndMaxAnz = np.where(Maximum[0, :] != 0)[0]
|
|
MaxValue = np.max(Maximum[0, :]) if len(Maximum[0, :]) > 0 else 0
|
|
if len(IndMaxAnz) > 1:
|
|
for i in range(len(IndMaxAnz)):
|
|
Value = Maximum[0, IndMaxAnz[i]]
|
|
if MaxValue != 0 and abs(Value / MaxValue) < ThrNoiseDae:
|
|
Maximum[0, IndMaxAnz[i]] = 0
|
|
Maximum[1, IndMaxAnz[i]] = 0
|
|
|
|
IndMaxAnz = np.where(Maximum[0, :] != 0)[0]
|
|
for i in range(len(IndMaxAnz)):
|
|
Value = Maximum[0, IndMaxAnz[i]]
|
|
if abs(Value) < ThrAttGrad:
|
|
Maximum[0, IndMaxAnz[i]] = 0
|
|
Maximum[1, IndMaxAnz[i]] = 0
|
|
|
|
IndMaxAnz = np.where(Maximum[0, :] != 0)[0]
|
|
if len(IndMaxAnz) > 0:
|
|
if abs(Maximum[1, IndMaxAnz[0]] - Indxlr11) < 15:
|
|
Maximum[0, IndMaxAnz[0]] = 0
|
|
Maximum[1, IndMaxAnz[0]] = 0
|
|
|
|
IndMaxAnz = np.where(Maximum[0, :] != 0)[0]
|
|
if len(IndMaxAnz) > 0:
|
|
MaxAnz = len(IndMaxAnz)
|
|
IndMaxGrad = Maximum[1, IndMaxAnz]
|
|
|
|
elif DaeGrad == 2:
|
|
if MinMax == 0:
|
|
if Minimum.shape[1] > 0:
|
|
Ind = np.where(Minimum[0, :])[0]
|
|
if len(Ind) > 0:
|
|
MinimumMean = np.mean(Minimum[0, Ind])
|
|
else:
|
|
MinimumMean = 0
|
|
for j_idx in range(Minimum.shape[1]):
|
|
if Minimum[0, j_idx] > MinimumMean:
|
|
Minimum[0, j_idx] = 0
|
|
Minimum[1, j_idx] = 0
|
|
|
|
IndMinAnz = np.where(Minimum[0, :] != 0)[0]
|
|
if len(IndMinAnz) > 1:
|
|
for i in range(len(IndMinAnz) - 1):
|
|
Index = Minimum[1, IndMinAnz[i]]
|
|
Value = Minimum[0, IndMinAnz[i]]
|
|
IndexNext = Minimum[1, IndMinAnz[i + 1]]
|
|
ValueNext = Minimum[0, IndMinAnz[i + 1]]
|
|
if (IndexNext - Index) <= IndexGrenze:
|
|
if abs(Value) < abs(ValueNext):
|
|
Minimum[0, IndMinAnz[i]] = 0
|
|
Minimum[1, IndMinAnz[i]] = 0
|
|
elif abs(Value) > abs(ValueNext):
|
|
if i < (len(IndMinAnz) - 1):
|
|
IndexNext2 = Minimum[1, IndMinAnz[i + 2]]
|
|
ValueNext2 = Minimum[0, IndMinAnz[i + 2]]
|
|
if (IndexNext2 - IndexNext) <= IndexGrenze:
|
|
if abs(Value) < abs(ValueNext2):
|
|
Minimum[0, IndMinAnz[i]] = 0
|
|
Minimum[1, IndMinAnz[i]] = 0
|
|
Minimum[0, IndMinAnz[i + 1]] = 0
|
|
Minimum[1, IndMinAnz[i + 1]] = 0
|
|
elif abs(Value) > abs(ValueNext2):
|
|
Minimum[0, IndMinAnz[i + 1]] = 0
|
|
Minimum[1, IndMinAnz[i + 1]] = 0
|
|
Minimum[0, IndMinAnz[i + 2]] = 0
|
|
Minimum[1, IndMinAnz[i + 2]] = 0
|
|
else:
|
|
Minimum[0, IndMinAnz[i + 1]] = 0
|
|
Minimum[1, IndMinAnz[i + 1]] = 0
|
|
else:
|
|
Minimum[0, IndMinAnz[i + 1]] = 0
|
|
Minimum[1, IndMinAnz[i + 1]] = 0
|
|
|
|
IndMinAnz = np.where(Minimum[0, :] != 0)[0]
|
|
MinValue = np.min(Minimum[0, :]) if len(Minimum[0, :]) > 0 else 0
|
|
if len(IndMinAnz) > 1:
|
|
for i in range(len(IndMinAnz)):
|
|
Value = Minimum[0, IndMinAnz[i]]
|
|
if MinValue != 0 and abs(Value / MinValue) < ThrNoiseDae:
|
|
Minimum[0, IndMinAnz[i]] = 0
|
|
Minimum[1, IndMinAnz[i]] = 0
|
|
|
|
IndMinAnz = np.where(Minimum[0, :] != 0)[0]
|
|
for i in range(len(IndMinAnz)):
|
|
Value = Minimum[0, IndMinAnz[i]]
|
|
if abs(Value) < ThrAttGrad:
|
|
Minimum[0, IndMinAnz[i]] = 0
|
|
Minimum[1, IndMinAnz[i]] = 0
|
|
|
|
IndMinAnz = np.where(Minimum[0, :] != 0)[0]
|
|
if len(IndMinAnz) > 0:
|
|
MinAnz = len(IndMinAnz)
|
|
IndMinGrad = Minimum[1, IndMinAnz]
|
|
|
|
elif MinMax == 1:
|
|
if Maximum.shape[1] > 0:
|
|
Ind = np.where(Maximum[0, :])[0]
|
|
if len(Ind) > 0:
|
|
MaximumMean = np.mean(Maximum[0, Ind])
|
|
else:
|
|
MaximumMean = 0
|
|
for i in range(Maximum.shape[1]):
|
|
if Maximum[0, i] < MaximumMean:
|
|
Maximum[0, i] = 0
|
|
Maximum[1, i] = 0
|
|
|
|
IndMaxAnz = np.where(Maximum[0, :] != 0)[0]
|
|
if len(IndMaxAnz) > 1:
|
|
for i in range(len(IndMaxAnz) - 1):
|
|
Index = Maximum[1, IndMaxAnz[i]]
|
|
Value = Maximum[0, IndMaxAnz[i]]
|
|
IndexNext = Maximum[1, IndMaxAnz[i + 1]]
|
|
ValueNext = Maximum[0, IndMaxAnz[i + 1]]
|
|
if (IndexNext - Index) <= IndexGrenze:
|
|
if abs(Value) < abs(ValueNext):
|
|
Maximum[0, IndMaxAnz[i]] = 0
|
|
Maximum[1, IndMaxAnz[i]] = 0
|
|
elif abs(Value) > abs(ValueNext):
|
|
if i < (len(IndMaxAnz) - 1):
|
|
IndexNext2 = Maximum[1, IndMaxAnz[i + 2]]
|
|
ValueNext2 = Maximum[0, IndMaxAnz[i + 2]]
|
|
if (IndexNext2 - IndexNext) <= IndexGrenze:
|
|
if abs(Value) < abs(ValueNext2):
|
|
Maximum[0, IndMaxAnz[i]] = 0
|
|
Maximum[1, IndMaxAnz[i]] = 0
|
|
Maximum[0, IndMaxAnz[i + 1]] = 0
|
|
Maximum[1, IndMaxAnz[i + 1]] = 0
|
|
elif abs(Value) > abs(ValueNext2):
|
|
Maximum[0, IndMaxAnz[i + 1]] = 0
|
|
Maximum[1, IndMaxAnz[i + 1]] = 0
|
|
Maximum[0, IndMaxAnz[i + 2]] = 0
|
|
Maximum[1, IndMaxAnz[i + 2]] = 0
|
|
else:
|
|
Maximum[0, IndMaxAnz[i + 1]] = 0
|
|
Maximum[1, IndMaxAnz[i + 1]] = 0
|
|
else:
|
|
Maximum[0, IndMaxAnz[i + 1]] = 0
|
|
Maximum[1, IndMaxAnz[i + 1]] = 0
|
|
|
|
IndMaxAnz = np.where(Maximum[0, :] != 0)[0]
|
|
MaxValue = np.max(Maximum[0, :]) if len(Maximum[0, :]) > 0 else 0
|
|
if len(IndMaxAnz) > 1:
|
|
for i in range(len(IndMaxAnz)):
|
|
Value = Maximum[0, IndMaxAnz[i]]
|
|
if MaxValue != 0 and abs(Value / MaxValue) < ThrNoiseDae:
|
|
Maximum[0, IndMaxAnz[i]] = 0
|
|
Maximum[1, IndMaxAnz[i]] = 0
|
|
|
|
IndMaxAnz = np.where(Maximum[0, :] != 0)[0]
|
|
for i in range(len(IndMaxAnz)):
|
|
Value = Maximum[0, IndMaxAnz[i]]
|
|
if abs(Value) < ThrAttGrad:
|
|
Maximum[0, IndMaxAnz[i]] = 0
|
|
Maximum[1, IndMaxAnz[i]] = 0
|
|
|
|
IndMaxAnz = np.where(Maximum[0, :] != 0)[0]
|
|
if len(IndMaxAnz) > 0:
|
|
MaxAnz = len(IndMaxAnz)
|
|
IndMaxGrad = Maximum[1, IndMaxAnz]
|
|
|
|
return MinAnz, MaxAnz, IndMinGrad, IndMaxGrad
|