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

masks: unify remote and local handling #1

Merged
merged 1 commit into from
Jul 7, 2020
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
36 changes: 11 additions & 25 deletions ome_zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,20 @@ def is_zarr(self):
def is_ome_zarr(self):
return self.zgroup and "multiscales" in self.root_attrs

def has_ome_masks(self):
"Does the zarr Image also include /masks sub-dir"
return self.get_json('masks/.zgroup')

def is_ome_mask(self):
return self.zarr_path.endswith('masks/') and self.get_json('.zgroup')

def get_mask_names(self):
"""
Called if is_ome_mask is true
"""
# If this is a mask, the names are in root .zattrs
return self.root_attrs.get('masks', [])

def get_json(self, subpath):
raise NotImplementedError("unknown")

Expand Down Expand Up @@ -208,7 +219,6 @@ def load_omero_metadata(self, assert_channel_count=None):

return metadata


def load_ome_zarr(self):

resolutions = ["0"] # TODO: could be first alphanumeric dataset on err
Expand Down Expand Up @@ -266,17 +276,6 @@ def get_json(self, subpath):
with open(filename) as f:
return json.loads(f.read())

def has_ome_masks(self):
"Does the zarr Image also include /masks sub-dir"
mask_dir = os.path.join(self.zarr_path, 'masks')
return os.path.exists(mask_dir) and os.path.isdir(mask_dir) and self.get_json('masks/.zgroup')

def get_mask_names(self):
dirnames = os.listdir(self.zarr_path)
dirnames = [name for name in dirnames if os.path.isdir(
os.path.join(self.zarr_path, name))]
return dirnames

class RemoteZarr(BaseZarr):

def get_json(self, subpath):
Expand All @@ -294,19 +293,6 @@ def get_json(self, subpath):
LOGGER.error(f"({rsp.status_code}): {rsp.text}")
return {}

def get_mask_names(self):
# If this is a mask, the names are in root .zattrs
masks = self.root_attrs.get('masks')
if masks is not None:
return masks
return []

def has_ome_masks(self):
# check for /masks/.zattrs with 'masks' key
mask_attrs = self.get_json('masks/.zattrs')
masks = mask_attrs.get('masks')
return masks is not None and len(masks) > 0

def info(path):
"""
print information about the ome-zarr fileset
Expand Down