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