Mercurial > repos > rv43 > tomo
diff tomo.py @ 13:40395e60d2be draft
"planemo upload for repository https://github.com/rolfverberg/galaxytools commit e61a62f5b5950b3142fedad2c0e49a00f66f9980"
author | rv43 |
---|---|
date | Fri, 08 Apr 2022 17:49:28 +0000 |
parents | ec7c3e84d611 |
children | 1bcca1f2adb4 |
line wrap: on
line diff
--- a/tomo.py Fri Apr 08 16:56:53 2022 +0000 +++ b/tomo.py Fri Apr 08 17:49:28 2022 +0000 @@ -1149,14 +1149,14 @@ logging.debug(f'filtering and removing ring artifact took {time()-t0:.2f} seconds!') return recon_clean - def _plotEdgesOnePlane(self, recon_plane, title, path=None, name=None, weight=0.001): + def _plotEdgesOnePlane(self, recon_plane, title, path=None, weight=0.001): # RV parameters for the denoise, gaussian, and ring removal will be different for different feature sizes edges = denoise_tv_chambolle(recon_plane, weight = weight) vmax = np.max(edges[0,:,:]) vmin = -vmax if self.galaxy_flag: - msnc.quickImshow(edges[0,:,:], title, path=path, name=name, save_fig=True, - save_only=True, cmap='gray', vmin=vmin, vmax=vmax) + msnc.quickImshow(edges[0,:,:], title, path=path, save_fig=True, save_only=True, + cmap='gray', vmin=vmin, vmax=vmax) else: if path is None: path=self.output_folder @@ -1168,9 +1168,13 @@ del edges def _findCenterOnePlane(self, sinogram, row, thetas_deg, eff_pixel_size, cross_sectional_dim, - tol=0.1, num_core=1, recon_pngname=None, galaxy_param=None): + tol=0.1, num_core=1, galaxy_param=None): """Find center for a single tomography plane. """ + if self.galaxy_flag: + assert(galaxy_param) + if not os.path.exists('find_center_pngs'): + os.mkdir('find_center_pngs') # sinogram index order: theta,column # need index order column,theta for iradon, so take transpose sinogram_T = sinogram.T @@ -1185,23 +1189,19 @@ return float(center_offset_vo) elif self.galaxy_flag: logging.info(f'Center at row {row} using Nghia Vo’s method = {center_offset_vo:.2f}') - if recon_pngname: - assert(isinstance(recon_pngname, str)) - recon_plane = self._reconstructOnePlane(sinogram_T, tomo_center, thetas_deg, - eff_pixel_size, cross_sectional_dim, False, num_core) - title = os.path.basename(recon_pngname) - self._plotEdgesOnePlane(recon_plane, title, name=recon_pngname) - del recon_plane - if not galaxy_param or not galaxy_param['center_type_selector']: + recon_plane = self._reconstructOnePlane(sinogram_T, tomo_center, thetas_deg, + eff_pixel_size, cross_sectional_dim, False, num_core) + title = f'edges row{row} center offset{center_offset_vo:.2f} Vo' + self._plotEdgesOnePlane(recon_plane, title, path='find_center_pngs') + del recon_plane + if not galaxy_param['center_type_selector']: del sinogram_T return float(center_offset_vo) else: print(f'Center at row {row} using Nghia Vo’s method = {center_offset_vo:.2f}') - if recon_pngname: - logging.warning('Ignoring recon_pngname in _findCenterOnePlane (only for Galaxy)') recon_plane = self._reconstructOnePlane(sinogram_T, tomo_center, thetas_deg, eff_pixel_size, cross_sectional_dim, False, num_core) - title = f'edges row{row} center_offset_vo{center_offset_vo:.2f}' + title = f'edges row{row} center offset{center_offset_vo:.2f} Vo' self._plotEdgesOnePlane(recon_plane, title) if not self.galaxy_flag: if (pyip.inputYesNo('Try finding center using phase correlation '+ @@ -1218,7 +1218,7 @@ print(f'Center at row {row} using phase correlation = {center_offset:.2f}') recon_plane = self._reconstructOnePlane(sinogram_T, tomo_center, thetas_deg, eff_pixel_size, cross_sectional_dim, False, num_core) - title = f'edges row{row} center_offset{center_offset:.2f}' + title = f'edges row{row} center_offset{center_offset:.2f} PC' self._plotEdgesOnePlane(recon_plane, title) if (pyip.inputYesNo('Accept a center location ([y]) or continue '+ 'search (n)? ', blank=True) != 'no'): @@ -1232,8 +1232,6 @@ return float(center_offset) # perform center finding search - if self.galaxy_flag and not os.path.exists('png_files'): - os.mkdir('png_files') while True: if self.galaxy_flag and galaxy_param and galaxy_param['center_type_selector']: set_center = center_offset_vo @@ -1271,7 +1269,7 @@ thetas_deg, eff_pixel_size, cross_sectional_dim, False, num_core) title = f'edges row{row} center_offset{center_offset:.2f}' if self.galaxy_flag: - self._plotEdgesOnePlane(recon_plane, title, path='png_files') + self._plotEdgesOnePlane(recon_plane, title, path='find_center_pngs') else: self._plotEdgesOnePlane(recon_plane, title) if self.galaxy_flag or pyip.inputInt('\nContinue (0) or end the search (1): ', @@ -1760,13 +1758,9 @@ if self.save_plots_only: msnc.clearFig(f'theta={theta_start}') # center_stack order: row,theta,column - if galaxy_param: - recon_pngname = galaxy_param['recon_center_low'] - else: - recon_pngname = None center_offset = self._findCenterOnePlane(center_stack[row,:,:], row, thetas_deg, eff_pixel_size, cross_sectional_dim, num_core=num_core, - recon_pngname=recon_pngname, galaxy_param=galaxy_param) + galaxy_param=galaxy_param) logging.info(f'lower_center_offset = {center_offset:.2f} {type(center_offset)}') print(center_offset) @@ -1809,13 +1803,9 @@ if self.save_plots_only: msnc.clearFig(f'theta={theta_start}') # center_stack order: row,theta,column - if galaxy_param: - recon_pngname = galaxy_param['recon_center_upp'] - else: - recon_pngname = None center_offset = self._findCenterOnePlane(center_stack[row,:,:], row, thetas_deg, eff_pixel_size, cross_sectional_dim, num_core=num_core, - recon_pngname=recon_pngname, galaxy_param=galaxy_param) + galaxy_param=galaxy_param) logging.info(f'upper_center_offset = {center_offset:.2f}') del center_stack