Skip to content

Commit

Permalink
slice by timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
rpauszek committed Nov 17, 2023
1 parent 60736e8 commit 45e49e3
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions lumicks/pylake/tests/test_imaging_confocal/test_scan_slice_crop.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,53 @@ def test_scan_slicing_by_time_iterative(test_scan_slicing):
# until frame 2 signal stop
sliced = first_slice[:f"{-(frame_time + dead_time)}s"]
np.testing.assert_equal(sliced.get_image("rgb"), ref_sliced[:-2])


def test_scan_slicing_by_timestamps(test_scan_slicing):
multi_frame, ref = test_scan_slicing
multi_frame = multi_frame[:]

dt = np.int64(ref.timestamps.dt)
start = ref.infowave.data.start + (dt * ref.infowave.line_padding)

scan_time = (
dt
* ref.infowave.samples_per_pixel
* ref.metadata.lines_per_frame
* ref.metadata.pixels_per_line
+ (ref.metadata.lines_per_frame * dt * ref.infowave.line_padding)
)
dead_time = ref.infowave.line_padding * dt * 2
frame_time = scan_time + dead_time

# from frame 2 start until frame 4 start
sliced = multi_frame[start + 2 * frame_time : start + 4 * frame_time]
np.testing.assert_equal(sliced.get_image("rgb"), ref.image[2:4])

# from frame 2 start until end of frame 4 signal stop
sliced = multi_frame[start + 2 * frame_time : start + (4 * frame_time + scan_time)]
np.testing.assert_equal(sliced.get_image("rgb"), ref.image[2:4])

# from frame 2 start until just after end of frame 4 signal stop
sliced = multi_frame[start + 2 * frame_time : start + (4 * frame_time + scan_time + dt)]
np.testing.assert_equal(sliced.get_image("rgb"), ref.image[2:5])

# until just after end of frame 4 signal stop
sliced = multi_frame[: (start + (4 * frame_time + scan_time + dt))]
np.testing.assert_equal(sliced.get_image("rgb"), ref.image[:5])

# from frame 5 start
sliced = multi_frame[(start + 5 * frame_time) :]
np.testing.assert_equal(sliced.get_image("rgb"), ref.image[5:])

# iterative slicing; first slice from frame 2 start until just after frame 4 signal stop
first_slice = multi_frame[start + 2 * frame_time : start + (4 * frame_time + scan_time + dt)]
ref_sliced = ref.image[2:5]

# from start, past stop
sliced = first_slice[start : start + 10 * frame_time]
np.testing.assert_equal(sliced.get_image("rgb"), ref_sliced)

# from frame 3 start until just after frame 3 signal stop
sliced = first_slice[start + 3 * frame_time : start + (3 * frame_time + scan_time + dt)]
np.testing.assert_equal(sliced.get_image("rgb"), ref_sliced[1])

0 comments on commit 45e49e3

Please sign in to comment.