Skip to content

Commit

Permalink
Fix bug in BrukerTiffSinglePlaneImagingExtractor (#343)
Browse files Browse the repository at this point in the history
* fix bug in `BrukerTiffSinglePlaneImagingExtractor` where channel name is assumed to be part of the filename.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Szonja Weigl <[email protected]>
  • Loading branch information
3 people authored Jun 12, 2024
1 parent a3d0867 commit fee7dd3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Detect Changelog Updates was moved to its own dedicated workflow to avoid daily testing failures: [#336](https://github.com/catalystneuro/roiextractors/pull/336)
* Fixed the Daily testing workflows by passing along the appropriate secrets: [#340](https://github.com/catalystneuro/roiextractors/pull/340)
* Change the criteria of determining if Bruker data is volumetric [#342](https://github.com/catalystneuro/roiextractors/pull/342)
* Fixes a bug that assumes the channel name is is on the tiff file for `BrukerTiffSinglePlaneImagingExtractor` [#343](https://github.com/catalystneuro/roiextractors/pull/343)

### Improvements

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def __init__(self, folder_path: PathType, stream_name: Optional[str] = None):
folder_path : PathType
The path to the folder that contains the Bruker TIF image files (.ome.tif) and configuration files (.xml, .env).
stream_name: str, optional
The name of the recording channel (e.g. "Ch2").
The name of the recording channel (e.g. "Ch2" or "Green").
"""
self._tifffile = _get_tiff_reader()

Expand All @@ -372,25 +372,33 @@ def __init__(self, folder_path: PathType, stream_name: Optional[str] = None):
assert tif_file_paths, f"The TIF image files are missing from '{folder_path}'."

streams = self.get_streams(folder_path=folder_path)
channel_streams = streams["channel_streams"]
if stream_name is None:
if len(streams["channel_streams"]) > 1:
if len(channel_streams) > 1:
raise ValueError(
"More than one recording stream is detected! Please specify which stream you wish to load with the `stream_name` argument. "
"To see what streams are available, call `BrukerTiffSinglePlaneImagingExtractor.get_stream_names(folder_path=...)`."
f"To see what streams are available, call `BrukerTiffSinglePlaneImagingExtractor.get_stream_names(folder_path=...)`."
)
stream_name = streams["channel_streams"][0]
stream_name = channel_streams[0]

self.stream_name = stream_name
channel_stream_name = self.stream_name.split("_")[0]
if self.stream_name is not None and channel_stream_name not in streams["channel_streams"]:
raise ValueError(
f"The selected stream '{self.stream_name}' is not in the available channel_streams '{streams['channel_streams']}'!"
)

self._xml_root = _parse_xml(folder_path=folder_path)
file_elements = self._xml_root.findall(".//File")
file_names = [file.attrib["filename"] for file in file_elements]
file_names_for_stream = [file for file in file_names if self.stream_name in file]

# This is the case when stream_name is a channel name (e.g. "Green" or "Ch2")
if stream_name in channel_streams:
file_names_for_stream = [
f.attrib["filename"] for f in file_elements if f.attrib["channelName"] == stream_name
]

else: # This is the case for when stream_name is a plane_stream
file_names = [file.attrib["filename"] for file in file_elements]
file_names_for_stream = [file for file in file_names if self.stream_name in file]
if file_names_for_stream == []:
raise ValueError(
f"The selected stream '{self.stream_name}' is not in the available channel_streams '{streams['channel_streams']}'!"
)
# determine image shape and data type from first file
with self._tifffile.TiffFile(folder_path / file_names_for_stream[0], _multifile=False) as tif:
self._height, self._width = tif.pages[0].shape
Expand Down

0 comments on commit fee7dd3

Please sign in to comment.