Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add BrukerTiffImagingExtractor #220

Merged
merged 27 commits into from
Apr 24, 2023
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ec9328f
add extractor
weiglszonja Mar 31, 2023
a3a63b1
Update src/roiextractors/extractors/tiffimagingextractors/brukertiffi…
weiglszonja Apr 3, 2023
5ea6240
apply changes from review
weiglszonja Apr 3, 2023
713eb48
fix access single frame
weiglszonja Apr 3, 2023
3ab2605
update
weiglszonja Apr 3, 2023
3790f72
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 3, 2023
d6b3e4d
fix dict typehint
weiglszonja Apr 3, 2023
bf885d4
adapt to multiple z-planes
weiglszonja Apr 5, 2023
3aedfac
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 5, 2023
037dac2
Merge branch 'master' into add_BrukerTiffImagingExtractor
weiglszonja Apr 5, 2023
1779ed6
Revert "adapt to multiple z-planes"
weiglszonja Apr 5, 2023
f2dc54c
update
weiglszonja Apr 19, 2023
6c4cd42
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 19, 2023
bbe4308
add tests for BrukerTiffExtractor
weiglszonja Apr 19, 2023
ed3ff2b
Merge remote-tracking branch 'origin/add_BrukerTiffImagingExtractor' …
weiglszonja Apr 19, 2023
f3f295f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 19, 2023
5d138b4
update cache
CodyCBakerPhD Apr 19, 2023
2fc5eed
update path name
CodyCBakerPhD Apr 20, 2023
12b0e1b
loosen up tifffile version requirements-full.txt
weiglszonja Apr 20, 2023
4d81694
Merge remote-tracking branch 'origin/add_BrukerTiffImagingExtractor' …
weiglszonja Apr 20, 2023
5c446c3
try fix python3.7 CI error
weiglszonja Apr 20, 2023
fc77811
add test for single frame
weiglszonja Apr 20, 2023
358af54
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 20, 2023
24dd6c9
rollback accidental folder_path change
weiglszonja Apr 20, 2023
40ffaaf
Merge remote-tracking branch 'origin/add_BrukerTiffImagingExtractor' …
weiglszonja Apr 20, 2023
184eaae
finish unittest for temporary directory
weiglszonja Apr 21, 2023
4f1b3f5
remove tmp directory after test
weiglszonja Apr 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update
  • Loading branch information
weiglszonja committed Apr 19, 2023
commit f2dc54c07953e87e04a3e8f109108f8b5dd1caa8
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,15 @@ def __init__(self, folder_path: PathType):
folder_path : PathType
The path to the folder that contains the Bruker TIF image files (.ome.tif) and configuration files (.xml, .env).
"""
tifffile = _get_tiff_reader()
self._tifffile = _get_tiff_reader()

super().__init__()
self.folder_path = Path(folder_path)
tif_file_paths = list(self.folder_path.glob("*.ome.tif"))
assert tif_file_paths, f"The TIF image files are missing from '{self.folder_path}'."

self._xml_file_path = self.folder_path / f"{self.folder_path.name}.xml"
assert self._xml_file_path.is_file(), f"The XML configuration file is not found at '{self.folder_path}'."

sequences = self._get_xml_root().findall("Sequence")
num_sequences = len(sequences)
Expand All @@ -49,8 +54,6 @@ def __init__(self, folder_path: PathType):

files = self._sequence.findall(".//File")
self._file_paths = [file.attrib["filename"] for file in files]
tif_file_paths = list(self.folder_path.glob("*.ome.tif"))
assert tif_file_paths, f"The TIF image files are missing from '{self.folder_path}'."
if num_sequences != 1:
missing_files = [
file_path for file_path in self._file_paths if self.folder_path / file_path not in tif_file_paths
Expand All @@ -63,7 +66,7 @@ def __init__(self, folder_path: PathType):
tif_file_paths
), f"The number of TIF image files at '{self.folder_path}' should be equal to the number of frames ({len(self._file_paths)}) specified in the XML configuration file."

with tifffile.TiffFile(self.folder_path / self._file_paths[0], _multifile=False) as tif:
with self._tifffile.TiffFile(self.folder_path / self._file_paths[0], _multifile=False) as tif:
self._height, self._width = tif.pages.first.shape
self._dtype = tif.pages.first.dtype

Expand All @@ -78,9 +81,7 @@ def _get_xml_root(self):
"""
Parses the XML configuration file into element tree and returns the root of this tree.
"""
xml_file_path = self.folder_path / f"{self.folder_path.name}.xml"
assert Path(xml_file_path).is_file(), f"The XML configuration file is not found at '{self.folder_path}'."
tree = ElementTree.parse(xml_file_path)
tree = ElementTree.parse(self._xml_file_path)
return tree.getroot()

def _get_xml_metadata(self) -> Dict[str, Union[str, List[Dict[str, str]]]]:
Expand Down Expand Up @@ -144,14 +145,12 @@ def _frames_iterator(
start_frame: Optional[int] = None,
end_frame: Optional[int] = None,
) -> Iterable[np.memmap]:
tifffile = _get_tiff_reader()

if start_frame is not None and end_frame is not None:
if end_frame == start_frame:
yield tifffile.memmap(self.folder_path / self._file_paths[start_frame], mode="r", _multifile=False)
yield self._tifffile.memmap(self.folder_path / self._file_paths[start_frame], mode="r", _multifile=False)

for file in self._file_paths[start_frame:end_frame]:
yield tifffile.memmap(self.folder_path / file, mode="r", _multifile=False)
yield self._tifffile.memmap(self.folder_path / file, mode="r", _multifile=False)

def get_video(
self, start_frame: Optional[int] = None, end_frame: Optional[int] = None, channel: int = 0
Expand Down