Skip to content

Commit

Permalink
added _times to account for variable sampling rates (multiple frames …
Browse files Browse the repository at this point in the history
…per slice)
  • Loading branch information
pauladkisson committed Sep 26, 2023
1 parent 849b20c commit cabfa84
Showing 1 changed file with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,33 @@ def parse_metadata_v3_8(metadata):
return metadata_parsed


def extract_timestamps_from_file(file_path):
"""Extract the frame timestamps from a ScanImage TIFF file.
Parameters
----------
file_path : PathType
Path to the TIFF file.
Returns
-------
timestamps : numpy.ndarray
Array of frame timestamps in seconds.
"""
ScanImageTiffReader = _get_scanimage_reader()
io = ScanImageTiffReader(str(file_path))
num_frames = io.shape()[0]
timestamps = np.zeros(num_frames)
for iframe in range(num_frames):
description = io.description(iframe=iframe)
description_lines = description.split("\n")
for line in description_lines:
if "frameTimestamps_sec" in line:
timestamps[iframe] = float(line.split("=")[1].strip())
break
return timestamps


class MultiPlaneImagingExtractor(ImagingExtractor):
"""Class to combine multiple ImagingExtractor objects by depth plane."""

Expand Down Expand Up @@ -420,7 +447,6 @@ def __init__(
plane_name : str
Name of the plane for this extractor (default=None).
"""
super().__init__()
self.file_path = Path(file_path)
self.metadata = extract_extra_metadata(file_path)
parsed_metadata = parse_metadata(self.metadata)
Expand Down Expand Up @@ -460,6 +486,9 @@ def __init__(
"Extractor cannot handle 4D ScanImageTiff data. Please raise an issue to request this feature: "
"https://github.com/catalystneuro/roiextractors/issues "
)
timestamps = extract_timestamps_from_file(file_path)
index = [self.frame_to_raw_index(iframe) for iframe in range(self._num_frames)]
self._times = timestamps[index]

def get_frames(self, frame_idxs: ArrayType) -> np.ndarray:
"""Get specific video frames from indices (not necessarily continuous).
Expand Down

0 comments on commit cabfa84

Please sign in to comment.