Skip to content

Commit

Permalink
test_imaging_confocal: move in test_point_scan
Browse files Browse the repository at this point in the history
  • Loading branch information
rpauszek committed Nov 8, 2023
1 parent 8301183 commit b25c62d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 16 deletions.
32 changes: 31 additions & 1 deletion lumicks/pylake/tests/test_imaging_confocal/conftest.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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
Expand All @@ -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")
):
Expand Down

0 comments on commit b25c62d

Please sign in to comment.