Mercurial > repos > rv43 > plot_smb_tiff
annotate plot_smb_tiff.py @ 4:0ffa2fbc7546 draft default tip
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213-dirty
author | rv43 |
---|---|
date | Mon, 20 Mar 2023 17:12:07 +0000 |
parents | 6be076b081c4 |
children |
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') |
3
6be076b081c4
planemo upload for repository https://github.com/rolfverberg/galaxytools commit b5d7c209a0ba024789ccfb89ec874e8b9c280149-dirty
rv43
parents:
0
diff
changeset
|
16 parser.add_argument('-o', '--output_file', |
4
0ffa2fbc7546
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213-dirty
rv43
parents:
3
diff
changeset
|
17 required=True, |
0ffa2fbc7546
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213-dirty
rv43
parents:
3
diff
changeset
|
18 type=pathlib.Path, |
0ffa2fbc7546
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213-dirty
rv43
parents:
3
diff
changeset
|
19 help='''Full or relative path to the output file.''') |
0
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
20 parser.add_argument('--cycle', |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
21 required=True, |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
22 help='''Run cycle.''') |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
23 parser.add_argument('--station', |
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 choices=['id1a3', 'id3a'], |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
26 help='''Beamline station.''') |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
27 parser.add_argument('--btr', |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
28 required=True, |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
29 help='''BTR.''') |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
30 parser.add_argument('--sample', |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
31 required=True, |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
32 help='''Sample name.''') |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
33 parser.add_argument('--scan_number', |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
34 default=-1, |
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='SPEC scan number') |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
37 parser.add_argument('--image_index', |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
38 default=0, |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
39 type=int, |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
40 help='Image index relative the first') |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
41 parser.add_argument('-l', '--log', |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
42 # type=argparse.FileType('w'), |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
43 default=sys.stdout, |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
44 help='Logging stream or filename') |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
45 parser.add_argument('--log_level', |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
46 choices=logging._nameToLevel.keys(), |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
47 default='INFO', |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
48 help='''Specify a preferred logging level.''') |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
49 args = parser.parse_args() |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
50 |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
51 # Set log configuration |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
52 # 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
|
53 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
|
54 level = logging.getLevelName(args.log_level) |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
55 if args.log is sys.stdout: |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
56 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
|
57 handlers=[logging.StreamHandler()]) |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
58 else: |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
59 if isinstance(args.log, str): |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
60 logging.basicConfig(filename=f'{args.log}', filemode='w', |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
61 format=logging_format, level=level, force=True) |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
62 elif isinstance(args.log, io.TextIOWrapper): |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
63 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
|
64 stream=args.log, force=True) |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
65 else: |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
66 raise(ValueError(f'Invalid argument --log: {args.log}')) |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
67 stream_handler = logging.StreamHandler() |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
68 logging.getLogger().addHandler(stream_handler) |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
69 stream_handler.setLevel(logging.WARNING) |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
70 stream_handler.setFormatter(logging.Formatter(logging_format)) |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
71 |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
72 # Log command line arguments |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
73 logging.info(f'cycle = {args.cycle}') |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
74 logging.info(f'station = {args.station}') |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
75 logging.info(f'btr = {args.btr}') |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
76 logging.info(f'sample = {args.sample}') |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
77 logging.info(f'scan_number = {args.scan_number}') |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
78 logging.info(f'image_index = {args.image_index}') |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
79 logging.debug(f'log = {args.log}') |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
80 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
|
81 |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
82 # Check input parameters |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
83 if args.image_index < 0: |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
84 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
|
85 |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
86 # Check work directory |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
87 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
|
88 logging.info(f'workdir = {workdir}') |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
89 if not os.path.isdir(workdir): |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
90 raise ValueError('Invalid work directory: {workdir}') |
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 # Get all available scan_numbers |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
93 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
|
94 os.path.isdir(f'{workdir}/{v}')] |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
95 |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
96 if args.scan_number == -1: |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
97 # Pick lowest scan_number with image files |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
98 image_file = None |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
99 for scan_number in sorted(scan_numbers): |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
100 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
|
101 # indexRegex = re_compile(r'\d+') |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
102 path = f'{workdir}/{scan_number}/nf' |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
103 # 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
|
104 # f.endswith(".tif") and indexRegex.search(f)] |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
105 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
|
106 and f.endswith(".tif")] |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
107 if len(image_files): |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
108 image_file = f'{path}/{image_files[0]}' |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
109 break |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
110 else: |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
111 # Pick requested image file |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
112 scan_number = args.scan_number |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
113 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
|
114 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
|
115 path = f'{workdir}/{scan_number}/nf' |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
116 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
|
117 raise ValueError('Unable to find directory {path}') |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
118 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
|
119 and f.endswith(".tif")] |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
120 if args.image_index >= len(image_files): |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
121 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
|
122 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
|
123 |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
124 # Plot image to file |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
125 if image_file is None: |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
126 raise ValueError('Unable to find a valid image') |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
127 data = plt.imread(image_file) |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
128 title = 'image_files[0]' |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
129 plt.figure(title) |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
130 plt.imshow(data) |
3
6be076b081c4
planemo upload for repository https://github.com/rolfverberg/galaxytools commit b5d7c209a0ba024789ccfb89ec874e8b9c280149-dirty
rv43
parents:
0
diff
changeset
|
131 plt.savefig(args.output_file) |
0
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
132 plt.close(fig=title) |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
133 |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
134 if __name__ == "__main__": |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
135 __main__() |
9f331fb5be2c
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ec74ae97e0ca220d04cb668baa656358abf190e9
rv43
parents:
diff
changeset
|
136 |