last implement diff
This commit is contained in:
54
tests/test_fourier_complex_modes.py
Normal file
54
tests/test_fourier_complex_modes.py
Normal file
@ -0,0 +1,54 @@
|
||||
import numpy as np
|
||||
|
||||
from rfg_adc_plotter.processing.fourier import (
|
||||
compute_ifft_profile_from_sweep,
|
||||
reconstruct_complex_spectrum_from_real_trace,
|
||||
)
|
||||
|
||||
|
||||
def test_reconstruct_complex_spectrum_arccos_mode_returns_complex128():
|
||||
sweep = np.linspace(-3.0, 7.0, 128, dtype=np.float32)
|
||||
z = reconstruct_complex_spectrum_from_real_trace(sweep, complex_mode="arccos")
|
||||
assert z.dtype == np.complex128
|
||||
assert z.shape == sweep.shape
|
||||
assert np.all(np.isfinite(np.real(z)))
|
||||
assert np.all(np.isfinite(np.imag(z)))
|
||||
|
||||
|
||||
def test_reconstruct_complex_spectrum_diff_mode_returns_complex128():
|
||||
sweep = np.linspace(-1.0, 1.0, 128, dtype=np.float32)
|
||||
z = reconstruct_complex_spectrum_from_real_trace(sweep, complex_mode="diff")
|
||||
assert z.dtype == np.complex128
|
||||
assert z.shape == sweep.shape
|
||||
assert np.all(np.isfinite(np.real(z)))
|
||||
assert np.all(np.isfinite(np.imag(z)))
|
||||
|
||||
|
||||
def test_reconstruct_complex_spectrum_diff_mode_projects_to_unit_circle():
|
||||
sweep = np.sin(np.linspace(0.0, 6.0 * np.pi, 256)).astype(np.float32)
|
||||
z = reconstruct_complex_spectrum_from_real_trace(sweep, complex_mode="diff")
|
||||
mag = np.abs(z)
|
||||
assert np.all(np.isfinite(mag))
|
||||
assert np.allclose(mag, np.ones_like(mag), atol=1e-5, rtol=0.0)
|
||||
|
||||
|
||||
def test_compute_ifft_profile_from_sweep_accepts_both_modes():
|
||||
sweep = np.linspace(-5.0, 5.0, 257, dtype=np.float32)
|
||||
d1, y1 = compute_ifft_profile_from_sweep(sweep, complex_mode="arccos")
|
||||
d2, y2 = compute_ifft_profile_from_sweep(sweep, complex_mode="diff")
|
||||
|
||||
assert d1.dtype == np.float32 and y1.dtype == np.float32
|
||||
assert d2.dtype == np.float32 and y2.dtype == np.float32
|
||||
assert d1.size == y1.size and d2.size == y2.size
|
||||
assert d1.size > 0 and d2.size > 0
|
||||
assert np.all(np.diff(d1) >= 0.0)
|
||||
assert np.all(np.diff(d2) >= 0.0)
|
||||
|
||||
|
||||
def test_invalid_complex_mode_falls_back_deterministically_in_outer_wrapper():
|
||||
sweep = np.linspace(-1.0, 1.0, 64, dtype=np.float32)
|
||||
depth, y = compute_ifft_profile_from_sweep(sweep, complex_mode="unknown")
|
||||
assert depth.dtype == np.float32
|
||||
assert y.dtype == np.float32
|
||||
assert depth.size == y.size
|
||||
assert depth.size > 0
|
||||
@ -38,3 +38,28 @@ def test_ring_buffer_reallocates_fft_buffers_when_ifft_length_changes():
|
||||
assert second_shape == (ring.max_sweeps, second_bins)
|
||||
assert ring.fft_depth_axis_m is not None
|
||||
assert ring.fft_depth_axis_m.size == second_bins
|
||||
|
||||
|
||||
def test_ring_buffer_mode_switch_resets_fft_buffers_only():
|
||||
ring = RingBuffer(max_sweeps=4)
|
||||
ring.ensure_init(128)
|
||||
|
||||
ring.push(np.linspace(-1.0, 1.0, 128, dtype=np.float32))
|
||||
assert ring.ring is not None
|
||||
assert ring.ring_fft is not None
|
||||
raw_before = ring.ring.copy()
|
||||
|
||||
changed = ring.set_fft_complex_mode("diff")
|
||||
assert changed is True
|
||||
assert ring.fft_complex_mode == "diff"
|
||||
assert ring.ring is not None
|
||||
assert np.array_equal(ring.ring, raw_before, equal_nan=True)
|
||||
assert ring.ring_fft is None
|
||||
assert ring.fft_depth_axis_m is None
|
||||
assert ring.last_fft_vals is None
|
||||
assert ring.fft_bins == 0
|
||||
|
||||
ring.push(np.linspace(-1.0, 1.0, 128, dtype=np.float32))
|
||||
assert ring.ring_fft is not None
|
||||
assert ring.fft_depth_axis_m is not None
|
||||
assert ring.last_fft_vals is not None
|
||||
|
||||
Reference in New Issue
Block a user