diff --git a/changelog.md b/changelog.md index ca29d8a92..5c049dcb6 100644 --- a/changelog.md +++ b/changelog.md @@ -8,6 +8,10 @@ * Shortcuts `"r"`, `"g"`, and `"b"` can now be used for plotting single color channels in addition to `"red"`, `"green"`, and `"blue"`. * Two-channel visualizations can be plotted using `"rg"`, `"gb"`, or `"rb"`. +#### Bug fixes + +* Fixed a bug in `downsampled_like` that would fail to indicate a lack of overlap between the low frequency and high frequency channel when sampling within the last sample of the low frequency channel. + #### Improvements * Kymographs consisting of a single scan line now return a valid `line_time_seconds`. This allows certain downstream functionality, such as `Kymo.plot()`. diff --git a/lumicks/pylake/channel.py b/lumicks/pylake/channel.py index e0e687e3e..39437b5cf 100644 --- a/lumicks/pylake/channel.py +++ b/lumicks/pylake/channel.py @@ -456,7 +456,7 @@ def downsampled_like(self, other_slice, reduce=np.mean): timestamps = other_slice.timestamps delta_time = np.diff(timestamps) - if self._src.start >= timestamps[-1] or self._src.stop <= timestamps[0]: + if self._src.start > (timestamps[-1] - delta_time[-1]) or self._src.stop <= timestamps[0]: raise RuntimeError("No overlap between slices.") # When the frame rate changes, one frame is very long due to the delay of the camera. It diff --git a/lumicks/pylake/tests/test_channels/test_channels.py b/lumicks/pylake/tests/test_channels/test_channels.py index 94e4a07e2..5d2027457 100644 --- a/lumicks/pylake/tests/test_channels/test_channels.py +++ b/lumicks/pylake/tests/test_channels/test_channels.py @@ -748,11 +748,17 @@ def test_downsampling_like(): ): s.downsampled_like(s) - for offset in (-4 * 4, t_downsampled[-1] + 1): + timestep = 4 + for offset in (with_offset(-4 * timestep), t_downsampled[-1] - timestep + 1): with pytest.raises(RuntimeError, match="No overlap between slices"): - s = channel.Slice(channel.Continuous(np.array([1, 2, 3, 4]), with_offset(offset), 4)) + s = channel.Slice(channel.Continuous(np.array([1, 2, 3, 4]), offset, timestep)) s.downsampled_like(reference) + for offset in (with_offset(-4 * timestep + 1), t_downsampled[-1] - timestep): + print(offset - 1592916040906356300) + s = channel.Slice(channel.Continuous(np.array([1, 2, 3, 4]), offset, timestep)) + s.downsampled_like(reference) + def test_channel_plot(): def testLine(x, y):