-
Notifications
You must be signed in to change notification settings - Fork 7
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
draft of multi-tiff multi-page imaging extractor #323
Draft
bendichter
wants to merge
35
commits into
main
Choose a base branch
from
multitiff_multipage_imaging_extractor
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.
Draft
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
c4904c8
upload draft of multi-tiff multi-page imaging extractor. This could b…
bendichter fddf198
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 66c59f2
Merge branch 'main' into multitiff_multipage_imaging_extractor
bendichter ccf4d90
add tests
bendichter 6de2ca4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 85e90db
dynamic import of tifffile
bendichter 93b2545
Merge remote-tracking branch 'origin/multitiff_multipage_imaging_extr…
bendichter fb772d6
fix tests
bendichter 31c9df4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7263bd9
fix test
bendichter 3b6fb6b
Merge remote-tracking branch 'origin/multitiff_multipage_imaging_extr…
bendichter f760ba6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7892f8d
rmv print
bendichter 44d64f7
Merge remote-tracking branch 'origin/multitiff_multipage_imaging_extr…
bendichter fda7b9c
use multiimaginginterface
bendichter 96152ac
add parse as a dependency
bendichter dbdf11e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4925b40
move parse to minimal requirements
bendichter c11fc24
Merge remote-tracking branch 'origin/multitiff_multipage_imaging_extr…
bendichter 435f600
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] c1ae185
Add docstring for match_paths
bendichter 2313673
Merge remote-tracking branch 'origin/multitiff_multipage_imaging_extr…
bendichter a798a7c
pass docstring tests
bendichter a904272
use named vars?
bendichter 66289fb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 293dc1c
add docstring for module
bendichter 9f36886
Merge remote-tracking branch 'origin/multitiff_multipage_imaging_extr…
bendichter b47ad48
add check for if no TIFF files were found
bendichter c54c052
move multitiffmultipage extractor over to existing tiffimagingextract…
bendichter a9153f1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5c7b751
make sure match_paths can sub-select
bendichter 6ed3bca
Merge remote-tracking branch 'origin/multitiff_multipage_imaging_extr…
bendichter a383ecd
refactor
bendichter fb93606
update tests
bendichter eb5cc8e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 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 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 |
---|---|---|
|
@@ -6,3 +6,4 @@ dill>=0.3.2 | |
scipy>=1.5.2 | ||
psutil>=5.8.0 | ||
PyYAML | ||
parse>=1.20.0 |
This file contains 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 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 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 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 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,38 @@ | ||
"""Utility functions for the ROIExtractors package.""" | ||
|
||
import glob | ||
import os | ||
from typing import Dict, Any | ||
|
||
from parse import parse | ||
|
||
|
||
def match_paths(base: str, pattern: str, sort=True) -> Dict[str, Dict[str, Any]]: | ||
""" | ||
Match paths in a directory to a pattern. | ||
|
||
Parameters | ||
---------- | ||
base: str | ||
The base directory to search in. | ||
pattern: str | ||
The f-string pattern to match the paths to. | ||
sort: bool, default=True | ||
Whether to sort the output by the values of the named groups in the pattern. | ||
|
||
Returns | ||
------- | ||
dict | ||
""" | ||
full_pattern = os.path.join(base, pattern) | ||
paths = glob.glob(os.path.join(base, "*")) | ||
out = {} | ||
for path in paths: | ||
parsed = parse(full_pattern, path) | ||
if parsed is not None: | ||
out[path] = parsed.named | ||
|
||
if sort: | ||
out = dict(sorted(out.items(), key=lambda item: tuple(item[1].values()))) | ||
|
||
return out |
This file contains 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,56 @@ | ||
import os | ||
|
||
from roiextractors.utils import match_paths | ||
from tempfile import TemporaryDirectory | ||
|
||
|
||
def test_match_paths(): | ||
# create temporary directory | ||
with TemporaryDirectory() as tmpdir: | ||
# create temporary files | ||
files = [ | ||
"split_1.tif", | ||
"split_2.tif", | ||
"split_3.tif", | ||
"split_4.tif", | ||
"split_5.tif", | ||
"split_6.tif", | ||
"split_7.tif", | ||
"split_8.tif", | ||
"split_9.tif", | ||
"split_10.tif", | ||
] | ||
for file in files: | ||
with open(os.path.join(tmpdir, file), "w") as f: | ||
f.write("") | ||
|
||
# test match_paths | ||
out = match_paths(tmpdir, "split_{split:d}.tif") | ||
assert list(out.keys()) == [os.path.join(tmpdir, x) for x in files] | ||
assert list([x["split"] for x in out.values()]) == list(range(1, 11)) | ||
|
||
|
||
def test_match_paths_sub_select(): | ||
# create temporary directory | ||
with TemporaryDirectory() as tmpdir: | ||
# create temporary files | ||
files = [ | ||
"chanA_split_1.tif", | ||
"chanA_split_2.tif", | ||
"chanA_split_3.tif", | ||
"chanA_split_4.tif", | ||
"chanA_split_5.tif", | ||
"chanB_split_1.tif", | ||
"chanB_split_2.tif", | ||
"chanB_split_3.tif", | ||
"chanB_split_4.tif", | ||
"chanB_split_5.tif", | ||
] | ||
for file in files: | ||
with open(os.path.join(tmpdir, file), "w") as f: | ||
f.write("") | ||
|
||
# test match_paths | ||
out = match_paths(tmpdir, "chanA_split_{split:d}.tif") | ||
assert list(out.keys()) == [os.path.join(tmpdir, x) for x in files[:5]] | ||
assert list([x["split"] for x in out.values()]) == list(range(1, 6)) |
This file contains 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,64 @@ | ||
from roiextractors import MultiTiffImagingExtractor, FolderTiffImagingExtractor | ||
|
||
from tests.setup_paths import OPHYS_DATA_PATH | ||
|
||
|
||
def test_init_folder_tiff_imaging_extractor_multi_page(): | ||
extractor = FolderTiffImagingExtractor( | ||
folder_path=OPHYS_DATA_PATH / "imaging_datasets" / "Tif" / "splits", | ||
pattern="split_{split:d}.tif", | ||
sampling_frequency=1.0, | ||
) | ||
|
||
assert extractor.get_num_channels() == 1 | ||
assert extractor.get_num_frames() == 2000 | ||
assert extractor.get_sampling_frequency() == 1.0 | ||
assert extractor.get_channel_names() is None | ||
assert extractor.get_dtype() == "uint16" | ||
assert extractor.get_image_size() == (60, 80) | ||
assert extractor.get_video().shape == (2000, 60, 80) | ||
assert list(extractor.file_paths) == [ | ||
str(OPHYS_DATA_PATH / "imaging_datasets" / "Tif" / "splits" / x) | ||
for x in ( | ||
"split_1.tif", | ||
"split_2.tif", | ||
"split_3.tif", | ||
"split_4.tif", | ||
"split_5.tif", | ||
"split_6.tif", | ||
"split_7.tif", | ||
"split_8.tif", | ||
"split_9.tif", | ||
"split_10.tif", | ||
) | ||
] | ||
|
||
|
||
def test_init_multitiff_imaging_extractor_multi_page(): | ||
extractor = MultiTiffImagingExtractor( | ||
file_paths=[OPHYS_DATA_PATH / "imaging_datasets" / "Tif" / "splits" / f"split_{i}.tif" for i in range(1, 11)], | ||
sampling_frequency=1.0, | ||
) | ||
|
||
assert extractor.get_num_channels() == 1 | ||
assert extractor.get_num_frames() == 2000 | ||
assert extractor.get_sampling_frequency() == 1.0 | ||
assert extractor.get_channel_names() is None | ||
assert extractor.get_dtype() == "uint16" | ||
assert extractor.get_image_size() == (60, 80) | ||
assert extractor.get_video().shape == (2000, 60, 80) | ||
assert list(extractor.file_paths) == [ | ||
OPHYS_DATA_PATH / "imaging_datasets" / "Tif" / "splits" / x | ||
for x in ( | ||
"split_1.tif", | ||
"split_2.tif", | ||
"split_3.tif", | ||
"split_4.tif", | ||
"split_5.tif", | ||
"split_6.tif", | ||
"split_7.tif", | ||
"split_8.tif", | ||
"split_9.tif", | ||
"split_10.tif", | ||
) | ||
] |
Oops, something went wrong.
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.
Some extra tests for this, at a minimum, should include cases of (a) multiple cameras/microscopes (the specifier for each device being something in the file name), and (b) multiple optic channels for a single one of those devices (the channel name/ID also being a part of the filename)
Not that I'm not saying the
TiffFolderImagingExtractor
should by default support multiple optic channels, or auto-detection of channel IDs from this pattern (that is a more complicated feature that could be done in a follow-up, or not at all); I just want to make sure that a single instance made from a pattern specification that restricts to only one channel from a folder that contains several correctly identifies list of files only for that channel