Mercurial > repos > rv43 > plot_smb_tiff
annotate plot_smb_tiff.py @ 0:9f331fb5be2c draft
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
| author | rv43 |
|---|---|
| date | Fri, 10 Mar 2023 20:57:05 +0000 |
| parents | |
| children | 6be076b081c4 |
| rev | line source |
|---|---|
|
0
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
2 |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
3 import logging |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
4 |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
5 import argparse |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
6 import matplotlib.pyplot as plt |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
7 import os |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
8 #from re import compile as re_compile |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
9 import sys |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
10 |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
11 def __main__(): |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
12 |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
13 # Parse command line arguments |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
14 parser = argparse.ArgumentParser( |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
15 description='Plot an image for the SMB schema') |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
16 parser.add_argument('--cycle', |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
17 required=True, |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
18 help='''Run cycle.''') |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
19 parser.add_argument('--station', |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
20 required=True, |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
21 choices=['id1a3', 'id3a'], |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
22 help='''Beamline station.''') |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
23 parser.add_argument('--btr', |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
24 required=True, |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
25 help='''BTR.''') |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
26 parser.add_argument('--sample', |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
27 required=True, |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
28 help='''Sample name.''') |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
29 parser.add_argument('--scan_number', |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
30 default=-1, |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
31 type=int, |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
32 help='SPEC scan number') |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
33 parser.add_argument('--image_index', |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
34 default=0, |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
35 type=int, |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
36 help='Image index relative the first') |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
37 parser.add_argument('-l', '--log', |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
38 # type=argparse.FileType('w'), |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
39 default=sys.stdout, |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
40 help='Logging stream or filename') |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
41 parser.add_argument('--log_level', |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
42 choices=logging._nameToLevel.keys(), |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
43 default='INFO', |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
44 help='''Specify a preferred logging level.''') |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
45 args = parser.parse_args() |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
46 |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
47 # Set log configuration |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
48 # When logging to file, the stdout log level defaults to WARNING |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
49 logging_format = '%(asctime)s : %(levelname)s - %(module)s : %(funcName)s - %(message)s' |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
50 level = logging.getLevelName(args.log_level) |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
51 if args.log is sys.stdout: |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
52 logging.basicConfig(format=logging_format, level=level, force=True, |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
53 handlers=[logging.StreamHandler()]) |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
54 else: |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
55 if isinstance(args.log, str): |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
56 logging.basicConfig(filename=f'{args.log}', filemode='w', |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
57 format=logging_format, level=level, force=True) |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
58 elif isinstance(args.log, io.TextIOWrapper): |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
59 logging.basicConfig(filemode='w', format=logging_format, level=level, |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
60 stream=args.log, force=True) |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
61 else: |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
62 raise(ValueError(f'Invalid argument --log: {args.log}')) |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
63 stream_handler = logging.StreamHandler() |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
64 logging.getLogger().addHandler(stream_handler) |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
65 stream_handler.setLevel(logging.WARNING) |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
66 stream_handler.setFormatter(logging.Formatter(logging_format)) |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
67 |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
68 # Log command line arguments |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
69 logging.info(f'cycle = {args.cycle}') |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
70 logging.info(f'station = {args.station}') |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
71 logging.info(f'btr = {args.btr}') |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
72 logging.info(f'sample = {args.sample}') |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
73 logging.info(f'scan_number = {args.scan_number}') |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
74 logging.info(f'image_index = {args.image_index}') |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
75 logging.debug(f'log = {args.log}') |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
76 logging.debug(f'is log stdout? {args.log is sys.stdout}') |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
77 |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
78 # Check input parameters |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
79 if args.image_index < 0: |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
80 raise ValueError(f'Invalid "image_index" parameter ({args.image_index})') |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
81 |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
82 # Check work directory |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
83 workdir = f'/nfs/chess/{args.station}/{args.cycle}/{args.btr}/{args.sample}' |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
84 logging.info(f'workdir = {workdir}') |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
85 if not os.path.isdir(workdir): |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
86 raise ValueError('Invalid work directory: {workdir}') |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
87 |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
88 # Get all available scan_numbers |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
89 scan_numbers = [int(v) for v in os.listdir(workdir) if v.isdigit() and |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
90 os.path.isdir(f'{workdir}/{v}')] |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
91 |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
92 if args.scan_number == -1: |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
93 # Pick lowest scan_number with image files |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
94 image_file = None |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
95 for scan_number in sorted(scan_numbers): |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
96 if 'nf' in os.listdir(f'{workdir}/{scan_number}'): |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
97 # indexRegex = re_compile(r'\d+') |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
98 path = f'{workdir}/{scan_number}/nf' |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
99 # image_files = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f)) and |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
100 # f.endswith(".tif") and indexRegex.search(f)] |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
101 image_files = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f)) |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
102 and f.endswith(".tif")] |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
103 if len(image_files): |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
104 image_file = f'{path}/{image_files[0]}' |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
105 break |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
106 else: |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
107 # Pick requested image file |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
108 scan_number = args.scan_number |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
109 if not os.path.isdir(f'{workdir}/{scan_number}'): |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
110 raise ValueError('Invalid scan_number (non-existing directory {workdir}/{scan_number})') |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
111 path = f'{workdir}/{scan_number}/nf' |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
112 if 'nf' not in os.listdir(f'{workdir}/{scan_number}'): |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
113 raise ValueError('Unable to find directory {path}') |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
114 image_files = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f)) |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
115 and f.endswith(".tif")] |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
116 if args.image_index >= len(image_files): |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
117 raise ValueError('Unable to open the {args.image_index}th image file in {path}') |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
118 image_file = f'{path}/{image_files[args.image_index]}' |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
119 |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
120 # Plot image to file |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
121 if image_file is None: |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
122 raise ValueError('Unable to find a valid image') |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
123 data = plt.imread(image_file) |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
124 title = 'image_files[0]' |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
125 plt.figure(title) |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
126 plt.imshow(data) |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
127 plt.savefig('image.jpg') |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
128 plt.close(fig=title) |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
129 |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
130 if __name__ == "__main__": |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
131 __main__() |
|
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
132 |
