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