Mercurial > repos > rv43 > tomo
changeset 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 | 27d4a36a8c4a |
children | 50c8d19d5f89 |
files | config_l_center.yaml run_tomo_find_center run_tomo_reconstruct run_tomo_setup tomo.py tomo_find_center.py tomo_find_center.xml |
diffstat | 7 files changed, 24 insertions(+), 94 deletions(-) [+] |
line wrap: on
line diff
--- a/config_l_center.yaml Fri Apr 08 16:56:53 2022 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -bright_field: - data_path: /nfs/chess/scratch/user/rv43/2022-1/id3b/sobhani-3249-A/tomo7C/tomo7C_flat_ANDOR2_001.h5 - img_offset: 1 - img_start: 0 - num: 20 -dark_field: - data_path: null - img_start: -1 - num: 0 -data_filetype: h5 -detector: - columns: 1700 - id: andor2 - pixel_size: 0.0013 - rows: 1436 -preprocess: - img_x_bounds: - - 0 - - 1436 - num_theta_skip: 0 - zoom_perc: 100 -stack_info: - num: 1 - stacks: - - data_path: /nfs/chess/scratch/user/rv43/2022-1/id3b/sobhani-3249-A/tomo7C/tomo7C_ANDOR2_001.h5 - img_offset: 1 - img_start: 0 - index: 1 - num: 354 - preprocessed: true - ref_height: 0.0 -theta_range: - end: 180.0 - num: 354 - start: 0.0 -work_folder: /nfs/chess/scratch/user/rv43/2022-1/id3b/sobhani-3249-A
--- a/run_tomo_find_center Fri Apr 08 16:56:53 2022 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -#!/bin/bash - -#python tomo_find_center.py -i red_stacks.npz -c 'config_l_center.yaml' --row_bounds 620 950 --center_rows 670 890 --output_config 'output.yaml' --recon_center_low 'recon_center_low.png' --recon_center_upp 'recon_center_upp.png' -python tomo_find_center.py -i red_stacks.npz -c 'config_l_center.yaml' --row_bounds 620 950 --center_rows 670 890 --output_config 'output.yaml' --recon_center_low 'recon_center_low.png' --recon_center_upp 'recon_center_upp.png' --center_type_selector 'vo' --set_range 2 --set_step 0.9 -#python tomo_find_center.py -i red_stacks.npz -c 'config_l_center.yaml' --row_bounds 620 950 --center_rows 670 890 --output_config 'output.yaml' --recon_center_low 'recon_center_low.png' --recon_center_upp 'recon_center_upp.png' --center_type_selector 'user' --set_center 10 --set_range 2 --set_step 0.9
--- a/run_tomo_reconstruct Fri Apr 08 16:56:53 2022 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -#!/bin/bash - -python tomo_reconstruct.py -i red_stacks.npz -c 'config_l_recon.yaml' --output_config 'output.yaml' --output_data 'output.npz'
--- a/run_tomo_setup Fri Apr 08 16:56:53 2022 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -#!/bin/bash - -python tomo_setup.py -i inputfiles_l.txt -c 'config_l_setup.yaml' --theta_range '0.0 180.0 354' --output_config 'output.yaml' --output_data 'output.npz' --dark 'dark.png' --bright 'bright.png' --tomo 'tomo.png' --detectorbounds 'detectorbounds.png' 1 20 1 354
--- 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
--- a/tomo_find_center.py Fri Apr 08 16:56:53 2022 +0000 +++ b/tomo_find_center.py Fri Apr 08 17:49:28 2022 +0000 @@ -30,10 +30,6 @@ type=float, help='Set step') parser.add_argument('--output_config', required=True, help='Output config') - parser.add_argument('--recon_center_low', - help='Lower reconstructed slice center image name') - parser.add_argument('--recon_center_upp', - help='Upper reconstructed slice center image name') parser.add_argument('-l', '--log', type=argparse.FileType('w'), default=sys.stdout, help='Log file') args = parser.parse_args() @@ -56,8 +52,6 @@ logging.debug(f'set_range = {args.set_range}') logging.debug(f'set_step = {args.set_step}') logging.debug(f'output_config = {args.output_config}') - logging.debug(f'recon_center_low = {args.recon_center_low}') - logging.debug(f'recon_center_upp = {args.recon_center_upp}') logging.debug(f'log = {args.log}') logging.debug(f'is log stdout? {args.log is sys.stdout}') @@ -74,8 +68,7 @@ # Find centers galaxy_param = {'row_bounds' : args.row_bounds, 'center_rows' : args.center_rows, 'center_type_selector' : args.center_type_selector, 'set_center' : args.set_center, - 'set_range' : args.set_range, 'set_step' : args.set_step, - 'recon_center_low' : args.recon_center_low, 'recon_center_upp' : args.recon_center_upp} + 'set_range' : args.set_range, 'set_step' : args.set_step} tomo.findCenters(galaxy_param) if __name__ == "__main__":
--- a/tomo_find_center.xml Fri Apr 08 16:56:53 2022 +0000 +++ b/tomo_find_center.xml Fri Apr 08 17:49:28 2022 +0000 @@ -5,9 +5,7 @@ </macros> <expand macro="requirements" /> <command detect_errors="exit_code"><![CDATA[ - #if str( $set.set_selector ) == "yes" - mkdir png_files; - #end if + mkdir find_center_pngs; $__tool_directory__/tomo_find_center.py -i '$red_stacks' -c '$config' @@ -22,8 +20,6 @@ --set_step '$set.set_step' #end if --output_config 'output_config.yaml' - --recon_center_low 'recon_center_low.png' - --recon_center_upp 'recon_center_upp.png' -l '$log' ]]></command> <inputs> @@ -59,14 +55,12 @@ </inputs> <outputs> <expand macro="common_outputs"/> - <data name="recon_center_low" format="png" label="Recontructed slice lower center using Nghia Vo’s method" from_work_dir="recon_center_low.png"/> - <data name="recon_center_upp" format="png" label="Recontructed slice upper center using Nghia Vo’s method" from_work_dir="recon_center_upp.png"/> - <collection name="recon_center_set" type="list" label="Recontructed slices center position set"> - <discover_datasets pattern="__name_and_ext__" directory="png_files"/> + <collection name="recon_center_set" type="list" label="Recontructed slices at various centers"> + <discover_datasets pattern="__name_and_ext__" directory="find_center_pngs"/> </collection> </outputs> <help><![CDATA[ - Preprocess tomography images. + Find the center axis for a tomography reconstruction. ]]></help> <expand macro="citations"/> </tool>