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

fix: Workaround for lack of zsd support in czifile #1142

Merged
merged 9 commits into from
Jul 15, 2024
Merged

Conversation

Czaki
Copy link
Collaborator

@Czaki Czaki commented Jul 12, 2024

Workaround for bug reported cgohlke/czifile#10

Summary by CodeRabbit

  • New Features

    • Added support for new compression formats in image reading.
    • Introduced max_workers parameter for improved image processing performance.
  • Tests

    • Added unit tests for reading compressed CZI files.
    • Implemented fixture to set maximum workers for CZI processing.

fix PARTSEG-V0

@Czaki Czaki added this to the 0.15.4 milestone Jul 12, 2024
Copy link
Contributor

coderabbitai bot commented Jul 12, 2024

Walkthrough

Recent updates to the PartSegImage package enhance image reading capabilities by incorporating additional codecs and compression support. Key improvements include the introduction of ZSTD decompression functions, adjustments to the CziImageReader class for better multi-threading, and new unit tests for compressed file handling.

Changes

Files Change Summary
package/PartSegImage/image_reader.py Added new imports, decompression functions, ZSTD1Header class, and modified DECOMPRESS dictionary. Enhanced read method with max_workers parameter.
package/tests/test_PartSegImage/... Introduced fixture _set_max_workers_czi and test test_czi_file_read_compressed for verifying compressed CZI file reading.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CziImageReader
    participant image_file
    User->>CziImageReader: read(image_path, mask_path, ext)
    CziImageReader->>CziImageReader: Determine max_workers
    CziImageReader->>image_file: asarray(max_workers)
    image_file->>CziImageReader: Return image data
    CziImageReader->>User: Return Image
Loading

Poem

In the realm of code so bright,
Images compressed, now take flight.
ZSTD whispers, "I’ll decode,"
Multi-threaded, on we rode.
Tests affirmed, all is right,
In this update, pure delight!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

sourcery-ai bot commented Jul 12, 2024

🧙 Sourcery has finished reviewing your pull request!


Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

We've reviewed this pull request using the Sourcery rules engine. If you would also like our AI-powered code review then let us know.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bfb4d59 and 2f61872.

Files selected for processing (1)
  • package/PartSegImage/image_reader.py (3 hunks)
Additional comments not posted (6)
package/PartSegImage/image_reader.py (6)

6-6: LGTM! New imports are appropriate.

The new imports are necessary for the new functionalities introduced related to ZSTD decoding and version checking.

Also applies to: 11-11, 17-17


28-37: LGTM! Class ZSTD1Header is well-defined.

The class represents the header structure for ZSTD1 compression and references an external source for clarity.


39-57: LGTM! Function parse_zstd1_header is correctly implemented.

The function parses the header for ZSTD1 compression using data and size parameters and references an external source for accuracy.


60-61: Potential maintenance issue with _get_dtype.

The function relies on specific assumptions about the calling context, which could lead to maintenance challenges. Ensure that the context in which this function is used is well-documented and consistent.


81-83: LGTM! Dictionary modifications are appropriate.

The DECOMPRESS dictionary is correctly updated to handle ZSTD0 and ZSTD1 decoding.


335-335: LGTM! Addition of max_workers parameter is beneficial.

The max_workers parameter potentially improves performance by enabling parallel processing.

package/PartSegImage/image_reader.py Outdated Show resolved Hide resolved
package/PartSegImage/image_reader.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jul 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.02%. Comparing base (e13f990) to head (48d5a42).
Report is 56 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1142      +/-   ##
===========================================
+ Coverage    93.01%   93.02%   +0.01%     
===========================================
  Files          207      207              
  Lines        32658    32700      +42     
===========================================
+ Hits         30376    30420      +44     
+ Misses        2282     2280       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Czaki Czaki changed the title fix: Workaround for lack of zsd supprot in czifile fix: Workaround for lack of zsd support in czifile Jul 12, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2f61872 and 809c3dd.

Files selected for processing (2)
  • package/PartSegImage/image_reader.py (3 hunks)
  • package/tests/test_PartSegImage/test_image_reader.py (1 hunks)
Additional comments not posted (7)
package/tests/test_PartSegImage/test_image_reader.py (1)

38-45: LGTM!

The test function test_czi_file_read_compressed is well-written and effectively tests the decompression functionality of CZI files.

package/PartSegImage/image_reader.py (6)

1-17: LGTM!

The new imports are necessary and correctly imported.


28-37: LGTM!

The class ZSTD1Header is well-defined and includes appropriate attributes with a clear docstring.


39-57: LGTM!

The function parse_zstd1_header is well-written and includes a clear docstring. The logic for parsing the header is correct.


60-61: LGTM!

The function _get_dtype correctly determines the data type using inspect.


343-343: LGTM!

The addition of the max_workers parameter in the image_file.asarray() call potentially improves performance by leveraging parallel processing.


81-86: Replace np.fromstring with np.frombuffer.

The function decodes ZSTD0 data correctly, but np.fromstring is deprecated.

-  return np.fromstring(imagecodecs.zstd_decode(data), dtype)
+  return np.frombuffer(imagecodecs.zstd_decode(data), dtype)

Likely invalid or redundant comment.

package/PartSegImage/image_reader.py Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 809c3dd and 15c8fde.

Files selected for processing (2)
  • package/PartSegImage/image_reader.py (4 hunks)
  • package/tests/test_PartSegImage/test_image_reader.py (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • package/PartSegImage/image_reader.py
Additional comments not posted (1)
package/tests/test_PartSegImage/test_image_reader.py (1)

6-6: Review of New Imports, Fixtures, and Test Functions

  1. New Imports:

    • The imports on lines 6 and 12 (version from importlib.metadata and parse_version from packaging.version) are correctly added and relevant to the new features being tested, particularly the version checking for czifile.
  2. New Fixture _set_max_workers_czi:

    • This fixture correctly sets the CZI_MAX_WORKERS to 1 using monkeypatch. This is a good practice to ensure that the tests are not affected by parallel execution environments which might introduce non-determinism.
  3. New Test test_czi_file_read_compressed:

    • The test uses version checking to skip tests for versions of czifile below 2019.7.2, which is a good practice to ensure backward compatibility.
    • The use of pytest.mark.parametrize to test multiple file types (test_czi_zstd0.czi, test_czi_zstd1.czi, test_czi_zstd1_hilo.czi) is excellent for ensuring that all relevant cases are covered.
    • Assertions in the test are comprehensive, checking for non-zero channel data, correct number of channels and layers, file path correctness, and spatial dimensions.
  4. Assertions:

    • The assertions on lines 39 and 67 are crucial for verifying the integrity and correctness of the image data loaded from different types of CZI files.

These changes are well-implemented and follow good testing practices. No further action is required unless additional test scenarios are considered necessary.

Also applies to: 12-12, 18-22, 39-39, 47-61, 67-67

Copy link

sonarcloud bot commented Jul 15, 2024

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 15c8fde and 48d5a42.

Files selected for processing (1)
  • package/PartSegImage/image_reader.py (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • package/PartSegImage/image_reader.py

@Czaki Czaki merged commit 052bf57 into develop Jul 15, 2024
53 of 55 checks passed
@Czaki Czaki deleted the fix_czi_read branch July 15, 2024 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant