Mercurial > repos > rv43 > tomo
annotate workflow/models.py @ 75:d5e1d4ea2b7e draft default tip
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
author | rv43 |
---|---|
date | Thu, 23 Mar 2023 13:39:14 +0000 |
parents | 1cf15b61cd83 |
children |
rev | line source |
---|---|
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
2 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
3 import logging |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
4 logger = logging.getLogger(__name__) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
5 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
6 import logging |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
7 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
8 import numpy as np |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
9 import os |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
10 import yaml |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
11 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
12 from functools import cache |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
13 from pathlib import PosixPath |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
14 from pydantic import BaseModel as PydanticBaseModel |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
15 from pydantic import validator, ValidationError, conint, confloat, constr, conlist, FilePath, \ |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
16 PrivateAttr |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
17 from nexusformat.nexus import * |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
18 from time import time |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
19 from typing import Optional, Literal |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
20 from typing_extensions import TypedDict |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
21 try: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
22 from pyspec.file.spec import FileSpec |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
23 except: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
24 pass |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
25 |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
26 try: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
27 from msnctools.general import is_int, is_num, input_int, input_int_list, input_num, \ |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
28 input_yesno, input_menu, index_nearest, string_to_list, file_exists_and_readable |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
29 except: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
30 from general import is_int, is_num, input_int, input_int_list, input_num, \ |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
31 input_yesno, input_menu, index_nearest, string_to_list, file_exists_and_readable |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
32 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
33 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
34 def import_scanparser(station): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
35 if station in ('id1a3', 'id3a'): |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
36 try: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
37 from msnctools.scanparsers import SMBRotationScanParser |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
38 globals()['ScanParser'] = SMBRotationScanParser |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
39 except: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
40 try: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
41 from scanparsers import SMBRotationScanParser |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
42 globals()['ScanParser'] = SMBRotationScanParser |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
43 except: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
44 pass |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
45 elif station in ('id3b'): |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
46 try: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
47 from msnctools.scanparsers import FMBRotationScanParser |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
48 globals()['ScanParser'] = FMBRotationScanParser |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
49 except: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
50 try: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
51 from scanparsers import FMBRotationScanParser |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
52 globals()['ScanParser'] = FMBRotationScanParser |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
53 except: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
54 pass |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
55 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
56 raise RuntimeError(f'Invalid station: {station}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
57 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
58 @cache |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
59 def get_available_scan_numbers(spec_file:str): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
60 scans = FileSpec(spec_file).scans |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
61 scan_numbers = list(scans.keys()) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
62 for scan_number in scan_numbers.copy(): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
63 try: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
64 parser = ScanParser(spec_file, scan_number) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
65 try: |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
66 scan_type = parser.scan_type |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
67 except: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
68 scan_type = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
69 except: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
70 scan_numbers.remove(scan_number) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
71 return(scan_numbers) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
72 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
73 @cache |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
74 def get_scanparser(spec_file:str, scan_number:int): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
75 if scan_number not in get_available_scan_numbers(spec_file): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
76 return(None) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
77 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
78 return(ScanParser(spec_file, scan_number)) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
79 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
80 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
81 class BaseModel(PydanticBaseModel): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
82 class Config: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
83 validate_assignment = True |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
84 arbitrary_types_allowed = True |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
85 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
86 @classmethod |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
87 def construct_from_cli(cls): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
88 obj = cls.construct() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
89 obj.cli() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
90 return(obj) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
91 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
92 @classmethod |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
93 def construct_from_yaml(cls, filename): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
94 try: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
95 with open(filename, 'r') as infile: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
96 indict = yaml.load(infile, Loader=yaml.CLoader) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
97 except: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
98 raise ValueError(f'Could not load a dictionary from {filename}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
99 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
100 obj = cls(**indict) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
101 return(obj) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
102 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
103 @classmethod |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
104 def construct_from_file(cls, filename): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
105 file_exists_and_readable(filename) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
106 filename = os.path.abspath(filename) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
107 fileformat = os.path.splitext(filename)[1] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
108 yaml_extensions = ('.yaml','.yml') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
109 nexus_extensions = ('.nxs','.nx5','.h5','.hdf5') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
110 t0 = time() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
111 if fileformat.lower() in yaml_extensions: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
112 obj = cls.construct_from_yaml(filename) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
113 logger.info(f'Constructed a model from {filename} in {time()-t0:.2f} seconds.') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
114 return(obj) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
115 elif fileformat.lower() in nexus_extensions: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
116 obj = cls.construct_from_nexus(filename) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
117 logger.info(f'Constructed a model from {filename} in {time()-t0:.2f} seconds.') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
118 return(obj) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
119 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
120 logger.error(f'Unsupported file extension for constructing a model: {fileformat}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
121 raise TypeError(f'Unrecognized file extension: {fileformat}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
122 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
123 def dict_for_yaml(self, exclude_fields=[]): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
124 yaml_dict = {} |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
125 for field_name in self.__fields__: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
126 if field_name in exclude_fields: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
127 continue |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
128 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
129 field_value = getattr(self, field_name, None) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
130 if field_value is not None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
131 if isinstance(field_value, BaseModel): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
132 yaml_dict[field_name] = field_value.dict_for_yaml() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
133 elif isinstance(field_value,list) and all(isinstance(item,BaseModel) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
134 for item in field_value): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
135 yaml_dict[field_name] = [item.dict_for_yaml() for item in field_value] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
136 elif isinstance(field_value, PosixPath): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
137 yaml_dict[field_name] = str(field_value) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
138 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
139 yaml_dict[field_name] = field_value |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
140 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
141 continue |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
142 return(yaml_dict) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
143 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
144 def write_to_yaml(self, filename=None): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
145 yaml_dict = self.dict_for_yaml() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
146 if filename is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
147 logger.info('Printing yaml representation here:\n'+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
148 f'{yaml.dump(yaml_dict, sort_keys=False)}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
149 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
150 try: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
151 with open(filename, 'w') as outfile: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
152 yaml.dump(yaml_dict, outfile, sort_keys=False) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
153 logger.info(f'Successfully wrote this model to {filename}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
154 except: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
155 logger.error(f'Unknown error -- could not write to {filename} in yaml format.') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
156 logger.info('Printing yaml representation here:\n'+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
157 f'{yaml.dump(yaml_dict, sort_keys=False)}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
158 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
159 def write_to_file(self, filename, force_overwrite=False): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
160 file_writeable, fileformat = self.output_file_valid(filename, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
161 force_overwrite=force_overwrite) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
162 if fileformat == 'yaml': |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
163 if file_writeable: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
164 self.write_to_yaml(filename=filename) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
165 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
166 self.write_to_yaml() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
167 elif fileformat == 'nexus': |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
168 if file_writeable: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
169 self.write_to_nexus(filename=filename) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
170 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
171 def output_file_valid(self, filename, force_overwrite=False): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
172 filename = os.path.abspath(filename) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
173 fileformat = os.path.splitext(filename)[1] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
174 yaml_extensions = ('.yaml','.yml') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
175 nexus_extensions = ('.nxs','.nx5','.h5','.hdf5') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
176 if fileformat.lower() not in (*yaml_extensions, *nexus_extensions): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
177 return(False, None) # Only yaml and NeXus files allowed for output now. |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
178 elif fileformat.lower() in yaml_extensions: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
179 fileformat = 'yaml' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
180 elif fileformat.lower() in nexus_extensions: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
181 fileformat = 'nexus' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
182 if os.path.isfile(filename): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
183 if os.access(filename, os.W_OK): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
184 if not force_overwrite: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
185 logger.error(f'{filename} will not be overwritten.') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
186 return(False, fileformat) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
187 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
188 logger.error(f'Cannot access {filename} for writing.') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
189 return(False, fileformat) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
190 if os.path.isdir(os.path.dirname(filename)): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
191 if os.access(os.path.dirname(filename), os.W_OK): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
192 return(True, fileformat) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
193 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
194 logger.error(f'Cannot access {os.path.dirname(filename)} for writing.') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
195 return(False, fileformat) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
196 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
197 try: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
198 os.makedirs(os.path.dirname(filename)) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
199 return(True, fileformat) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
200 except: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
201 logger.error(f'Cannot create {os.path.dirname(filename)} for output.') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
202 return(False, fileformat) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
203 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
204 def set_single_attr_cli(self, attr_name, attr_desc='unknown attribute', list_flag=False, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
205 **cli_kwargs): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
206 if cli_kwargs.get('chain_attr_desc', False): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
207 cli_kwargs['attr_desc'] = attr_desc |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
208 try: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
209 attr = getattr(self, attr_name, None) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
210 if attr is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
211 attr = self.__fields__[attr_name].type_.construct() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
212 if cli_kwargs.get('chain_attr_desc', False): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
213 cli_kwargs['attr_desc'] = attr_desc |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
214 input_accepted = False |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
215 while not input_accepted: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
216 try: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
217 attr.cli(**cli_kwargs) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
218 except ValidationError as e: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
219 print(e) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
220 print(f'Removing {attr_desc} configuration') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
221 attr = self.__fields__[attr_name].type_.construct() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
222 continue |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
223 except KeyboardInterrupt as e: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
224 raise e |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
225 except BaseException as e: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
226 print(f'{type(e).__name__}: {e}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
227 print(f'Removing {attr_desc} configuration') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
228 attr = self.__fields__[attr_name].type_.construct() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
229 continue |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
230 try: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
231 setattr(self, attr_name, attr) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
232 except ValidationError as e: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
233 print(e) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
234 except KeyboardInterrupt as e: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
235 raise e |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
236 except BaseException as e: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
237 print(f'{type(e).__name__}: {e}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
238 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
239 input_accepted = True |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
240 except: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
241 input_accepted = False |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
242 while not input_accepted: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
243 attr = getattr(self, attr_name, None) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
244 if attr is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
245 input_value = input(f'Type and enter a value for {attr_desc}: ') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
246 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
247 input_value = input(f'Type and enter a new value for {attr_desc} or press '+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
248 f'enter to keep the current one ({attr}): ') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
249 if list_flag: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
250 input_value = string_to_list(input_value, remove_duplicates=False, sort=False) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
251 if len(input_value) == 0: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
252 input_value = getattr(self, attr_name, None) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
253 try: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
254 setattr(self, attr_name, input_value) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
255 except ValidationError as e: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
256 print(e) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
257 except KeyboardInterrupt as e: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
258 raise e |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
259 except BaseException as e: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
260 print(f'Unexpected {type(e).__name__}: {e}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
261 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
262 input_accepted = True |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
263 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
264 def set_list_attr_cli(self, attr_name, attr_desc='unknown attribute', **cli_kwargs): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
265 if cli_kwargs.get('chain_attr_desc', False): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
266 cli_kwargs['attr_desc'] = attr_desc |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
267 attr = getattr(self, attr_name, None) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
268 if attr is not None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
269 # Check existing items |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
270 for item in attr: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
271 item_accepted = False |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
272 while not item_accepted: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
273 item.cli(**cli_kwargs) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
274 try: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
275 setattr(self, attr_name, attr) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
276 except ValidationError as e: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
277 print(e) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
278 except KeyboardInterrupt as e: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
279 raise e |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
280 except BaseException as e: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
281 print(f'{type(e).__name__}: {e}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
282 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
283 item_accepted = True |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
284 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
285 # Initialize list for new attribute & starting item |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
286 attr = [] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
287 item = self.__fields__[attr_name].type_.construct() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
288 # Append (optional) additional items |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
289 append = input_yesno(f'Add a {attr_desc} configuration? (y/n)', 'n') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
290 while append: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
291 attr.append(item.__class__.construct_from_cli()) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
292 try: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
293 setattr(self, attr_name, attr) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
294 except ValidationError as e: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
295 print(e) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
296 print(f'Removing last {attr_desc} configuration from the list') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
297 attr.pop() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
298 except KeyboardInterrupt as e: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
299 raise e |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
300 except BaseException as e: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
301 print(f'{type(e).__name__}: {e}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
302 print(f'Removing last {attr_desc} configuration from the list') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
303 attr.pop() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
304 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
305 append = input_yesno(f'Add another {attr_desc} configuration? (y/n)', 'n') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
306 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
307 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
308 class Detector(BaseModel): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
309 prefix: constr(strip_whitespace=True, min_length=1) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
310 rows: conint(gt=0) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
311 columns: conint(gt=0) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
312 pixel_size: conlist(item_type=confloat(gt=0), min_items=1, max_items=2) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
313 lens_magnification: confloat(gt=0) = 1.0 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
314 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
315 @property |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
316 def get_pixel_size(self): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
317 return(list(np.asarray(self.pixel_size)/self.lens_magnification)) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
318 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
319 def construct_from_yaml(self, filename): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
320 try: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
321 with open(filename, 'r') as infile: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
322 indict = yaml.load(infile, Loader=yaml.CLoader) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
323 detector = indict['detector'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
324 self.prefix = detector['id'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
325 pixels = detector['pixels'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
326 self.rows = pixels['rows'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
327 self.columns = pixels['columns'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
328 self.pixel_size = pixels['size'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
329 self.lens_magnification = indict['lens_magnification'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
330 except: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
331 logging.warning(f'Could not load a dictionary from {filename}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
332 return(False) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
333 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
334 return(True) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
335 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
336 def cli(self): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
337 print('\n -- Configure the detector -- ') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
338 self.set_single_attr_cli('prefix', 'detector ID') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
339 self.set_single_attr_cli('rows', 'number of pixel rows') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
340 self.set_single_attr_cli('columns', 'number of pixel columns') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
341 self.set_single_attr_cli('pixel_size', 'pixel size in mm (enter either a single value for '+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
342 'square pixels or a pair of values for the size in the respective row and column '+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
343 'directions)', list_flag=True) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
344 self.set_single_attr_cli('lens_magnification', 'lens magnification') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
345 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
346 def construct_nxdetector(self): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
347 nxdetector = NXdetector() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
348 nxdetector.local_name = self.prefix |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
349 pixel_size = self.get_pixel_size |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
350 if len(pixel_size) == 1: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
351 nxdetector.x_pixel_size = pixel_size[0] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
352 nxdetector.y_pixel_size = pixel_size[0] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
353 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
354 nxdetector.x_pixel_size = pixel_size[0] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
355 nxdetector.y_pixel_size = pixel_size[1] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
356 nxdetector.x_pixel_size.attrs['units'] = 'mm' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
357 nxdetector.y_pixel_size.attrs['units'] = 'mm' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
358 return(nxdetector) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
359 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
360 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
361 class ScanInfo(TypedDict): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
362 scan_number: int |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
363 starting_image_offset: conint(ge=0) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
364 num_image: conint(gt=0) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
365 ref_x: float |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
366 ref_z: float |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
367 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
368 class SpecScans(BaseModel): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
369 spec_file: FilePath |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
370 scan_numbers: conlist(item_type=conint(gt=0), min_items=1) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
371 stack_info: conlist(item_type=ScanInfo, min_items=1) = [] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
372 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
373 @validator('spec_file') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
374 def validate_spec_file(cls, spec_file): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
375 try: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
376 spec_file = os.path.abspath(spec_file) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
377 sspec_file = FileSpec(spec_file) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
378 except: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
379 raise ValueError(f'Invalid SPEC file {spec_file}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
380 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
381 return(spec_file) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
382 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
383 @validator('scan_numbers') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
384 def validate_scan_numbers(cls, scan_numbers, values): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
385 spec_file = values.get('spec_file') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
386 if spec_file is not None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
387 spec_scans = FileSpec(spec_file) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
388 for scan_number in scan_numbers: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
389 scan = spec_scans.get_scan_by_number(scan_number) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
390 if scan is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
391 raise ValueError(f'There is no scan number {scan_number} in {spec_file}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
392 return(scan_numbers) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
393 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
394 @validator('stack_info') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
395 def validate_stack_info(cls, stack_info, values): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
396 scan_numbers = values.get('scan_numbers') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
397 assert(len(scan_numbers) == len(stack_info)) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
398 for scan_info in stack_info: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
399 assert(scan_info['scan_number'] in scan_numbers) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
400 is_int(scan_info['starting_image_offset'], ge=0, lt=scan_info['num_image'], |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
401 raise_error=True) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
402 return(stack_info) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
403 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
404 @classmethod |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
405 def construct_from_nxcollection(cls, nxcollection:NXcollection): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
406 config = {} |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
407 config['spec_file'] = nxcollection.attrs['spec_file'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
408 scan_numbers = [] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
409 stack_info = [] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
410 for nxsubentry_name, nxsubentry in nxcollection.items(): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
411 scan_number = int(nxsubentry_name.split('_')[-1]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
412 scan_numbers.append(scan_number) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
413 stack_info.append({'scan_number': scan_number, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
414 'starting_image_offset': int(nxsubentry.instrument.detector.frame_start_number), |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
415 'num_image': len(nxsubentry.sample.rotation_angle), |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
416 'ref_x': float(nxsubentry.sample.x_translation), |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
417 'ref_z': float(nxsubentry.sample.z_translation)}) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
418 config['scan_numbers'] = sorted(scan_numbers) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
419 config['stack_info'] = stack_info |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
420 return(cls(**config)) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
421 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
422 @property |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
423 def available_scan_numbers(self): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
424 return(get_available_scan_numbers(self.spec_file)) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
425 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
426 def set_from_nxcollection(self, nxcollection:NXcollection): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
427 self.spec_file = nxcollection.attrs['spec_file'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
428 scan_numbers = [] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
429 stack_info = [] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
430 for nxsubentry_name, nxsubentry in nxcollection.items(): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
431 scan_number = int(nxsubentry_name.split('_')[-1]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
432 scan_numbers.append(scan_number) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
433 stack_info.append({'scan_number': scan_number, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
434 'starting_image_offset': int(nxsubentry.instrument.detector.frame_start_number), |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
435 'num_image': len(nxsubentry.sample.rotation_angle), |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
436 'ref_x': float(nxsubentry.sample.x_translation), |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
437 'ref_z': float(nxsubentry.sample.z_translation)}) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
438 self.scan_numbers = sorted(scan_numbers) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
439 self.stack_info = stack_info |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
440 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
441 def get_scan_index(self, scan_number): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
442 scan_index = [scan_index for scan_index, scan_info in enumerate(self.stack_info) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
443 if scan_info['scan_number'] == scan_number] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
444 if len(scan_index) > 1: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
445 raise ValueError('Duplicate scan_numbers in image stack') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
446 elif len(scan_index) == 1: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
447 return(scan_index[0]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
448 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
449 return(None) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
450 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
451 def get_scanparser(self, scan_number): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
452 return(get_scanparser(self.spec_file, scan_number)) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
453 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
454 def get_detector_data(self, detector_prefix, scan_number=None, scan_step_index=None): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
455 image_stacks = [] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
456 if scan_number is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
457 scan_numbers = self.scan_numbers |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
458 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
459 scan_numbers = [scan_number] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
460 for scan_number in scan_numbers: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
461 parser = self.get_scanparser(scan_number) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
462 scan_info = self.stack_info[self.get_scan_index(scan_number)] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
463 image_offset = scan_info['starting_image_offset'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
464 if scan_step_index is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
465 num_image = scan_info['num_image'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
466 image_stacks.append(parser.get_detector_data(detector_prefix, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
467 (image_offset, image_offset+num_image))) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
468 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
469 image_stacks.append(parser.get_detector_data(detector_prefix, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
470 image_offset+scan_step_index)) |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
471 if scan_number is not None and scan_step_index is not None: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
472 # Return a single image for a specific scan_number and scan_step_index request |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
473 return(image_stacks[0]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
474 else: |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
475 # Return a list otherwise |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
476 return(image_stacks) |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
477 return(image_stacks) |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
478 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
479 def scan_numbers_cli(self, attr_desc, **kwargs): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
480 available_scan_numbers = self.available_scan_numbers |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
481 station = kwargs.get('station') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
482 if (station is not None and station in ('id1a3', 'id3a') and |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
483 'scan_type' in kwargs): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
484 scan_type = kwargs['scan_type'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
485 if scan_type == 'ts1': |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
486 available_scan_numbers = [] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
487 for scan_number in self.available_scan_numbers: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
488 parser = self.get_scanparser(scan_number) |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
489 try: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
490 if parser.scan_type == scan_type: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
491 available_scan_numbers.append(scan_number) |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
492 except: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
493 pass |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
494 elif scan_type == 'df1': |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
495 tomo_scan_numbers = kwargs['tomo_scan_numbers'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
496 available_scan_numbers = [] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
497 for scan_number in tomo_scan_numbers: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
498 parser = self.get_scanparser(scan_number-2) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
499 assert(parser.scan_type == scan_type) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
500 available_scan_numbers.append(scan_number-2) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
501 elif scan_type == 'bf1': |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
502 tomo_scan_numbers = kwargs['tomo_scan_numbers'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
503 available_scan_numbers = [] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
504 for scan_number in tomo_scan_numbers: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
505 parser = self.get_scanparser(scan_number-1) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
506 assert(parser.scan_type == scan_type) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
507 available_scan_numbers.append(scan_number-1) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
508 if len(available_scan_numbers) == 1: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
509 input_mode = 1 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
510 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
511 if hasattr(self, 'scan_numbers'): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
512 print(f'Currently selected {attr_desc}scan numbers are: {self.scan_numbers}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
513 menu_options = [f'Select a subset of the available {attr_desc}scan numbers', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
514 f'Use all available {attr_desc}scan numbers in {self.spec_file}', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
515 f'Keep the currently selected {attr_desc}scan numbers'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
516 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
517 menu_options = [f'Select a subset of the available {attr_desc}scan numbers', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
518 f'Use all available {attr_desc}scan numbers in {self.spec_file}'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
519 print(f'Available scan numbers in {self.spec_file} are: '+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
520 f'{available_scan_numbers}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
521 input_mode = input_menu(menu_options, header='Choose one of the following options '+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
522 'for selecting scan numbers') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
523 if input_mode == 0: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
524 accept_scan_numbers = False |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
525 while not accept_scan_numbers: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
526 try: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
527 self.scan_numbers = \ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
528 input_int_list(f'Enter a series of {attr_desc}scan numbers') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
529 except ValidationError as e: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
530 print(e) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
531 except KeyboardInterrupt as e: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
532 raise e |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
533 except BaseException as e: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
534 print(f'Unexpected {type(e).__name__}: {e}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
535 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
536 accept_scan_numbers = True |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
537 elif input_mode == 1: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
538 self.scan_numbers = available_scan_numbers |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
539 elif input_mode == 2: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
540 pass |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
541 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
542 def cli(self, **cli_kwargs): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
543 if cli_kwargs.get('attr_desc') is not None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
544 attr_desc = f'{cli_kwargs["attr_desc"]} ' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
545 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
546 attr_desc = '' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
547 print(f'\n -- Configure which scans to use from a single {attr_desc}SPEC file') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
548 self.set_single_attr_cli('spec_file', attr_desc+'SPEC file path') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
549 self.scan_numbers_cli(attr_desc) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
550 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
551 def construct_nxcollection(self, image_key, thetas, detector): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
552 nxcollection = NXcollection() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
553 nxcollection.attrs['spec_file'] = str(self.spec_file) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
554 parser = self.get_scanparser(self.scan_numbers[0]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
555 nxcollection.attrs['date'] = parser.spec_scan.file_date |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
556 for scan_number in self.scan_numbers: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
557 # Get scan info |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
558 scan_info = self.stack_info[self.get_scan_index(scan_number)] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
559 # Add an NXsubentry to the NXcollection for each scan |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
560 entry_name = f'scan_{scan_number}' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
561 nxsubentry = NXsubentry() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
562 nxcollection[entry_name] = nxsubentry |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
563 parser = self.get_scanparser(scan_number) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
564 nxsubentry.start_time = parser.spec_scan.date |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
565 nxsubentry.spec_command = parser.spec_command |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
566 # Add an NXdata for independent dimensions to the scan's NXsubentry |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
567 num_image = scan_info['num_image'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
568 if thetas is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
569 thetas = num_image*[0.0] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
570 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
571 assert(num_image == len(thetas)) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
572 # nxsubentry.independent_dimensions = NXdata() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
573 # nxsubentry.independent_dimensions.rotation_angle = thetas |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
574 # nxsubentry.independent_dimensions.rotation_angle.units = 'degrees' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
575 # Add an NXinstrument to the scan's NXsubentry |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
576 nxsubentry.instrument = NXinstrument() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
577 # Add an NXdetector to the NXinstrument to the scan's NXsubentry |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
578 nxsubentry.instrument.detector = detector.construct_nxdetector() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
579 nxsubentry.instrument.detector.frame_start_number = scan_info['starting_image_offset'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
580 nxsubentry.instrument.detector.image_key = image_key |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
581 # Add an NXsample to the scan's NXsubentry |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
582 nxsubentry.sample = NXsample() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
583 nxsubentry.sample.rotation_angle = thetas |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
584 nxsubentry.sample.rotation_angle.units = 'degrees' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
585 nxsubentry.sample.x_translation = scan_info['ref_x'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
586 nxsubentry.sample.x_translation.units = 'mm' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
587 nxsubentry.sample.z_translation = scan_info['ref_z'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
588 nxsubentry.sample.z_translation.units = 'mm' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
589 return(nxcollection) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
590 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
591 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
592 class FlatField(SpecScans): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
593 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
594 def image_range_cli(self, attr_desc, detector_prefix): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
595 stack_info = self.stack_info |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
596 for scan_number in self.scan_numbers: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
597 # Parse the available image range |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
598 parser = self.get_scanparser(scan_number) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
599 image_offset = parser.starting_image_offset |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
600 num_image = parser.get_num_image(detector_prefix.upper()) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
601 scan_index = self.get_scan_index(scan_number) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
602 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
603 # Select the image set |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
604 last_image_index = image_offset+num_image |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
605 print(f'Available good image set index range: [{image_offset}, {last_image_index})') |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
606 image_set_approved = False |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
607 if scan_index is not None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
608 scan_info = stack_info[scan_index] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
609 print(f'Current starting image offset and number of images: '+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
610 f'{scan_info["starting_image_offset"]} and {scan_info["num_image"]}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
611 image_set_approved = input_yesno(f'Accept these values (y/n)?', 'y') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
612 if not image_set_approved: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
613 print(f'Default starting image offset and number of images: '+ |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
614 f'{image_offset} and {num_image}') |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
615 image_set_approved = input_yesno(f'Accept these values (y/n)?', 'y') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
616 if image_set_approved: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
617 offset = image_offset |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
618 num = last_image_index-offset |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
619 while not image_set_approved: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
620 offset = input_int(f'Enter the starting image offset', ge=image_offset, |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
621 lt=last_image_index)#, default=image_offset) |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
622 num = input_int(f'Enter the number of images', ge=1, |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
623 le=last_image_index-offset)#, default=last_image_index-offset) |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
624 print(f'Current starting image offset and number of images: {offset} and {num}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
625 image_set_approved = input_yesno(f'Accept these values (y/n)?', 'y') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
626 if scan_index is not None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
627 scan_info['starting_image_offset'] = offset |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
628 scan_info['num_image'] = num |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
629 scan_info['ref_x'] = parser.horizontal_shift |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
630 scan_info['ref_z'] = parser.vertical_shift |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
631 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
632 stack_info.append({'scan_number': scan_number, 'starting_image_offset': offset, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
633 'num_image': num, 'ref_x': parser.horizontal_shift, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
634 'ref_z': parser.vertical_shift}) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
635 self.stack_info = stack_info |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
636 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
637 def cli(self, **cli_kwargs): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
638 if cli_kwargs.get('attr_desc') is not None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
639 attr_desc = f'{cli_kwargs["attr_desc"]} ' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
640 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
641 attr_desc = '' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
642 station = cli_kwargs.get('station') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
643 detector = cli_kwargs.get('detector') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
644 print(f'\n -- Configure the location of the {attr_desc}scan data -- ') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
645 if station in ('id1a3', 'id3a'): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
646 self.spec_file = cli_kwargs['spec_file'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
647 tomo_scan_numbers = cli_kwargs['tomo_scan_numbers'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
648 scan_type = cli_kwargs['scan_type'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
649 self.scan_numbers_cli(attr_desc, station=station, tomo_scan_numbers=tomo_scan_numbers, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
650 scan_type=scan_type) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
651 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
652 self.set_single_attr_cli('spec_file', attr_desc+'SPEC file path') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
653 self.scan_numbers_cli(attr_desc) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
654 self.image_range_cli(attr_desc, detector.prefix) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
655 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
656 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
657 class TomoField(SpecScans): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
658 theta_range: dict = {} |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
659 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
660 @validator('theta_range') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
661 def validate_theta_range(cls, theta_range): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
662 if len(theta_range) != 3 and len(theta_range) != 4: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
663 raise ValueError(f'Invalid theta range {theta_range}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
664 is_num(theta_range['start'], raise_error=True) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
665 is_num(theta_range['end'], raise_error=True) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
666 is_int(theta_range['num'], gt=1, raise_error=True) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
667 if theta_range['end'] <= theta_range['start']: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
668 raise ValueError(f'Invalid theta range {theta_range}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
669 if 'start_index' in theta_range: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
670 is_int(theta_range['start_index'], ge=0, raise_error=True) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
671 return(theta_range) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
672 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
673 @classmethod |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
674 def construct_from_nxcollection(cls, nxcollection:NXcollection): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
675 #RV Can I derive this from the same classfunction for SpecScans by adding theta_range |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
676 config = {} |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
677 config['spec_file'] = nxcollection.attrs['spec_file'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
678 scan_numbers = [] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
679 stack_info = [] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
680 for nxsubentry_name, nxsubentry in nxcollection.items(): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
681 scan_number = int(nxsubentry_name.split('_')[-1]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
682 scan_numbers.append(scan_number) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
683 stack_info.append({'scan_number': scan_number, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
684 'starting_image_offset': int(nxsubentry.instrument.detector.frame_start_number), |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
685 'num_image': len(nxsubentry.sample.rotation_angle), |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
686 'ref_x': float(nxsubentry.sample.x_translation), |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
687 'ref_z': float(nxsubentry.sample.z_translation)}) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
688 config['scan_numbers'] = sorted(scan_numbers) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
689 config['stack_info'] = stack_info |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
690 for name in nxcollection.entries: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
691 if 'scan_' in name: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
692 thetas = np.asarray(nxcollection[name].sample.rotation_angle) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
693 config['theta_range'] = {'start': thetas[0], 'end': thetas[-1], 'num': thetas.size} |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
694 break |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
695 return(cls(**config)) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
696 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
697 def get_horizontal_shifts(self, scan_number=None): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
698 horizontal_shifts = [] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
699 if scan_number is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
700 scan_numbers = self.scan_numbers |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
701 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
702 scan_numbers = [scan_number] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
703 for scan_number in scan_numbers: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
704 parser = self.get_scanparser(scan_number) |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
705 horizontal_shifts.append(parser.horizontal_shift) |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
706 if len(horizontal_shifts) == 1: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
707 return(horizontal_shifts[0]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
708 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
709 return(horizontal_shifts) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
710 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
711 def get_vertical_shifts(self, scan_number=None): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
712 vertical_shifts = [] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
713 if scan_number is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
714 scan_numbers = self.scan_numbers |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
715 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
716 scan_numbers = [scan_number] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
717 for scan_number in scan_numbers: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
718 parser = self.get_scanparser(scan_number) |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
719 vertical_shifts.append(parser.vertical_shift) |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
720 if len(vertical_shifts) == 1: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
721 return(vertical_shifts[0]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
722 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
723 return(vertical_shifts) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
724 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
725 def theta_range_cli(self, scan_number, attr_desc, station): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
726 # Parse the available theta range |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
727 parser = self.get_scanparser(scan_number) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
728 theta_vals = parser.theta_vals |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
729 spec_theta_start = theta_vals.get('start') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
730 spec_theta_end = theta_vals.get('end') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
731 spec_num_theta = theta_vals.get('num') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
732 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
733 # Check for consistency of theta ranges between scans |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
734 if scan_number != self.scan_numbers[0]: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
735 parser = self.get_scanparser(self.scan_numbers[0]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
736 if (parser.theta_vals.get('start') != spec_theta_start or |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
737 parser.theta_vals.get('end') != spec_theta_end or |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
738 parser.theta_vals.get('num') != spec_num_theta): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
739 raise ValueError(f'Incompatible theta ranges between {attr_desc}scans:'+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
740 f'\n\tScan {scan_number}: {theta_vals}'+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
741 f'\n\tScan {self.scan_numbers[0]}: {parser.theta_vals}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
742 return |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
743 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
744 # Select the theta range for the tomo reconstruction from the first scan |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
745 theta_range_approved = False |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
746 thetas = np.linspace(spec_theta_start, spec_theta_end, spec_num_theta) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
747 delta_theta = thetas[1]-thetas[0] |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
748 print(f'Theta range obtained from SPEC data: [{spec_theta_start}, {spec_theta_end}]') |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
749 print(f'Theta step size = {delta_theta}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
750 print(f'Number of theta values: {spec_num_theta}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
751 default_start = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
752 default_end = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
753 if station in ('id1a3', 'id3a'): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
754 theta_range_approved = input_yesno(f'Accept this theta range (y/n)?', 'y') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
755 if theta_range_approved: |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
756 self.theta_range = {'start': float(spec_theta_start), 'end': float(spec_theta_end), |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
757 'num': int(spec_num_theta), 'start_index': 0} |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
758 return |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
759 elif station in ('id3b'): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
760 if spec_theta_start <= 0.0 and spec_theta_end >= 180.0: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
761 default_start = 0 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
762 default_end = 180 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
763 elif spec_theta_end-spec_theta_start == 180: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
764 default_start = spec_theta_start |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
765 default_end = spec_theta_end |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
766 while not theta_range_approved: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
767 theta_start = input_num(f'Enter the first theta (included)', ge=spec_theta_start, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
768 lt=spec_theta_end, default=default_start) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
769 theta_index_start = index_nearest(thetas, theta_start) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
770 theta_start = thetas[theta_index_start] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
771 theta_end = input_num(f'Enter the last theta (excluded)', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
772 ge=theta_start+delta_theta, le=spec_theta_end, default=default_end) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
773 theta_index_end = index_nearest(thetas, theta_end) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
774 theta_end = thetas[theta_index_end] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
775 num_theta = theta_index_end-theta_index_start |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
776 print(f'Selected theta range: [{theta_start}, {theta_start+delta_theta}, ..., '+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
777 f'{theta_end})') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
778 print(f'Number of theta values: {num_theta}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
779 theta_range_approved = input_yesno(f'Accept this theta range (y/n)?', 'y') |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
780 self.theta_range = {'start': float(theta_start), 'end': float(theta_end), |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
781 'num': int(num_theta), 'start_index': int(theta_index_start)} |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
782 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
783 def image_range_cli(self, attr_desc, detector_prefix): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
784 stack_info = self.stack_info |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
785 for scan_number in self.scan_numbers: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
786 # Parse the available image range |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
787 parser = self.get_scanparser(scan_number) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
788 image_offset = parser.starting_image_offset |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
789 num_image = parser.get_num_image(detector_prefix.upper()) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
790 scan_index = self.get_scan_index(scan_number) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
791 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
792 # Select the image set matching the theta range |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
793 num_theta = self.theta_range['num'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
794 theta_index_start = self.theta_range['start_index'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
795 if num_theta > num_image-theta_index_start: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
796 raise ValueError(f'Available {attr_desc}image indices incompatible with thetas:'+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
797 f'\n\tNumber of thetas and offset = {num_theta} and {theta_index_start}'+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
798 f'\n\tNumber of available images {num_image}') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
799 if scan_index is not None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
800 scan_info = stack_info[scan_index] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
801 scan_info['starting_image_offset'] = image_offset+theta_index_start |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
802 scan_info['num_image'] = num_theta |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
803 scan_info['ref_x'] = parser.horizontal_shift |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
804 scan_info['ref_z'] = parser.vertical_shift |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
805 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
806 stack_info.append({'scan_number': scan_number, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
807 'starting_image_offset': image_offset+theta_index_start, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
808 'num_image': num_theta, 'ref_x': parser.horizontal_shift, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
809 'ref_z': parser.vertical_shift}) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
810 self.stack_info = stack_info |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
811 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
812 def cli(self, **cli_kwargs): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
813 if cli_kwargs.get('attr_desc') is not None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
814 attr_desc = f'{cli_kwargs["attr_desc"]} ' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
815 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
816 attr_desc = '' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
817 cycle = cli_kwargs.get('cycle') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
818 btr = cli_kwargs.get('btr') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
819 station = cli_kwargs.get('station') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
820 detector = cli_kwargs.get('detector') |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
821 sample_name = cli_kwargs.get('sample_name') |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
822 print(f'\n -- Configure the location of the {attr_desc}scan data -- ') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
823 if station in ('id1a3', 'id3a'): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
824 basedir = f'/nfs/chess/{station}/{cycle}/{btr}' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
825 runs = [d for d in os.listdir(basedir) if os.path.isdir(os.path.join(basedir, d))] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
826 #RV index = 15-1 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
827 #RV index = 7-1 |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
828 if sample_name is not None and sample_name in runs: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
829 index = runs.index(sample_name) |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
830 else: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
831 index = input_menu(runs, header='Choose a sample directory') |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
832 self.spec_file = f'{basedir}/{runs[index]}/spec.log' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
833 self.scan_numbers_cli(attr_desc, station=station, scan_type='ts1') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
834 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
835 self.set_single_attr_cli('spec_file', attr_desc+'SPEC file path') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
836 self.scan_numbers_cli(attr_desc) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
837 for scan_number in self.scan_numbers: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
838 self.theta_range_cli(scan_number, attr_desc, station) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
839 self.image_range_cli(attr_desc, detector.prefix) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
840 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
841 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
842 class Sample(BaseModel): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
843 name: constr(min_length=1) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
844 description: Optional[str] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
845 rotation_angles: Optional[list] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
846 x_translations: Optional[list] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
847 z_translations: Optional[list] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
848 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
849 @classmethod |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
850 def construct_from_nxsample(cls, nxsample:NXsample): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
851 config = {} |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
852 config['name'] = nxsample.name.nxdata |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
853 if 'description' in nxsample: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
854 config['description'] = nxsample.description.nxdata |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
855 if 'rotation_angle' in nxsample: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
856 config['rotation_angle'] = nxsample.rotation_angle.nxdata |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
857 if 'x_translation' in nxsample: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
858 config['x_translation'] = nxsample.x_translation.nxdata |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
859 if 'z_translation' in nxsample: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
860 config['z_translation'] = nxsample.z_translation.nxdata |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
861 return(cls(**config)) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
862 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
863 def cli(self): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
864 print('\n -- Configure the sample metadata -- ') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
865 #RV self.name = 'sobhani-3249-A' |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
866 #RV self.name = 'tenstom_1304r-1' |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
867 self.set_single_attr_cli('name', 'the sample name') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
868 #RV self.description = 'test sample' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
869 self.set_single_attr_cli('description', 'a description of the sample (optional)') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
870 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
871 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
872 class MapConfig(BaseModel): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
873 cycle: constr(strip_whitespace=True, min_length=1) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
874 btr: constr(strip_whitespace=True, min_length=1) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
875 title: constr(strip_whitespace=True, min_length=1) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
876 station: Literal['id1a3', 'id3a', 'id3b'] = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
877 sample: Sample |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
878 detector: Detector = Detector.construct() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
879 tomo_fields: TomoField |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
880 dark_field: Optional[FlatField] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
881 bright_field: FlatField |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
882 _thetas: list[float] = PrivateAttr() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
883 _field_types = ({'name': 'dark_field', 'image_key': 2}, {'name': 'bright_field', |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
884 'image_key': 1}, {'name': 'tomo_fields', 'image_key': 0}) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
885 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
886 @classmethod |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
887 def construct_from_nxentry(cls, nxentry:NXentry): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
888 config = {} |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
889 config['cycle'] = nxentry.instrument.source.attrs['cycle'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
890 config['btr'] = nxentry.instrument.source.attrs['btr'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
891 config['title'] = nxentry.nxname |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
892 config['station'] = nxentry.instrument.source.attrs['station'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
893 config['sample'] = Sample.construct_from_nxsample(nxentry['sample']) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
894 for nxobject_name, nxobject in nxentry.spec_scans.items(): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
895 if isinstance(nxobject, NXcollection): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
896 config[nxobject_name] = SpecScans.construct_from_nxcollection(nxobject) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
897 return(cls(**config)) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
898 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
899 #FIX cache? |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
900 @property |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
901 def thetas(self): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
902 try: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
903 return(self._thetas) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
904 except: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
905 theta_range = self.tomo_fields.theta_range |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
906 self._thetas = list(np.linspace(theta_range['start'], theta_range['end'], |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
907 theta_range['num'])) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
908 return(self._thetas) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
909 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
910 def cli(self): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
911 print('\n -- Configure a map from a set of SPEC scans (dark, bright, and tomo), '+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
912 'and / or detector data -- ') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
913 #RV self.cycle = '2021-3' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
914 #RV self.cycle = '2022-2' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
915 #RV self.cycle = '2023-1' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
916 self.set_single_attr_cli('cycle', 'beam cycle') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
917 #RV self.btr = 'z-3234-A' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
918 #RV self.btr = 'sobhani-3249-A' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
919 #RV self.btr = 'przybyla-3606-a' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
920 self.set_single_attr_cli('btr', 'BTR') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
921 #RV self.title = 'z-3234-A' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
922 #RV self.title = 'tomo7C' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
923 #RV self.title = 'cmc-test-dwell-1' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
924 self.set_single_attr_cli('title', 'title for the map entry') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
925 #RV self.station = 'id3a' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
926 #RV self.station = 'id3b' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
927 #RV self.station = 'id1a3' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
928 self.set_single_attr_cli('station', 'name of the station at which scans were collected '+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
929 '(currently choose from: id1a3, id3a, id3b)') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
930 import_scanparser(self.station) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
931 self.set_single_attr_cli('sample') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
932 use_detector_config = False |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
933 if hasattr(self.detector, 'prefix') and len(self.detector.prefix): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
934 use_detector_config = input_yesno(f'Current detector settings:\n{self.detector}\n'+ |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
935 f'Keep these settings? (y/n)') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
936 if not use_detector_config: |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
937 menu_options = ['not listed', 'andor2', 'manta', 'retiga'] |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
938 input_mode = input_menu(menu_options, header='Choose one of the following detector '+ |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
939 'configuration options') |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
940 if input_mode: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
941 detector_config_file = f'{menu_options[input_mode]}.yaml' |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
942 have_detector_config = self.detector.construct_from_yaml(detector_config_file) |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
943 else: |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
944 have_detector_config = False |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
945 if not have_detector_config: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
946 self.set_single_attr_cli('detector', 'detector') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
947 self.set_single_attr_cli('tomo_fields', 'Tomo field', chain_attr_desc=True, |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
948 cycle=self.cycle, btr=self.btr, station=self.station, detector=self.detector, |
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
949 sample_name=self.sample.name) |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
950 if self.station in ('id1a3', 'id3a'): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
951 have_dark_field = True |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
952 tomo_spec_file = self.tomo_fields.spec_file |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
953 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
954 have_dark_field = input_yesno(f'Are Dark field images available? (y/n)') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
955 tomo_spec_file = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
956 if have_dark_field: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
957 self.set_single_attr_cli('dark_field', 'Dark field', chain_attr_desc=True, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
958 station=self.station, detector=self.detector, spec_file=tomo_spec_file, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
959 tomo_scan_numbers=self.tomo_fields.scan_numbers, scan_type='df1') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
960 self.set_single_attr_cli('bright_field', 'Bright field', chain_attr_desc=True, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
961 station=self.station, detector=self.detector, spec_file=tomo_spec_file, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
962 tomo_scan_numbers=self.tomo_fields.scan_numbers, scan_type='bf1') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
963 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
964 def construct_nxentry(self, nxroot, include_raw_data=True): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
965 # Construct base NXentry |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
966 nxentry = NXentry() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
967 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
968 # Add an NXentry to the NXroot |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
969 nxroot[self.title] = nxentry |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
970 nxroot.attrs['default'] = self.title |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
971 nxentry.definition = 'NXtomo' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
972 # nxentry.attrs['default'] = 'data' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
973 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
974 # Add an NXinstrument to the NXentry |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
975 nxinstrument = NXinstrument() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
976 nxentry.instrument = nxinstrument |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
977 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
978 # Add an NXsource to the NXinstrument |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
979 nxsource = NXsource() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
980 nxinstrument.source = nxsource |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
981 nxsource.type = 'Synchrotron X-ray Source' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
982 nxsource.name = 'CHESS' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
983 nxsource.probe = 'x-ray' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
984 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
985 # Tag the NXsource with the runinfo (as an attribute) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
986 nxsource.attrs['cycle'] = self.cycle |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
987 nxsource.attrs['btr'] = self.btr |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
988 nxsource.attrs['station'] = self.station |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
989 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
990 # Add an NXdetector to the NXinstrument (don't fill in data fields yet) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
991 nxinstrument.detector = self.detector.construct_nxdetector() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
992 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
993 # Add an NXsample to NXentry (don't fill in data fields yet) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
994 nxsample = NXsample() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
995 nxentry.sample = nxsample |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
996 nxsample.name = self.sample.name |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
997 nxsample.description = self.sample.description |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
998 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
999 # Add an NXcollection to the base NXentry to hold metadata about the spec scans in the map |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1000 # Also obtain the data fields in NXsample and NXdetector |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1001 nxspec_scans = NXcollection() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1002 nxentry.spec_scans = nxspec_scans |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1003 image_keys = [] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1004 sequence_numbers = [] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1005 image_stacks = [] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1006 rotation_angles = [] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1007 x_translations = [] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1008 z_translations = [] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1009 for field_type in self._field_types: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1010 field_name = field_type['name'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1011 field = getattr(self, field_name) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1012 if field is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1013 continue |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1014 image_key = field_type['image_key'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1015 if field_type['name'] == 'tomo_fields': |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1016 thetas = self.thetas |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1017 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1018 thetas = None |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1019 # Add the scans in a single spec file |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1020 nxspec_scans[field_name] = field.construct_nxcollection(image_key, thetas, |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1021 self.detector) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1022 if include_raw_data: |
71
1cf15b61cd83
planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents:
69
diff
changeset
|
1023 image_stacks += field.get_detector_data(self.detector.prefix) |
69
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1024 for scan_number in field.scan_numbers: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1025 parser = field.get_scanparser(scan_number) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1026 scan_info = field.stack_info[field.get_scan_index(scan_number)] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1027 num_image = scan_info['num_image'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1028 image_keys += num_image*[image_key] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1029 sequence_numbers += [i for i in range(num_image)] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1030 if thetas is None: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1031 rotation_angles += scan_info['num_image']*[0.0] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1032 else: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1033 assert(num_image == len(thetas)) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1034 rotation_angles += thetas |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1035 x_translations += scan_info['num_image']*[scan_info['ref_x']] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1036 z_translations += scan_info['num_image']*[scan_info['ref_z']] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1037 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1038 if include_raw_data: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1039 # Add image data to NXdetector |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1040 nxinstrument.detector.image_key = image_keys |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1041 nxinstrument.detector.sequence_number = sequence_numbers |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1042 nxinstrument.detector.data = np.concatenate([image for image in image_stacks]) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1043 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1044 # Add image data to NXsample |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1045 nxsample.rotation_angle = rotation_angles |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1046 nxsample.rotation_angle.attrs['units'] = 'degrees' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1047 nxsample.x_translation = x_translations |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1048 nxsample.x_translation.attrs['units'] = 'mm' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1049 nxsample.z_translation = z_translations |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1050 nxsample.z_translation.attrs['units'] = 'mm' |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1051 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1052 # Add an NXdata to NXentry |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1053 nxdata = NXdata() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1054 nxentry.data = nxdata |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1055 nxdata.makelink(nxentry.instrument.detector.data, name='data') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1056 nxdata.makelink(nxentry.instrument.detector.image_key) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1057 nxdata.makelink(nxentry.sample.rotation_angle) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1058 nxdata.makelink(nxentry.sample.x_translation) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1059 nxdata.makelink(nxentry.sample.z_translation) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1060 # nxdata.attrs['axes'] = ['field', 'row', 'column'] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1061 # nxdata.attrs['field_indices'] = 0 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1062 # nxdata.attrs['row_indices'] = 1 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1063 # nxdata.attrs['column_indices'] = 2 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1064 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1065 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1066 class TomoWorkflow(BaseModel): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1067 sample_maps: conlist(item_type=MapConfig, min_items=1) = [MapConfig.construct()] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1068 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1069 @classmethod |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1070 def construct_from_nexus(cls, filename): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1071 nxroot = nxload(filename) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1072 sample_maps = [] |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1073 config = {'sample_maps': sample_maps} |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1074 for nxentry_name, nxentry in nxroot.items(): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1075 sample_maps.append(MapConfig.construct_from_nxentry(nxentry)) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1076 return(cls(**config)) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1077 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1078 def cli(self): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1079 print('\n -- Configure a map -- ') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1080 self.set_list_attr_cli('sample_maps', 'sample map') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1081 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1082 def construct_nxfile(self, filename, mode='w-'): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1083 nxroot = NXroot() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1084 t0 = time() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1085 for sample_map in self.sample_maps: |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1086 logger.info(f'Start constructing the {sample_map.title} map.') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1087 import_scanparser(sample_map.station) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1088 sample_map.construct_nxentry(nxroot) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1089 logger.info(f'Constructed all sample maps in {time()-t0:.2f} seconds.') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1090 logger.info(f'Start saving all sample maps to {filename}.') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1091 nxroot.save(filename, mode=mode) |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1092 |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1093 def write_to_nexus(self, filename): |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1094 t0 = time() |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1095 self.construct_nxfile(filename, mode='w') |
fba792d5f83b
planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff
changeset
|
1096 logger.info(f'Saved all sample maps to {filename} in {time()-t0:.2f} seconds.') |