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