Skip to content

Commit

Permalink
Merge branch 'main' into feat-support-other-annos
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-sweet committed May 15, 2024
2 parents 8efcc9b + 8f5c5c5 commit 7455469
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/napari_cryoet_data_portal/_open_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ def _loadTomogram(
) -> Generator[FullLayerData, None, None]:
logger.debug("OpenWidget._loadTomogram: %s", tomogram.name)
image_layer = read_tomogram(tomogram)
# Extract image_scale before the resolution is taken into account.
image_scale = image_layer[1]["scale"]
yield _handle_image_at_resolution(image_layer, resolution)

# Looking up tomogram.tomogram_voxel_spacing.annotations triggers a query
Expand All @@ -154,6 +156,8 @@ def _loadTomogram(
for layer in read_annotation_files(annotation, tomogram=tomogram):
if layer[2] == "labels":
layer = _handle_image_at_resolution(layer, resolution=resolution, dtype=np.uint8)
elif layer[2] == "points":
layer = _handle_points_annotation(layer, image_scale)
yield layer

def _onLayerLoaded(self, layer_data: FullLayerData) -> None:
Expand Down Expand Up @@ -193,3 +197,13 @@ def _handle_image_at_resolution(layer_data: FullLayerData, resolution: Resolutio
image_translate = attrs.get("translate", (0,) * len(attrs["scale"]))
attrs["translate"] = tuple(resolution.offset + t for t in image_translate)
return data, attrs, layer_type


def _handle_points_annotation(layer_data: FullLayerData, image_scale: Tuple[float, float, float]) -> FullLayerData:
data, attrs, layer_type = layer_data
# Inherit scale from full resolution image so that we can pick up
# that scale when it changes.
attrs["scale"] = image_scale
# Scaling points also changes the size, so adjust accordingly.
attrs["size"] /= np.mean(image_scale)
return data, attrs, layer_type
4 changes: 3 additions & 1 deletion src/napari_cryoet_data_portal/_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ def read_points_annotations_ndjson(path: str) -> FullLayerData:
"size": 14,
"face_color": "red",
"opacity": 0.5,
"out_of_slice_display": True,
# Disable out-of-slice display because of:
# https://github.com/napari/napari/issues/6914
"out_of_slice_display": False,
}
return data, attributes, "points"

Expand Down

0 comments on commit 7455469

Please sign in to comment.