From c76547f52fb508f9438acbf17e2a868f72293184 Mon Sep 17 00:00:00 2001 From: Lorenzo Gaifas Date: Fri, 12 Jul 2024 12:28:59 +0200 Subject: [PATCH] Add units and axis labels (#175) --- src/blik/reader.py | 22 ++++++++++++++-------- src/blik/widgets/main_widget.py | 10 +++++++++- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/blik/reader.py b/src/blik/reader.py index 4f9d6ba..db33501 100644 --- a/src/blik/reader.py +++ b/src/blik/reader.py @@ -8,14 +8,10 @@ import pandas as pd from cryotypes.image import ImageProtocol from cryotypes.poseset import PoseSetProtocol -from packaging.version import parse as parse_version from scipy.spatial.transform import Rotation from .utils import generate_vectors, invert_xyz -NAPARI_050 = parse_version(version("napari")) >= parse_version("0.5.0a") - - def get_reader(path): return read_layers @@ -42,11 +38,13 @@ def _construct_positions_layer( "scale": [scale] * 3, "shading": "spherical", "antialiasing": 0, + "border_width": 0, "metadata": {"experiment_id": exp_id, "p_id": p_id, "source": source}, "out_of_slice_display": True, + "projection_mode": "all", + "axis_labels": ('z', 'y', 'x'), + "units": 'angstrom', **pt_kwargs, - **({"projection_mode": "all"} if NAPARI_050 else {}), - **({"border_width": 0} if NAPARI_050 else {"edge_width": 0}), }, "points", ) @@ -72,7 +70,9 @@ def _construct_orientations_layer( "metadata": {"experiment_id": exp_id, "p_id": p_id, "source": source}, "vector_style": "arrow", "out_of_slice_display": True, - **({"projection_mode": "all"} if NAPARI_050 else {}), + "projection_mode": "all", + "axis_labels": ('z', 'y', 'x'), + "units": 'angstrom', }, "vectors", ) @@ -178,7 +178,9 @@ def read_image(image): "depiction": "plane", "blending": "translucent", "plane": {"thickness": 5}, - **({"projection_mode": "mean"} if NAPARI_050 else {}), + "projection_mode": "mean", + "axis_labels": ('z', 'y', 'x'), + "units": 'angstrom', }, "image", ) @@ -210,6 +212,8 @@ def read_surface_picks(path): "edge_color": "surface_id", "shape_type": "path", "ndim": 3, + "axis_labels": ('z', 'y', 'x'), + "units": 'angstrom', }, "shapes", ) @@ -232,6 +236,8 @@ def read_surface(path): "scale": scale, # TODO: needs to exposed in napari # colormap=colormap + "axis_labels": ('z', 'y', 'x'), + "units": 'angstrom', }, "surface", ) diff --git a/src/blik/widgets/main_widget.py b/src/blik/widgets/main_widget.py index 6054dcc..b33ea66 100644 --- a/src/blik/widgets/main_widget.py +++ b/src/blik/widgets/main_widget.py @@ -76,8 +76,10 @@ def _attach_callbacks_to_viewer(wdg): viewer.layers.events.inserted.connect(lambda e: _connect_layers(viewer, e)) _connect_layers(viewer, None) - viewer.scale_bar.unit = "0.1nm" # pixels are 1 A + # pixels are 1 A. We put 0.1nm cause it's more readable with multiples + viewer.scale_bar.unit = "0.1nm" viewer.scale_bar.visible = True + viewer.dims.axis_labels = ['z', 'y', 'x'] def _connect_layers(viewer, e): @@ -173,6 +175,8 @@ def new( np.zeros(lay.data.shape, dtype=np.int32), name=f"{exp_id} - segmentation", scale=lay.scale, + axis_labels=('z', 'y', 'x'), + units='angstrom', metadata={ "experiment_id": exp_id, "stack": lay.metadata["stack"], @@ -203,6 +207,8 @@ def new( edge_color_cycle=np.random.rand(30, 3), edge_color="surface_id", ndim=3, + axis_labels=('z', 'y', 'x'), + units='angstrom', ) return [pts] @@ -216,6 +222,8 @@ def new( metadata={"experiment_id": exp_id}, face_color_cycle=np.random.rand(30, 3), ndim=3, + axis_labels=('z', 'y', 'x'), + units='angstrom', ) return [pts]