Skip to content

Commit

Permalink
Check if a plate or an image zarr_url is loaded
Browse files Browse the repository at this point in the history
Translate label and rectangle position if the zarr_url contains a plate and but not if only a single well is loaded.
  • Loading branch information
fdsteffen committed Oct 1, 2024
1 parent 8dc1bed commit e24850a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
16 changes: 14 additions & 2 deletions src/napari_ome_zarr_navigator/img_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ def __init__(self, viewer: "napari.viewer.Viewer"):
def initialize_filters(self):
self.zarr_dict = parse_zarr_url(self.zarr_dir.value)
self.zarr_root = self.zarr_dict["root"]

if self.zarr_root == self.zarr_dir.value:
self.is_plate = True
else:
self.is_plate = False
if self.zarr_root:
adt = self.load_table()
if adt:
Expand Down Expand Up @@ -206,7 +211,11 @@ def load_roi(self):
self.viewer.window.remove_dock_widget(self.roi_widget)

self.roi_loader = ROILoaderPlate(
self.viewer, str(self.zarr_root), row_alpha[0], col_str[0]
self.viewer,
str(self.zarr_root),
row_alpha[0],
col_str[0],
self.is_plate,
)
self.roi_widget = self.viewer.window.add_dock_widget(
widget=self.roi_loader,
Expand All @@ -233,7 +242,10 @@ def go_to_well(self):
top_left_corner,
bottom_right_corner,
) = calculate_well_positions(
plate_url=self.zarr_root, row=well[0], col=well[1]
plate_url=self.zarr_root,
row=well[0],
col=well[1],
is_plate=self.is_plate,
)
rec = np.array([top_left_corner, bottom_right_corner])
self.viewer.add_shapes(
Expand Down
11 changes: 7 additions & 4 deletions src/napari_ome_zarr_navigator/roi_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,12 @@ def update_image_selection(self):

class ROILoaderPlate(ROILoader):
def __init__(
self, viewer: napari.viewer.Viewer, plate_url: str, row: str, col: str
self,
viewer: napari.viewer.Viewer,
plate_url: str,
row: str,
col: str,
is_plate: bool,
):
self._zarr_picker = ComboBox(label="Image")
self.plate_url = plate_url.rstrip("/")
Expand All @@ -416,9 +421,7 @@ def __init__(

# Calculate base translation for a given well
self.translation, _ = calculate_well_positions(
plate_url=plate_url,
row=row,
col=col,
plate_url=plate_url, row=row, col=col, is_plate=is_plate
)

# # Handle defaults for plate loading
Expand Down
4 changes: 2 additions & 2 deletions src/napari_ome_zarr_navigator/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def add_features_to_labels(
pass


def calculate_well_positions(plate_url, row, col, plate=True):
def calculate_well_positions(plate_url, row, col, is_plate=True):
dataset = 0
level = 0
zarr_url = f"{plate_url}/{row}/{col}/{dataset}"
Expand All @@ -70,7 +70,7 @@ def calculate_well_positions(plate_url, row, col, plate=True):
row = rows.index(row)
col = cols.index(col)

if plate:
if is_plate:
top_left_corner = [
row * scale[0] * shape[0],
col * scale[1] * shape[1],
Expand Down

0 comments on commit e24850a

Please sign in to comment.