Skip to content

Commit

Permalink
Add units and axis labels (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
brisvag authored Jul 12, 2024
1 parent 1ddd0d2 commit c76547f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
22 changes: 14 additions & 8 deletions src/blik/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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",
)
Expand All @@ -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",
)
Expand Down Expand Up @@ -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",
)
Expand Down Expand Up @@ -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",
)
Expand All @@ -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",
)
Expand Down
10 changes: 9 additions & 1 deletion src/blik/widgets/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"],
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand Down

0 comments on commit c76547f

Please sign in to comment.