comparison tomo.py @ 43:0b9ce9489ecc draft

"planemo upload for repository https://github.com/rolfverberg/galaxytools commit 006ce85b82c2f8eb386cb1648803d7768016c067"
author rv43
date Thu, 21 Apr 2022 16:12:21 +0000
parents ef5c2f7b49ec
children 0ac719053d6f
comparison
equal deleted inserted replaced
42:009d2d45ac79 43:0b9ce9489ecc
834 if img_x_bounds[0] is not None and img_x_bounds[1] is not None: 834 if img_x_bounds[0] is not None and img_x_bounds[1] is not None:
835 tmp = np.copy(tomo_stack[0,:,:]) 835 tmp = np.copy(tomo_stack[0,:,:])
836 tmp_max = tmp.max() 836 tmp_max = tmp.max()
837 tmp[img_x_bounds[0],:] = tmp_max 837 tmp[img_x_bounds[0],:] = tmp_max
838 tmp[img_x_bounds[1]-1,:] = tmp_max 838 tmp[img_x_bounds[1]-1,:] = tmp_max
839 title = f'tomography image at theta={self.config["theta_range"]["start"]}'
839 msnc.quickImshow(tmp, title=title) 840 msnc.quickImshow(tmp, title=title)
840 del tmp 841 del tmp
841 x_sum_min = x_sum.min() 842 x_sum_min = x_sum.min()
842 x_sum_max = x_sum.max() 843 x_sum_max = x_sum.max()
843 msnc.quickPlot((range(x_sum.size), x_sum), 844 msnc.quickPlot((range(x_sum.size), x_sum),
868 if img_x_bounds[0] is not None and img_x_bounds[1] is not None: 869 if img_x_bounds[0] is not None and img_x_bounds[1] is not None:
869 tmp = np.copy(self.tbf) 870 tmp = np.copy(self.tbf)
870 tmp_max = tmp.max() 871 tmp_max = tmp.max()
871 tmp[img_x_bounds[0],:] = tmp_max 872 tmp[img_x_bounds[0],:] = tmp_max
872 tmp[img_x_bounds[1]-1,:] = tmp_max 873 tmp[img_x_bounds[1]-1,:] = tmp_max
873 title = 'Bright field' 874 title = 'bright field'
874 msnc.quickImshow(tmp, title=title) 875 msnc.quickImshow(tmp, title=title)
875 del tmp 876 del tmp
876 msnc.quickPlot((range(x_sum.size), x_sum), 877 msnc.quickPlot((range(x_sum.size), x_sum),
877 ([img_x_bounds[0], img_x_bounds[0]], [x_sum_min, x_sum_max], 'r-'), 878 ([img_x_bounds[0], img_x_bounds[0]], [x_sum_min, x_sum_max], 'r-'),
878 ([img_x_bounds[1]-1, img_x_bounds[1]-1], [x_sum_min, x_sum_max], 'r-'), 879 ([img_x_bounds[1]-1, img_x_bounds[1]-1], [x_sum_min, x_sum_max], 'r-'),
902 x_upp = x_sum.size 903 x_upp = x_sum.size
903 tmp = np.copy(self.tbf) 904 tmp = np.copy(self.tbf)
904 tmp_max = tmp.max() 905 tmp_max = tmp.max()
905 tmp[x_low,:] = tmp_max 906 tmp[x_low,:] = tmp_max
906 tmp[x_upp-1,:] = tmp_max 907 tmp[x_upp-1,:] = tmp_max
907 title = 'Bright field' 908 title = 'bright field'
908 msnc.quickImshow(tmp, title=title) 909 msnc.quickImshow(tmp, title=title)
909 del tmp 910 del tmp
910 msnc.quickPlot((range(x_sum.size), x_sum), 911 msnc.quickPlot((range(x_sum.size), x_sum),
911 ([x_low, x_low], [x_sum_min, x_sum_max], 'r-'), 912 ([x_low, x_low], [x_sum_min, x_sum_max], 'r-'),
912 ([x_upp, x_upp], [x_sum_min, x_sum_max], 'r-'), 913 ([x_upp, x_upp], [x_sum_min, x_sum_max], 'r-'),
938 if num_x_min is not None: 939 if num_x_min is not None:
939 tomo_stack_max = tomo_stack.max() 940 tomo_stack_max = tomo_stack.max()
940 tomo_stack[img_x_bounds[0],:] = tomo_stack_max 941 tomo_stack[img_x_bounds[0],:] = tomo_stack_max
941 tomo_stack[img_x_bounds[1]-1,:] = tomo_stack_max 942 tomo_stack[img_x_bounds[1]-1,:] = tomo_stack_max
942 title = f'tomography image at theta={self.config["theta_range"]["start"]}' 943 title = f'tomography image at theta={self.config["theta_range"]["start"]}'
943 msnc.quickImshow(tomo_stack, title=title, path='setup_pngs', 944 if self.galaxy_flag:
944 name=f'tomo_{stack["index"]}.png', save_fig=self.save_plots, save_only=True, 945 msnc.quickImshow(tomo_stack, title=title, path='setup_pngs',
945 show_grid=True) 946 name=f'tomo_{stack["index"]}.png', save_fig=True, save_only=True,
947 show_grid=True)
948 else:
949 msnc.quickImshow(tomo_stack, title=title, path=self.output_folder,
950 name=f'tomo_{stack["index"]}.png', save_fig=self.save_plots,
951 save_only=True, show_grid=True)
946 del tomo_stack 952 del tomo_stack
947 logging.debug(f'img_x_bounds: {img_x_bounds}') 953 logging.debug(f'img_x_bounds: {img_x_bounds}')
948 954
949 if self.save_plots_only: 955 if self.save_plots_only:
950 msnc.clearFig('bright field') 956 msnc.clearFig('bright field')
1846 1852
1847 # Lower row center 1853 # Lower row center
1848 use_row = 'no' 1854 use_row = 'no'
1849 use_center = 'no' 1855 use_center = 'no'
1850 row = center_rows[0] 1856 row = center_rows[0]
1857 print('Ok1')
1851 if self.test_mode or self.galaxy_flag: 1858 if self.test_mode or self.galaxy_flag:
1852 assert(msnc.is_int(row, n1, n2-2)) 1859 assert(msnc.is_int(row, n1, n2-2))
1860 print('Ok2')
1853 if msnc.is_int(row, n1, n2-2): 1861 if msnc.is_int(row, n1, n2-2):
1854 if self.test_mode or self.galaxy_flag: 1862 if self.test_mode or self.galaxy_flag:
1855 use_row = 'yes' 1863 use_row = 'yes'
1856 else: 1864 else:
1857 msnc.quickImshow(center_stack[:,0,:], title=f'theta={theta_start}', aspect='auto') 1865 msnc.quickImshow(center_stack[:,0,:], title=f'theta={theta_start}', aspect='auto')
1862 if use_row != 'no': 1870 if use_row != 'no':
1863 center_offset = find_center.get('lower_center_offset') 1871 center_offset = find_center.get('lower_center_offset')
1864 if msnc.is_num(center_offset): 1872 if msnc.is_num(center_offset):
1865 use_center = pyip.inputYesNo('Current lower center offset = '+ 1873 use_center = pyip.inputYesNo('Current lower center offset = '+
1866 f'{center_offset}, use this value ([y]/n)? ', blank=True) 1874 f'{center_offset}, use this value ([y]/n)? ', blank=True)
1875 print(f'Ok3 {use_center} {use_row}')
1867 if use_center == 'no': 1876 if use_center == 'no':
1868 if use_row == 'no': 1877 if use_row == 'no':
1869 if not self.test_mode: 1878 if not self.test_mode:
1870 msnc.quickImshow(center_stack[:,0,:], title=f'theta={theta_start}', 1879 msnc.quickImshow(center_stack[:,0,:], title=f'theta={theta_start}',
1871 aspect='auto') 1880 aspect='auto')
1874 if row == '': 1883 if row == '':
1875 row = n1 1884 row = n1
1876 if self.save_plots_only: 1885 if self.save_plots_only:
1877 msnc.clearFig(f'theta={theta_start}') 1886 msnc.clearFig(f'theta={theta_start}')
1878 # center_stack order: row,theta,column 1887 # center_stack order: row,theta,column
1888 print('Ok4')
1879 center_offset = self._findCenterOnePlane(center_stack[row,:,:], row, thetas_deg, 1889 center_offset = self._findCenterOnePlane(center_stack[row,:,:], row, thetas_deg,
1880 eff_pixel_size, cross_sectional_dim, num_core=num_core, 1890 eff_pixel_size, cross_sectional_dim, num_core=num_core,
1881 galaxy_param=galaxy_param) 1891 galaxy_param=galaxy_param)
1892 print('Ok5')
1882 logging.info(f'lower_center_offset = {center_offset:.2f} {type(center_offset)}') 1893 logging.info(f'lower_center_offset = {center_offset:.2f} {type(center_offset)}')
1894 print('Ok6')
1883 1895
1884 # Update config and save to file 1896 # Update config and save to file
1885 find_center['row_bounds'] = [n1, n2] 1897 find_center['row_bounds'] = [n1, n2]
1886 find_center['lower_row'] = row 1898 find_center['lower_row'] = row
1887 find_center['lower_center_offset'] = center_offset 1899 find_center['lower_center_offset'] = center_offset