diff --git a/lumicks/pylake/tests/test_imaging_confocal/test_kymo_plotting.py b/lumicks/pylake/tests/test_imaging_confocal/test_kymo_plotting.py index 2761c327e..83bf016ca 100644 --- a/lumicks/pylake/tests/test_imaging_confocal/test_kymo_plotting.py +++ b/lumicks/pylake/tests/test_imaging_confocal/test_kymo_plotting.py @@ -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], @@ -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") @@ -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." ): diff --git a/lumicks/pylake/tests/test_imaging_confocal_old/test_kymo.py b/lumicks/pylake/tests/test_imaging_confocal_old/test_kymo.py index 17a022dc0..22cd89147 100644 --- a/lumicks/pylake/tests/test_imaging_confocal_old/test_kymo.py +++ b/lumicks/pylake/tests/test_imaging_confocal_old/test_kymo.py @@ -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 @@ -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"]