From b25c62dda630f7ba076ccfb6e1b98593a96a1165 Mon Sep 17 00:00:00 2001 From: rpauszek Date: Tue, 7 Nov 2023 11:35:34 +0100 Subject: [PATCH] test_imaging_confocal: move in test_point_scan --- .../tests/test_imaging_confocal/conftest.py | 32 ++++++++++++++++++- .../test_point_scan.py | 32 ++++++++++--------- 2 files changed, 48 insertions(+), 16 deletions(-) rename lumicks/pylake/tests/{test_imaging_confocal_old => test_imaging_confocal}/test_point_scan.py (72%) diff --git a/lumicks/pylake/tests/test_imaging_confocal/conftest.py b/lumicks/pylake/tests/test_imaging_confocal/conftest.py index 0bff13c78..a8f3da212 100644 --- a/lumicks/pylake/tests/test_imaging_confocal/conftest.py +++ b/lumicks/pylake/tests/test_imaging_confocal/conftest.py @@ -1,8 +1,10 @@ import numpy as np import pytest +from lumicks.pylake.point_scan import PointScan + from ..data.mock_file import MockDataFile_v2 -from ..data.mock_confocal import generate_scan_json, generate_kymo_with_ref +from ..data.mock_confocal import MockConfocalFile, generate_scan_json, generate_kymo_with_ref start = np.int64(20e9) dt = np.int64(62.5e6) @@ -198,3 +200,31 @@ def kymo_h5_file(tmpdir_factory, test_kymo): ) return mock_file.file + + +@pytest.fixture(scope="module") +def test_point_scan(): + n_samples = 90 + data = {c: np.random.poisson(15, n_samples) for c in ("red", "green", "blue")} + + mock_file, metadata, stop = MockConfocalFile.from_streams( + start, + dt, + [], + [], + [], + infowave=np.zeros(data["red"].shape), + red_photon_counts=data["red"], + green_photon_counts=data["green"], + blue_photon_counts=data["blue"], + ) + point_scan = PointScan("PointScan1", mock_file, start, stop, metadata) + + reference = { + "data": data, + "timestamps": np.arange(n_samples, dtype=np.int64) * dt + start, + "dt": dt, + "start": start, + } + + return point_scan, reference diff --git a/lumicks/pylake/tests/test_imaging_confocal_old/test_point_scan.py b/lumicks/pylake/tests/test_imaging_confocal/test_point_scan.py similarity index 72% rename from lumicks/pylake/tests/test_imaging_confocal_old/test_point_scan.py rename to lumicks/pylake/tests/test_imaging_confocal/test_point_scan.py index 87247c83d..81d653b2e 100644 --- a/lumicks/pylake/tests/test_imaging_confocal_old/test_point_scan.py +++ b/lumicks/pylake/tests/test_imaging_confocal/test_point_scan.py @@ -5,19 +5,21 @@ import matplotlib.pyplot as plt -def test_point_scans_basic(test_point_scans, reference_timestamps, reference_counts): - ps = test_point_scans["PointScan1"] - ps_red = ps.red_photon_count +def test_point_scans_basic(test_point_scan): + ps, ref = test_point_scan - assert ps_red.data.shape == (90,) + for color, ref_data in ref["data"].items(): + count = getattr(ps, f"{color}_photon_count") - np.testing.assert_allclose(ps_red.timestamps, reference_timestamps) - np.testing.assert_allclose(ps_red.data, reference_counts) + assert count.data.shape == ref_data.shape + np.testing.assert_equal(count.timestamps, ref["timestamps"]) + np.testing.assert_equal(count.data, ref_data) -def test_point_scan_slicing(test_point_scans, reference_timestamps, reference_counts): - ps = test_point_scans["PointScan1"] - dt = int(1e9 / ps.red_photon_count.sample_rate) + +def test_point_scan_slicing(test_point_scan): + ps, ref = test_point_scan + dt = ref["dt"] for crop in ( (ps.start, ps.stop), # No crop @@ -32,8 +34,8 @@ def test_point_scan_slicing(test_point_scans, reference_timestamps, reference_co ): p_sliced_red = ps[crop[0] : crop[1]].red_photon_count ps_red = ps.red_photon_count[crop[0] : crop[1]] - np.testing.assert_allclose(p_sliced_red.timestamps, ps_red.timestamps) - np.testing.assert_allclose(p_sliced_red.data, ps_red.data) + np.testing.assert_equal(p_sliced_red.timestamps, ps_red.timestamps) + np.testing.assert_equal(p_sliced_red.data, ps_red.data) with pytest.raises(IndexError, match="Scalar indexing is not supported, only slicing"): ps[5] @@ -42,8 +44,8 @@ def test_point_scan_slicing(test_point_scans, reference_timestamps, reference_co ps["0s":"10s":"1s"] -def test_plotting(test_point_scans): - ps = test_point_scans["PointScan1"] +def test_plotting(test_point_scan): + ps, _ = test_point_scan for channel in ("red", "green", "blue"): xline, yline = ps.plot(channel=channel)[0].get_xydata().T @@ -62,8 +64,8 @@ def test_plotting(test_point_scans): plt.close() -def test_deprecated_plotting(test_point_scans): - ps = test_point_scans["PointScan1"] +def test_deprecated_plotting(test_point_scan): + ps, _ = test_point_scan with pytest.raises( TypeError, match=re.escape("plot() takes from 1 to 2 positional arguments but 3 were given") ):