Mercurial > repos > rv43 > tomo
comparison tomo_combine.py @ 48:059819ea1f0e draft
"planemo upload for repository https://github.com/rolfverberg/galaxytools commit b97c6a8f181dea6d2f9cfa2069b86d30dcc47b4d"
| author | rv43 |
|---|---|
| date | Wed, 27 Apr 2022 17:28:26 +0000 |
| parents | |
| children | ba5866d0251d |
comparison
equal
deleted
inserted
replaced
| 47:c693117d01e9 | 48:059819ea1f0e |
|---|---|
| 1 #!/usr/bin/env python3 | |
| 2 | |
| 3 import logging | |
| 4 | |
| 5 import sys | |
| 6 import argparse | |
| 7 import tracemalloc | |
| 8 | |
| 9 from tomo import Tomo | |
| 10 | |
| 11 def __main__(): | |
| 12 | |
| 13 # Parse command line arguments | |
| 14 parser = argparse.ArgumentParser( | |
| 15 description='Combine reconstructed tomography stacks') | |
| 16 parser.add_argument('-i', '--input_stacks', | |
| 17 help='Reconstructed image file stacks') | |
| 18 parser.add_argument('-c', '--config', | |
| 19 help='Input config') | |
| 20 parser.add_argument('--x_bounds', | |
| 21 required=True, nargs=2, type=int, help='Reconstructed range in x direction') | |
| 22 parser.add_argument('--y_bounds', | |
| 23 required=True, nargs=2, type=int, help='Reconstructed range in y direction') | |
| 24 parser.add_argument('--z_bounds', | |
| 25 required=True, nargs=2, type=int, help='Reconstructed range in z direction') | |
| 26 parser.add_argument('--output_config', | |
| 27 help='Output config') | |
| 28 parser.add_argument('--output_data', | |
| 29 help='Combined tomography stacks') | |
| 30 parser.add_argument('-l', '--log', | |
| 31 type=argparse.FileType('w'), | |
| 32 default=sys.stdout, | |
| 33 help='Log file') | |
| 34 args = parser.parse_args() | |
| 35 | |
| 36 # Starting memory monitoring | |
| 37 tracemalloc.start() | |
| 38 | |
| 39 # Set basic log configuration | |
| 40 logging_format = '%(asctime)s : %(levelname)s - %(module)s : %(funcName)s - %(message)s' | |
| 41 log_level = 'INFO' | |
| 42 level = getattr(logging, log_level.upper(), None) | |
| 43 if not isinstance(level, int): | |
| 44 raise ValueError(f'Invalid log_level: {log_level}') | |
| 45 logging.basicConfig(format=logging_format, level=level, force=True, | |
| 46 handlers=[logging.StreamHandler()]) | |
| 47 | |
| 48 logging.debug(f'input_stacks = {args.input_stacks}') | |
| 49 logging.debug(f'config = {args.config}') | |
| 50 logging.debug(f'x_bounds = {args.x_bounds} {type(args.x_bounds)}') | |
| 51 logging.debug(f'y_bounds = {args.y_bounds} {type(args.y_bounds)}') | |
| 52 logging.debug(f'z_bounds = {args.z_bounds} {type(args.z_bounds)}') | |
| 53 logging.debug(f'output_config = {args.output_config}') | |
| 54 logging.debug(f'output_data = {args.output_data}') | |
| 55 logging.debug(f'log = {args.log}') | |
| 56 logging.debug(f'is log stdout? {args.log is sys.stdout}') | |
| 57 | |
| 58 # Instantiate Tomo object | |
| 59 tomo = Tomo(config_file=args.config, config_out=args.output_config, log_level=log_level, | |
| 60 log_stream=args.log, galaxy_flag=True) | |
| 61 if not tomo.is_valid: | |
| 62 raise ValueError('Invalid config file provided.') | |
| 63 logging.debug(f'config:\n{tomo.config}') | |
| 64 | |
| 65 # Load reconstructed image files | |
| 66 tomo.loadTomoStacks(args.input_stacks, recon_flag=True) | |
| 67 | |
| 68 # Combined reconstructed tomography stacks | |
| 69 galaxy_param = {'x_bounds' : args.x_bounds, 'y_bounds' : args.y_bounds, | |
| 70 'z_bounds' : args.z_bounds, 'output_name' : args.output_data} | |
| 71 logging.info(f'galaxy_param = {galaxy_param}') | |
| 72 tomo.combineTomoStacks(galaxy_param) | |
| 73 | |
| 74 # Displaying memory usage | |
| 75 logging.info(f'Memory usage: {tracemalloc.get_traced_memory()}') | |
| 76 | |
| 77 # stopping memory monitoring | |
| 78 tracemalloc.stop() | |
| 79 | |
| 80 if __name__ == "__main__": | |
| 81 __main__() | |
| 82 |
