Mercurial > repos > rv43 > tomo
comparison tomo_reduce.py @ 73:adb84c450789 draft
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213-dirty
| author | rv43 |
|---|---|
| date | Mon, 20 Mar 2023 17:30:24 +0000 |
| parents | 1cf15b61cd83 |
| children | 4f4ee8db5f67 |
comparison
equal
deleted
inserted
replaced
| 72:d5329ca0210d | 73:adb84c450789 |
|---|---|
| 13 #@profile | 13 #@profile |
| 14 def __main__(): | 14 def __main__(): |
| 15 # Parse command line arguments | 15 # Parse command line arguments |
| 16 parser = argparse.ArgumentParser( | 16 parser = argparse.ArgumentParser( |
| 17 description='Reduce tomography data') | 17 description='Reduce tomography data') |
| 18 parser.add_argument('-i', '--input_file', | 18 # parser.add_argument('-i', '--input_file', |
| 19 required=True, | 19 # required=True, |
| 20 type=pathlib.Path, | 20 # type=pathlib.Path, |
| 21 help='''Full or relative path to the input file (in yaml or nxs format).''') | 21 # help='''Full or relative path to the input file (in yaml or nxs format).''') |
| 22 parser.add_argument('-o', '--output_file', | 22 # parser.add_argument('-o', '--output_file', |
| 23 required=True, | 23 # required=True, |
| 24 type=pathlib.Path, | 24 # type=pathlib.Path, |
| 25 help='''Full or relative path to the output file (in Nexus format).''') | 25 # help='''Full or relative path to the output file (in Nexus format).''') |
| 26 parser.add_argument('--galaxy_flag', | 26 # parser.add_argument('--galaxy_flag', |
| 27 action='store_true', | 27 # action='store_true', |
| 28 help='''Use this flag to run the scripts as a galaxy tool.''') | 28 # help='''Use this flag to run the scripts as a galaxy tool.''') |
| 29 parser.add_argument('--img_x_bounds', | 29 # parser.add_argument('--img_x_bounds', |
| 30 required=False, | 30 # required=False, |
| 31 nargs=2, | 31 # nargs=2, |
| 32 type=int, | 32 # type=int, |
| 33 help='Vertical data reduction image range') | 33 # help='Vertical data reduction image range') |
| 34 parser.add_argument('-l', '--log', | 34 parser.add_argument('-l', '--log', |
| 35 # type=argparse.FileType('w'), | 35 # type=argparse.FileType('w'), |
| 36 default=sys.stdout, | 36 default=sys.stdout, |
| 37 help='Logging stream or filename') | 37 help='Logging stream or filename') |
| 38 parser.add_argument('--log_level', | 38 # parser.add_argument('--log_level', |
| 39 choices=logging._nameToLevel.keys(), | 39 # choices=logging._nameToLevel.keys(), |
| 40 default='INFO', | 40 # default='INFO', |
| 41 help='''Specify a preferred logging level.''') | 41 # help='''Specify a preferred logging level.''') |
| 42 args = parser.parse_args() | 42 args = parser.parse_args() |
| 43 | 43 |
| 44 # Set log configuration | 44 # Set log configuration |
| 45 # When logging to file, the stdout log level defaults to WARNING | 45 # When logging to file, the stdout log level defaults to WARNING |
| 46 logging_format = '%(asctime)s : %(levelname)s - %(module)s : %(funcName)s - %(message)s' | 46 logging_format = '%(asctime)s : %(levelname)s - %(module)s : %(funcName)s - %(message)s' |
| 64 | 64 |
| 65 # Start memory monitoring | 65 # Start memory monitoring |
| 66 # tracemalloc.start() | 66 # tracemalloc.start() |
| 67 | 67 |
| 68 # Log command line arguments | 68 # Log command line arguments |
| 69 logging.info(f'input_file = {args.input_file}') | 69 # logging.info(f'input_file = {args.input_file}') |
| 70 logging.info(f'output_file = {args.output_file}') | 70 # logging.info(f'output_file = {args.output_file}') |
| 71 logging.info(f'galaxy_flag = {args.galaxy_flag}') | 71 # logging.info(f'galaxy_flag = {args.galaxy_flag}') |
| 72 logging.info(f'img_x_bounds = {args.img_x_bounds}') | 72 # logging.info(f'img_x_bounds = {args.img_x_bounds}') |
| 73 logging.debug(f'log = {args.log}') | 73 # logging.debug(f'log = {args.log}') |
| 74 logging.debug(f'is log stdout? {args.log is sys.stdout}') | 74 # logging.debug(f'is log stdout? {args.log is sys.stdout}') |
| 75 logging.debug(f'log_level = {args.log_level}') | 75 # logging.debug(f'log_level = {args.log_level}') |
| 76 logging.info(f'log = {args.log}') | |
| 77 logging.info(f'is log stdout? {args.log is sys.stdout}') | |
| 78 print('Done') | |
| 76 | 79 |
| 77 # Instantiate Tomo object | 80 # Instantiate Tomo object |
| 78 tomo = Tomo(galaxy_flag=args.galaxy_flag) | 81 # tomo = Tomo(galaxy_flag=args.galaxy_flag) |
| 79 | 82 |
| 80 # Read input file | 83 # Read input file |
| 81 data = tomo.read(args.input_file) | 84 # data = tomo.read(args.input_file) |
| 82 | 85 |
| 83 # Generate reduced tomography images | 86 # Generate reduced tomography images |
| 84 data = tomo.gen_reduced_data(data, img_x_bounds=args.img_x_bounds) | 87 # data = tomo.gen_reduced_data(data, img_x_bounds=args.img_x_bounds) |
| 85 | 88 |
| 86 # Write output file | 89 # Write output file |
| 87 data = tomo.write(data, args.output_file) | 90 # data = tomo.write(data, args.output_file) |
| 88 | 91 |
| 89 # Displaying memory usage | 92 # Displaying memory usage |
| 90 # logging.info(f'Memory usage: {tracemalloc.get_traced_memory()}') | 93 # logging.info(f'Memory usage: {tracemalloc.get_traced_memory()}') |
| 91 | 94 |
| 92 # Stop memory monitoring | 95 # Stop memory monitoring |
