Skip to content

Commit

Permalink
allow getting also highest-resolution pyramid level with _digest_pyra…
Browse files Browse the repository at this point in the history
…mid_level

Co-authored-by: Silvia Barbiero <[email protected]>
Co-authored-by: Charlotte Soneson <[email protected]>
Co-authored-by: Michael Stadler <[email protected]>
  • Loading branch information
3 people committed Aug 8, 2024
1 parent 3e52e7a commit f251ada
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/ez_zarr/ome_zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,29 +278,37 @@ def _find_path_of_highest_resolution_level(datasets: list[dict[str, Any]]) -> Op
minx = datasets[i]['coordinateTransformations'][0]['scale'][-1]
return lev

def _digest_pyramid_level_argument(self, pyramid_level=None, label_name=None) -> str:
def _digest_pyramid_level_argument(self,
pyramid_level=None,
label_name=None,
default_to='lowest') -> str:
"""
[internal] Interpret a `pyramid_level` argument in the context of a given Image object.
Parameters:
pyramid_level (int, str or None): pyramid level, coerced to str. If None,
the last pyramid level (typically the lowest-resolution one) will be returned.
the lowest-resolution pyramid level (or the highest-resolution one,
if `default_to='highest'`) will be returned.
label_name (str or None): defines what `pyramid_level` refers to. If None,
it refers to the intensity image. Otherwise, it refers to a label with
the name given by `label_name`. For example, to select the 'nuclei' labels,
the argument would be set to `nuclei`.
the name given by `label_name`. For example, to select the 'nuclei'
labels, the argument would be set to `nuclei`.
default_to (str): Defines what pyramid level to return if `pyramid_level`
is `None`. Currently supported are `'lowest'` and `'highest'`.
Returns:
Integer index of the pyramid level.
"""
if label_name is not None and label_name not in self.label_names:
raise ValueError(f"invalid label name '{label_name}' - must be one of {self.label_names}")
if pyramid_level == None:
# no pyramid level given -> pick lowest resolution one
# no pyramid level given -> pick according to `default_to`
methods = {'lowest': self._find_path_of_lowest_resolution_level,
'highest': self._find_path_of_highest_resolution_level}
if label_name is None: # intensity image
pyramid_level = self._find_path_of_lowest_resolution_level(self.multiscales_image['datasets'])
pyramid_level = methods[default_to](self.multiscales_image['datasets'])
else: # label image
pyramid_level = self._find_path_of_lowest_resolution_level(self.multiscales_labels[label_name]['datasets'])
pyramid_level = methods[default_to](self.multiscales_labels[label_name]['datasets'])
else:
# make sure it is a string
pyramid_level = str(pyramid_level)
Expand Down

0 comments on commit f251ada

Please sign in to comment.