Mercurial > repos > rv43 > tomo
annotate workflow/run_tomo.py @ 75:d5e1d4ea2b7e draft default tip
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
author | rv43 |
---|---|
date | Thu, 23 Mar 2023 13:39:14 +0000 |
parents | 1cf15b61cd83 |
children |
rev | line source |
---|---|
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
2 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
3 import logging |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
4 logger = logging.getLogger(__name__) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
5 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
6 import numpy as np |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
7 try: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
8 import numexpr as ne |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
9 except: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
10 pass |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
11 try: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
12 import scipy.ndimage as spi |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
13 except: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
14 pass |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
15 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
16 from multiprocessing import cpu_count |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
17 from nexusformat.nexus import * |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
18 from os import mkdir, environ |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
19 from os import path as os_path |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
20 try: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
21 from skimage.transform import iradon |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
22 except: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
23 pass |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
24 try: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
25 from skimage.restoration import denoise_tv_chambolle |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
26 except: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
27 pass |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
28 from time import time |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
29 try: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
30 import tomopy |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
31 except: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
32 pass |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
33 from yaml import safe_load, safe_dump |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
34 |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
35 try: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
36 from msnctools.fit import Fit |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
37 except: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
38 from fit import Fit |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
39 try: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
40 from msnctools.general import illegal_value, is_int, is_int_pair, is_num, is_index_range, \ |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
41 input_int, input_num, input_yesno, input_menu, draw_mask_1d, select_image_bounds, \ |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
42 select_one_image_bound, clear_imshow, quick_imshow, clear_plot, quick_plot |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
43 except: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
44 from general import illegal_value, is_int, is_int_pair, is_num, is_index_range, \ |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
45 input_int, input_num, input_yesno, input_menu, draw_mask_1d, select_image_bounds, \ |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
46 select_one_image_bound, clear_imshow, quick_imshow, clear_plot, quick_plot |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
47 |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
48 try: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
49 from workflow.models import import_scanparser, FlatField, TomoField, TomoWorkflow |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
50 from workflow.__version__ import __version__ |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
51 except: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
52 pass |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
53 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
54 num_core_tomopy_limit = 24 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
55 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
56 def nxcopy(nxobject:NXobject, exclude_nxpaths:list[str]=[], nxpath_prefix:str='') -> NXobject: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
57 '''Function that returns a copy of a nexus object, optionally exluding certain child items. |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
58 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
59 :param nxobject: the original nexus object to return a "copy" of |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
60 :type nxobject: nexusformat.nexus.NXobject |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
61 :param exlude_nxpaths: a list of paths to child nexus objects that |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
62 should be exluded from the returned "copy", defaults to `[]` |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
63 :type exclude_nxpaths: list[str], optional |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
64 :param nxpath_prefix: For use in recursive calls from inside this |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
65 function only! |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
66 :type nxpath_prefix: str |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
67 :return: a copy of `nxobject` with some children optionally exluded. |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
68 :rtype: NXobject |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
69 ''' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
70 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
71 nxobject_copy = nxobject.__class__() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
72 if not len(nxpath_prefix): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
73 if 'default' in nxobject.attrs: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
74 nxobject_copy.attrs['default'] = nxobject.attrs['default'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
75 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
76 for k, v in nxobject.attrs.items(): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
77 nxobject_copy.attrs[k] = v |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
78 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
79 for k, v in nxobject.items(): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
80 nxpath = os_path.join(nxpath_prefix, k) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
81 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
82 if nxpath in exclude_nxpaths: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
83 continue |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
84 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
85 if isinstance(v, NXgroup): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
86 nxobject_copy[k] = nxcopy(v, exclude_nxpaths=exclude_nxpaths, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
87 nxpath_prefix=os_path.join(nxpath_prefix, k)) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
88 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
89 nxobject_copy[k] = v |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
90 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
91 return(nxobject_copy) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
92 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
93 class set_numexpr_threads: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
94 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
95 def __init__(self, num_core): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
96 if num_core is None or num_core < 1 or num_core > cpu_count(): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
97 self.num_core = cpu_count() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
98 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
99 self.num_core = num_core |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
100 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
101 def __enter__(self): |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
102 self.num_core_org = ne.set_num_threads(min(self.num_core, ne.MAX_THREADS)) |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
103 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
104 def __exit__(self, exc_type, exc_value, traceback): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
105 ne.set_num_threads(self.num_core_org) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
106 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
107 class Tomo: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
108 """Processing tomography data with misalignment. |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
109 """ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
110 def __init__(self, galaxy_flag=False, num_core=-1, output_folder='.', save_figs=None, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
111 test_mode=False): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
112 """Initialize with optional config input file or dictionary |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
113 """ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
114 if not isinstance(galaxy_flag, bool): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
115 raise ValueError(f'Invalid parameter galaxy_flag ({galaxy_flag})') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
116 self.galaxy_flag = galaxy_flag |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
117 self.num_core = num_core |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
118 if self.galaxy_flag: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
119 if output_folder != '.': |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
120 logger.warning('Ignoring output_folder in galaxy mode') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
121 self.output_folder = '.' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
122 if test_mode != False: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
123 logger.warning('Ignoring test_mode in galaxy mode') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
124 self.test_mode = False |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
125 if save_figs is not None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
126 logger.warning('Ignoring save_figs in galaxy mode') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
127 save_figs = 'only' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
128 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
129 self.output_folder = os_path.abspath(output_folder) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
130 if not os_path.isdir(output_folder): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
131 mkdir(os_path.abspath(output_folder)) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
132 if not isinstance(test_mode, bool): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
133 raise ValueError(f'Invalid parameter test_mode ({test_mode})') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
134 self.test_mode = test_mode |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
135 if save_figs is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
136 save_figs = 'no' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
137 self.test_config = {} |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
138 if self.test_mode: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
139 if save_figs != 'only': |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
140 logger.warning('Ignoring save_figs in test mode') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
141 save_figs = 'only' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
142 if save_figs == 'only': |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
143 self.save_only = True |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
144 self.save_figs = True |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
145 elif save_figs == 'yes': |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
146 self.save_only = False |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
147 self.save_figs = True |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
148 elif save_figs == 'no': |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
149 self.save_only = False |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
150 self.save_figs = False |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
151 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
152 raise ValueError(f'Invalid parameter save_figs ({save_figs})') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
153 if self.save_only: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
154 self.block = False |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
155 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
156 self.block = True |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
157 if self.num_core == -1: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
158 self.num_core = cpu_count() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
159 if not is_int(self.num_core, gt=0, log=False): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
160 raise ValueError(f'Invalid parameter num_core ({num_core})') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
161 if self.num_core > cpu_count(): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
162 logger.warning(f'num_core = {self.num_core} is larger than the number of available ' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
163 f'processors and reduced to {cpu_count()}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
164 self.num_core= cpu_count() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
165 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
166 def read(self, filename): |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
167 logger.info(f'looking for {filename}') |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
168 if self.galaxy_flag: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
169 try: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
170 with open(filename, 'r') as f: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
171 config = safe_load(f) |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
172 return(config) |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
173 except: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
174 try: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
175 with NXFile(filename, mode='r') as nxfile: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
176 nxroot = nxfile.readfile() |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
177 return(nxroot) |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
178 except: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
179 raise ValueError(f'Unable to open ({filename})') |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
180 else: |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
181 extension = os_path.splitext(filename)[1] |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
182 if extension == '.yml' or extension == '.yaml': |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
183 with open(filename, 'r') as f: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
184 config = safe_load(f) |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
185 # if len(config) > 1: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
186 # raise ValueError(f'Multiple root entries in {filename} not yet implemented') |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
187 # if len(list(config.values())[0]) > 1: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
188 # raise ValueError(f'Multiple sample maps in {filename} not yet implemented') |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
189 return(config) |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
190 elif extension == '.nxs': |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
191 with NXFile(filename, mode='r') as nxfile: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
192 nxroot = nxfile.readfile() |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
193 return(nxroot) |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
194 else: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
195 raise ValueError(f'Invalid filename extension ({extension})') |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
196 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
197 def write(self, data, filename): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
198 extension = os_path.splitext(filename)[1] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
199 if extension == '.yml' or extension == '.yaml': |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
200 with open(filename, 'w') as f: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
201 safe_dump(data, f) |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
202 elif extension == '.nxs' or extension == '.nex': |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
203 data.save(filename, mode='w') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
204 elif extension == '.nc': |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
205 data.to_netcdf(os_path=filename) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
206 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
207 raise ValueError(f'Invalid filename extension ({extension})') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
208 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
209 def gen_reduced_data(self, data, img_x_bounds=None): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
210 """Generate the reduced tomography images. |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
211 """ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
212 logger.info('Generate the reduced tomography images') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
213 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
214 # Create plot galaxy path directory if needed |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
215 if self.galaxy_flag and not os_path.exists('tomo_reduce_plots'): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
216 mkdir('tomo_reduce_plots') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
217 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
218 if isinstance(data, dict): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
219 # Create Nexus format object from input dictionary |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
220 wf = TomoWorkflow(**data) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
221 if len(wf.sample_maps) > 1: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
222 raise ValueError(f'Multiple sample maps not yet implemented') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
223 # print(f'\nwf:\n{wf}\n') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
224 nxroot = NXroot() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
225 t0 = time() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
226 for sample_map in wf.sample_maps: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
227 logger.info(f'Start constructing the {sample_map.title} map.') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
228 import_scanparser(sample_map.station) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
229 sample_map.construct_nxentry(nxroot, include_raw_data=False) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
230 logger.info(f'Constructed all sample maps in {time()-t0:.2f} seconds.') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
231 nxentry = nxroot[nxroot.attrs['default']] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
232 # Get test mode configuration info |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
233 if self.test_mode: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
234 self.test_config = data['sample_maps'][0]['test_mode'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
235 elif isinstance(data, NXroot): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
236 nxentry = data[data.attrs['default']] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
237 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
238 raise ValueError(f'Invalid parameter data ({data})') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
239 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
240 # Create an NXprocess to store data reduction (meta)data |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
241 reduced_data = NXprocess() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
242 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
243 # Generate dark field |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
244 if 'dark_field' in nxentry['spec_scans']: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
245 reduced_data = self._gen_dark(nxentry, reduced_data) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
246 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
247 # Generate bright field |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
248 reduced_data = self._gen_bright(nxentry, reduced_data) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
249 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
250 # Set vertical detector bounds for image stack |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
251 img_x_bounds = self._set_detector_bounds(nxentry, reduced_data, img_x_bounds=img_x_bounds) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
252 logger.info(f'img_x_bounds = {img_x_bounds}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
253 reduced_data['img_x_bounds'] = img_x_bounds |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
254 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
255 # Set zoom and/or theta skip to reduce memory the requirement |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
256 zoom_perc, num_theta_skip = self._set_zoom_or_skip() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
257 if zoom_perc is not None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
258 reduced_data.attrs['zoom_perc'] = zoom_perc |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
259 if num_theta_skip is not None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
260 reduced_data.attrs['num_theta_skip'] = num_theta_skip |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
261 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
262 # Generate reduced tomography fields |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
263 reduced_data = self._gen_tomo(nxentry, reduced_data) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
264 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
265 # Create a copy of the input Nexus object and remove raw and any existing reduced data |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
266 if isinstance(data, NXroot): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
267 exclude_items = [f'{nxentry._name}/reduced_data/data', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
268 f'{nxentry._name}/instrument/detector/data', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
269 f'{nxentry._name}/instrument/detector/image_key', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
270 f'{nxentry._name}/instrument/detector/sequence_number', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
271 f'{nxentry._name}/sample/rotation_angle', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
272 f'{nxentry._name}/sample/x_translation', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
273 f'{nxentry._name}/sample/z_translation', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
274 f'{nxentry._name}/data/data', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
275 f'{nxentry._name}/data/image_key', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
276 f'{nxentry._name}/data/rotation_angle', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
277 f'{nxentry._name}/data/x_translation', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
278 f'{nxentry._name}/data/z_translation'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
279 nxroot = nxcopy(data, exclude_nxpaths=exclude_items) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
280 nxentry = nxroot[nxroot.attrs['default']] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
281 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
282 # Add the reduced data NXprocess |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
283 nxentry.reduced_data = reduced_data |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
284 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
285 if 'data' not in nxentry: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
286 nxentry.data = NXdata() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
287 nxentry.attrs['default'] = 'data' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
288 nxentry.data.makelink(nxentry.reduced_data.data.tomo_fields, name='reduced_data') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
289 nxentry.data.makelink(nxentry.reduced_data.rotation_angle, name='rotation_angle') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
290 nxentry.data.attrs['signal'] = 'reduced_data' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
291 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
292 return(nxroot) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
293 |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
294 def find_centers(self, nxroot, center_rows=None, center_stack_index=None): |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
295 """Find the calibrated center axis info |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
296 """ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
297 logger.info('Find the calibrated center axis info') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
298 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
299 if not isinstance(nxroot, NXroot): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
300 raise ValueError(f'Invalid parameter nxroot ({nxroot})') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
301 nxentry = nxroot[nxroot.attrs['default']] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
302 if not isinstance(nxentry, NXentry): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
303 raise ValueError(f'Invalid nxentry ({nxentry})') |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
304 if center_rows is not None: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
305 if self.galaxy_flag: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
306 if not is_int_pair(center_rows, ge=-1): |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
307 raise ValueError(f'Invalid parameter center_rows ({center_rows})') |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
308 if (center_rows[0] != -1 and center_rows[1] != -1 and |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
309 center_rows[0] > center_rows[1]): |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
310 center_rows = (center_rows[1], center_rows[0]) |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
311 else: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
312 center_rows = tuple(center_rows) |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
313 else: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
314 logger.warning(f'Ignoring parameter center_rows ({center_rows})') |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
315 center_rows = None |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
316 if self.galaxy_flag: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
317 if center_stack_index is not None and not is_int(center_stack_index, ge=0): |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
318 raise ValueError(f'Invalid parameter center_stack_index ({center_stack_index})') |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
319 elif center_stack_index is not None: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
320 logger.warning(f'Ignoring parameter center_stack_index ({center_stack_index})') |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
321 center_stack_index = None |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
322 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
323 # Create plot galaxy path directory and path if needed |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
324 if self.galaxy_flag: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
325 if not os_path.exists('tomo_find_centers_plots'): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
326 mkdir('tomo_find_centers_plots') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
327 path = 'tomo_find_centers_plots' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
328 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
329 path = self.output_folder |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
330 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
331 # Check if reduced data is available |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
332 if ('reduced_data' not in nxentry or 'reduced_data' not in nxentry.data): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
333 raise KeyError(f'Unable to find valid reduced data in {nxentry}.') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
334 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
335 # Select the image stack to calibrate the center axis |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
336 # reduced data axes order: stack,theta,row,column |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
337 # Note: Nexus cannot follow a link if the data it points to is too big, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
338 # so get the data from the actual place, not from nxentry.data |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
339 tomo_fields_shape = nxentry.reduced_data.data.tomo_fields.shape |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
340 if len(tomo_fields_shape) != 4 or any(True for dim in tomo_fields_shape if not dim): |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
341 raise KeyError('Unable to load the required reduced tomography stack') |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
342 num_tomo_stacks = tomo_fields_shape[0] |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
343 if num_tomo_stacks == 1: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
344 center_stack_index = 0 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
345 default = 'n' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
346 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
347 if self.test_mode: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
348 center_stack_index = self.test_config['center_stack_index']-1 # make offset 0 |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
349 elif self.galaxy_flag: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
350 if center_stack_index is None: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
351 center_stack_index = int(num_tomo_stacks/2) |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
352 if center_stack_index >= num_tomo_stacks: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
353 raise ValueError(f'Invalid parameter center_stack_index ({center_stack_index})') |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
354 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
355 center_stack_index = input_int('\nEnter tomography stack index to calibrate the ' |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
356 'center axis', ge=1, le=num_tomo_stacks, default=int(1+num_tomo_stacks/2)) |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
357 center_stack_index -= 1 |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
358 default = 'y' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
359 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
360 # Get thetas (in degrees) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
361 thetas = np.asarray(nxentry.reduced_data.rotation_angle) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
362 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
363 # Get effective pixel_size |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
364 if 'zoom_perc' in nxentry.reduced_data: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
365 eff_pixel_size = 100.*(nxentry.instrument.detector.x_pixel_size/ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
366 nxentry.reduced_data.attrs['zoom_perc']) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
367 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
368 eff_pixel_size = nxentry.instrument.detector.x_pixel_size |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
369 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
370 # Get cross sectional diameter |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
371 cross_sectional_dim = tomo_fields_shape[3]*eff_pixel_size |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
372 logger.debug(f'cross_sectional_dim = {cross_sectional_dim}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
373 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
374 # Determine center offset at sample row boundaries |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
375 logger.info('Determine center offset at sample row boundaries') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
376 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
377 # Lower row center |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
378 if self.test_mode: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
379 lower_row = self.test_config['lower_row'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
380 elif self.galaxy_flag: |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
381 if center_rows is None or center_rows[0] == -1: |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
382 lower_row = 0 |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
383 else: |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
384 lower_row = center_rows[0] |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
385 if not 0 <= lower_row < tomo_fields_shape[2]-1: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
386 raise ValueError(f'Invalid parameter center_rows ({center_rows})') |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
387 else: |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
388 lower_row = select_one_image_bound( |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
389 nxentry.reduced_data.data.tomo_fields[center_stack_index,0,:,:], 0, bound=0, |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
390 title=f'theta={round(thetas[0], 2)+0}', |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
391 bound_name='row index to find lower center', default=default, raise_error=True) |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
392 logger.debug('Finding center...') |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
393 t0 = time() |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
394 lower_center_offset = self._find_center_one_plane( |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
395 nxentry.reduced_data.data.tomo_fields[center_stack_index,:,lower_row,:], |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
396 lower_row, thetas, eff_pixel_size, cross_sectional_dim, path=path, |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
397 num_core=self.num_core) |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
398 logger.debug(f'... done in {time()-t0:.2f} seconds') |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
399 logger.debug(f'lower_row = {lower_row:.2f}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
400 logger.debug(f'lower_center_offset = {lower_center_offset:.2f}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
401 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
402 # Upper row center |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
403 if self.test_mode: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
404 upper_row = self.test_config['upper_row'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
405 elif self.galaxy_flag: |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
406 if center_rows is None or center_rows[1] == -1: |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
407 upper_row = tomo_fields_shape[2]-1 |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
408 else: |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
409 upper_row = center_rows[1] |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
410 if not lower_row < upper_row < tomo_fields_shape[2]: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
411 raise ValueError(f'Invalid parameter center_rows ({center_rows})') |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
412 else: |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
413 upper_row = select_one_image_bound( |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
414 nxentry.reduced_data.data.tomo_fields[center_stack_index,0,:,:], 0, |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
415 bound=tomo_fields_shape[2]-1, title=f'theta={round(thetas[0], 2)+0}', |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
416 bound_name='row index to find upper center', default=default, raise_error=True) |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
417 logger.debug('Finding center...') |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
418 t0 = time() |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
419 upper_center_offset = self._find_center_one_plane( |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
420 #np.asarray(nxentry.reduced_data.data.tomo_fields[center_stack_index,:,upper_row,:]), |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
421 nxentry.reduced_data.data.tomo_fields[center_stack_index,:,upper_row,:], |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
422 upper_row, thetas, eff_pixel_size, cross_sectional_dim, path=path, |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
423 num_core=self.num_core) |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
424 logger.debug(f'... done in {time()-t0:.2f} seconds') |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
425 logger.debug(f'upper_row = {upper_row:.2f}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
426 logger.debug(f'upper_center_offset = {upper_center_offset:.2f}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
427 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
428 center_config = {'lower_row': lower_row, 'lower_center_offset': lower_center_offset, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
429 'upper_row': upper_row, 'upper_center_offset': upper_center_offset} |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
430 if num_tomo_stacks > 1: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
431 center_config['center_stack_index'] = center_stack_index+1 # save as offset 1 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
432 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
433 # Save test data to file |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
434 if self.test_mode: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
435 with open(f'{self.output_folder}/center_config.yaml', 'w') as f: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
436 safe_dump(center_config, f) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
437 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
438 return(center_config) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
439 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
440 def reconstruct_data(self, nxroot, center_info, x_bounds=None, y_bounds=None): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
441 """Reconstruct the tomography data. |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
442 """ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
443 logger.info('Reconstruct the tomography data') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
444 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
445 if not isinstance(nxroot, NXroot): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
446 raise ValueError(f'Invalid parameter nxroot ({nxroot})') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
447 nxentry = nxroot[nxroot.attrs['default']] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
448 if not isinstance(nxentry, NXentry): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
449 raise ValueError(f'Invalid nxentry ({nxentry})') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
450 if not isinstance(center_info, dict): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
451 raise ValueError(f'Invalid parameter center_info ({center_info})') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
452 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
453 # Create plot galaxy path directory and path if needed |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
454 if self.galaxy_flag: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
455 if not os_path.exists('tomo_reconstruct_plots'): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
456 mkdir('tomo_reconstruct_plots') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
457 path = 'tomo_reconstruct_plots' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
458 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
459 path = self.output_folder |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
460 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
461 # Check if reduced data is available |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
462 if ('reduced_data' not in nxentry or 'reduced_data' not in nxentry.data): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
463 raise KeyError(f'Unable to find valid reduced data in {nxentry}.') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
464 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
465 # Create an NXprocess to store image reconstruction (meta)data |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
466 nxprocess = NXprocess() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
467 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
468 # Get rotation axis rows and centers |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
469 lower_row = center_info.get('lower_row') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
470 lower_center_offset = center_info.get('lower_center_offset') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
471 upper_row = center_info.get('upper_row') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
472 upper_center_offset = center_info.get('upper_center_offset') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
473 if (lower_row is None or lower_center_offset is None or upper_row is None or |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
474 upper_center_offset is None): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
475 raise KeyError(f'Unable to find valid calibrated center axis info in {center_info}.') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
476 center_slope = (upper_center_offset-lower_center_offset)/(upper_row-lower_row) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
477 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
478 # Get thetas (in degrees) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
479 thetas = np.asarray(nxentry.reduced_data.rotation_angle) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
480 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
481 # Reconstruct tomography data |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
482 # reduced data axes order: stack,theta,row,column |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
483 # reconstructed data order in each stack: row/z,x,y |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
484 # Note: Nexus cannot follow a link if the data it points to is too big, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
485 # so get the data from the actual place, not from nxentry.data |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
486 if 'zoom_perc' in nxentry.reduced_data: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
487 res_title = f'{nxentry.reduced_data.attrs["zoom_perc"]}p' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
488 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
489 res_title = 'fullres' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
490 load_error = False |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
491 num_tomo_stacks = nxentry.reduced_data.data.tomo_fields.shape[0] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
492 tomo_recon_stacks = num_tomo_stacks*[np.array([])] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
493 for i in range(num_tomo_stacks): |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
494 # Convert reduced data stack from theta,row,column to row,theta,column |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
495 logger.debug(f'Reading reduced data stack {i+1}...') |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
496 t0 = time() |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
497 tomo_stack = np.asarray(nxentry.reduced_data.data.tomo_fields[i]) |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
498 logger.debug(f'... done in {time()-t0:.2f} seconds') |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
499 if len(tomo_stack.shape) != 3 or any(True for dim in tomo_stack.shape if not dim): |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
500 raise ValueError(f'Unable to load tomography stack {i+1} for reconstruction') |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
501 tomo_stack = np.swapaxes(tomo_stack, 0, 1) |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
502 assert(len(thetas) == tomo_stack.shape[1]) |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
503 assert(0 <= lower_row < upper_row < tomo_stack.shape[0]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
504 center_offsets = [lower_center_offset-lower_row*center_slope, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
505 upper_center_offset+(tomo_stack.shape[0]-1-upper_row)*center_slope] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
506 t0 = time() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
507 logger.debug(f'Running _reconstruct_one_tomo_stack on {self.num_core} cores ...') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
508 tomo_recon_stack = self._reconstruct_one_tomo_stack(tomo_stack, thetas, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
509 center_offsets=center_offsets, num_core=self.num_core, algorithm='gridrec') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
510 logger.debug(f'... done in {time()-t0:.2f} seconds') |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
511 logger.info(f'Reconstruction of stack {i+1} took {time()-t0:.2f} seconds') |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
512 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
513 # Combine stacks |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
514 tomo_recon_stacks[i] = tomo_recon_stack |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
515 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
516 # Resize the reconstructed tomography data |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
517 # reconstructed data order in each stack: row/z,x,y |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
518 if self.test_mode: |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
519 x_bounds = tuple(self.test_config.get('x_bounds')) |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
520 y_bounds = tuple(self.test_config.get('y_bounds')) |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
521 z_bounds = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
522 elif self.galaxy_flag: |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
523 x_max = tomo_recon_stacks[0].shape[1] |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
524 if x_bounds is None: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
525 x_bounds = (0, x_max) |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
526 elif is_int_pair(x_bounds, ge=-1, le=x_max): |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
527 x_bounds = tuple(x_bounds) |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
528 if x_bounds[0] == -1: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
529 x_bounds = (0, x_bounds[1]) |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
530 if x_bounds[1] == -1: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
531 x_bounds = (x_bounds[0], x_max) |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
532 if not is_index_range(x_bounds, ge=0, le=x_max): |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
533 raise ValueError(f'Invalid parameter x_bounds ({x_bounds})') |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
534 y_max = tomo_recon_stacks[0].shape[1] |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
535 if y_bounds is None: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
536 y_bounds = (0, y_max) |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
537 elif is_int_pair(y_bounds, ge=-1, le=y_max): |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
538 y_bounds = tuple(y_bounds) |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
539 if y_bounds[0] == -1: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
540 y_bounds = (0, y_bounds[1]) |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
541 if y_bounds[1] == -1: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
542 y_bounds = (y_bounds[0], y_max) |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
543 if not is_index_range(y_bounds, ge=0, le=y_max): |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
544 raise ValueError(f'Invalid parameter y_bounds ({y_bounds})') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
545 z_bounds = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
546 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
547 x_bounds, y_bounds, z_bounds = self._resize_reconstructed_data(tomo_recon_stacks) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
548 if x_bounds is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
549 x_range = (0, tomo_recon_stacks[0].shape[1]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
550 x_slice = int(x_range[1]/2) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
551 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
552 x_range = (min(x_bounds), max(x_bounds)) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
553 x_slice = int((x_bounds[0]+x_bounds[1])/2) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
554 if y_bounds is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
555 y_range = (0, tomo_recon_stacks[0].shape[2]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
556 y_slice = int(y_range[1]/2) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
557 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
558 y_range = (min(y_bounds), max(y_bounds)) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
559 y_slice = int((y_bounds[0]+y_bounds[1])/2) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
560 if z_bounds is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
561 z_range = (0, tomo_recon_stacks[0].shape[0]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
562 z_slice = int(z_range[1]/2) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
563 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
564 z_range = (min(z_bounds), max(z_bounds)) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
565 z_slice = int((z_bounds[0]+z_bounds[1])/2) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
566 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
567 # Plot a few reconstructed image slices |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
568 if num_tomo_stacks == 1: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
569 basetitle = 'recon' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
570 else: |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
571 basetitle = f'recon stack' |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
572 for i, stack in enumerate(tomo_recon_stacks): |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
573 title = f'{basetitle} {i+1} {res_title} xslice{x_slice}' |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
574 quick_imshow(stack[z_range[0]:z_range[1],x_slice,y_range[0]:y_range[1]], |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
575 title=title, path=path, save_fig=self.save_figs, save_only=self.save_only, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
576 block=self.block) |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
577 title = f'{basetitle} {i+1} {res_title} yslice{y_slice}' |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
578 quick_imshow(stack[z_range[0]:z_range[1],x_range[0]:x_range[1],y_slice], |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
579 title=title, path=path, save_fig=self.save_figs, save_only=self.save_only, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
580 block=self.block) |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
581 title = f'{basetitle} {i+1} {res_title} zslice{z_slice}' |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
582 quick_imshow(stack[z_slice,x_range[0]:x_range[1],y_range[0]:y_range[1]], |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
583 title=title, path=path, save_fig=self.save_figs, save_only=self.save_only, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
584 block=self.block) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
585 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
586 # Save test data to file |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
587 # reconstructed data order in each stack: row/z,x,y |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
588 if self.test_mode: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
589 for i, stack in enumerate(tomo_recon_stacks): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
590 np.savetxt(f'{self.output_folder}/recon_stack_{i+1}.txt', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
591 stack[z_slice,x_range[0]:x_range[1],y_range[0]:y_range[1]], fmt='%.6e') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
592 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
593 # Add image reconstruction to reconstructed data NXprocess |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
594 # reconstructed data order in each stack: row/z,x,y |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
595 nxprocess.data = NXdata() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
596 nxprocess.attrs['default'] = 'data' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
597 for k, v in center_info.items(): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
598 nxprocess[k] = v |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
599 if x_bounds is not None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
600 nxprocess.x_bounds = x_bounds |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
601 if y_bounds is not None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
602 nxprocess.y_bounds = y_bounds |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
603 if z_bounds is not None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
604 nxprocess.z_bounds = z_bounds |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
605 nxprocess.data['reconstructed_data'] = np.asarray([stack[z_range[0]:z_range[1], |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
606 x_range[0]:x_range[1],y_range[0]:y_range[1]] for stack in tomo_recon_stacks]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
607 nxprocess.data.attrs['signal'] = 'reconstructed_data' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
608 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
609 # Create a copy of the input Nexus object and remove reduced data |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
610 exclude_items = [f'{nxentry._name}/reduced_data/data', f'{nxentry._name}/data/reduced_data'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
611 nxroot_copy = nxcopy(nxroot, exclude_nxpaths=exclude_items) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
612 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
613 # Add the reconstructed data NXprocess to the new Nexus object |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
614 nxentry_copy = nxroot_copy[nxroot_copy.attrs['default']] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
615 nxentry_copy.reconstructed_data = nxprocess |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
616 if 'data' not in nxentry_copy: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
617 nxentry_copy.data = NXdata() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
618 nxentry_copy.attrs['default'] = 'data' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
619 nxentry_copy.data.makelink(nxprocess.data.reconstructed_data, name='reconstructed_data') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
620 nxentry_copy.data.attrs['signal'] = 'reconstructed_data' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
621 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
622 return(nxroot_copy) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
623 |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
624 def combine_data(self, nxroot, x_bounds=None, y_bounds=None): |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
625 """Combine the reconstructed tomography stacks. |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
626 """ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
627 logger.info('Combine the reconstructed tomography stacks') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
628 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
629 if not isinstance(nxroot, NXroot): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
630 raise ValueError(f'Invalid parameter nxroot ({nxroot})') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
631 nxentry = nxroot[nxroot.attrs['default']] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
632 if not isinstance(nxentry, NXentry): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
633 raise ValueError(f'Invalid nxentry ({nxentry})') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
634 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
635 # Create plot galaxy path directory and path if needed |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
636 if self.galaxy_flag: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
637 if not os_path.exists('tomo_combine_plots'): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
638 mkdir('tomo_combine_plots') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
639 path = 'tomo_combine_plots' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
640 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
641 path = self.output_folder |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
642 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
643 # Check if reconstructed image data is available |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
644 if ('reconstructed_data' not in nxentry or 'reconstructed_data' not in nxentry.data): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
645 raise KeyError(f'Unable to find valid reconstructed image data in {nxentry}.') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
646 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
647 # Create an NXprocess to store combined image reconstruction (meta)data |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
648 nxprocess = NXprocess() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
649 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
650 # Get the reconstructed data |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
651 # reconstructed data order: stack,row(z),x,y |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
652 # Note: Nexus cannot follow a link if the data it points to is too big, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
653 # so get the data from the actual place, not from nxentry.data |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
654 num_tomo_stacks = nxentry.reconstructed_data.data.reconstructed_data.shape[0] |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
655 if num_tomo_stacks == 1: |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
656 logger.info('Only one stack available: leaving combine_data') |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
657 return(None) |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
658 |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
659 # Combine the reconstructed stacks |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
660 # (load one stack at a time to reduce risk of hitting Nexus data access limit) |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
661 t0 = time() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
662 logger.debug(f'Combining the reconstructed stacks ...') |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
663 tomo_recon_combined = np.asarray(nxentry.reconstructed_data.data.reconstructed_data[0]) |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
664 if num_tomo_stacks > 2: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
665 tomo_recon_combined = np.concatenate([tomo_recon_combined]+ |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
666 [nxentry.reconstructed_data.data.reconstructed_data[i] |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
667 for i in range(1, num_tomo_stacks-1)]) |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
668 if num_tomo_stacks > 1: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
669 tomo_recon_combined = np.concatenate([tomo_recon_combined]+ |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
670 [nxentry.reconstructed_data.data.reconstructed_data[num_tomo_stacks-1]]) |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
671 logger.debug(f'... done in {time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
672 logger.info(f'Combining the reconstructed stacks took {time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
673 |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
674 # Resize the combined tomography data stacks |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
675 # combined data order: row/z,x,y |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
676 if self.test_mode: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
677 x_bounds = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
678 y_bounds = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
679 z_bounds = self.test_config.get('z_bounds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
680 elif self.galaxy_flag: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
681 if x_bounds is not None and not is_int_pair(x_bounds, ge=0, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
682 lt=tomo_recon_stacks[0].shape[1]): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
683 raise ValueError(f'Invalid parameter x_bounds ({x_bounds})') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
684 if y_bounds is not None and not is_int_pair(y_bounds, ge=0, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
685 lt=tomo_recon_stacks[0].shape[1]): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
686 raise ValueError(f'Invalid parameter y_bounds ({y_bounds})') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
687 z_bounds = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
688 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
689 x_bounds, y_bounds, z_bounds = self._resize_reconstructed_data(tomo_recon_combined, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
690 z_only=True) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
691 if x_bounds is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
692 x_range = (0, tomo_recon_combined.shape[1]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
693 x_slice = int(x_range[1]/2) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
694 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
695 x_range = x_bounds |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
696 x_slice = int((x_bounds[0]+x_bounds[1])/2) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
697 if y_bounds is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
698 y_range = (0, tomo_recon_combined.shape[2]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
699 y_slice = int(y_range[1]/2) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
700 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
701 y_range = y_bounds |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
702 y_slice = int((y_bounds[0]+y_bounds[1])/2) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
703 if z_bounds is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
704 z_range = (0, tomo_recon_combined.shape[0]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
705 z_slice = int(z_range[1]/2) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
706 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
707 z_range = z_bounds |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
708 z_slice = int((z_bounds[0]+z_bounds[1])/2) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
709 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
710 # Plot a few combined image slices |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
711 quick_imshow(tomo_recon_combined[z_range[0]:z_range[1],x_slice,y_range[0]:y_range[1]], |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
712 title=f'recon combined xslice{x_slice}', path=path, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
713 save_fig=self.save_figs, save_only=self.save_only, block=self.block) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
714 quick_imshow(tomo_recon_combined[z_range[0]:z_range[1],x_range[0]:x_range[1],y_slice], |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
715 title=f'recon combined yslice{y_slice}', path=path, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
716 save_fig=self.save_figs, save_only=self.save_only, block=self.block) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
717 quick_imshow(tomo_recon_combined[z_slice,x_range[0]:x_range[1],y_range[0]:y_range[1]], |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
718 title=f'recon combined zslice{z_slice}', path=path, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
719 save_fig=self.save_figs, save_only=self.save_only, block=self.block) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
720 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
721 # Save test data to file |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
722 # combined data order: row/z,x,y |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
723 if self.test_mode: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
724 np.savetxt(f'{self.output_folder}/recon_combined.txt', tomo_recon_combined[ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
725 z_slice,x_range[0]:x_range[1],y_range[0]:y_range[1]], fmt='%.6e') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
726 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
727 # Add image reconstruction to reconstructed data NXprocess |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
728 # combined data order: row/z,x,y |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
729 nxprocess.data = NXdata() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
730 nxprocess.attrs['default'] = 'data' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
731 if x_bounds is not None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
732 nxprocess.x_bounds = x_bounds |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
733 if y_bounds is not None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
734 nxprocess.y_bounds = y_bounds |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
735 if z_bounds is not None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
736 nxprocess.z_bounds = z_bounds |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
737 nxprocess.data['combined_data'] = tomo_recon_combined |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
738 nxprocess.data.attrs['signal'] = 'combined_data' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
739 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
740 # Create a copy of the input Nexus object and remove reconstructed data |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
741 exclude_items = [f'{nxentry._name}/reconstructed_data/data', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
742 f'{nxentry._name}/data/reconstructed_data'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
743 nxroot_copy = nxcopy(nxroot, exclude_nxpaths=exclude_items) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
744 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
745 # Add the combined data NXprocess to the new Nexus object |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
746 nxentry_copy = nxroot_copy[nxroot_copy.attrs['default']] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
747 nxentry_copy.combined_data = nxprocess |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
748 if 'data' not in nxentry_copy: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
749 nxentry_copy.data = NXdata() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
750 nxentry_copy.attrs['default'] = 'data' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
751 nxentry_copy.data.makelink(nxprocess.data.combined_data, name='combined_data') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
752 nxentry_copy.data.attrs['signal'] = 'combined_data' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
753 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
754 return(nxroot_copy) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
755 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
756 def _gen_dark(self, nxentry, reduced_data): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
757 """Generate dark field. |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
758 """ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
759 # Get the dark field images |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
760 image_key = nxentry.instrument.detector.get('image_key', None) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
761 if image_key and 'data' in nxentry.instrument.detector: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
762 field_indices = [index for index, key in enumerate(image_key) if key == 2] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
763 tdf_stack = nxentry.instrument.detector.data[field_indices,:,:] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
764 # RV the default NXtomo form does not accomodate bright or dark field stacks |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
765 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
766 dark_field_scans = nxentry.spec_scans.dark_field |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
767 dark_field = FlatField.construct_from_nxcollection(dark_field_scans) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
768 prefix = str(nxentry.instrument.detector.local_name) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
769 tdf_stack = dark_field.get_detector_data(prefix) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
770 if isinstance(tdf_stack, list): |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
771 assert(len(tdf_stack) == 1) # TODO |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
772 tdf_stack = tdf_stack[0] |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
773 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
774 # Take median |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
775 if tdf_stack.ndim == 2: |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
776 tdf = tdf_stack.astype('float64') |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
777 elif tdf_stack.ndim == 3: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
778 tdf = np.median(tdf_stack, axis=0) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
779 del tdf_stack |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
780 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
781 raise ValueError(f'Invalid tdf_stack shape ({tdf_stack.shape})') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
782 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
783 # Remove dark field intensities above the cutoff |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
784 #RV tdf_cutoff = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
785 tdf_cutoff = tdf.min()+2*(np.median(tdf)-tdf.min()) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
786 logger.debug(f'tdf_cutoff = {tdf_cutoff}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
787 if tdf_cutoff is not None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
788 if not is_num(tdf_cutoff, ge=0): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
789 logger.warning(f'Ignoring illegal value of tdf_cutoff {tdf_cutoff}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
790 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
791 tdf[tdf > tdf_cutoff] = np.nan |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
792 logger.debug(f'tdf_cutoff = {tdf_cutoff}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
793 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
794 # Remove nans |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
795 tdf_mean = np.nanmean(tdf) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
796 logger.debug(f'tdf_mean = {tdf_mean}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
797 np.nan_to_num(tdf, copy=False, nan=tdf_mean, posinf=tdf_mean, neginf=0.) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
798 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
799 # Plot dark field |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
800 if self.galaxy_flag: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
801 quick_imshow(tdf, title='dark field', path='tomo_reduce_plots', save_fig=self.save_figs, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
802 save_only=self.save_only) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
803 elif not self.test_mode: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
804 quick_imshow(tdf, title='dark field', path=self.output_folder, save_fig=self.save_figs, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
805 save_only=self.save_only) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
806 clear_imshow('dark field') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
807 # quick_imshow(tdf, title='dark field', block=True) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
808 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
809 # Add dark field to reduced data NXprocess |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
810 reduced_data.data = NXdata() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
811 reduced_data.data['dark_field'] = tdf |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
812 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
813 return(reduced_data) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
814 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
815 def _gen_bright(self, nxentry, reduced_data): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
816 """Generate bright field. |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
817 """ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
818 # Get the bright field images |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
819 image_key = nxentry.instrument.detector.get('image_key', None) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
820 if image_key and 'data' in nxentry.instrument.detector: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
821 field_indices = [index for index, key in enumerate(image_key) if key == 1] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
822 tbf_stack = nxentry.instrument.detector.data[field_indices,:,:] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
823 # RV the default NXtomo form does not accomodate bright or dark field stacks |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
824 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
825 bright_field_scans = nxentry.spec_scans.bright_field |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
826 bright_field = FlatField.construct_from_nxcollection(bright_field_scans) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
827 prefix = str(nxentry.instrument.detector.local_name) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
828 tbf_stack = bright_field.get_detector_data(prefix) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
829 if isinstance(tbf_stack, list): |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
830 assert(len(tbf_stack) == 1) # TODO |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
831 tbf_stack = tbf_stack[0] |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
832 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
833 # Take median if more than one image |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
834 """Median or mean: It may be best to try the median because of some image |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
835 artifacts that arise due to crinkles in the upstream kapton tape windows |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
836 causing some phase contrast images to appear on the detector. |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
837 One thing that also may be useful in a future implementation is to do a |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
838 brightfield adjustment on EACH frame of the tomo based on a ROI in the |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
839 corner of the frame where there is no sample but there is the direct X-ray |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
840 beam because there is frame to frame fluctuations from the incoming beam. |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
841 We don’t typically account for them but potentially could. |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
842 """ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
843 if tbf_stack.ndim == 2: |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
844 tbf = tbf_stack.astype('float64') |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
845 elif tbf_stack.ndim == 3: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
846 tbf = np.median(tbf_stack, axis=0) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
847 del tbf_stack |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
848 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
849 raise ValueError(f'Invalid tbf_stack shape ({tbf_stacks.shape})') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
850 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
851 # Subtract dark field |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
852 if 'data' in reduced_data and 'dark_field' in reduced_data.data: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
853 tbf -= reduced_data.data.dark_field |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
854 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
855 logger.warning('Dark field unavailable') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
856 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
857 # Set any non-positive values to one |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
858 # (avoid negative bright field values for spikes in dark field) |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
859 tbf[tbf < 1.0] = 1.0 |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
860 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
861 # Plot bright field |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
862 if self.galaxy_flag: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
863 quick_imshow(tbf, title='bright field', path='tomo_reduce_plots', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
864 save_fig=self.save_figs, save_only=self.save_only) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
865 elif not self.test_mode: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
866 quick_imshow(tbf, title='bright field', path=self.output_folder, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
867 save_fig=self.save_figs, save_only=self.save_only) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
868 clear_imshow('bright field') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
869 # quick_imshow(tbf, title='bright field', block=True) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
870 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
871 # Add bright field to reduced data NXprocess |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
872 if 'data' not in reduced_data: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
873 reduced_data.data = NXdata() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
874 reduced_data.data['bright_field'] = tbf |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
875 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
876 return(reduced_data) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
877 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
878 def _set_detector_bounds(self, nxentry, reduced_data, img_x_bounds=None): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
879 """Set vertical detector bounds for each image stack. |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
880 Right now the range is the same for each set in the image stack. |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
881 """ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
882 if self.test_mode: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
883 return(tuple(self.test_config['img_x_bounds'])) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
884 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
885 # Get the first tomography image and the reference heights |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
886 image_key = nxentry.instrument.detector.get('image_key', None) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
887 if image_key and 'data' in nxentry.instrument.detector: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
888 field_indices = [index for index, key in enumerate(image_key) if key == 0] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
889 first_image = np.asarray(nxentry.instrument.detector.data[field_indices[0],:,:]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
890 theta = float(nxentry.sample.rotation_angle[field_indices[0]]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
891 z_translation_all = nxentry.sample.z_translation[field_indices] |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
892 vertical_shifts = sorted(list(set(z_translation_all))) |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
893 num_tomo_stacks = len(vertical_shifts) |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
894 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
895 tomo_field_scans = nxentry.spec_scans.tomo_fields |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
896 tomo_fields = TomoField.construct_from_nxcollection(tomo_field_scans) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
897 vertical_shifts = tomo_fields.get_vertical_shifts() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
898 if not isinstance(vertical_shifts, list): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
899 vertical_shifts = [vertical_shifts] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
900 prefix = str(nxentry.instrument.detector.local_name) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
901 t0 = time() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
902 first_image = tomo_fields.get_detector_data(prefix, tomo_fields.scan_numbers[0], 0) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
903 logger.debug(f'Getting first image took {time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
904 num_tomo_stacks = len(tomo_fields.scan_numbers) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
905 theta = tomo_fields.theta_range['start'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
906 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
907 # Select image bounds |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
908 title = f'tomography image at theta={round(theta, 2)+0}' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
909 if nxentry.instrument.source.attrs['station'] in ('id1a3', 'id3a'): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
910 pixel_size = nxentry.instrument.detector.x_pixel_size |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
911 # Try to get a fit from the bright field |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
912 tbf = np.asarray(reduced_data.data.bright_field) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
913 tbf_shape = tbf.shape |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
914 x_sum = np.sum(tbf, 1) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
915 x_sum_min = x_sum.min() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
916 x_sum_max = x_sum.max() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
917 fit = Fit.fit_data(x_sum, 'rectangle', x=np.array(range(len(x_sum))), form='atan', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
918 guess=True) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
919 parameters = fit.best_values |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
920 x_low_fit = parameters.get('center1', None) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
921 x_upp_fit = parameters.get('center2', None) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
922 sig_low = parameters.get('sigma1', None) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
923 sig_upp = parameters.get('sigma2', None) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
924 have_fit = fit.success and x_low_fit is not None and x_upp_fit is not None and \ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
925 sig_low is not None and sig_upp is not None and \ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
926 0 <= x_low_fit < x_upp_fit <= x_sum.size and \ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
927 (sig_low+sig_upp)/(x_upp_fit-x_low_fit) < 0.1 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
928 if have_fit: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
929 # Set a 5% margin on each side |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
930 margin = 0.05*(x_upp_fit-x_low_fit) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
931 x_low_fit = max(0, x_low_fit-margin) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
932 x_upp_fit = min(tbf_shape[0], x_upp_fit+margin) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
933 if num_tomo_stacks == 1: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
934 if have_fit: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
935 # Set the default range to enclose the full fitted window |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
936 x_low = int(x_low_fit) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
937 x_upp = int(x_upp_fit) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
938 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
939 # Center a default range of 1 mm (RV: can we get this from the slits?) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
940 num_x_min = int((1.0-0.5*pixel_size)/pixel_size) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
941 x_low = int(0.5*(tbf_shape[0]-num_x_min)) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
942 x_upp = x_low+num_x_min |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
943 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
944 # Get the default range from the reference heights |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
945 delta_z = vertical_shifts[1]-vertical_shifts[0] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
946 for i in range(2, num_tomo_stacks): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
947 delta_z = min(delta_z, vertical_shifts[i]-vertical_shifts[i-1]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
948 logger.debug(f'delta_z = {delta_z}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
949 num_x_min = int((delta_z-0.5*pixel_size)/pixel_size) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
950 logger.debug(f'num_x_min = {num_x_min}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
951 if num_x_min > tbf_shape[0]: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
952 logger.warning('Image bounds and pixel size prevent seamless stacking') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
953 if have_fit: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
954 # Center the default range relative to the fitted window |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
955 x_low = int(0.5*(x_low_fit+x_upp_fit-num_x_min)) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
956 x_upp = x_low+num_x_min |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
957 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
958 # Center the default range |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
959 x_low = int(0.5*(tbf_shape[0]-num_x_min)) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
960 x_upp = x_low+num_x_min |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
961 if self.galaxy_flag: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
962 img_x_bounds = (x_low, x_upp) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
963 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
964 tmp = np.copy(tbf) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
965 tmp_max = tmp.max() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
966 tmp[x_low,:] = tmp_max |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
967 tmp[x_upp-1,:] = tmp_max |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
968 quick_imshow(tmp, title='bright field') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
969 tmp = np.copy(first_image) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
970 tmp_max = tmp.max() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
971 tmp[x_low,:] = tmp_max |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
972 tmp[x_upp-1,:] = tmp_max |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
973 quick_imshow(tmp, title=title) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
974 del tmp |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
975 quick_plot((range(x_sum.size), x_sum), |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
976 ([x_low, x_low], [x_sum_min, x_sum_max], 'r-'), |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
977 ([x_upp, x_upp], [x_sum_min, x_sum_max], 'r-'), |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
978 title='sum over theta and y') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
979 print(f'lower bound = {x_low} (inclusive)') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
980 print(f'upper bound = {x_upp} (exclusive)]') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
981 accept = input_yesno('Accept these bounds (y/n)?', 'y') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
982 clear_imshow('bright field') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
983 clear_imshow(title) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
984 clear_plot('sum over theta and y') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
985 if accept: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
986 img_x_bounds = (x_low, x_upp) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
987 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
988 while True: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
989 mask, img_x_bounds = draw_mask_1d(x_sum, title='select x data range', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
990 legend='sum over theta and y') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
991 if len(img_x_bounds) == 1: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
992 break |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
993 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
994 print(f'Choose a single connected data range') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
995 img_x_bounds = tuple(img_x_bounds[0]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
996 if (num_tomo_stacks > 1 and img_x_bounds[1]-img_x_bounds[0]+1 < |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
997 int((delta_z-0.5*pixel_size)/pixel_size)): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
998 logger.warning('Image bounds and pixel size prevent seamless stacking') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
999 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1000 if num_tomo_stacks > 1: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1001 raise NotImplementedError('Selecting image bounds for multiple stacks on FMB') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1002 # For FMB: use the first tomography image to select range |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1003 # RV: revisit if they do tomography with multiple stacks |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1004 x_sum = np.sum(first_image, 1) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1005 x_sum_min = x_sum.min() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1006 x_sum_max = x_sum.max() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1007 if self.galaxy_flag: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1008 if img_x_bounds is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1009 img_x_bounds = (0, first_image.shape[0]) |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1010 elif is_int_pair(img_x_bounds, ge=-1, le=first_image.shape[0]): |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1011 img_x_bounds = tuple(img_x_bounds) |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1012 if img_x_bounds[0] == -1: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1013 img_x_bounds = (0, img_x_bounds[1]) |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1014 if img_x_bounds[1] == -1: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1015 img_x_bounds = (img_x_bounds[0], first_image.shape[0]) |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1016 if not is_index_range(img_x_bounds, ge=0, le=first_image.shape[0]): |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1017 raise ValueError(f'Invalid parameter img_x_bounds ({img_x_bounds})') |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1018 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1019 quick_imshow(first_image, title=title) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1020 print('Select vertical data reduction range from first tomography image') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1021 img_x_bounds = select_image_bounds(first_image, 0, title=title) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1022 clear_imshow(title) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1023 if img_x_bounds is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1024 raise ValueError('Unable to select image bounds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1025 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1026 # Plot results |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1027 if self.galaxy_flag: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1028 path = 'tomo_reduce_plots' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1029 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1030 path = self.output_folder |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1031 x_low = img_x_bounds[0] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1032 x_upp = img_x_bounds[1] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1033 tmp = np.copy(first_image) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1034 tmp_max = tmp.max() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1035 tmp[x_low,:] = tmp_max |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1036 tmp[x_upp-1,:] = tmp_max |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1037 quick_imshow(tmp, title=title, path=path, save_fig=self.save_figs, save_only=self.save_only, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1038 block=self.block) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1039 del tmp |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1040 quick_plot((range(x_sum.size), x_sum), |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1041 ([x_low, x_low], [x_sum_min, x_sum_max], 'r-'), |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1042 ([x_upp, x_upp], [x_sum_min, x_sum_max], 'r-'), |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1043 title='sum over theta and y', path=path, save_fig=self.save_figs, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1044 save_only=self.save_only, block=self.block) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1045 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1046 return(img_x_bounds) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1047 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1048 def _set_zoom_or_skip(self): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1049 """Set zoom and/or theta skip to reduce memory the requirement for the analysis. |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1050 """ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1051 # if input_yesno('\nDo you want to zoom in to reduce memory requirement (y/n)?', 'n'): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1052 # zoom_perc = input_int(' Enter zoom percentage', ge=1, le=100) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1053 # else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1054 # zoom_perc = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1055 zoom_perc = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1056 # if input_yesno('Do you want to skip thetas to reduce memory requirement (y/n)?', 'n'): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1057 # num_theta_skip = input_int(' Enter the number skip theta interval', ge=0, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1058 # lt=num_theta) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1059 # else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1060 # num_theta_skip = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1061 num_theta_skip = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1062 logger.debug(f'zoom_perc = {zoom_perc}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1063 logger.debug(f'num_theta_skip = {num_theta_skip}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1064 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1065 return(zoom_perc, num_theta_skip) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1066 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1067 def _gen_tomo(self, nxentry, reduced_data): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1068 """Generate tomography fields. |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1069 """ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1070 # Get full bright field |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1071 tbf = np.asarray(reduced_data.data.bright_field) |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1072 img_shape = tbf.shape |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1073 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1074 # Get image bounds |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1075 img_x_bounds = tuple(reduced_data.get('img_x_bounds', (0, img_shape[0]))) |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1076 img_y_bounds = tuple(reduced_data.get('img_y_bounds', (0, img_shape[1]))) |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1077 if img_x_bounds == (0, img_shape[0]) and img_y_bounds == (0, img_shape[1]): |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1078 resize_flag = False |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1079 else: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1080 resize_flag = True |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1081 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1082 # Get resized dark field |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1083 if 'dark_field' in reduced_data.data: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1084 if resize_flag: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1085 tdf = np.asarray(reduced_data.data.dark_field[ |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1086 img_x_bounds[0]:img_x_bounds[1],img_y_bounds[0]:img_y_bounds[1]]) |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1087 else: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1088 tdf = np.asarray(reduced_data.data.dark_field) |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1089 else: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1090 logger.warning('Dark field unavailable') |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1091 tdf = None |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1092 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1093 # Resize bright field |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1094 if resize_flag: |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1095 tbf = tbf[img_x_bounds[0]:img_x_bounds[1],img_y_bounds[0]:img_y_bounds[1]] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1096 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1097 # Get the tomography images |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1098 image_key = nxentry.instrument.detector.get('image_key', None) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1099 if image_key and 'data' in nxentry.instrument.detector: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1100 field_indices_all = [index for index, key in enumerate(image_key) if key == 0] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1101 z_translation_all = nxentry.sample.z_translation[field_indices_all] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1102 z_translation_levels = sorted(list(set(z_translation_all))) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1103 num_tomo_stacks = len(z_translation_levels) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1104 tomo_stacks = num_tomo_stacks*[np.array([])] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1105 horizontal_shifts = [] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1106 vertical_shifts = [] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1107 thetas = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1108 tomo_stacks = [] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1109 for i, z_translation in enumerate(z_translation_levels): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1110 field_indices = [field_indices_all[index] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1111 for index, z in enumerate(z_translation_all) if z == z_translation] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1112 horizontal_shift = list(set(nxentry.sample.x_translation[field_indices])) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1113 assert(len(horizontal_shift) == 1) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1114 horizontal_shifts += horizontal_shift |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1115 vertical_shift = list(set(nxentry.sample.z_translation[field_indices])) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1116 assert(len(vertical_shift) == 1) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1117 vertical_shifts += vertical_shift |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1118 sequence_numbers = nxentry.instrument.detector.sequence_number[field_indices] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1119 if thetas is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1120 thetas = np.asarray(nxentry.sample.rotation_angle[field_indices]) \ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1121 [sequence_numbers] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1122 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1123 assert(all(thetas[i] == nxentry.sample.rotation_angle[field_indices[index]] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1124 for i, index in enumerate(sequence_numbers))) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1125 assert(list(set(sequence_numbers)) == [i for i in range(len(sequence_numbers))]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1126 if list(sequence_numbers) == [i for i in range(len(sequence_numbers))]: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1127 tomo_stack = np.asarray(nxentry.instrument.detector.data[field_indices]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1128 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1129 raise ValueError('Unable to load the tomography images') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1130 tomo_stacks.append(tomo_stack) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1131 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1132 tomo_field_scans = nxentry.spec_scans.tomo_fields |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1133 tomo_fields = TomoField.construct_from_nxcollection(tomo_field_scans) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1134 horizontal_shifts = tomo_fields.get_horizontal_shifts() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1135 vertical_shifts = tomo_fields.get_vertical_shifts() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1136 prefix = str(nxentry.instrument.detector.local_name) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1137 t0 = time() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1138 tomo_stacks = tomo_fields.get_detector_data(prefix) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1139 logger.debug(f'Getting tomography images took {time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1140 logger.debug(f'Getting all images took {time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1141 thetas = np.linspace(tomo_fields.theta_range['start'], tomo_fields.theta_range['end'], |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1142 tomo_fields.theta_range['num']) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1143 if not isinstance(tomo_stacks, list): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1144 horizontal_shifts = [horizontal_shifts] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1145 vertical_shifts = [vertical_shifts] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1146 tomo_stacks = [tomo_stacks] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1147 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1148 reduced_tomo_stacks = [] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1149 if self.galaxy_flag: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1150 path = 'tomo_reduce_plots' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1151 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1152 path = self.output_folder |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1153 for i, tomo_stack in enumerate(tomo_stacks): |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1154 # Resize the tomography images as needed |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1155 # Right now the range is the same for each set in the image stack |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1156 if resize_flag: |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1157 t0 = time() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1158 tomo_stack = tomo_stack[:,img_x_bounds[0]:img_x_bounds[1], |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1159 img_y_bounds[0]:img_y_bounds[1]].astype('float64') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1160 logger.debug(f'Resizing tomography images took {time()-t0:.2f} seconds') |
75
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1161 else: |
d5e1d4ea2b7e
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
rv43
parents:
71
diff
changeset
|
1162 tomo_stack = tomo_stack.astype('float64') |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1163 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1164 # Subtract dark field |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1165 if tdf is not None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1166 t0 = time() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1167 with set_numexpr_threads(self.num_core): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1168 ne.evaluate('tomo_stack-tdf', out=tomo_stack) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1169 logger.debug(f'Subtracting dark field took {time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1170 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1171 # Normalize |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1172 t0 = time() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1173 with set_numexpr_threads(self.num_core): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1174 ne.evaluate('tomo_stack/tbf', out=tomo_stack, truediv=True) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1175 logger.debug(f'Normalizing took {time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1176 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1177 # Remove non-positive values and linearize data |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1178 t0 = time() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1179 cutoff = 1.e-6 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1180 with set_numexpr_threads(self.num_core): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1181 ne.evaluate('where(tomo_stack<cutoff, cutoff, tomo_stack)', out=tomo_stack) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1182 with set_numexpr_threads(self.num_core): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1183 ne.evaluate('-log(tomo_stack)', out=tomo_stack) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1184 logger.debug('Removing non-positive values and linearizing data took '+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1185 f'{time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1186 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1187 # Get rid of nans/infs that may be introduced by normalization |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1188 t0 = time() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1189 np.where(np.isfinite(tomo_stack), tomo_stack, 0.) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1190 logger.debug(f'Remove nans/infs took {time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1191 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1192 # Downsize tomography stack to smaller size |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1193 # TODO use theta_skip as well |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1194 tomo_stack = tomo_stack.astype('float32') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1195 if not self.test_mode: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1196 if len(tomo_stacks) == 1: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1197 title = f'red fullres theta {round(thetas[0], 2)+0}' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1198 else: |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
1199 title = f'red stack {i+1} fullres theta {round(thetas[0], 2)+0}' |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1200 quick_imshow(tomo_stack[0,:,:], title=title, path=path, save_fig=self.save_figs, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1201 save_only=self.save_only, block=self.block) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1202 # if not self.block: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1203 # clear_imshow(title) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1204 if False and zoom_perc != 100: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1205 t0 = time() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1206 logger.debug(f'Zooming in ...') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1207 tomo_zoom_list = [] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1208 for j in range(tomo_stack.shape[0]): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1209 tomo_zoom = spi.zoom(tomo_stack[j,:,:], 0.01*zoom_perc) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1210 tomo_zoom_list.append(tomo_zoom) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1211 tomo_stack = np.stack([tomo_zoom for tomo_zoom in tomo_zoom_list]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1212 logger.debug(f'... done in {time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1213 logger.info(f'Zooming in took {time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1214 del tomo_zoom_list |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1215 if not self.test_mode: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1216 title = f'red stack {zoom_perc}p theta {round(thetas[0], 2)+0}' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1217 quick_imshow(tomo_stack[0,:,:], title=title, path=path, save_fig=self.save_figs, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1218 save_only=self.save_only, block=self.block) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1219 # if not self.block: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1220 # clear_imshow(title) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1221 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1222 # Save test data to file |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1223 if self.test_mode: |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
1224 # row_index = int(tomo_stack.shape[0]/2) |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
1225 # np.savetxt(f'{self.output_folder}/red_stack_{i+1}.txt', tomo_stack[row_index,:,:], |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
1226 # fmt='%.6e') |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
1227 row_index = int(tomo_stack.shape[1]/2) |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
1228 np.savetxt(f'{self.output_folder}/red_stack_{i+1}.txt', tomo_stack[:,row_index,:], |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1229 fmt='%.6e') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1230 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1231 # Combine resized stacks |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1232 reduced_tomo_stacks.append(tomo_stack) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1233 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1234 # Add tomo field info to reduced data NXprocess |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1235 reduced_data['rotation_angle'] = thetas |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1236 reduced_data['x_translation'] = np.asarray(horizontal_shifts) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1237 reduced_data['z_translation'] = np.asarray(vertical_shifts) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1238 reduced_data.data['tomo_fields'] = np.asarray(reduced_tomo_stacks) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1239 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1240 if tdf is not None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1241 del tdf |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1242 del tbf |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1243 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1244 return(reduced_data) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1245 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1246 def _find_center_one_plane(self, sinogram, row, thetas, eff_pixel_size, cross_sectional_dim, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1247 path=None, tol=0.1, num_core=1): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1248 """Find center for a single tomography plane. |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1249 """ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1250 # Try automatic center finding routines for initial value |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1251 # sinogram index order: theta,column |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1252 # need column,theta for iradon, so take transpose |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
1253 sinogram = np.asarray(sinogram) |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1254 sinogram_T = sinogram.T |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1255 center = sinogram.shape[1]/2 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1256 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1257 # Try using Nghia Vo’s method |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1258 t0 = time() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1259 if num_core > num_core_tomopy_limit: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1260 logger.debug(f'Running find_center_vo on {num_core_tomopy_limit} cores ...') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1261 tomo_center = tomopy.find_center_vo(sinogram, ncore=num_core_tomopy_limit) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1262 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1263 logger.debug(f'Running find_center_vo on {num_core} cores ...') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1264 tomo_center = tomopy.find_center_vo(sinogram, ncore=num_core) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1265 logger.debug(f'... done in {time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1266 logger.info(f'Finding the center using Nghia Vo’s method took {time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1267 center_offset_vo = tomo_center-center |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1268 logger.info(f'Center at row {row} using Nghia Vo’s method = {center_offset_vo:.2f}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1269 t0 = time() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1270 logger.debug(f'Running _reconstruct_one_plane on {self.num_core} cores ...') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1271 recon_plane = self._reconstruct_one_plane(sinogram_T, tomo_center, thetas, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1272 eff_pixel_size, cross_sectional_dim, False, num_core) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1273 logger.debug(f'... done in {time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1274 logger.info(f'Reconstructing row {row} took {time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1275 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1276 title = f'edges row{row} center offset{center_offset_vo:.2f} Vo' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1277 self._plot_edges_one_plane(recon_plane, title, path=path) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1278 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1279 # Try using phase correlation method |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1280 # if input_yesno('Try finding center using phase correlation (y/n)?', 'n'): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1281 # t0 = time() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1282 # logger.debug(f'Running find_center_pc ...') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1283 # tomo_center = tomopy.find_center_pc(sinogram, sinogram, tol=0.1, rotc_guess=tomo_center) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1284 # error = 1. |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1285 # while error > tol: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1286 # prev = tomo_center |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1287 # tomo_center = tomopy.find_center_pc(sinogram, sinogram, tol=tol, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1288 # rotc_guess=tomo_center) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1289 # error = np.abs(tomo_center-prev) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1290 # logger.debug(f'... done in {time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1291 # logger.info('Finding the center using the phase correlation method took '+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1292 # f'{time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1293 # center_offset = tomo_center-center |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1294 # print(f'Center at row {row} using phase correlation = {center_offset:.2f}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1295 # t0 = time() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1296 # logger.debug(f'Running _reconstruct_one_plane on {self.num_core} cores ...') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1297 # recon_plane = self._reconstruct_one_plane(sinogram_T, tomo_center, thetas, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1298 # eff_pixel_size, cross_sectional_dim, False, num_core) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1299 # logger.debug(f'... done in {time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1300 # logger.info(f'Reconstructing row {row} took {time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1301 # |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1302 # title = f'edges row{row} center_offset{center_offset:.2f} PC' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1303 # self._plot_edges_one_plane(recon_plane, title, path=path) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1304 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1305 # Select center location |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1306 # if input_yesno('Accept a center location (y) or continue search (n)?', 'y'): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1307 if True: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1308 # center_offset = input_num(' Enter chosen center offset', ge=-center, le=center, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1309 # default=center_offset_vo) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1310 center_offset = center_offset_vo |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1311 del sinogram_T |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1312 del recon_plane |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1313 return float(center_offset) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1314 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1315 # perform center finding search |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1316 while True: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1317 center_offset_low = input_int('\nEnter lower bound for center offset', ge=-center, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1318 le=center) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1319 center_offset_upp = input_int('Enter upper bound for center offset', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1320 ge=center_offset_low, le=center) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1321 if center_offset_upp == center_offset_low: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1322 center_offset_step = 1 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1323 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1324 center_offset_step = input_int('Enter step size for center offset search', ge=1, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1325 le=center_offset_upp-center_offset_low) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1326 num_center_offset = 1+int((center_offset_upp-center_offset_low)/center_offset_step) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1327 center_offsets = np.linspace(center_offset_low, center_offset_upp, num_center_offset) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1328 for center_offset in center_offsets: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1329 if center_offset == center_offset_vo: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1330 continue |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1331 t0 = time() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1332 logger.debug(f'Running _reconstruct_one_plane on {num_core} cores ...') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1333 recon_plane = self._reconstruct_one_plane(sinogram_T, center_offset+center, thetas, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1334 eff_pixel_size, cross_sectional_dim, False, num_core) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1335 logger.debug(f'... done in {time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1336 logger.info(f'Reconstructing center_offset {center_offset} took '+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1337 f'{time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1338 title = f'edges row{row} center_offset{center_offset:.2f}' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1339 self._plot_edges_one_plane(recon_plane, title, path=path) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1340 if input_int('\nContinue (0) or end the search (1)', ge=0, le=1): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1341 break |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1342 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1343 del sinogram_T |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1344 del recon_plane |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1345 center_offset = input_num(' Enter chosen center offset', ge=-center, le=center) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1346 return float(center_offset) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1347 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1348 def _reconstruct_one_plane(self, tomo_plane_T, center, thetas, eff_pixel_size, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1349 cross_sectional_dim, plot_sinogram=True, num_core=1): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1350 """Invert the sinogram for a single tomography plane. |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1351 """ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1352 # tomo_plane_T index order: column,theta |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1353 assert(0 <= center < tomo_plane_T.shape[0]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1354 center_offset = center-tomo_plane_T.shape[0]/2 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1355 two_offset = 2*int(np.round(center_offset)) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1356 two_offset_abs = np.abs(two_offset) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1357 max_rad = int(0.55*(cross_sectional_dim/eff_pixel_size)) # 10% slack to avoid edge effects |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1358 if max_rad > 0.5*tomo_plane_T.shape[0]: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1359 max_rad = 0.5*tomo_plane_T.shape[0] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1360 dist_from_edge = max(1, int(np.floor((tomo_plane_T.shape[0]-two_offset_abs)/2.)-max_rad)) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1361 if two_offset >= 0: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1362 logger.debug(f'sinogram range = [{two_offset+dist_from_edge}, {-dist_from_edge}]') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1363 sinogram = tomo_plane_T[two_offset+dist_from_edge:-dist_from_edge,:] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1364 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1365 logger.debug(f'sinogram range = [{dist_from_edge}, {two_offset-dist_from_edge}]') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1366 sinogram = tomo_plane_T[dist_from_edge:two_offset-dist_from_edge,:] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1367 if not self.galaxy_flag and plot_sinogram: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1368 quick_imshow(sinogram.T, f'sinogram center offset{center_offset:.2f}', aspect='auto', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1369 path=self.output_folder, save_fig=self.save_figs, save_only=self.save_only, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1370 block=self.block) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1371 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1372 # Inverting sinogram |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1373 t0 = time() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1374 recon_sinogram = iradon(sinogram, theta=thetas, circle=True) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1375 logger.debug(f'Inverting sinogram took {time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1376 del sinogram |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1377 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1378 # Performing Gaussian filtering and removing ring artifacts |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1379 recon_parameters = None#self.config.get('recon_parameters') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1380 if recon_parameters is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1381 sigma = 1.0 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1382 ring_width = 15 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1383 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1384 sigma = recon_parameters.get('gaussian_sigma', 1.0) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1385 if not is_num(sigma, ge=0.0): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1386 logger.warning(f'Invalid gaussian_sigma ({sigma}) in _reconstruct_one_plane, '+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1387 'set to a default value of 1.0') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1388 sigma = 1.0 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1389 ring_width = recon_parameters.get('ring_width', 15) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1390 if not is_int(ring_width, ge=0): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1391 logger.warning(f'Invalid ring_width ({ring_width}) in _reconstruct_one_plane, '+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1392 'set to a default value of 15') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1393 ring_width = 15 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1394 t0 = time() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1395 recon_sinogram = spi.gaussian_filter(recon_sinogram, sigma, mode='nearest') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1396 recon_clean = np.expand_dims(recon_sinogram, axis=0) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1397 del recon_sinogram |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1398 recon_clean = tomopy.misc.corr.remove_ring(recon_clean, rwidth=ring_width, ncore=num_core) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1399 logger.debug(f'Filtering and removing ring artifacts took {time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1400 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1401 return recon_clean |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1402 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1403 def _plot_edges_one_plane(self, recon_plane, title, path=None): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1404 vis_parameters = None#self.config.get('vis_parameters') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1405 if vis_parameters is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1406 weight = 0.1 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1407 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1408 weight = vis_parameters.get('denoise_weight', 0.1) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1409 if not is_num(weight, ge=0.0): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1410 logger.warning(f'Invalid weight ({weight}) in _plot_edges_one_plane, '+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1411 'set to a default value of 0.1') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1412 weight = 0.1 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1413 edges = denoise_tv_chambolle(recon_plane, weight=weight) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1414 vmax = np.max(edges[0,:,:]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1415 vmin = -vmax |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1416 if path is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1417 path = self.output_folder |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1418 quick_imshow(edges[0,:,:], f'{title} coolwarm', path=path, cmap='coolwarm', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1419 save_fig=self.save_figs, save_only=self.save_only, block=self.block) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1420 quick_imshow(edges[0,:,:], f'{title} gray', path=path, cmap='gray', vmin=vmin, vmax=vmax, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1421 save_fig=self.save_figs, save_only=self.save_only, block=self.block) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1422 del edges |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1423 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1424 def _reconstruct_one_tomo_stack(self, tomo_stack, thetas, center_offsets=[], num_core=1, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1425 algorithm='gridrec'): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1426 """Reconstruct a single tomography stack. |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1427 """ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1428 # tomo_stack order: row,theta,column |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1429 # input thetas must be in degrees |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1430 # centers_offset: tomography axis shift in pixels relative to column center |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1431 # RV should we remove stripes? |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1432 # https://tomopy.readthedocs.io/en/latest/api/tomopy.prep.stripe.html |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1433 # RV should we remove rings? |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1434 # https://tomopy.readthedocs.io/en/latest/api/tomopy.misc.corr.html |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1435 # RV: Add an option to do (extra) secondary iterations later or to do some sort of convergence test? |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1436 if not len(center_offsets): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1437 centers = np.zeros((tomo_stack.shape[0])) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1438 elif len(center_offsets) == 2: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1439 centers = np.linspace(center_offsets[0], center_offsets[1], tomo_stack.shape[0]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1440 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1441 if center_offsets.size != tomo_stack.shape[0]: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1442 raise ValueError('center_offsets dimension mismatch in reconstruct_one_tomo_stack') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1443 centers = center_offsets |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1444 centers += tomo_stack.shape[2]/2 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1445 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1446 # Get reconstruction parameters |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1447 recon_parameters = None#self.config.get('recon_parameters') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1448 if recon_parameters is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1449 sigma = 2.0 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1450 secondary_iters = 0 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1451 ring_width = 15 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1452 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1453 sigma = recon_parameters.get('stripe_fw_sigma', 2.0) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1454 if not is_num(sigma, ge=0): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1455 logger.warning(f'Invalid stripe_fw_sigma ({sigma}) in '+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1456 '_reconstruct_one_tomo_stack, set to a default value of 2.0') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1457 ring_width = 15 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1458 secondary_iters = recon_parameters.get('secondary_iters', 0) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1459 if not is_int(secondary_iters, ge=0): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1460 logger.warning(f'Invalid secondary_iters ({secondary_iters}) in '+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1461 '_reconstruct_one_tomo_stack, set to a default value of 0 (skip them)') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1462 ring_width = 0 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1463 ring_width = recon_parameters.get('ring_width', 15) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1464 if not is_int(ring_width, ge=0): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1465 logger.warning(f'Invalid ring_width ({ring_width}) in _reconstruct_one_plane, '+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1466 'set to a default value of 15') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1467 ring_width = 15 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1468 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1469 # Remove horizontal stripe |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1470 t0 = time() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1471 if num_core > num_core_tomopy_limit: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1472 logger.debug('Running remove_stripe_fw on {num_core_tomopy_limit} cores ...') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1473 tomo_stack = tomopy.prep.stripe.remove_stripe_fw(tomo_stack, sigma=sigma, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1474 ncore=num_core_tomopy_limit) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1475 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1476 logger.debug(f'Running remove_stripe_fw on {num_core} cores ...') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1477 tomo_stack = tomopy.prep.stripe.remove_stripe_fw(tomo_stack, sigma=sigma, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1478 ncore=num_core) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1479 logger.debug(f'... tomopy.prep.stripe.remove_stripe_fw took {time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1480 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1481 # Perform initial image reconstruction |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1482 logger.debug('Performing initial image reconstruction') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1483 t0 = time() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1484 logger.debug(f'Running recon on {num_core} cores ...') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1485 tomo_recon_stack = tomopy.recon(tomo_stack, np.radians(thetas), centers, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1486 sinogram_order=True, algorithm=algorithm, ncore=num_core) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1487 logger.debug(f'... done in {time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1488 logger.info(f'Performing initial image reconstruction took {time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1489 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1490 # Run optional secondary iterations |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1491 if secondary_iters > 0: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1492 logger.debug(f'Running {secondary_iters} secondary iterations') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1493 #options = {'method':'SIRT_CUDA', 'proj_type':'cuda', 'num_iter':secondary_iters} |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1494 #RV: doesn't work for me: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1495 #"Error: CUDA error 803: system has unsupported display driver/cuda driver combination." |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1496 #options = {'method':'SIRT', 'proj_type':'linear', 'MinConstraint': 0, 'num_iter':secondary_iters} |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1497 #SIRT did not finish while running overnight |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1498 #options = {'method':'SART', 'proj_type':'linear', 'num_iter':secondary_iters} |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1499 options = {'method':'SART', 'proj_type':'linear', 'MinConstraint': 0, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1500 'num_iter':secondary_iters} |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1501 t0 = time() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1502 logger.debug(f'Running recon on {num_core} cores ...') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1503 tomo_recon_stack = tomopy.recon(tomo_stack, np.radians(thetas), centers, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1504 init_recon=tomo_recon_stack, options=options, sinogram_order=True, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1505 algorithm=tomopy.astra, ncore=num_core) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1506 logger.debug(f'... done in {time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1507 logger.info(f'Performing secondary iterations took {time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1508 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1509 # Remove ring artifacts |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1510 t0 = time() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1511 tomopy.misc.corr.remove_ring(tomo_recon_stack, rwidth=ring_width, out=tomo_recon_stack, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1512 ncore=num_core) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1513 logger.debug(f'Removing ring artifacts took {time()-t0:.2f} seconds') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1514 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1515 return tomo_recon_stack |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1516 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1517 def _resize_reconstructed_data(self, data, z_only=False): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1518 """Resize the reconstructed tomography data. |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1519 """ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1520 # Data order: row(z),x,y or stack,row(z),x,y |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1521 if isinstance(data, list): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1522 for stack in data: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1523 assert(stack.ndim == 3) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1524 num_tomo_stacks = len(data) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1525 tomo_recon_stacks = data |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1526 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1527 assert(data.ndim == 3) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1528 num_tomo_stacks = 1 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1529 tomo_recon_stacks = [data] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1530 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1531 if z_only: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1532 x_bounds = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1533 y_bounds = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1534 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1535 # Selecting x bounds (in yz-plane) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1536 tomosum = 0 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1537 [tomosum := tomosum+np.sum(tomo_recon_stacks[i], axis=(0,2)) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1538 for i in range(num_tomo_stacks)] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1539 select_x_bounds = input_yesno('\nDo you want to change the image x-bounds (y/n)?', 'y') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1540 if not select_x_bounds: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1541 x_bounds = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1542 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1543 accept = False |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1544 index_ranges = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1545 while not accept: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1546 mask, x_bounds = draw_mask_1d(tomosum, current_index_ranges=index_ranges, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1547 title='select x data range', legend='recon stack sum yz') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1548 while len(x_bounds) != 1: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1549 print('Please select exactly one continuous range') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1550 mask, x_bounds = draw_mask_1d(tomosum, title='select x data range', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1551 legend='recon stack sum yz') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1552 x_bounds = x_bounds[0] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1553 # quick_plot(tomosum, vlines=x_bounds, title='recon stack sum yz') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1554 # print(f'x_bounds = {x_bounds} (lower bound inclusive, upper bound '+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1555 # 'exclusive)') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1556 # accept = input_yesno('Accept these bounds (y/n)?', 'y') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1557 accept = True |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1558 logger.debug(f'x_bounds = {x_bounds}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1559 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1560 # Selecting y bounds (in xz-plane) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1561 tomosum = 0 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1562 [tomosum := tomosum+np.sum(tomo_recon_stacks[i], axis=(0,1)) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1563 for i in range(num_tomo_stacks)] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1564 select_y_bounds = input_yesno('\nDo you want to change the image y-bounds (y/n)?', 'y') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1565 if not select_y_bounds: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1566 y_bounds = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1567 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1568 accept = False |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1569 index_ranges = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1570 while not accept: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1571 mask, y_bounds = draw_mask_1d(tomosum, current_index_ranges=index_ranges, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1572 title='select x data range', legend='recon stack sum xz') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1573 while len(y_bounds) != 1: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1574 print('Please select exactly one continuous range') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1575 mask, y_bounds = draw_mask_1d(tomosum, title='select x data range', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1576 legend='recon stack sum xz') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1577 y_bounds = y_bounds[0] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1578 # quick_plot(tomosum, vlines=y_bounds, title='recon stack sum xz') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1579 # print(f'y_bounds = {y_bounds} (lower bound inclusive, upper bound '+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1580 # 'exclusive)') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1581 # accept = input_yesno('Accept these bounds (y/n)?', 'y') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1582 accept = True |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1583 logger.debug(f'y_bounds = {y_bounds}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1584 |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
1585 # Selecting z bounds (in xy-plane) (only valid for a single image stack) |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1586 if num_tomo_stacks != 1: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1587 z_bounds = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1588 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1589 tomosum = 0 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1590 [tomosum := tomosum+np.sum(tomo_recon_stacks[i], axis=(1,2)) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1591 for i in range(num_tomo_stacks)] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1592 select_z_bounds = input_yesno('Do you want to change the image z-bounds (y/n)?', 'n') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1593 if not select_z_bounds: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1594 z_bounds = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1595 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1596 accept = False |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1597 index_ranges = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1598 while not accept: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1599 mask, z_bounds = draw_mask_1d(tomosum, current_index_ranges=index_ranges, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1600 title='select x data range', legend='recon stack sum xy') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1601 while len(z_bounds) != 1: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1602 print('Please select exactly one continuous range') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1603 mask, z_bounds = draw_mask_1d(tomosum, title='select x data range', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1604 legend='recon stack sum xy') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1605 z_bounds = z_bounds[0] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1606 # quick_plot(tomosum, vlines=z_bounds, title='recon stack sum xy') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1607 # print(f'z_bounds = {z_bounds} (lower bound inclusive, upper bound '+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1608 # 'exclusive)') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1609 # accept = input_yesno('Accept these bounds (y/n)?', 'y') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1610 accept = True |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1611 logger.debug(f'z_bounds = {z_bounds}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1612 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1613 return(x_bounds, y_bounds, z_bounds) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1614 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1615 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1616 def run_tomo(input_file:str, output_file:str, modes:list[str], center_file=None, num_core=-1, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1617 output_folder='.', save_figs='no', test_mode=False) -> None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1618 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1619 if test_mode: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1620 logging_format = '%(asctime)s : %(levelname)s - %(module)s : %(funcName)s - %(message)s' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1621 level = logging.getLevelName('INFO') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1622 logging.basicConfig(filename=f'{output_folder}/tomo.log', filemode='w', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1623 format=logging_format, level=level, force=True) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1624 logger.info(f'input_file = {input_file}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1625 logger.info(f'center_file = {center_file}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1626 logger.info(f'output_file = {output_file}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1627 logger.debug(f'modes= {modes}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1628 logger.debug(f'num_core= {num_core}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1629 logger.info(f'output_folder = {output_folder}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1630 logger.info(f'save_figs = {save_figs}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1631 logger.info(f'test_mode = {test_mode}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1632 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1633 # Check for correction modes |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
1634 legal_modes = ['reduce_data', 'find_center', 'reconstruct_data', 'combine_data', 'all'] |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1635 if modes is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1636 modes = ['all'] |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
1637 if not all(True if mode in legal_modes else False for mode in modes): |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
1638 raise ValueError(f'Invalid parameter modes ({modes})') |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1639 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1640 # Instantiate Tomo object |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1641 tomo = Tomo(num_core=num_core, output_folder=output_folder, save_figs=save_figs, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1642 test_mode=test_mode) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1643 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1644 # Read input file |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1645 data = tomo.read(input_file) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1646 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1647 # Generate reduced tomography images |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1648 if 'reduce_data' in modes or 'all' in modes: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1649 data = tomo.gen_reduced_data(data) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1650 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1651 # Find rotation axis centers for the tomography stacks. |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1652 center_data = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1653 if 'find_center' in modes or 'all' in modes: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1654 center_data = tomo.find_centers(data) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1655 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1656 # Reconstruct tomography stacks |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1657 if 'reconstruct_data' in modes or 'all' in modes: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1658 if center_data is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1659 # Read input file |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1660 center_data = tomo.read(center_file) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1661 data = tomo.reconstruct_data(data, center_data) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1662 center_data = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1663 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1664 # Combine reconstructed tomography stacks |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1665 if 'combine_data' in modes or 'all' in modes: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1666 data = tomo.combine_data(data) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1667 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1668 # Write output file |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
1669 if data is not None and not test_mode: |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1670 if center_data is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1671 data = tomo.write(data, output_file) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1672 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1673 data = tomo.write(center_data, output_file) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1674 |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
1675 logger.info(f'Completed modes: {modes}') |