Skip to content

Commit

Permalink
clean up code for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
pauladkisson committed Sep 25, 2023
1 parent 663b819 commit 36f9394
Showing 1 changed file with 12 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -526,39 +526,32 @@ def get_video(self, start_frame=None, end_frame=None) -> np.ndarray:
end_frame_inclusive = end_frame - 1
self.check_frame_inputs(end_frame_inclusive)
self.check_frame_inputs(start_frame)
start_cycle = start_frame // self._frames_per_slice
end_cycle = end_frame // self._frames_per_slice
# raw_start = self.frame_to_raw_index(start_cycle * self._frames_per_slice)
# raw_start = start_cycle * self._num_raw_per_cycle
raw_start = self.frame_to_raw_index(start_frame)
raw_end = self.frame_to_raw_index(end_frame_inclusive)
raw_end += 1 # ScanImageTiffReader is exclusive of the end index
raw_end_inclusive = self.frame_to_raw_index(end_frame_inclusive) # frame_to_raw_index requires inclusive frame
raw_end = raw_end_inclusive + 1

ScanImageTiffReader = _get_scanimage_reader()
with ScanImageTiffReader(filename=str(self.file_path)) as io:
raw_video = io.data(beg=raw_start, end=raw_end)

start_cycle = np.ceil(start_frame / self._frames_per_slice).astype("int")
end_cycle = end_frame // self._frames_per_slice
num_cycles = end_cycle - start_cycle
start_frame_in_cycle = start_frame % self._frames_per_slice
end_frame_in_cycle = end_frame % self._frames_per_slice
start_left_in_cycle = (self._frames_per_slice - start_frame_in_cycle) % self._frames_per_slice
end_left_in_cycle = (self._frames_per_slice - end_frame_in_cycle) % self._frames_per_slice
print(f"raw_start: {raw_start}")
print(f"raw_end: {raw_end}")
print(f"start_frame_in_cycle: {start_frame_in_cycle}")
print(f"end_frame_in_cycle: {end_frame_in_cycle}")
ScanImageTiffReader = _get_scanimage_reader()
with ScanImageTiffReader(filename=str(self.file_path)) as io:
raw_video = io.data(beg=raw_start, end=raw_end)
num_cycles = end_cycle - np.ceil(start_frame / self._frames_per_slice).astype("int")
index = []
for j in range(start_left_in_cycle): # Add remaining frames from first (incomplete) cycle
idx = j * self._num_channels
index.append(idx)
index.append(j * self._num_channels)
for i in range(num_cycles):
for j in range(self._frames_per_slice):
index.append(
(j - start_frame_in_cycle) * self._num_channels
+ (i + bool(start_left_in_cycle)) * self._num_raw_per_cycle
)
for j in range(end_left_in_cycle): # Add remaining frames from last (incomplete) cycle
idx = (j - start_frame_in_cycle) * self._num_channels + num_cycles * self._num_raw_per_cycle
index.append(idx)
print(f"index: {index}")
index.append(j - start_frame_in_cycle) * self._num_channels + num_cycles * self._num_raw_per_cycle
video = raw_video[index]
return video

Expand Down

0 comments on commit 36f9394

Please sign in to comment.