Skip to content

Commit

Permalink
Use image scale for points annotations (#29)
Browse files Browse the repository at this point in the history
This introduces a workaround for handling a pending change to the
physical scale and units of the OME-Zarr metadata:
chanzuckerberg/cryoet-data-portal-backend#24

The workaround is to use the highest-resolution image scale from the
tomogram image, and also use it for the annotation points layer because
its coordinates are given in the data space of the highest resolution
image.

This should not change the behavior with respect to the existing
OME-Zarrs (which have a high-res scale of 1), but should ensure that the
points remain aligned with the images when the scale change comes in.

An alternative fix would have been to multiply the points data with the
scale, but I avoided this because it mutates the primary data rather
than its visualization.
  • Loading branch information
andy-sweet authored Apr 1, 2024
1 parent e285545 commit 8f5c5c5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/napari_cryoet_data_portal/_open_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,10 @@ def _loadTomogram(
# Materialize low resolution immediately on this thread to prevent napari blocking.
if resolution is LOW_RESOLUTION:
image_data = np.asarray(image_data)
# Get scale before resolution scaling for annotations.
image_scale = image_attrs["scale"]
image_attrs["scale"] = tuple(
resolution.scale * s for s in image_attrs["scale"]
resolution.scale * s for s in image_scale
)
image_translate = image_attrs.get("translate", (0,) * len(image_attrs["scale"]))
image_attrs["translate"] = tuple(
Expand All @@ -171,7 +173,13 @@ def _loadTomogram(
if f.shape_type == "Point"
)
if len(point_paths) > 0:
yield read_annotation(annotation, tomogram=tomogram)
anno_data, anno_attrs, anno_type = read_annotation(annotation, tomogram=tomogram)
# Inherit scale from full resolution image so that we can pick up
# that scale when it changes.
anno_attrs["scale"] = image_scale
# Scaling points also changes the size, so adjust accordingly.
anno_attrs["size"] /= np.mean(image_scale)
yield anno_data, anno_attrs, anno_type
else:
logger.warn("Found no points annotations. Skipping.")

Expand Down

0 comments on commit 8f5c5c5

Please sign in to comment.