Skip to content

Commit

Permalink
test_imaging_confocal_old: remove reworked plotting tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rpauszek committed Oct 27, 2023
1 parent b3099fd commit a2d4ac4
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ def test_plotting(test_kymo):
plt.figure()
kymo.plot(channel="red")

# todo: this is confusing even in the context of the old test, check on this
# # The following assertion fails because of unequal line times in the test data. These
# # unequal line times are not typical for BL data. Kymo nowadays assumes equal line times
# # which is why the old version of this test fails.
np.testing.assert_allclose(
np.sort(plt.xlim()),
[-0.5 * line_time, (n_lines - 0.5) * line_time],
Expand Down Expand Up @@ -52,7 +48,7 @@ def test_plotting(test_kymo):


def test_deprecated_plotting(test_kymo):
kymo, ref = test_kymo
kymo, _ = test_kymo

with pytest.raises(
TypeError, match=re.escape("plot() takes from 1 to 2 positional arguments but 3 were given")
Expand Down Expand Up @@ -129,8 +125,6 @@ def test_plot_with_lf_force(kymo_h5_file):
kymo = f.kymos["tester"]
n_lines = kymo.get_image("red").shape[1]

print(f.downsampled_force2y.timestamps)

with pytest.warns(
RuntimeWarning, match="Using downsampled force since high frequency force is unavailable."
):
Expand Down
158 changes: 0 additions & 158 deletions lumicks/pylake/tests/test_imaging_confocal_old/test_kymo.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,132 +109,6 @@ def test_kymo_slicing(test_kymos):
assert isinstance(kymo["24.2s":], EmptyKymo)


def test_plotting(test_kymos):
kymo = test_kymos["Kymo1"]

plt.figure()
kymo.plot(channel="red")
# # The following assertion fails because of unequal line times in the test data. These
# # unequal line times are not typical for BL data. Kymo nowadays assumes equal line times
# # which is why the old version of this test fails.
line_time = 1.5625
np.testing.assert_allclose(np.sort(plt.xlim()), [-0.5 * line_time, 3.5 * line_time], atol=0.05)

image = plt.gca().get_images()[0]
np.testing.assert_allclose(image.get_array(), kymo.get_image("red"))
np.testing.assert_allclose(
image.get_extent(), [-0.5 * line_time, 3.5 * line_time, 0.045, -0.005]
)

# test original kymo is labeled with microns and
# that kymo calibrated with base pairs has appropriate label
assert plt.gca().get_ylabel() == r"position (μm)"
plt.close()

kymo_bp = kymo.calibrate_to_kbp(10.000)
kymo_bp.plot(channel="red")
assert plt.gca().get_ylabel() == "position (kbp)"
plt.close()


def test_deprecated_plotting(test_kymos):
kymo = test_kymos["Kymo1"]
with pytest.raises(
TypeError, match=re.escape("plot() takes from 1 to 2 positional arguments but 3 were given")
):
ih = kymo.plot("red", None)
np.testing.assert_allclose(ih.get_array(), kymo.get_image("red"))
plt.close()
# Test rejection of deprecated call with positional `axes` and double keyword assignment
with pytest.raises(
TypeError,
match=re.escape(
"plot() takes from 1 to 2 positional arguments but 3 positional"
" arguments (and 1 keyword-only argument) were given"
),
):
kymo.plot("rgb", None, axes=None)


def test_plotting_with_force(kymo_h5_file):
f = pylake.File.from_h5py(kymo_h5_file)
kymo = f.kymos["Kymo1"]

kymo.plot_with_force(force_channel="2x", color_channel="red")
np.testing.assert_allclose(plt.gca().lines[0].get_ydata(), [30, 30, 10, 10])
np.testing.assert_allclose(plt.xlim(), [-0.5 * 1.5625, 3.5 * 1.5625])
np.testing.assert_allclose(np.sort(plt.ylim()), [10, 30])


def test_regression_plot_with_force(kymo_h5_file):
# Plot_with_force used to fail when the last line of a kymograph was incomplete. The reason for
# this was that the last few timestamps on the last line had zero as their timestamp. This meant
# it was trying to downsample a range from X to 0, which made the downsampler think that there
# was no overlap between the kymograph and the force channel (as it checks the last timestamp
# of the ranges to downsample to against the first one of the channel to downsample).
f = pylake.File.from_h5py(kymo_h5_file)

# Kymo ends before last pixel is finished. All but the last timestamps are OK.
kymo = f.kymos["Kymo1"]
kymo.stop = int(kymo.stop - 2 * 1e9 / 16)
kymo.plot_with_force(force_channel="2x", color_channel="red")
ds = f.force2x.downsampled_over(kymo.line_timestamp_ranges(include_dead_time=False))
np.testing.assert_allclose(ds.data, [30, 30, 10, 10])

# Kymo ends on a partial last line. Multiple timestamps are zero now.
kymo = f.kymos["Kymo1"]
kymo.stop = int(kymo.stop - 10 * 1e9 / 16)
kymo.plot_with_force(force_channel="2x", color_channel="red")
ds = f.force2x.downsampled_over(kymo.line_timestamp_ranges(include_dead_time=False))
np.testing.assert_allclose(ds.data, [30, 30, 10, 10])


def test_plotting_with_histograms(test_kymos):
def get_rectangle_data():
widths = [p.get_width() for p in plt.gca().patches]
heights = [p.get_height() for p in plt.gca().patches]
return widths, heights

kymo = test_kymos["Kymo1"]

kymo.plot_with_position_histogram(color_channel="red", pixels_per_bin=1)
w, h = get_rectangle_data()
np.testing.assert_allclose(h, 0.01)
assert np.all(np.equal(w, [3, 1, 1, 1, 3]))
np.testing.assert_allclose(np.sort(plt.xlim()), [0, 3], atol=0.05)

plt.close("all")
kymo.plot_with_time_histogram(color_channel="red", pixels_per_bin=1)
w, h = get_rectangle_data()
np.testing.assert_allclose(w, [1.5625] * 4, atol=0.002)
assert np.all(np.equal(h, [4, 0, 2, 3]))
np.testing.assert_allclose(np.sort(plt.ylim()), [0, 4], atol=0.05)

with pytest.warns(UserWarning):
plt.close("all")
kymo.plot_with_position_histogram(color_channel="red", pixels_per_bin=3)
w, h = get_rectangle_data()
np.testing.assert_allclose(h, [0.03, 0.02])
assert np.all(np.equal(w, [5, 4]))
np.testing.assert_allclose(np.sort(plt.xlim()), [0, 5], atol=0.05)

with pytest.warns(UserWarning):
plt.close("all")
kymo.plot_with_time_histogram(color_channel="red", pixels_per_bin=3)
w, h = get_rectangle_data()
np.testing.assert_allclose(w, [4.6875, 1.5625], atol=0.02)
assert np.all(np.equal(h, [6, 3]))
np.testing.assert_allclose(np.sort(plt.ylim()), [0, 6], atol=0.05)

with pytest.raises(ValueError):
plt.close("all")
kymo.plot_with_position_histogram(color_channel="red", pixels_per_bin=6)

with pytest.raises(ValueError):
plt.close("all")
kymo.plot_with_time_histogram(color_channel="red", pixels_per_bin=6)


def test_export_tiff(tmp_path, test_kymos, grab_tiff_tags):
from os import stat

Expand Down Expand Up @@ -630,38 +504,6 @@ def check_factory_forwarding(kymo1, kymo2, check_timestamps):
)


def test_plot_with_lf_force():
dt = int(1e9 / 78125)
start = 1536582124217030400
kymo = generate_kymo(
"Mock",
np.ones((5, 5)),
pixel_size_nm=100,
start=start,
dt=dt,
samples_per_pixel=2,
line_padding=0,
)

# Mock a force channel onto this file
data = np.array([-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
timestamps = data * 5 * dt + start
channel = Slice(TimeSeries(data, timestamps))
setattr(kymo.file, "force1x", empty_slice) # Not present in file
setattr(kymo.file, "downsampled_force1x", empty_slice) # Not present in file
setattr(kymo.file, "force2y", empty_slice) # Not present in file
setattr(kymo.file, "downsampled_force2y", channel)

with pytest.warns(
RuntimeWarning, match="Using downsampled force since high frequency force is unavailable."
):
kymo.plot_with_force("2y", "red")
np.testing.assert_allclose(plt.gca().lines[0].get_ydata(), [0.5, 2.5, 4.5, 6.5, 8.5])

with pytest.raises(RuntimeError, match="Desired force channel 1x not available in h5 file"):
kymo.plot_with_force("1x", "red")


def test_kymo_plot_rgb_absolute_color_adjustment(test_kymos):
"""Tests whether we can set an absolute color range for the RGB plot."""
kymo = test_kymos["Kymo1"]
Expand Down

0 comments on commit a2d4ac4

Please sign in to comment.