Skip to content

Commit

Permalink
kymo: add duration property
Browse files Browse the repository at this point in the history
  • Loading branch information
rpauszek committed Nov 1, 2022
1 parent f5f7b89 commit d8441fd
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* `CorrelatedStack`: See deprecation changelog entry.
* `Kymo.plot()` now returns a handle of the plotted image
* `PointScan.plot()` now returns a list of handles of the plotted lines
* Added the `Kymo.duration` property.

#### Other changes

Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/kymographs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ There are also several properties available for convenient access to the kymogra
between successive lines
* :attr:`kymo.pixel_time_seconds <lumicks.pylake.kymo.Kymo.pixel_time_seconds>` provides the pixel
dwell time.
* :attr:`kymo.duration <lumicks.pylake.kymo.Kymo.duration>` provides the full duration of the kymograph
in seconds. This is equivalent to the number of scan lines times `line_time_seconds`.


Cropping and slicing
Expand Down
18 changes: 15 additions & 3 deletions lumicks/pylake/kymo.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,14 @@ def line_time_seconds(self):
"""Line time in seconds"""
return self._line_time_factory(self)

@property
def duration(self):
"""Duration of the kymograph in seconds. This value is equivalent to the number of scan
lines times the line time in seconds. It does not take into account incomplete scan
lines or mirror fly-in/out time.
"""
return self.line_time_seconds * self.shape[1]

@property
def pixelsize(self):
"""Returns a `List` of axes dimensions in calibrated units. The length of the
Expand Down Expand Up @@ -314,17 +322,17 @@ def plot(
image = self._get_plot_data(channel, adjustment)

size_calibrated = self._calibration.value * self._num_pixels[0]
duration = self.line_time_seconds * image.shape[1]

default_kwargs = dict(
# With origin set to upper (default) bounds should be given as (0, n, n, 0)
# pixel center aligned with mean time per line
extent=[
-0.5 * self.line_time_seconds,
duration - 0.5 * self.line_time_seconds,
self.duration - 0.5 * self.line_time_seconds,
size_calibrated - 0.5 * self.pixelsize[0],
-0.5 * self.pixelsize[0],
],
aspect=(image.shape[0] / image.shape[1]) * (duration / size_calibrated),
aspect=(image.shape[0] / image.shape[1]) * (self.duration / size_calibrated),
cmap=linear_colormaps[channel],
)

Expand Down Expand Up @@ -695,6 +703,10 @@ def _image(self, channel):
def get_image(self, channel="rgb"):
return self._image(channel)

@property
def duration(self):
return 0

@property
@deprecated(
reason=(
Expand Down
20 changes: 20 additions & 0 deletions lumicks/pylake/tests/test_imaging_confocal/test_kymo.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def test_kymo_properties(test_kymos):
assert kymo.fast_axis == "X"
np.testing.assert_allclose(kymo.pixelsize_um, 10/1000)
np.testing.assert_allclose(kymo.line_time_seconds, 1.03125)
np.testing.assert_allclose(kymo.duration, 1.03125 * 4)
np.testing.assert_allclose(kymo.center_point_um["x"], 58.075877109272604)
np.testing.assert_allclose(kymo.center_point_um["y"], 31.978375270573267)
np.testing.assert_allclose(kymo.center_point_um["z"], 0)
Expand All @@ -52,6 +53,25 @@ def test_kymo_properties(test_kymos):
assert kymo.green_image.shape == (5, 4)


def test_empty_kymo_properties(test_kymos):
kymo = test_kymos["Kymo1"]
empty_kymo = kymo["3s":"2s"]

assert empty_kymo.fast_axis == "X"
np.testing.assert_allclose(empty_kymo.pixelsize_um, 10/1000)
np.testing.assert_equal(empty_kymo.duration, 0)
np.testing.assert_allclose(empty_kymo.center_point_um["x"], 58.075877109272604)
np.testing.assert_allclose(empty_kymo.center_point_um["y"], 31.978375270573267)
np.testing.assert_allclose(empty_kymo.center_point_um["z"], 0)
np.testing.assert_allclose(empty_kymo.size_um, [0.050])

with pytest.raises(RuntimeError, match="Can't get pixel timestamps if there are no pixels"):
empty_kymo.line_time_seconds

with pytest.raises(RuntimeError, match="Can't get pixel timestamps if there are no pixels"):
empty_kymo.pixel_time_seconds


def test_kymo_slicing(test_kymos):
kymo = test_kymos["Kymo1"]
kymo_reference = np.transpose([[2, 0, 0, 0, 2], [0, 0, 0, 0, 0], [1, 0, 0, 0, 1], [0, 1, 1, 1, 0]])
Expand Down

0 comments on commit d8441fd

Please sign in to comment.