now if F0 and F4 data both present -- FFT not calculated. It is taken from F4

This commit is contained in:
2025-11-14 01:30:21 +03:00
parent be9991bdd8
commit bb09c0d2e7

67
main.py
View File

@ -120,6 +120,7 @@ def resize_2d_interpolate(data, target_rows, target_cols):
return data_resampled
def BF_fft_postprocessor(spectrum: np.ndarray) -> np.ndarray:
"""Болванка постобработки FFT-данных, полученных из файла (F4).
@ -143,6 +144,21 @@ def BF_fft_postprocessor(spectrum: np.ndarray) -> np.ndarray:
return spectrum
'''
def BF_fft_postprocessor(spectrum: np.ndarray) -> np.ndarray:
"""Болванка постобработки FFT-данных, полученных из файла (F4).
Принимает 1D массив амплитуд спектра и возвращает преобразованный массив
той же длины. По умолчанию — тождественное преобразование.
"""
try:
return np.asarray(spectrum, dtype=float)
except Exception:
return spectrum
'''
def load_data_with_type(filename):
"""Загружает данные и определяет их тип по первой строке."""
with open(filename, 'r') as f:
@ -185,36 +201,31 @@ def parse_hex_file(filename):
def finalize_segment():
nonlocal cur
# Приоритет выбора сегмента:
# 1) Если есть F0 — используем как SYNC_DET (F4 игнорируем временно)
# 1) Если есть F4 — используем как FOURIER; F0 (если есть) передаём для отображения без расчёта FFT
# 2) Иначе F1+F2 → амплитуда
# 3) Иначе F4 (если нет F0)
# 4) Иначе F3 (sqrt)
# 3) Иначе F3 (sqrt)
# 4) Иначе F0 как SYNC_DET
# 5) Иначе D0 как RAW
#print("cur:", cur)
if cur["F0"]:
# print("got F0!")
seg_sync.append(np.asarray(cur["F0"], dtype=float))
elif cur["F1"] and cur["F2"] and len(cur["F1"]) == len(cur["F2"]):
print("got F1,F2!")
re = np.asarray(cur["F1"], dtype=float)
im = np.asarray(cur["F2"], dtype=float)
seg_fourier.append(np.sqrt(re * re + im * im))
elif cur["F4"]:
# print("got F4!")
# print("got fourier!")
if cur["F4"]:
# FOURIER данные получены напрямую из файла (F4)
col = np.asarray(cur["F4"], dtype=float)
col = BF_fft_postprocessor(col)
seg_fourier.append(col)
if cur["F0"]:
# Сохраняем F0 рядом с F4 для отображения (без расчёта FFT)
f0 = np.asarray(cur["F0"], dtype=float)
seg_fourier.append((col, f0))
else:
seg_fourier.append(col)
elif cur["F1"] and cur["F2"] and len(cur["F1"]) == len(cur["F2"]):
re = np.asarray(cur["F1"], dtype=float)
im = np.asarray(cur["F2"], dtype=float)
seg_fourier.append(np.sqrt(re * re + im * im))
elif cur["F3"]:
# print("got F3!")
arr = np.asarray(cur["F3"], dtype=float)
seg_fourier.append(np.sqrt(np.maximum(0.0, arr)))
elif cur["F0"]:
seg_sync.append(np.asarray(cur["F0"], dtype=float))
elif cur["D0"]:
# print("got D0!")
seg_raw.append(np.asarray(cur["D0"], dtype=float))
# Сброс
cur = {"D0": [], "F0": [], "F1": [], "F2": [], "F3": [], "F4": []}
@ -973,8 +984,18 @@ class DataAnalyzerApp:
# A может быть: list[np.ndarray] (из HEX) или numpy.ndarray
if isinstance(A, list):
for seg in A:
col = np.asarray(seg, dtype=float)
columns_to_add.append(col)
# Если сегмент — кортеж (fourier_col, f0), отобразим F0 в временной области,
# но B-scan пополняем только спектром (fourier_col)
if isinstance(seg, tuple) and len(seg) == 2:
col = np.asarray(seg[0], dtype=float)
f0 = np.asarray(seg[1], dtype=float)
self.signal = f0
self.signalView = f0 * 0.1
self.timeSignal = np.arange(len(f0))
columns_to_add.append(col)
else:
col = np.asarray(seg, dtype=float)
columns_to_add.append(col)
return True, columns_to_add
if A.ndim == 1: