Mercurial > repos > imgteam > libcarna_render
annotate render.py @ 4:a9f10dceb17e draft default tip
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 99d6ebe67515f1362ea4412b143ab2a140c8d631
| author | imgteam |
|---|---|
| date | Tue, 13 Jan 2026 12:21:55 +0000 |
| parents | 31a2e1909ae5 |
| children |
| 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, |
|
4
a9f10dceb17e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 99d6ebe67515f1362ea4412b143ab2a140c8d631
imgteam
parents:
3
diff
changeset
|
73 units=tool.args.params['units'], |
|
0
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
74 spacing=[ |
|
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
75 { |
|
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
76 '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
|
77 '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
|
78 '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
|
79 } |
|
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
80 [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
|
81 ], |
|
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
82 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
|
83 ) |
|
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
84 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
|
85 parent=root, |
|
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
86 ).frustum( |
|
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
87 **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
|
88 ).translate( |
|
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
89 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
|
90 ) |
|
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
91 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
|
92 libcarna.volume( |
|
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
93 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
|
94 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
|
95 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
|
96 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
|
97 ) |
|
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
98 |
|
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
99 # Apply colormap |
|
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 case 'relative': |
|
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
106 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
|
107 case 'absolute': |
|
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
108 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
|
109 case _: |
|
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
110 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
|
111 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
|
112 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
|
113 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
|
114 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
|
115 else: |
|
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
116 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
|
117 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
|
118 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
|
119 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
|
120 (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
|
121 (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
|
122 ): |
|
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
123 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
|
124 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
|
125 ) |
|
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
126 cmap_kwargs['ramp'] = tuple(ramp_values) |
|
4
a9f10dceb17e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 99d6ebe67515f1362ea4412b143ab2a140c8d631
imgteam
parents:
3
diff
changeset
|
127 cmap_kwargs['n_samples'] = 1000 # high precision is required when sampling ramps to avoid "soft" corners |
|
0
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
128 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
|
129 |
|
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
130 # Render |
|
3
31a2e1909ae5
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 9abf60fee6ba4f5d4f4a18d8f4d33e6263b3c065
imgteam
parents:
0
diff
changeset
|
131 colorbars = list() |
|
31a2e1909ae5
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 9abf60fee6ba4f5d4f4a18d8f4d33e6263b3c065
imgteam
parents:
0
diff
changeset
|
132 if tool.args.params['colorbar']: |
|
31a2e1909ae5
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 9abf60fee6ba4f5d4f4a18d8f4d33e6263b3c065
imgteam
parents:
0
diff
changeset
|
133 colorbars.append(mode.cmap.bar(intensities_volume)) |
|
0
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
134 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
|
135 libcarna.animate( |
|
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
136 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
|
137 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
|
138 ).render(r, camera), |
|
3
31a2e1909ae5
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 9abf60fee6ba4f5d4f4a18d8f4d33e6263b3c065
imgteam
parents:
0
diff
changeset
|
139 *colorbars, |
|
0
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
140 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
|
141 ) |
|
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
142 |
|
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
143 # 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
|
144 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
|
145 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
|
146 |
|
7d6be2b7e1e2
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/libcarna/ commit 20db59ffe2a97f25d82ba02e451bf73f93ef84ee
imgteam
parents:
diff
changeset
|
147 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
|
148 exit(err.args[0]) |
