comparison tomo.py @ 17:7f723407beb3 draft

"planemo upload for repository https://github.com/rolfverberg/galaxytools commit d1744188635274aa3d0bb0e10fcb683602a23b59"
author rv43
date Fri, 15 Apr 2022 20:26:25 +0000
parents 1bcca1f2adb4
children b0a816c8f66c
comparison
equal deleted inserted replaced
16:44f168e1e14f 17:7f723407beb3
1875 self.config = msnc.update('config.txt', 'check_centers', True, 'find_centers') 1875 self.config = msnc.update('config.txt', 'check_centers', True, 'find_centers')
1876 1876
1877 def reconstructTomoStacks(self, galaxy_param=None, num_core=None): 1877 def reconstructTomoStacks(self, galaxy_param=None, num_core=None):
1878 """Reconstruct tomography stacks. 1878 """Reconstruct tomography stacks.
1879 """ 1879 """
1880 print('OK1')
1880 if num_core is None: 1881 if num_core is None:
1881 num_core = self.num_core 1882 num_core = self.num_core
1882 logging.debug('Reconstruct tomography stacks') 1883 logging.debug('Reconstruct tomography stacks')
1883 stacks = self.config['stack_info']['stacks'] 1884 stacks = self.config['stack_info']['stacks']
1884 assert(len(self.tomo_stacks) == self.config['stack_info']['num']) 1885 assert(len(self.tomo_stacks) == self.config['stack_info']['num'])
1885 assert(len(self.tomo_stacks) == len(stacks)) 1886 assert(len(self.tomo_stacks) == len(stacks))
1886 assert(len(self.tomo_recon_stacks) == len(stacks)) 1887 assert(len(self.tomo_recon_stacks) == len(stacks))
1888 print('OK2')
1887 if self.galaxy_flag: 1889 if self.galaxy_flag:
1888 assert(isinstance(galaxy_param, dict)) 1890 assert(isinstance(galaxy_param, dict))
1889 # Get rotation axis centers 1891 # Get rotation axis centers
1890 center_offsets = galaxy_param['center_offsets'] 1892 center_offsets = galaxy_param['center_offsets']
1891 assert(isinstance(center_offsets, list) and len(center_offsets) == 2) 1893 assert(isinstance(center_offsets, list) and len(center_offsets) == 2)
1897 if galaxy_param: 1899 if galaxy_param:
1898 logging.warning('Ignoring galaxy_param in reconstructTomoStacks (only for Galaxy)') 1900 logging.warning('Ignoring galaxy_param in reconstructTomoStacks (only for Galaxy)')
1899 galaxy_param = None 1901 galaxy_param = None
1900 lower_center_offset = None 1902 lower_center_offset = None
1901 upper_center_offset = None 1903 upper_center_offset = None
1904 print('OK3')
1902 1905
1903 # Get rotation axis rows and centers 1906 # Get rotation axis rows and centers
1904 find_center = self.config['find_center'] 1907 find_center = self.config['find_center']
1905 lower_row = find_center.get('lower_row') 1908 lower_row = find_center.get('lower_row')
1906 if lower_row is None: 1909 if lower_row is None:
1923 logging.error('Unable to read upper_center_offset from config') 1926 logging.error('Unable to read upper_center_offset from config')
1924 return 1927 return
1925 center_slope = (upper_center_offset-lower_center_offset)/(upper_row-lower_row) 1928 center_slope = (upper_center_offset-lower_center_offset)/(upper_row-lower_row)
1926 1929
1927 # Set thetas (in radians) 1930 # Set thetas (in radians)
1931 print('OK4')
1928 theta_range = self.config['theta_range'] 1932 theta_range = self.config['theta_range']
1929 theta_start = theta_range['start'] 1933 theta_start = theta_range['start']
1930 theta_end = theta_range['end'] 1934 theta_end = theta_range['end']
1931 num_theta = theta_range['num'] 1935 num_theta = theta_range['num']
1932 num_theta_skip = self.config['preprocess'].get('num_theta_skip', 0) 1936 num_theta_skip = self.config['preprocess'].get('num_theta_skip', 0)
1933 thetas = np.radians(np.linspace(theta_start, theta_end, 1937 thetas = np.radians(np.linspace(theta_start, theta_end,
1934 int(num_theta/(num_theta_skip+1)), endpoint=False)) 1938 int(num_theta/(num_theta_skip+1)), endpoint=False))
1935 1939
1940 print('OK5')
1936 # Reconstruct tomo stacks 1941 # Reconstruct tomo stacks
1937 zoom_perc = self.config['preprocess'].get('zoom_perc', 100) 1942 zoom_perc = self.config['preprocess'].get('zoom_perc', 100)
1938 if zoom_perc == 100: 1943 if zoom_perc == 100:
1939 basetitle = 'recon stack full' 1944 basetitle = 'recon stack full'
1940 else: 1945 else:
1958 continue 1963 continue
1959 stack['reconstructed'] = False 1964 stack['reconstructed'] = False
1960 if not self.tomo_stacks[i].size: 1965 if not self.tomo_stacks[i].size:
1961 self.tomo_stacks[i], available = self._loadTomo('red stack', index, 1966 self.tomo_stacks[i], available = self._loadTomo('red stack', index,
1962 required=True) 1967 required=True)
1968 print(f'self.tomo_stacks.shape = {self.tomo_stacks[i].shape}')
1963 if not self.tomo_stacks[i].size: 1969 if not self.tomo_stacks[i].size:
1964 logging.error(f'Unable to load tomography stack {index} for reconstruction') 1970 logging.error(f'Unable to load tomography stack {index} for reconstruction')
1965 stack[i]['preprocessed'] = False 1971 stack[i]['preprocessed'] = False
1966 load_error = True 1972 load_error = True
1967 continue 1973 continue
1987 self._saveTomo('recon stack', self.tomo_recon_stacks[i], index) 1993 self._saveTomo('recon stack', self.tomo_recon_stacks[i], index)
1988 # else: 1994 # else:
1989 # np.savetxt(self.output_folder+f'recon_stack_{index}.txt', 1995 # np.savetxt(self.output_folder+f'recon_stack_{index}.txt',
1990 # self.tomo_recon_stacks[i][row_slice,:,:], fmt='%.6e') 1996 # self.tomo_recon_stacks[i][row_slice,:,:], fmt='%.6e')
1991 self.tomo_stacks[i] = np.array([]) 1997 self.tomo_stacks[i] = np.array([])
1998 print('OK6')
1992 1999
1993 # Update config and save to file 2000 # Update config and save to file
1994 stack['reconstructed'] = True 2001 stack['reconstructed'] = True
1995 combine_stacks = self.config.get('combine_stacks') 2002 combine_stacks = self.config.get('combine_stacks')
1996 if combine_stacks and index in combine_stacks.get('stacks', []): 2003 if combine_stacks and index in combine_stacks.get('stacks', []):
1997 combine_stacks['stacks'].remove(index) 2004 combine_stacks['stacks'].remove(index)
1998 self.cf.saveFile(self.config_out) 2005 self.cf.saveFile(self.config_out)
1999 2006
2007 print('OK7')
2000 # Save reconstructed tomography stack to file 2008 # Save reconstructed tomography stack to file
2001 if self.galaxy_flag: 2009 if self.galaxy_flag:
2002 t0 = time() 2010 t0 = time()
2003 output_name = galaxy_param['output_name'] 2011 output_name = galaxy_param['output_name']
2004 logging.info(f'Saving reconstructed tomography stack to {output_name} ...') 2012 logging.info(f'Saving reconstructed tomography stack to {output_name} ...')