Mercurial > repos > rv43 > tomo
comparison tomo_reconstruct.py @ 3:f9c52762c32c draft
"planemo upload for repository https://github.com/rolfverberg/galaxytools commit 7dce44d576e4149f31bdc2ee4dce0bb6962badb6"
| author | rv43 |
|---|---|
| date | Tue, 05 Apr 2022 18:23:54 +0000 |
| parents | |
| children | 1bcca1f2adb4 |
comparison
equal
deleted
inserted
replaced
| 2:b8977c98800b | 3:f9c52762c32c |
|---|---|
| 1 #!/usr/bin/env python3 | |
| 2 | |
| 3 import logging | |
| 4 | |
| 5 import sys | |
| 6 import argparse | |
| 7 | |
| 8 from tomo import Tomo | |
| 9 | |
| 10 def __main__(): | |
| 11 | |
| 12 # Parse command line arguments | |
| 13 parser = argparse.ArgumentParser( | |
| 14 description='Perfrom a tomography reconstruction') | |
| 15 parser.add_argument('-i', '--input_stacks', | |
| 16 help='Preprocessed image file stacks') | |
| 17 parser.add_argument('-c', '--config', | |
| 18 help='Input config') | |
| 19 parser.add_argument('--output_config', | |
| 20 help='Output config') | |
| 21 parser.add_argument('--output_data', | |
| 22 help='Reconstructed tomography data') | |
| 23 parser.add_argument('-l', '--log', | |
| 24 type=argparse.FileType('w'), | |
| 25 default=sys.stdout, | |
| 26 help='Log file') | |
| 27 args = parser.parse_args() | |
| 28 | |
| 29 # Set basic log configuration | |
| 30 logging_format = '%(asctime)s : %(levelname)s - %(module)s : %(funcName)s - %(message)s' | |
| 31 log_level = 'INFO' | |
| 32 level = getattr(logging, log_level.upper(), None) | |
| 33 if not isinstance(level, int): | |
| 34 raise ValueError(f'Invalid log_level: {log_level}') | |
| 35 logging.basicConfig(format=logging_format, level=level, force=True, | |
| 36 handlers=[logging.StreamHandler()]) | |
| 37 | |
| 38 logging.debug(f'input_stacks = {args.input_stacks}') | |
| 39 logging.debug(f'config = {args.config}') | |
| 40 logging.debug(f'output_config = {args.output_config}') | |
| 41 logging.debug(f'output_data = {args.output_data}') | |
| 42 logging.debug(f'log = {args.log}') | |
| 43 logging.debug(f'is log stdout? {args.log is sys.stdout}') | |
| 44 | |
| 45 # Instantiate Tomo object | |
| 46 tomo = Tomo(config_file=args.config, config_out=args.output_config, log_level=log_level, | |
| 47 log_stream=args.log, galaxy_flag=True) | |
| 48 if not tomo.is_valid: | |
| 49 raise ValueError('Invalid config file provided.') | |
| 50 logging.debug(f'config:\n{tomo.config}') | |
| 51 | |
| 52 # Load preprocessed image files | |
| 53 tomo.loadTomoStacks(args.input_stacks) | |
| 54 | |
| 55 # Reconstruct tomography stacks | |
| 56 tomo.reconstructTomoStacks(args.output_data) | |
| 57 | |
| 58 if __name__ == "__main__": | |
| 59 __main__() | |
| 60 |
