Skip to content

Commit

Permalink
fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
rpauszek committed Nov 6, 2023
1 parent 58d070b commit d8973e2
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions lumicks/pylake/tests/test_imaging_confocal/test_kymo_slice_crop.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def test_kymo_slicing(test_kymo):
dead_time = (ref.timestamps.dt * ref.infowave.line_padding * 2) * 1e-9
line_time = scan_time + dead_time

# need to start slicing from the first sample _after_ the dead time
deadtime_slice_offset = (1 + ref.infowave.line_padding) * ref.timestamps.dt * 1e-9

assert kymo.get_image("red").shape == (ref_pixels, ref_lines)
Expand All @@ -35,11 +36,11 @@ def test_kymo_slicing(test_kymo):
assert sliced.get_image("red").shape == (ref_pixels, ref_lines)
np.testing.assert_allclose(sliced.get_image("red").data, ref.image[:, :, 0])

factor = 2
sliced = kymo["0s":f"{factor * line_time}s"]
assert sliced.get_image("red").shape == (ref_pixels, factor)
assert sliced.shape == (ref_pixels, factor, 3)
np.testing.assert_allclose(sliced.get_image("red").data, ref.image[:, :factor, 0])
num_lines = 2
sliced = kymo["0s":f"{num_lines * line_time}s"]
assert sliced.get_image("red").shape == (ref_pixels, num_lines)
assert sliced.shape == (ref_pixels, num_lines, 3)
np.testing.assert_allclose(sliced.get_image("red").data, ref.image[:, :num_lines, 0])

sliced = kymo["0s":f"-{line_time * 0.6}s"]
assert sliced.get_image("red").shape == (ref_pixels, ref_lines - 1)
Expand All @@ -65,12 +66,14 @@ def test_kymo_slicing(test_kymo):
assert sliced.get_image("red").shape == (ref_pixels, 3)
np.testing.assert_allclose(sliced.get_image("red").data, ref.image[:, :3, 0])

sliced = kymo["3.5s":"14s"]
# slice from deadtime before first line until deadtime after first line
sliced = kymo[f"{scan_time + dead_time / 2}s":f"{2 * line_time - dead_time / 2}s"]
assert sliced.get_image("red").shape == (ref_pixels, 1)
assert sliced.shape == (ref_pixels, 1, 3)
np.testing.assert_allclose(sliced.get_image("red").data, ref.image[:, 1:2, 0])

sliced = kymo["0s":"85s"]
# slice over entire kymo
sliced = kymo["0s":f"{line_time * (ref.metadata.lines_per_frame + 1)}s"]
assert sliced.get_image("red").shape == (ref_pixels, ref_lines)
assert sliced.shape == (ref_pixels, ref_lines, 3)
np.testing.assert_allclose(sliced.get_image("red").data, ref.image[:, :, 0])
Expand Down Expand Up @@ -167,9 +170,12 @@ def test_kymo_crop(cropping_kymo):
ref.image[2:3, :, 0],
)

# Test cropping in base pairs
def test_kymo_basepairs_crop(cropping_kymo):
"""Test basic cropping functionality"""
kymo, ref = cropping_kymo
kymo_bp = kymo.calibrate_to_kbp(1.000)
px_size = kymo_bp.pixelsize[0]

np.testing.assert_allclose(
kymo_bp.crop_by_distance(px_size, 3 * px_size).get_image("red"), ref.image[1:3, :, 0]
)
Expand Down Expand Up @@ -256,9 +262,6 @@ def test_incremental_offset(cropping_kymo):
cropped = kymo.crop_by_distance(px_size, 4 * px_size)
twice_cropped = cropped.crop_by_distance(px_size, 4 * px_size)

print(kymo.get_image("red"))
print(cropped.get_image("red"))
print(twice_cropped.get_image("red"))
np.testing.assert_allclose(
twice_cropped.get_image("red"),
ref.image[2:4, :, 0],
Expand Down

0 comments on commit d8973e2

Please sign in to comment.