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

Multiscale labeled images #45

Merged
merged 39 commits into from
Sep 4, 2020
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
c45f450
Open images for a mask via the array link
joshmoore Aug 18, 2020
47d8563
Move python code to a module
joshmoore Aug 19, 2020
aafd5ed
Fix mypy errors
joshmoore Aug 19, 2020
185157f
Refactor to re-use multiscale loading
joshmoore Aug 19, 2020
266b357
Have mypy check all API methods
joshmoore Aug 19, 2020
fc8df8f
Enfore mypy annotations on all definitions
joshmoore Aug 19, 2020
db43af5
Fix 'bool(false)' in color test
joshmoore Aug 19, 2020
967b36c
move create_test_data to ome_zarr.data
joshmoore Aug 21, 2020
c146101
Add isort as the first pre-commit step
joshmoore Aug 21, 2020
1c50a26
refactor create_zarr method for use from CLI
joshmoore Aug 21, 2020
3a9f360
Major API refactoring
joshmoore Aug 24, 2020
7c8cff1
More tests and bug fixes
joshmoore Aug 25, 2020
b57d439
Deal with empty labels from astronauts
joshmoore Aug 26, 2020
9665c4c
ome_zarr.scale: migrate scale.py to ome_zarr
joshmoore Aug 26, 2020
6b18581
Enable make_test_viewer from napari
joshmoore Aug 26, 2020
4fb4213
Fix recursive reading, info, and downloading
joshmoore Aug 26, 2020
c4ef738
Fix number of channels in coins()
joshmoore Aug 26, 2020
77e631a
Fix CLI tools incl. prefix stripping
joshmoore Aug 27, 2020
7a4f865
Update style and fill out well-formed docs
joshmoore Aug 28, 2020
56f7ef5
Use GH Actions & Conda for tests
joshmoore Aug 31, 2020
12b9493
Fix "loaded as" doc sentence
joshmoore Aug 31, 2020
b90b68d
Activate doctests
joshmoore Aug 31, 2020
151c52e
Correct channel array for grayscale images
joshmoore Aug 31, 2020
930c303
Use latest setup-conda for posix and windows
joshmoore Aug 31, 2020
b7e8196
Try pyside2 for all platforms
joshmoore Aug 31, 2020
69288fc
Fix label colors key
joshmoore Aug 31, 2020
ab0cdc1
Fix 'colormap' key thanks to Will
joshmoore Sep 1, 2020
723fe0c
Remove unwrapping of pyramids thanks to Will
joshmoore Sep 1, 2020
8125dd4
Change 'Layer' to 'Node'
joshmoore Sep 2, 2020
31082bc
Remove is_zarr() in favor of exists()
joshmoore Sep 3, 2020
0a95ff2
Fix double negative
joshmoore Sep 3, 2020
f2cff53
Remove extra 'of'
joshmoore Sep 3, 2020
c0806ec
Rename test_layer to test_node
joshmoore Sep 3, 2020
6cc1c25
Re-instate visiblility via a property
joshmoore Sep 3, 2020
171e122
Use 'greyscale'
joshmoore Sep 4, 2020
ee73e06
Restore downloading without --output
joshmoore Sep 4, 2020
d2f9f1c
Rework Node.add documentation
joshmoore Sep 4, 2020
fbfa932
Disable napari viewer test on non-OSX platforms
joshmoore Sep 4, 2020
4ed3078
Use bash script with activated conda environment on Windows
joshmoore Sep 4, 2020
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
Next Next commit
Open images for a mask via the array link
joshmoore committed Aug 19, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit c45f4502cf87491612952f548d6ae3589717cf19
52 changes: 44 additions & 8 deletions ome_zarr.py
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
import json
import requests
import dask.array as da
import posixpath
import warnings

from dask.diagnostics import ProgressBar
@@ -128,7 +129,10 @@ def to_rgba(self, v):
"""Get rgba (0-1) e.g. (1, 0.5, 0, 1) from integer"""
return [x / 255 for x in v.to_bytes(4, signed=True, byteorder="big")]

def reader_function(self, path: Optional[PathLike]) -> Optional[List[LayerData]]:
def reader_function(self,
path: Optional[PathLike],
recurse: bool = True,
) -> Optional[List[LayerData]]:
"""Take a path or list of paths and return a list of LayerData tuples."""

if isinstance(path, list):
@@ -139,23 +143,48 @@ def reader_function(self, path: Optional[PathLike]) -> Optional[List[LayerData]]
LOGGER.debug(f"treating {path} as ome-zarr")
layers = [self.load_ome_zarr()]
# If the Image contains labels...
if self.has_ome_labels():
if recurse and self.has_ome_labels():
label_path = os.path.join(self.zarr_path, "labels")
# Create a new OME Zarr Reader to load labels
labels = self.__class__(label_path).reader_function(None)
labels = self.__class__(label_path).reader_function(
None, recurse=False)
if labels:
layers.extend(labels)
return layers

elif self.is_ome_label():
LOGGER.debug(f"treating {path} as labels")
layers = self.load_ome_labels()
rv = []
try:
for layer in layers:
metadata = layer[1].get("metadata", {})
path = metadata.get("path", None)
array = metadata.get("image", {}).get("array", None)
if recurse and path and array:
# This is an ome mask, load the image
parent = posixpath.normpath(f"{path}/{array}")
LOGGER.debug(f"delegating to parent image: {parent}")
# Create a new OME Zarr Reader to load labels
replace = self.__class__(parent).reader_function(
None, recurse=False)
for r in replace:
r[1]["visible"] = False
rv.extend(replace)
layer[1]["visible"] = True
rv.append(layer)
return rv
except Exception as e:
LOGGER.error(e)
return []

# TODO: might also be an individiaul mask

elif self.zarray:
LOGGER.debug(f"treating {path} as raw zarr")
data = da.from_zarr(f"{self.zarr_path}")
return [(data,)]

elif self.is_ome_label():
LOGGER.debug(f"treating {path} as labels")
return self.load_ome_labels()

else:
LOGGER.debug(f"ignoring {path}")
return None
@@ -290,7 +319,14 @@ def load_ome_labels(self):
labels.append(
(
data[:, n, :, :, :],
{"visible": False, "name": name, "color": colors},
{"visible": False,
"name": name,
"color": colors,
"metadata": {
"image": label_attrs.get("image", {}),
"path": label_path,
},
},
"labels",
)
)