-
Notifications
You must be signed in to change notification settings - Fork 14
Zlib compression #180
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
Open
LukasMicroscopy
wants to merge
16
commits into
micro-manager:main
Choose a base branch
from
LukasMicroscopy:zlib-compression
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Zlib compression #180
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
2ae54cf
change seek to write for new file
LukasMicroscopy a03ba0d
tiff bit depth 8bit bug fix
LukasMicroscopy 6454951
put image lock to prevent errors when threading
LukasMicroscopy b12f641
zlib pixel compression
LukasMicroscopy 9ad18f9
add multithreading with compression test
LukasMicroscopy 5abe218
compression bugfix, tested
LukasMicroscopy acaea97
bugfix tiff tag bits per sample, byte_depth assignment
LukasMicroscopy e5014cb
added lock to put_image in ndtiff dataset. Heavy threaded writing did…
LukasMicroscopy 9df1b0a
prevent duplicated reader object when writing in ndtiff dataset
LukasMicroscopy 887520d
speed up random access reads with mmap in SingleNDTiffWriter
LukasMicroscopy 779250d
Merge remote-tracking branch 'origin/8bit-tiff-tag-asignment-bugfix' …
LukasMicroscopy 910b92b
Merge branch 'adding-lock-for-thread-safety' into zlib-compression
LukasMicroscopy fca093d
Merge branch 'optimize-reader' into zlib-compression
LukasMicroscopy 2932901
bugfixes pixel compression and test
LukasMicroscopy 136d57d
renaming
LukasMicroscopy 70af5cd
renaming
LukasMicroscopy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import numpy as np | ||
| import os | ||
| import shutil | ||
| import threading | ||
| import time | ||
| import sys | ||
| from collections import deque | ||
| #from ..ndtiff_file import SingleNDTiffWriter, SingleNDTiffReader | ||
| from ..ndtiff_dataset import NDTiffDataset | ||
| #from ..ndram_dataset import NDRAMDataset | ||
| import pytest | ||
|
|
||
| @pytest.fixture(scope="function") | ||
| def test_data_path(tmp_path_factory): | ||
| data_path = tmp_path_factory.mktemp('writer_tests') | ||
| for f in os.listdir(data_path): | ||
| os.remove(os.path.join(data_path, f)) | ||
| yield str(data_path) | ||
| shutil.rmtree(data_path) | ||
|
|
||
| # loop for threaded writing | ||
| @pytest.mark.skip(reason="loop for threaded writing") | ||
| def image_write_loop(my_deque: deque, dataset: NDTiffDataset, run_event: threading.Event): | ||
| while run_event.is_set() or len(my_deque) != 0: | ||
| try: | ||
| if my_deque: | ||
| current_time, pixels = my_deque.popleft() | ||
| axes = {'time': current_time} | ||
| dataset.put_image(axes, pixels, {'time_metadata': current_time}) | ||
| else: | ||
| time.sleep(0.001) | ||
| except IndexError: | ||
| break | ||
|
|
||
| #@pytest.mark.skipif(sys.version_info < (3, 13), reason="For test_write_multithreaded_zlib Python >= 3.13 is recommended") | ||
| def test_write_multithreaded_zlib(test_data_path): | ||
| """ | ||
| Write an NDTiff dataset and read it back in, testing pixels and metadata | ||
| """ | ||
| #assert sys.version_info[0] >= 3, "For test_write_multithreaded_zlib Python >= 3.13 is recommended" | ||
| #assert sys.version_info[1] >= 13, "For test_write_multithreaded_zlib Python >= 3.13 is recommended" | ||
|
|
||
| full_path = os.path.join(test_data_path, 'test_write_full_dataset') | ||
| dataset = NDTiffDataset(full_path, summary_metadata={}, writable=True, pixel_compression=8) | ||
| image_deque = deque() | ||
| run_event = threading.Event() | ||
| run_event.set() | ||
|
|
||
| image_height = 256 | ||
| image_width = 256 | ||
|
|
||
| thread = threading.Thread(target=image_write_loop, args=(image_deque, dataset, run_event)) | ||
| thread.start() | ||
|
|
||
| time_counter = 0 | ||
| time_limit = 10 | ||
|
|
||
| while True: | ||
| if len(image_deque) < 4: | ||
| pixels = np.ones(image_height * image_width, dtype=np.uint16).reshape((image_height, image_width)) * time_counter | ||
| image_deque.append((time_counter, pixels)) | ||
| time_counter += 1 | ||
| if time_counter >= time_limit: | ||
| break | ||
| else: | ||
| time.sleep(0.001) # if the deque is full, wait a bit | ||
|
|
||
| run_event.clear() | ||
| thread.join() | ||
| dataset.finish() | ||
|
|
||
| # read the file back in | ||
| dataset = NDTiffDataset(full_path) | ||
| for time_index in range(time_limit): | ||
| pixels = np.ones(image_height * image_width, dtype=np.uint16).reshape((image_height, image_width)) * time_index | ||
| axes = {'time': time_index} | ||
| read_image = dataset.read_image(**axes) | ||
| assert np.all(read_image == pixels) | ||
| assert dataset.read_metadata(**axes) == {'time_metadata': time_index} | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems redundant to
UNCOMPRESSED. IfNO_COMPRESSIONis a standard name, maybe good to remove uncompressed