comparison tomo.py @ 39:8a3036b0a34c draft

"planemo upload for repository https://github.com/rolfverberg/galaxytools commit ebd998fc223b35670269b851ff6d12178ced3ee8"
author rv43
date Tue, 19 Apr 2022 18:43:00 +0000
parents c09b8ee8f68f
children fa94fe25ca46
comparison
equal deleted inserted replaced
38:c09b8ee8f68f 39:8a3036b0a34c
1148 recon_clean = np.expand_dims(recon_sinogram, axis=0) 1148 recon_clean = np.expand_dims(recon_sinogram, axis=0)
1149 del recon_sinogram 1149 del recon_sinogram
1150 t1 = time() 1150 t1 = time()
1151 logging.info(f'running tomopy.misc.corr.remove_ring on {num_core} cores ...') 1151 logging.info(f'running tomopy.misc.corr.remove_ring on {num_core} cores ...')
1152 recon_clean = tomopy.misc.corr.remove_ring(recon_clean, rwidth=17, ncore=num_core) 1152 recon_clean = tomopy.misc.corr.remove_ring(recon_clean, rwidth=17, ncore=num_core)
1153 logging.info('... tomopy.misc.corr.remove_ring took {time()-t1:.2f} seconds!') 1153 logging.info(f'... tomopy.misc.corr.remove_ring took {time()-t1:.2f} seconds!')
1154 logging.debug(f'filtering and removing ring artifact took {time()-t0:.2f} seconds!') 1154 logging.debug(f'filtering and removing ring artifact took {time()-t0:.2f} seconds!')
1155 return recon_clean 1155 return recon_clean
1156 1156
1157 def _plotEdgesOnePlane(self, recon_plane, title, path=None, weight=0.001): 1157 def _plotEdgesOnePlane(self, recon_plane, title, path=None, weight=0.001):
1158 # RV parameters for the denoise, gaussian, and ring removal will be different for different feature sizes 1158 # RV parameters for the denoise, gaussian, and ring removal will be different for different feature sizes
1191 logging.info('running tomopy.find_center_vo on 24 cores ...') 1191 logging.info('running tomopy.find_center_vo on 24 cores ...')
1192 tomo_center = tomopy.find_center_vo(sinogram, ncore=24) 1192 tomo_center = tomopy.find_center_vo(sinogram, ncore=24)
1193 else: 1193 else:
1194 logging.info(f'running tomopy.find_center_vo on {num_core} cores ...') 1194 logging.info(f'running tomopy.find_center_vo on {num_core} cores ...')
1195 tomo_center = tomopy.find_center_vo(sinogram, ncore=num_core) 1195 tomo_center = tomopy.find_center_vo(sinogram, ncore=num_core)
1196 logging.info('... tomopy.find_center_vo took {time()-t0:.2f} seconds!') 1196 logging.info(f'... tomopy.find_center_vo took {time()-t0:.2f} seconds!')
1197 center_offset_vo = tomo_center-center 1197 center_offset_vo = tomo_center-center
1198 if self.test_mode: 1198 if self.test_mode:
1199 logging.info(f'Center at row {row} using Nghia Vo’s method = {center_offset_vo:.2f}') 1199 logging.info(f'Center at row {row} using Nghia Vo’s method = {center_offset_vo:.2f}')
1200 del sinogram_T 1200 del sinogram_T
1201 return float(center_offset_vo) 1201 return float(center_offset_vo)
1202 elif self.galaxy_flag: 1202 elif self.galaxy_flag:
1203 logging.info(f'Center at row {row} using Nghia Vo’s method = {center_offset_vo:.2f}') 1203 logging.info(f'Center at row {row} using Nghia Vo’s method = {center_offset_vo:.2f}')
1204 t0 = time() 1204 t0 = time()
1205 logging.info('running self._reconstructOnePlane on {num_core} cores ...') 1205 logging.info(f'running self._reconstructOnePlane on {num_core} cores ...')
1206 recon_plane = self._reconstructOnePlane(sinogram_T, tomo_center, thetas_deg, 1206 recon_plane = self._reconstructOnePlane(sinogram_T, tomo_center, thetas_deg,
1207 eff_pixel_size, cross_sectional_dim, False, num_core) 1207 eff_pixel_size, cross_sectional_dim, False, num_core)
1208 logging.info('... self._reconstructOnePlane took {time()-t0:.2f} seconds!') 1208 logging.info(f'... self._reconstructOnePlane took {time()-t0:.2f} seconds!')
1209 title = f'edges row{row} center offset{center_offset_vo:.2f} Vo' 1209 title = f'edges row{row} center offset{center_offset_vo:.2f} Vo'
1210 self._plotEdgesOnePlane(recon_plane, title, path='find_center_pngs') 1210 self._plotEdgesOnePlane(recon_plane, title, path='find_center_pngs')
1211 del recon_plane 1211 del recon_plane
1212 if not galaxy_param['center_type_selector']: 1212 if not galaxy_param['center_type_selector']:
1213 del sinogram_T 1213 del sinogram_T
1279 for center_offset in center_offsets: 1279 for center_offset in center_offsets:
1280 if center_offset == center_offset_vo: 1280 if center_offset == center_offset_vo:
1281 continue 1281 continue
1282 logging.info(f'center_offset = {center_offset:.2f}') 1282 logging.info(f'center_offset = {center_offset:.2f}')
1283 t0 = time() 1283 t0 = time()
1284 logging.info('running self._reconstructOnePlane on {num_core} cores ...') 1284 logging.info(f'running self._reconstructOnePlane on {num_core} cores ...')
1285 recon_plane = self._reconstructOnePlane(sinogram_T, center_offset+center, 1285 recon_plane = self._reconstructOnePlane(sinogram_T, center_offset+center,
1286 thetas_deg, eff_pixel_size, cross_sectional_dim, False, num_core) 1286 thetas_deg, eff_pixel_size, cross_sectional_dim, False, num_core)
1287 logging.info('... self._reconstructOnePlane took {time()-t0:.2f} seconds!') 1287 logging.info(f'... self._reconstructOnePlane took {time()-t0:.2f} seconds!')
1288 title = f'edges row{row} center_offset{center_offset:.2f}' 1288 title = f'edges row{row} center_offset{center_offset:.2f}'
1289 if self.galaxy_flag: 1289 if self.galaxy_flag:
1290 self._plotEdgesOnePlane(recon_plane, title, path='find_center_pngs') 1290 self._plotEdgesOnePlane(recon_plane, title, path='find_center_pngs')
1291 else: 1291 else:
1292 self._plotEdgesOnePlane(recon_plane, title) 1292 self._plotEdgesOnePlane(recon_plane, title)
1333 raise ValueError('center_offsets dimension mismatch in reconstructOneTomoStack') 1333 raise ValueError('center_offsets dimension mismatch in reconstructOneTomoStack')
1334 centers = center_offsets 1334 centers = center_offsets
1335 centers += tomo_stack.shape[2]/2 1335 centers += tomo_stack.shape[2]/2
1336 # RV hangs here with more than 24 cores and sge_64G_4 1336 # RV hangs here with more than 24 cores and sge_64G_4
1337 if True: 1337 if True:
1338 t0 = time()
1339 logging.info(f'running tomopy.prep.stripe.remove_stripe_fw on {num_core} cores ...')
1338 tomo_stack = tomopy.prep.stripe.remove_stripe_fw( 1340 tomo_stack = tomopy.prep.stripe.remove_stripe_fw(
1339 tomo_stack[row_bounds[0]:row_bounds[1]], sigma=sigma, ncore=num_core) 1341 tomo_stack[row_bounds[0]:row_bounds[1]], sigma=sigma, ncore=num_core)
1342 logging.info(f'... tomopy.prep.stripe.remove_stripe_fw took {time()-t0:.2f} seconds!')
1340 else: 1343 else:
1341 tomo_stack = tomo_stack[row_bounds[0]:row_bounds[1]] 1344 tomo_stack = tomo_stack[row_bounds[0]:row_bounds[1]]
1342 logging.info('performing initial reconstruction') 1345 logging.info('performing initial reconstruction')
1346 t0 = time()
1347 logging.info(f'running tomopy.recon on {num_core} cores ...')
1343 tomo_recon_stack = tomopy.recon(tomo_stack, thetas, centers, sinogram_order=True, 1348 tomo_recon_stack = tomopy.recon(tomo_stack, thetas, centers, sinogram_order=True,
1344 algorithm=algorithm, ncore=num_core) 1349 algorithm=algorithm, ncore=num_core)
1350 logging.info(f'... tomopy.recon took {time()-t0:.2f} seconds!')
1345 if run_secondary_sirt and secondary_iter > 0: 1351 if run_secondary_sirt and secondary_iter > 0:
1346 logging.info(f'running {secondary_iter} secondary iterations') 1352 logging.info(f'running {secondary_iter} secondary iterations')
1347 #options = {'method':'SIRT_CUDA', 'proj_type':'cuda', 'num_iter':secondary_iter} 1353 #options = {'method':'SIRT_CUDA', 'proj_type':'cuda', 'num_iter':secondary_iter}
1348 #RV: doesn't work for me: "Error: CUDA error 803: system has unsupported display driver / 1354 #RV: doesn't work for me: "Error: CUDA error 803: system has unsupported display driver /
1349 # cuda driver combination." 1355 # cuda driver combination."
1350 #options = {'method':'SIRT', 'proj_type':'linear', 'MinConstraint': 0, 'num_iter':secondary_iter} 1356 #options = {'method':'SIRT', 'proj_type':'linear', 'MinConstraint': 0, 'num_iter':secondary_iter}
1351 #SIRT did not finish while running overnight 1357 #SIRT did not finish while running overnight
1352 #options = {'method':'SART', 'proj_type':'linear', 'num_iter':secondary_iter} 1358 #options = {'method':'SART', 'proj_type':'linear', 'num_iter':secondary_iter}
1353 options = {'method':'SART', 'proj_type':'linear', 'MinConstraint': 0, 1359 options = {'method':'SART', 'proj_type':'linear', 'MinConstraint': 0,
1354 'num_iter':secondary_iter} 1360 'num_iter':secondary_iter}
1361 t0 = time()
1362 logging.info(f'running tomopy.recon on {num_core} cores ...')
1355 tomo_recon_stack = tomopy.recon(tomo_stack, thetas, centers, 1363 tomo_recon_stack = tomopy.recon(tomo_stack, thetas, centers,
1356 init_recon=tomo_recon_stack, options=options, sinogram_order=True, 1364 init_recon=tomo_recon_stack, options=options, sinogram_order=True,
1357 algorithm=tomopy.astra, ncore=num_core) 1365 algorithm=tomopy.astra, ncore=num_core)
1366 logging.info(f'... tomopy.recon took {time()-t0:.2f} seconds!')
1358 if True: 1367 if True:
1368 t0 = time()
1369 logging.info(f'running tomopy.misc.corr.remove_ring on {num_core} cores ...')
1359 tomopy.misc.corr.remove_ring(tomo_recon_stack, rwidth=rwidth, out=tomo_recon_stack, 1370 tomopy.misc.corr.remove_ring(tomo_recon_stack, rwidth=rwidth, out=tomo_recon_stack,
1360 ncore=num_core) 1371 ncore=num_core)
1372 logging.info(f'... tomopy.misc.corr.remove_ring took {time()-t0:.2f} seconds!')
1361 return tomo_recon_stack 1373 return tomo_recon_stack
1362 1374
1363 def findImageFiles(self): 1375 def findImageFiles(self):
1364 """Find all available image files. 1376 """Find all available image files.
1365 """ 1377 """
1909 """Reconstruct tomography stacks. 1921 """Reconstruct tomography stacks.
1910 """ 1922 """
1911 if num_core is None: 1923 if num_core is None:
1912 num_core = self.num_core 1924 num_core = self.num_core
1913 logging.info(f'num_core available = {num_core}') 1925 logging.info(f'num_core available = {num_core}')
1914 if num_core > 24: 1926 #if num_core > 24:
1915 num_core = 24 1927 # num_core = 24
1916 logging.info(f'num_core used = {num_core}') 1928 logging.info(f'num_core used = {num_core}')
1917 if self.galaxy_flag: 1929 if self.galaxy_flag:
1918 assert(galaxy_param) 1930 assert(galaxy_param)
1919 if not os.path.exists('center_slice_pngs'): 1931 if not os.path.exists('center_slice_pngs'):
1920 os.mkdir('center_slice_pngs') 1932 os.mkdir('center_slice_pngs')
2006 continue 2018 continue
2007 assert(0 <= lower_row < upper_row < self.tomo_stacks[i].shape[0]) 2019 assert(0 <= lower_row < upper_row < self.tomo_stacks[i].shape[0])
2008 center_offsets = [lower_center_offset-lower_row*center_slope, 2020 center_offsets = [lower_center_offset-lower_row*center_slope,
2009 upper_center_offset+(self.tomo_stacks[i].shape[0]-1-upper_row)*center_slope] 2021 upper_center_offset+(self.tomo_stacks[i].shape[0]-1-upper_row)*center_slope]
2010 t0 = time() 2022 t0 = time()
2023 logging.info(f'running self._reconstructOneTomoStack on {num_core} cores ...')
2011 self.tomo_recon_stacks[i]= self._reconstructOneTomoStack(self.tomo_stacks[i], 2024 self.tomo_recon_stacks[i]= self._reconstructOneTomoStack(self.tomo_stacks[i],
2012 thetas, center_offsets=center_offsets, sigma=0.1, num_core=num_core, 2025 thetas, center_offsets=center_offsets, sigma=0.1, num_core=num_core,
2013 algorithm='gridrec', run_secondary_sirt=True, secondary_iter=25) 2026 algorithm='gridrec', run_secondary_sirt=True, secondary_iter=25)
2014 logging.info(f'Reconstruction of stack {index} took {time()-t0:.2f} seconds!') 2027 logging.info(f'... self._reconstructOneTomoStack took {time()-t0:.2f} seconds!')
2028 #logging.info(f'Reconstruction of stack {index} took {time()-t0:.2f} seconds!')
2015 if self.galaxy_flag: 2029 if self.galaxy_flag:
2016 x_slice = int(self.tomo_stacks[i].shape[0]/2) 2030 x_slice = int(self.tomo_stacks[i].shape[0]/2)
2017 title = f'{basetitle} {index} xslice{x_slice}' 2031 title = f'{basetitle} {index} xslice{x_slice}'
2018 msnc.quickImshow(self.tomo_recon_stacks[i][x_slice,:,:], title=title, 2032 msnc.quickImshow(self.tomo_recon_stacks[i][x_slice,:,:], title=title,
2019 path='center_slice_pngs', save_fig=True, save_only=True) 2033 path='center_slice_pngs', save_fig=True, save_only=True)