implemented positive and negative values handling
This commit is contained in:
@ -295,25 +295,17 @@ class SweepReader(threading.Thread):
|
||||
ys.clear()
|
||||
continue
|
||||
|
||||
# stp X Y
|
||||
if len(line) >= 5 and (line[:3] == b"stp" or line[:3] == b"STP"):
|
||||
sp1 = line.find(b" ", 3)
|
||||
if sp1 == -1:
|
||||
sp1 = line.find(b"\t", 3)
|
||||
if sp1 == -1:
|
||||
continue
|
||||
sp2 = line.find(b" ", sp1 + 1)
|
||||
if sp2 == -1:
|
||||
sp2 = line.find(b"\t", sp1 + 1)
|
||||
if sp2 == -1:
|
||||
continue
|
||||
try:
|
||||
x = int(line[sp1 + 1 : sp2])
|
||||
y = int(line[sp2 + 1 :])
|
||||
except Exception:
|
||||
continue
|
||||
xs.append(x)
|
||||
ys.append(y)
|
||||
# stp X Y (оба целые со знаком). Разделяем по любым пробелам/табам.
|
||||
if len(line) >= 3:
|
||||
parts = line.split()
|
||||
if len(parts) >= 3 and parts[0].lower() == b"stp":
|
||||
try:
|
||||
x = int(parts[1], 10)
|
||||
y = int(parts[2], 10) # поддержка знака: "+…" и "-…"
|
||||
except Exception:
|
||||
continue
|
||||
xs.append(x)
|
||||
ys.append(y)
|
||||
|
||||
# Защита от переполнения буфера при отсутствии переводов строки
|
||||
if len(buf) > 1_000_000:
|
||||
@ -415,8 +407,8 @@ def main():
|
||||
ax_fft.set_xlabel("Бин")
|
||||
ax_fft.set_ylabel("Амплитуда, дБ")
|
||||
|
||||
# Фиксированный диапазон по Y для последнего свипа: 0..4095 (12-бит без знака)
|
||||
fixed_ylim: Optional[Tuple[float, float]] = (0.0, float(2 ** 12 - 1))
|
||||
# Диапазон по Y для последнего свипа: авто по умолчанию (поддерживает отрицательные значения)
|
||||
fixed_ylim: Optional[Tuple[float, float]] = None
|
||||
# CLI переопределение при необходимости
|
||||
if args.ylim:
|
||||
try:
|
||||
@ -424,7 +416,8 @@ def main():
|
||||
fixed_ylim = (float(y0), float(y1))
|
||||
except Exception:
|
||||
sys.stderr.write("[warn] Некорректный формат --ylim, игнорирую. Ожидалось min,max\n")
|
||||
ax_line.set_ylim(fixed_ylim)
|
||||
if fixed_ylim is not None:
|
||||
ax_line.set_ylim(fixed_ylim)
|
||||
|
||||
# Водопад (будет инициализирован при первом свипе)
|
||||
img_obj = ax_img.imshow(
|
||||
@ -569,7 +562,20 @@ def main():
|
||||
line_obj.set_data(xs, current_sweep)
|
||||
# Лимиты по X постоянные под текущую ширину
|
||||
ax_line.set_xlim(0, max(1, current_sweep.size - 1))
|
||||
# Y-лимиты фиксированы (±2048) или из --ylim; не автоподстраиваем
|
||||
# Адаптивные Y-лимиты (если не задан --ylim)
|
||||
if fixed_ylim is None:
|
||||
y0 = float(np.nanmin(current_sweep))
|
||||
y1 = float(np.nanmax(current_sweep))
|
||||
if np.isfinite(y0) and np.isfinite(y1):
|
||||
if y0 == y1:
|
||||
pad = max(1.0, abs(y0) * 0.05)
|
||||
y0 -= pad
|
||||
y1 += pad
|
||||
else:
|
||||
pad = 0.05 * (y1 - y0)
|
||||
y0 -= pad
|
||||
y1 += pad
|
||||
ax_line.set_ylim(y0, y1)
|
||||
|
||||
# Обновление спектра текущего свипа
|
||||
take_fft = min(int(current_sweep.size), FFT_LEN)
|
||||
@ -694,15 +700,16 @@ def run_pyqtgraph(args):
|
||||
ring_fft: Optional[np.ndarray] = None
|
||||
freq_shared: Optional[np.ndarray] = None
|
||||
y_min_fft, y_max_fft = None, None
|
||||
# Фиксированный диапазон по Y: 0..4095 (можно переопределить --ylim)
|
||||
fixed_ylim: Optional[Tuple[float, float]] = (0.0, float(2 ** 12 - 1))
|
||||
# Диапазон по Y: авто по умолчанию (поддерживает отрицательные значения)
|
||||
fixed_ylim: Optional[Tuple[float, float]] = None
|
||||
if args.ylim:
|
||||
try:
|
||||
y0, y1 = args.ylim.split(",")
|
||||
fixed_ylim = (float(y0), float(y1))
|
||||
except Exception:
|
||||
pass
|
||||
p_line.setYRange(fixed_ylim[0], fixed_ylim[1], padding=0)
|
||||
if fixed_ylim is not None:
|
||||
p_line.setYRange(fixed_ylim[0], fixed_ylim[1], padding=0)
|
||||
|
||||
def ensure_buffer(_w: int):
|
||||
nonlocal ring, head, width, x_shared, ring_fft, freq_shared
|
||||
|
||||
Reference in New Issue
Block a user