annotate render.py @ 0:8cd3d5261f28 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:11:01 +0000
parents
children e07bfdcb1d26
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
1 import giatools
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
2 import libcarna
8cd3d5261f28 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
8cd3d5261f28 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
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
5
8cd3d5261f28 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
8cd3d5261f28 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')
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
8
8cd3d5261f28 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
8cd3d5261f28 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
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
11
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
12
8cd3d5261f28 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
8cd3d5261f28 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
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
15
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
16
8cd3d5261f28 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:
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
18 """
8cd3d5261f28 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`.
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
20 """
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
21 result = dict()
8cd3d5261f28 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():
8cd3d5261f28 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':
8cd3d5261f28 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)
8cd3d5261f28 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
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
26 return result
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
27
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
28
8cd3d5261f28 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__":
8cd3d5261f28 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()
8cd3d5261f28 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')
8cd3d5261f28 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)
8cd3d5261f28 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)
8cd3d5261f28 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)
8cd3d5261f28 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()
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
36
8cd3d5261f28 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
8cd3d5261f28 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:
8cd3d5261f28 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')
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
40
8cd3d5261f28 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)
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
42 try:
8cd3d5261f28 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():
8cd3d5261f28 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'):
8cd3d5261f28 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.')
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
46
8cd3d5261f28 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
8cd3d5261f28 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'])
8cd3d5261f28 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'])(
8cd3d5261f28 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,
8cd3d5261f28 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'],
8cd3d5261f28 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']
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
53 )
8cd3d5261f28 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(
8cd3d5261f28 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,
8cd3d5261f28 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'],
8cd3d5261f28 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']),
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
58 )
8cd3d5261f28 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(
8cd3d5261f28 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'],
8cd3d5261f28 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'],
8cd3d5261f28 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],
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
63 )
8cd3d5261f28 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)
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
65
8cd3d5261f28 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
8cd3d5261f28 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()
8cd3d5261f28 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']
8cd3d5261f28 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(
8cd3d5261f28 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,
8cd3d5261f28 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,
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
72 parent=root,
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
73 spacing=[
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
74 {
8cd3d5261f28 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,
8cd3d5261f28 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,
8cd3d5261f28 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,
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
78 }
8cd3d5261f28 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']
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
80 ],
8cd3d5261f28 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'),
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
82 )
8cd3d5261f28 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(
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
84 parent=root,
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
85 ).frustum(
8cd3d5261f28 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'],
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
87 ).translate(
8cd3d5261f28 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'],
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
89 )
8cd3d5261f28 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')):
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
91 libcarna.volume(
8cd3d5261f28 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,
8cd3d5261f28 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,
8cd3d5261f28 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,
8cd3d5261f28 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,
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
96 )
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
97
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
98 # Apply colormap
8cd3d5261f28 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':
8cd3d5261f28 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()
8cd3d5261f28 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
8cd3d5261f28 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'):
8cd3d5261f28 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']:
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
104 case 'relative':
8cd3d5261f28 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']
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
106 case 'absolute':
8cd3d5261f28 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'])
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
108 case _:
8cd3d5261f28 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']))
8cd3d5261f28 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'])
8cd3d5261f28 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:
8cd3d5261f28 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)
8cd3d5261f28 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
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
114 else:
8cd3d5261f28 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()
8cd3d5261f28 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']):
8cd3d5261f28 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()
8cd3d5261f28 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 (
8cd3d5261f28 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']),
8cd3d5261f28 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']),
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
121 ):
8cd3d5261f28 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(
8cd3d5261f28 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),
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
124 )
8cd3d5261f28 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)
8cd3d5261f28 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)
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
127
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
128 # Render
8cd3d5261f28 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(
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
130 libcarna.animate(
8cd3d5261f28 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),
8cd3d5261f28 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'],
8cd3d5261f28 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),
8cd3d5261f28 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),
8cd3d5261f28 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'],
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
136 )
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
137
8cd3d5261f28 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
8cd3d5261f28 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:
8cd3d5261f28 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)
8cd3d5261f28 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff changeset
141
8cd3d5261f28 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:
8cd3d5261f28 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])