Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added tests/plot/__init__.py
Empty file.
57 changes: 57 additions & 0 deletions tests/plot/test_plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import tempfile
from pathlib import Path

import matplotlib.pyplot as plt
import matplotlib.testing.compare
import numpy as np
import scipy.signal

import sdr

sdr.plot.use_style()

WRITE_TRUTH = False
TEST_FOLDER = Path(tempfile.gettempdir())
TRUTH_FOLDER = Path(__file__).parent


def test_time_domain_y_only(request):
test_filename = (TEST_FOLDER / request.node.name).with_suffix(".png")
truth_filename = (TRUTH_FOLDER / request.node.name).with_suffix(".png")

N = 1_000 # Number of samples
T = 0.01 # Sample time
t = np.arange(N) * T # Time vector
x_lin = scipy.signal.chirp(t, f0=6, f1=1, t1=10, method="linear")

plt.figure()
sdr.plot.time_domain(x_lin)
plt.title("Linear chirp signal")
if WRITE_TRUTH:
plt.savefig(truth_filename)
plt.savefig(test_filename)
plt.close()

diff = matplotlib.testing.compare.compare_images(truth_filename, test_filename, tol=0)
assert diff is None


def test_time_domain_x_and_y(request):
test_filename = (TEST_FOLDER / request.node.name).with_suffix(".png")
truth_filename = (TRUTH_FOLDER / request.node.name).with_suffix(".png")

N = 1_000 # Number of samples
T = 0.01 # Sample time
t = np.arange(N) * T # Time vector
x_lin = scipy.signal.chirp(t, f0=6, f1=1, t1=10, method="linear")

plt.figure()
sdr.plot.time_domain(t, x_lin, sample_rate=1 / T)
plt.title("Linear chirp signal")
if WRITE_TRUTH:
plt.savefig(truth_filename)
plt.savefig(test_filename)
plt.close()

diff = matplotlib.testing.compare.compare_images(truth_filename, test_filename, tol=0)
assert diff is None
Binary file added tests/plot/test_time_domain_x_and_y.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/plot/test_time_domain_y_only.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading