annotate render.py @ 0:7d6be2b7e1e2 draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
author imgteam
date Mon, 05 Jan 2026 20:10:28 +0000
parents
children 31a2e1909ae5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
1 import giatools
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
2 import libcarna
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
3 import libcarna._imshow
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
4 import pandas as pd
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
5
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
6 # Fail early if an optional backend is not available
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
7 giatools.require_backend('omezarr')
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
8
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
9 # Patch `libcarna._imshow` to return plain HTML
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
10 libcarna._imshow.IPythonHTML = lambda html: html
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
11
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
12
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
13 GEOMETRY_TYPE_INTENSITIES = 0
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
14 GEOMETRY_TYPE_MASK = 1
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
15
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
16
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
17 def wrap_color(params: dict) -> dict:
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
18 """
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
19 Return the `params` dictionary but wrap values for `color` with `libcarna.color`.
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
20 """
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
21 result = dict()
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
22 for key, value in params.items():
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
23 if key == 'color':
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
24 value = libcarna.color(value)
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
25 result[key] = value
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
26 return result
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
27
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
28
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
29 if __name__ == "__main__":
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
30 tool = giatools.ToolBaseplate()
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
31 tool.add_input_image('intensities')
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
32 tool.add_input_image('mask', required=False)
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
33 tool.parser.add_argument('--colormap', type=str)
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
34 tool.parser.add_argument('--html', type=str)
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
35 tool.parse_args()
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
36
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
37 # Load custom colormap
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
38 if tool.args.raw_args.colormap:
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
39 df_colormap = pd.read_csv(tool.args.raw_args.colormap, delimiter='\t')
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
40
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
41 # Validate the input image(s)
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
42 try:
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
43 for image in tool.args.input_images.values():
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
44 if any(image.shape[image.axes.index(axis)] > 1 for axis in image.axes if axis not in 'ZYX'):
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
45 raise ValueError(f'This tool is not applicable to images with {image.original_axes} axes.')
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
46
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
47 # Create and configure frame renderer
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
48 print('Sample rate:', tool.args.params['sample_rate'])
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
49 mode = getattr(libcarna, tool.args.params['mode'])(
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
50 GEOMETRY_TYPE_INTENSITIES,
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
51 sr=tool.args.params['sample_rate'],
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
52 **tool.args.params['mode_kwargs']
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
53 )
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
54 mask_renderer = libcarna.mask_renderer(
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
55 GEOMETRY_TYPE_MASK,
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
56 sr=tool.args.params['sample_rate'],
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
57 **wrap_color(tool.args.params['mask_renderer_kwargs']),
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
58 )
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
59 r = libcarna.renderer(
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
60 tool.args.params['width'],
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
61 tool.args.params['height'],
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
62 [mode, mask_renderer],
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
63 )
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
64 print('EGL Vendor:', r.gl_context.vendor)
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
65
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
66 # Build the scene graph
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
67 root = libcarna.node()
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
68 intensities = tool.args.input_images['intensities']
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
69 intensities_volume = libcarna.volume(
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
70 GEOMETRY_TYPE_INTENSITIES,
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
71 intensities.normalize_axes_like(tool.args.params['axes']).data,
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
72 parent=root,
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
73 spacing=[
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
74 {
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
75 'X': intensities.metadata.pixel_size[0] or 1,
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
76 'Y': intensities.metadata.pixel_size[1] or 1,
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
77 'Z': intensities.metadata.z_spacing or 1,
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
78 }
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
79 [axis] for axis in tool.args.params['axes']
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
80 ],
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
81 normals=(tool.args.params['mode'] == 'dvr'),
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
82 )
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
83 camera = libcarna.camera(
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
84 parent=root,
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
85 ).frustum(
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
86 **tool.args.params['camera']['kwargs'],
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
87 ).translate(
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
88 z=tool.args.params['camera']['distance'],
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
89 )
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
90 if (mask := tool.args.input_images.get('mask')):
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
91 libcarna.volume(
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
92 GEOMETRY_TYPE_MASK,
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
93 mask.normalize_axes_like(tool.args.params['axes']).data,
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
94 parent=intensities_volume,
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
95 spacing=intensities_volume.spacing,
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
96 )
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
97
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
98 # Apply colormap
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
99 if tool.args.params['colormap'] == 'custom':
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
100 mode.cmap.clear()
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
101 i0, color0 = None, None
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
102 for row in df_colormap.to_dict(orient='records'):
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
103 match row['type']:
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
104 case 'relative':
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
105 i1 = row['intensity']
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
106 case 'absolute':
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
107 i1 = intensities_volume.normalized(row['intensity'])
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
108 case _:
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
109 raise ValueError('Unknown intensity type: "{}"'.format(row['type']))
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
110 color1 = libcarna.color(row['color'])
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
111 if i0 is not None:
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
112 mode.cmap.linear_segment(i0, i1, color0, color1)
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
113 i0, color0 = i1, color1
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
114 else:
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
115 cmap_kwargs = dict()
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
116 if (ramp_params := tool.args.params['ramp']):
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
117 ramp_values = list()
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
118 for val_type, value in (
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
119 (ramp_params['start_type'], ramp_params['start_value']),
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
120 (ramp_params['end_type'], ramp_params['end_value']),
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
121 ):
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
122 ramp_values.append(
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
123 value if val_type == 'relative' else intensities_volume.normalized(value),
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
124 )
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
125 cmap_kwargs['ramp'] = tuple(ramp_values)
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
126 mode.cmap(tool.args.params['colormap'], **cmap_kwargs)
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
127
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
128 # Render
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
129 html = libcarna.imshow(
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
130 libcarna.animate(
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
131 libcarna.animate.rotate_local(camera),
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
132 n_frames=tool.args.params['video']['frames'],
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
133 ).render(r, camera),
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
134 mode.cmap.bar(intensities_volume),
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
135 fps=tool.args.params['video']['fps'],
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
136 )
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
137
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
138 # Write the result
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
139 with open(tool.args.raw_args.html, 'w') as fhtml:
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
140 fhtml.write(html)
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
141
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
142 except ValueError as err:
7d6be2b7e1e2 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
143 exit(err.args[0])