8000 fix: Fix reading channel names from single channel czi files by Czaki · Pull Request #1194 · 4DNucleome/PartSeg · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: Fix reading channel names from single channel czi files #1194

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

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Changes from all commits
Commits
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
8 changes: 5 additions & 3 deletions package/PartSegImage/image_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,11 @@
scale_info.get("Y", self.default_spacing[1]),
scale_info.get("X", self.default_spacing[2]),
)
self.channel_names = [
x["Name"] for x in metadata["ImageDocument"]["Metadata"]["DisplaySetting"]["Channels"]["Channel"]
]
channel_meta = metadata["ImageDocument"]["Metadata"]["DisplaySetting"]["Channels"]["Channel"]
if isinstance(channel_meta, dict):
# single channel saved in czifile
channel_meta = [channel_meta]

Check warning on line 364 in package/PartSegImage/image_reader.py

View check run for this annotation

Codecov / codecov/patch

package/PartSegImage/image_reader.py#L364

Added line #L364 was not covered by tests
Comment on lines +361 to +364
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider adding error handling for unexpected metadata structure

The current implementation assumes the presence and structure of the 'Channel' key. Consider wrapping this block in a try-except to handle potential KeyError or TypeError exceptions, ensuring robustness against unexpected metadata formats.

try:
    channel_meta = metadata["ImageDocument"]["Metadata"]["DisplaySetting"]["Channels"]["Channel"]
    if isinstance(channel_meta, dict):
        channel_meta = [channel_meta]
except (KeyError, TypeError):
    channel_meta = []

self.channel_names = [x["Name"] for x in channel_meta]
# TODO add mask reading
if isinstance(image_path, BytesIO):
image_path = ""
Expand Down
Loading
0