ChessAnalysisPipeline 0.0.2__py3-none-any.whl → 0.0.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of ChessAnalysisPipeline might be problematic. Click here for more details.
- CHAP/__init__.py +3 -0
- CHAP/common/__init__.py +19 -0
- CHAP/common/models/__init__.py +2 -0
- CHAP/common/models/integration.py +515 -0
- CHAP/common/models/map.py +535 -0
- CHAP/common/processor.py +644 -0
- CHAP/common/reader.py +119 -0
- CHAP/common/utils/__init__.py +37 -0
- CHAP/common/utils/fit.py +2613 -0
- CHAP/common/utils/general.py +1225 -0
- CHAP/common/utils/material.py +231 -0
- CHAP/common/utils/scanparsers.py +785 -0
- CHAP/common/writer.py +96 -0
- CHAP/edd/__init__.py +7 -0
- CHAP/edd/models.py +215 -0
- CHAP/edd/processor.py +321 -0
- CHAP/edd/reader.py +5 -0
- CHAP/edd/writer.py +5 -0
- CHAP/inference/__init__.py +3 -0
- CHAP/inference/processor.py +68 -0
- CHAP/inference/reader.py +5 -0
- CHAP/inference/writer.py +5 -0
- CHAP/pipeline.py +1 -1
- CHAP/processor.py +11 -818
- CHAP/reader.py +18 -113
- CHAP/saxswaxs/__init__.py +6 -0
- CHAP/saxswaxs/processor.py +5 -0
- CHAP/saxswaxs/reader.py +5 -0
- CHAP/saxswaxs/writer.py +5 -0
- CHAP/sin2psi/__init__.py +7 -0
- CHAP/sin2psi/processor.py +5 -0
- CHAP/sin2psi/reader.py +5 -0
- CHAP/sin2psi/writer.py +5 -0
- CHAP/tomo/__init__.py +5 -0
- CHAP/tomo/models.py +125 -0
- CHAP/tomo/processor.py +2009 -0
- CHAP/tomo/reader.py +5 -0
- CHAP/tomo/writer.py +5 -0
- CHAP/writer.py +17 -167
- {ChessAnalysisPipeline-0.0.2.dist-info → ChessAnalysisPipeline-0.0.4.dist-info}/METADATA +1 -1
- ChessAnalysisPipeline-0.0.4.dist-info/RECORD +50 -0
- CHAP/async.py +0 -56
- ChessAnalysisPipeline-0.0.2.dist-info/RECORD +0 -17
- {ChessAnalysisPipeline-0.0.2.dist-info → ChessAnalysisPipeline-0.0.4.dist-info}/LICENSE +0 -0
- {ChessAnalysisPipeline-0.0.2.dist-info → ChessAnalysisPipeline-0.0.4.dist-info}/WHEEL +0 -0
- {ChessAnalysisPipeline-0.0.2.dist-info → ChessAnalysisPipeline-0.0.4.dist-info}/entry_points.txt +0 -0
- {ChessAnalysisPipeline-0.0.2.dist-info → ChessAnalysisPipeline-0.0.4.dist-info}/top_level.txt +0 -0
CHAP/reader.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env python
|
|
2
|
-
|
|
2
|
+
'''
|
|
3
3
|
File : reader.py
|
|
4
4
|
Author : Valentin Kuznetsov <vkuznet AT gmail dot com>
|
|
5
5
|
Description: generic Reader module
|
|
6
|
-
|
|
6
|
+
'''
|
|
7
7
|
|
|
8
8
|
# system modules
|
|
9
9
|
import argparse
|
|
@@ -16,14 +16,14 @@ from time import time
|
|
|
16
16
|
# from pipeline import PipelineObject
|
|
17
17
|
|
|
18
18
|
class Reader():
|
|
19
|
-
|
|
19
|
+
'''
|
|
20
20
|
Reader represent generic file writer
|
|
21
|
-
|
|
21
|
+
'''
|
|
22
22
|
|
|
23
23
|
def __init__(self):
|
|
24
|
-
|
|
24
|
+
'''
|
|
25
25
|
Constructor of Reader class
|
|
26
|
-
|
|
26
|
+
'''
|
|
27
27
|
self.__name__ = self.__class__.__name__
|
|
28
28
|
self.logger = logging.getLogger(self.__name__)
|
|
29
29
|
self.logger.propagate = False
|
|
@@ -75,119 +75,24 @@ class Reader():
|
|
|
75
75
|
data = file.read()
|
|
76
76
|
return(data)
|
|
77
77
|
|
|
78
|
-
class MultipleReader(Reader):
|
|
79
|
-
def read(self, readers):
|
|
80
|
-
'''Return resuts from multiple `Reader`s.
|
|
81
|
-
|
|
82
|
-
:param readers: a dictionary where the keys are specific names that are
|
|
83
|
-
used by the next item in the `Pipeline`, and the values are `Reader`
|
|
84
|
-
configurations.
|
|
85
|
-
:type readers: list[dict]
|
|
86
|
-
:return: The results of calling `Reader.read(**kwargs)` for each item
|
|
87
|
-
configured in `readers`.
|
|
88
|
-
:rtype: list[dict[str,object]]
|
|
89
|
-
'''
|
|
90
|
-
|
|
91
|
-
t0 = time()
|
|
92
|
-
self.logger.info(f'Executing "read" with {len(readers)} Readers')
|
|
93
|
-
|
|
94
|
-
data = []
|
|
95
|
-
for reader_config in readers:
|
|
96
|
-
reader_name = list(reader_config.keys())[0]
|
|
97
|
-
reader_class = getattr(sys.modules[__name__], reader_name)
|
|
98
|
-
reader = reader_class()
|
|
99
|
-
reader_kwargs = reader_config[reader_name]
|
|
100
|
-
|
|
101
|
-
data.extend(reader.read(**reader_kwargs))
|
|
102
|
-
|
|
103
|
-
self.logger.info(f'Finished "read" in {time()-t0:.3f} seconds\n')
|
|
104
|
-
|
|
105
|
-
return(data)
|
|
106
|
-
|
|
107
|
-
class YAMLReader(Reader):
|
|
108
|
-
def _read(self, filename):
|
|
109
|
-
'''Return a dictionary from the contents of a yaml file.
|
|
110
|
-
|
|
111
|
-
:param filename: name of the YAML file to read from
|
|
112
|
-
:return: the contents of `filename`
|
|
113
|
-
:rtype: dict
|
|
114
|
-
'''
|
|
115
|
-
|
|
116
|
-
import yaml
|
|
117
|
-
|
|
118
|
-
with open(filename) as file:
|
|
119
|
-
data = yaml.safe_load(file)
|
|
120
|
-
return(data)
|
|
121
|
-
|
|
122
|
-
class BinaryFileReader(Reader):
|
|
123
|
-
def _read(self, filename):
|
|
124
|
-
'''Return a content of a given file name
|
|
125
|
-
|
|
126
|
-
:param filename: name of the binart file to read from
|
|
127
|
-
:return: the content of `filename`
|
|
128
|
-
:rtype: binary
|
|
129
|
-
'''
|
|
130
|
-
with open(filename, 'rb') as file:
|
|
131
|
-
data = file.read()
|
|
132
|
-
return(data)
|
|
133
|
-
|
|
134
|
-
class NexusReader(Reader):
|
|
135
|
-
def _read(self, filename, nxpath='/'):
|
|
136
|
-
'''Return the NeXus object stored at `nxpath` in the nexus file
|
|
137
|
-
`filename`.
|
|
138
|
-
|
|
139
|
-
:param filename: name of the NeXus file to read from
|
|
140
|
-
:type filename: str
|
|
141
|
-
:param nxpath: path to a specific loaction in the NeXus file to read
|
|
142
|
-
from, defaults to `'/'`
|
|
143
|
-
:type nxpath: str, optional
|
|
144
|
-
:raises nexusformat.nexus.NeXusError: if `filename` is not a NeXus
|
|
145
|
-
file or `nxpath` is not in `filename`.
|
|
146
|
-
:return: the NeXus structure indicated by `filename` and `nxpath`.
|
|
147
|
-
:rtype: nexusformat.nexus.NXobject
|
|
148
|
-
'''
|
|
149
|
-
|
|
150
|
-
from nexusformat.nexus import nxload
|
|
151
|
-
|
|
152
|
-
nxobject = nxload(filename)[nxpath]
|
|
153
|
-
return(nxobject)
|
|
154
|
-
|
|
155
|
-
class URLReader(Reader):
|
|
156
|
-
def _read(self, url, headers={}):
|
|
157
|
-
'''Make an HTTPS request to the provided URL and return the results.
|
|
158
|
-
Headers for the request are optional.
|
|
159
|
-
|
|
160
|
-
:param url: the URL to read
|
|
161
|
-
:type url: str
|
|
162
|
-
:param headers: headers to attach to the request, defaults to `{}`
|
|
163
|
-
:type headers: dict, optional
|
|
164
|
-
:return: the content of the response
|
|
165
|
-
:rtype: object
|
|
166
|
-
'''
|
|
167
|
-
|
|
168
|
-
import requests
|
|
169
|
-
|
|
170
|
-
resp = requests.get(url, headers=headers)
|
|
171
|
-
data = resp.content
|
|
172
|
-
|
|
173
|
-
self.logger.debug(f'Response content: {data}')
|
|
174
|
-
|
|
175
|
-
return(data)
|
|
176
|
-
|
|
177
78
|
class OptionParser():
|
|
178
79
|
'''User based option parser'''
|
|
179
80
|
def __init__(self):
|
|
180
81
|
self.parser = argparse.ArgumentParser(prog='PROG')
|
|
181
|
-
self.parser.add_argument(
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
82
|
+
self.parser.add_argument(
|
|
83
|
+
'--filename', action='store',
|
|
84
|
+
dest='filename', default='', help='Input file')
|
|
85
|
+
self.parser.add_argument(
|
|
86
|
+
'--reader', action='store',
|
|
87
|
+
dest='reader', default='Reader', help='Reader class name')
|
|
88
|
+
self.parser.add_argument(
|
|
89
|
+
'--log-level', choices=logging._nameToLevel.keys(),
|
|
186
90
|
dest='log_level', default='INFO', help='logging level')
|
|
187
91
|
|
|
188
|
-
def main():
|
|
92
|
+
def main(opt_parser=OptionParser):
|
|
189
93
|
'''Main function'''
|
|
190
|
-
|
|
94
|
+
|
|
95
|
+
optmgr = opt_parser()
|
|
191
96
|
opts = optmgr.parser.parse_args()
|
|
192
97
|
clsName = opts.reader
|
|
193
98
|
try:
|
|
@@ -203,7 +108,7 @@ def main():
|
|
|
203
108
|
reader.logger.addHandler(log_handler)
|
|
204
109
|
data = reader.read(filename=opts.filename)
|
|
205
110
|
|
|
206
|
-
print(f
|
|
111
|
+
print(f'Reader {reader} reads from {opts.filename}, data {data}')
|
|
207
112
|
|
|
208
113
|
if __name__ == '__main__':
|
|
209
114
|
main()
|
CHAP/saxswaxs/reader.py
ADDED
CHAP/saxswaxs/writer.py
ADDED
CHAP/sin2psi/__init__.py
ADDED
CHAP/sin2psi/reader.py
ADDED
CHAP/sin2psi/writer.py
ADDED
CHAP/tomo/__init__.py
ADDED
CHAP/tomo/models.py
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# system modules
|
|
2
|
+
|
|
3
|
+
# third party imports
|
|
4
|
+
from pydantic import (
|
|
5
|
+
BaseModel,
|
|
6
|
+
StrictBool,
|
|
7
|
+
conint,
|
|
8
|
+
conlist,
|
|
9
|
+
confloat,
|
|
10
|
+
constr,
|
|
11
|
+
)
|
|
12
|
+
from typing import Literal, Optional
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Detector(BaseModel):
|
|
16
|
+
"""
|
|
17
|
+
Detector class to represent the detector used in the experiment.
|
|
18
|
+
|
|
19
|
+
:ivar prefix: Prefix of the detector in the SPEC file.
|
|
20
|
+
:type prefix: str
|
|
21
|
+
:ivar rows: Number of pixel rows on the detector
|
|
22
|
+
:type rows: int
|
|
23
|
+
:ivar columns: Number of pixel columns on the detector
|
|
24
|
+
:type columns: int
|
|
25
|
+
:ivar pixel_size: Pixel size of the detector in mm
|
|
26
|
+
:type pixel_size: int or list[int]
|
|
27
|
+
:ivar lens_magnification: Lens magnification for the detector
|
|
28
|
+
:type lens_magnification: float, optional
|
|
29
|
+
"""
|
|
30
|
+
prefix: constr(strip_whitespace=True, min_length=1)
|
|
31
|
+
rows: conint(gt=0)
|
|
32
|
+
columns: conint(gt=0)
|
|
33
|
+
pixel_size: conlist(item_type=confloat(gt=0, allow_inf_nan=False), min_items=1, max_items=2)
|
|
34
|
+
lens_magnification: confloat(gt=0, allow_inf_nan=False) = 1.0
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class TomoSetupConfig(BaseModel):
|
|
38
|
+
"""
|
|
39
|
+
Class representing the configuration for the tomography reconstruction setup.
|
|
40
|
+
|
|
41
|
+
:ivar detectors: Detector used in the tomography experiment
|
|
42
|
+
:type detectors: Detector
|
|
43
|
+
"""
|
|
44
|
+
detector: Detector.construct()
|
|
45
|
+
include_raw_data: Optional[StrictBool] = False
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class TomoReduceConfig(BaseModel):
|
|
49
|
+
"""
|
|
50
|
+
Class representing the configuration for tomography image reductions.
|
|
51
|
+
|
|
52
|
+
:ivar tool_type: Type of tomography reconstruction tool; always set to "reduce_data"
|
|
53
|
+
:type tool_type: str, optional
|
|
54
|
+
:ivar detectors: Detector used in the tomography experiment
|
|
55
|
+
:type detectors: Detector
|
|
56
|
+
:ivar img_x_bounds: Detector image bounds in the x-direction
|
|
57
|
+
:type img_x_bounds: list[int], optional
|
|
58
|
+
"""
|
|
59
|
+
tool_type: Literal['reduce_data'] = 'reduce_data'
|
|
60
|
+
detector: Detector = Detector.construct()
|
|
61
|
+
img_x_bounds: Optional[conlist(item_type=conint(ge=0), min_items=2, max_items=2)]
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class TomoFindCenterConfig(BaseModel):
|
|
65
|
+
"""
|
|
66
|
+
Class representing the configuration for tomography find center axis.
|
|
67
|
+
|
|
68
|
+
:ivar tool_type: Type of tomography reconstruction tool; always set to "find_center"
|
|
69
|
+
:type tool_type: str, optional
|
|
70
|
+
:ivar center_stack_index: Stack index of tomography set to find center axis (offset 1)
|
|
71
|
+
:type center_stack_index: int, optional
|
|
72
|
+
:ivar lower_row: Lower row index for center finding
|
|
73
|
+
:type lower_row: int, optional
|
|
74
|
+
:ivar lower_center_offset: Center at lower row index
|
|
75
|
+
:type lower_center_offset: float, optional
|
|
76
|
+
:ivar upper_row: Upper row index for center finding
|
|
77
|
+
:type upper_row: int, optional
|
|
78
|
+
:ivar upper_center_offset: Center at upper row index
|
|
79
|
+
:type upper_center_offset: float, optional
|
|
80
|
+
"""
|
|
81
|
+
tool_type: Literal['find_center'] = 'find_center'
|
|
82
|
+
center_stack_index: Optional[conint(ge=1)]
|
|
83
|
+
lower_row: Optional[conint(ge=-1)]
|
|
84
|
+
lower_center_offset: Optional[confloat(allow_inf_nan=False)]
|
|
85
|
+
upper_row: Optional[conint(ge=-1)]
|
|
86
|
+
upper_center_offset: Optional[confloat(allow_inf_nan=False)]
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class TomoReconstructConfig(BaseModel):
|
|
90
|
+
"""
|
|
91
|
+
Class representing the configuration for tomography image reconstruction.
|
|
92
|
+
|
|
93
|
+
:ivar tool_type: Type of tomography reconstruction tool; always set to "reconstruct_data"
|
|
94
|
+
:type tool_type: str, optional
|
|
95
|
+
:ivar x_bounds: Reconstructed image bounds in the x-direction
|
|
96
|
+
:type x_bounds: list[int], optional
|
|
97
|
+
:ivar y_bounds: Reconstructed image bounds in the y-direction
|
|
98
|
+
:type y_bounds: list[int], optional
|
|
99
|
+
:ivar z_bounds: Reconstructed image bounds in the z-direction
|
|
100
|
+
:type z_bounds: list[int], optional
|
|
101
|
+
"""
|
|
102
|
+
tool_type: Literal['reconstruct_data'] = 'reconstruct_data'
|
|
103
|
+
x_bounds: Optional[conlist(item_type=conint(ge=-1), min_items=2, max_items=2)]
|
|
104
|
+
y_bounds: Optional[conlist(item_type=conint(ge=-1), min_items=2, max_items=2)]
|
|
105
|
+
z_bounds: Optional[conlist(item_type=conint(ge=-1), min_items=2, max_items=2)]
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
class TomoCombineConfig(BaseModel):
|
|
109
|
+
"""
|
|
110
|
+
Class representing the configuration for combined tomography stacks.
|
|
111
|
+
|
|
112
|
+
:ivar tool_type: Type of tomography reconstruction tool; always set to "combine_data"
|
|
113
|
+
:type tool_type: str, optional
|
|
114
|
+
:ivar x_bounds: Reconstructed image bounds in the x-direction
|
|
115
|
+
:type x_bounds: list[int], optional
|
|
116
|
+
:ivar y_bounds: Reconstructed image bounds in the y-direction
|
|
117
|
+
:type y_bounds: list[int], optional
|
|
118
|
+
:ivar z_bounds: Reconstructed image bounds in the z-direction
|
|
119
|
+
:type z_bounds: list[int], optional
|
|
120
|
+
"""
|
|
121
|
+
tool_type: Literal['combine_data'] = 'combine_data'
|
|
122
|
+
x_bounds: Optional[conlist(item_type=conint(ge=-1), min_items=2, max_items=2)]
|
|
123
|
+
y_bounds: Optional[conlist(item_type=conint(ge=-1), min_items=2, max_items=2)]
|
|
124
|
+
z_bounds: Optional[conlist(item_type=conint(ge=-1), min_items=2, max_items=2)]
|
|
125
|
+
|