Mercurial > repos > rv43 > tomo
comparison tomo_find_center.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 | 845270a96464 |
comparison
equal
deleted
inserted
replaced
| 2:b8977c98800b | 3:f9c52762c32c |
|---|---|
| 1 #!/usr/bin/env python3 | |
| 2 | |
| 3 import logging | |
| 4 | |
| 5 import sys | |
| 6 import re | |
| 7 import argparse | |
| 8 | |
| 9 from tomo import Tomo | |
| 10 | |
| 11 def __main__(): | |
| 12 | |
| 13 # Parse command line arguments | |
| 14 parser = argparse.ArgumentParser( | |
| 15 description='Find the center axis for a tomography reconstruction') | |
| 16 parser.add_argument('-i', '--input_stacks', | |
| 17 help='Preprocessed image file stacks') | |
| 18 parser.add_argument('-c', '--config', | |
| 19 help='Input config') | |
| 20 parser.add_argument('--row_bounds', | |
| 21 help='Reconstruction row bounds') | |
| 22 parser.add_argument('--center_rows', | |
| 23 help='Center finding rows') | |
| 24 parser.add_argument('--output_config', | |
| 25 help='Output config') | |
| 26 parser.add_argument('--recon_center_low', | |
| 27 help='Lower reconstructed slice center') | |
| 28 parser.add_argument('--recon_center_upp', | |
| 29 help='Upper reconstructed slice center') | |
| 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 indexRegex = re.compile(r'\d+') | |
| 37 row_bounds = [int(i) for i in indexRegex.findall(args.row_bounds)] | |
| 38 center_rows = [int(i) for i in indexRegex.findall(args.center_rows)] | |
| 39 | |
| 40 # Set basic log configuration | |
| 41 logging_format = '%(asctime)s : %(levelname)s - %(module)s : %(funcName)s - %(message)s' | |
| 42 log_level = 'INFO' | |
| 43 level = getattr(logging, log_level.upper(), None) | |
| 44 if not isinstance(level, int): | |
| 45 raise ValueError(f'Invalid log_level: {log_level}') | |
| 46 logging.basicConfig(format=logging_format, level=level, force=True, | |
| 47 handlers=[logging.StreamHandler()]) | |
| 48 | |
| 49 logging.debug(f'input_stacks = {args.input_stacks}') | |
| 50 logging.debug(f'config = {args.config}') | |
| 51 logging.debug(f'row_bounds = {args.row_bounds} {row_bounds}') | |
| 52 logging.debug(f'center_rows = {args.center_rows} {center_rows}') | |
| 53 logging.debug(f'output_config = {args.output_config}') | |
| 54 logging.debug(f'recon_center_low = {args.recon_center_low}') | |
| 55 logging.debug(f'recon_center_uppm = {args.recon_center_upp}') | |
| 56 logging.debug(f'log = {args.log}') | |
| 57 logging.debug(f'is log stdout? {args.log is sys.stdout}') | |
| 58 | |
| 59 # Instantiate Tomo object | |
| 60 tomo = Tomo(config_file=args.config, config_out=args.output_config, log_level=log_level, | |
| 61 log_stream=args.log, galaxy_flag=True) | |
| 62 if not tomo.is_valid: | |
| 63 raise ValueError('Invalid config file provided.') | |
| 64 logging.debug(f'config:\n{tomo.config}') | |
| 65 | |
| 66 # Load preprocessed image files | |
| 67 tomo.loadTomoStacks(args.input_stacks) | |
| 68 | |
| 69 # Find centers | |
| 70 tomo.findCenters(row_bounds, center_rows, args.recon_center_low, args.recon_center_upp) | |
| 71 | |
| 72 if __name__ == "__main__": | |
| 73 __main__() | |
| 74 |
