Skip to content

Commit

Permalink
Merge pull request #1 from joshmoore/handle_masks
Browse files Browse the repository at this point in the history
masks: unify remote and local handling
  • Loading branch information
will-moore authored Jul 7, 2020
2 parents e59d928 + ec13afd commit e69f9fe
Showing 1 changed file with 11 additions and 25 deletions.
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

0 comments on commit e69f9fe

Please sign in to comment.