Skip to content

Commit

Permalink
fix minor issue in update omero window
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzocerrone committed Nov 5, 2024
1 parent 0ec7b1a commit fa7a405
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/ngio/core/ngff_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,18 @@ def get_image(
ngio_logger.info(f"- {image.pixel_size}")
return image

def _update_omero_window(
def update_omero_window(
self, start_percentile: int = 5, end_percentile: int = 95
) -> None:
"""Update the OMERO window."""
"""Update the OMERO window.
This will setup percentiles based values for the window of each channel.
Args:
start_percentile (int): The start percentile.
end_percentile (int): The end percentile
"""
meta = self.image_meta

lowest_res_image = self.get_image(highest_resolution=True)
Expand All @@ -102,24 +110,25 @@ def _update_omero_window(
num_c = lowest_res_image.dimensions.get("c", 1)

if meta.omero is None:
# TODO:
raise ValueError("OMERO metadata is not present in the image.")
raise NotImplementedError(
"OMERO metadata not found. " " Please add OMERO metadata to the image."
)

channel_list = meta.omero.channels
if len(channel_list) != num_c:
raise ValueError("The number of channels does not match the image.")

for c, channel in enumerate(channel_list):
data = image.get_array(c=c, mode="dask").ravel()
start_percentile = da.percentile(
_start_percentile = da.percentile(
data, start_percentile, method="nearest"
).compute()
end_percentile = da.percentile(
data, start_percentile, method="nearest"
_end_percentile = da.percentile(
data, end_percentile, method="nearest"
).compute()
channel.extra_fields["window"] = {
"start": start_percentile,
"end": end_percentile,
"start": _start_percentile,
"end": _end_percentile,
"min": 0,
"max": max_dtype,
}
Expand Down

0 comments on commit fa7a405

Please sign in to comment.