ChessAnalysisPipeline 0.0.12__py3-none-any.whl → 0.0.13__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 +2 -0
- CHAP/common/__init__.py +6 -2
- CHAP/common/processor.py +245 -153
- CHAP/common/reader.py +160 -124
- CHAP/common/writer.py +150 -94
- CHAP/tomo/models.py +10 -9
- CHAP/tomo/processor.py +554 -353
- CHAP/utils/general.py +21 -11
- CHAP/utils/scanparsers.py +78 -39
- {ChessAnalysisPipeline-0.0.12.dist-info → ChessAnalysisPipeline-0.0.13.dist-info}/METADATA +1 -1
- {ChessAnalysisPipeline-0.0.12.dist-info → ChessAnalysisPipeline-0.0.13.dist-info}/RECORD +15 -15
- {ChessAnalysisPipeline-0.0.12.dist-info → ChessAnalysisPipeline-0.0.13.dist-info}/WHEEL +1 -1
- {ChessAnalysisPipeline-0.0.12.dist-info → ChessAnalysisPipeline-0.0.13.dist-info}/LICENSE +0 -0
- {ChessAnalysisPipeline-0.0.12.dist-info → ChessAnalysisPipeline-0.0.13.dist-info}/entry_points.txt +0 -0
- {ChessAnalysisPipeline-0.0.12.dist-info → ChessAnalysisPipeline-0.0.13.dist-info}/top_level.txt +0 -0
CHAP/common/writer.py
CHANGED
|
@@ -5,11 +5,10 @@ Author : Valentin Kuznetsov <vkuznet AT gmail dot com>
|
|
|
5
5
|
Description: Module for Writers used in multiple experiment-specific workflows.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
-
#
|
|
9
|
-
from os import mkdir
|
|
8
|
+
# System modules
|
|
10
9
|
from os import path as os_path
|
|
11
10
|
|
|
12
|
-
#
|
|
11
|
+
# Local modules
|
|
13
12
|
from CHAP import Writer
|
|
14
13
|
|
|
15
14
|
def write_matplotlibfigure(data, filename, force_overwrite=False):
|
|
@@ -89,6 +88,9 @@ def write_yaml(data, filename, force_overwrite=False):
|
|
|
89
88
|
yaml.dump(data, f, sort_keys=False)
|
|
90
89
|
|
|
91
90
|
def write_filetree(data, outputdir, force_overwrite=False):
|
|
91
|
+
# System modules
|
|
92
|
+
from os import mkdir
|
|
93
|
+
|
|
92
94
|
# Third party modules
|
|
93
95
|
from nexusformat.nexus import (
|
|
94
96
|
NXentry,
|
|
@@ -130,15 +132,15 @@ def write_filetree(data, outputdir, force_overwrite=False):
|
|
|
130
132
|
class ExtractArchiveWriter(Writer):
|
|
131
133
|
"""Writer for tar files from binary data"""
|
|
132
134
|
def write(self, data, filename):
|
|
133
|
-
"""Take a .tar archive represented as bytes in `data`
|
|
134
|
-
write the extracted archive to files.
|
|
135
|
+
"""Take a .tar archive represented as bytes contained in `data`
|
|
136
|
+
and write the extracted archive to files.
|
|
135
137
|
|
|
136
|
-
:param data:
|
|
137
|
-
:type data:
|
|
138
|
-
:param filename:
|
|
139
|
-
files
|
|
138
|
+
:param data: The data to write to archive.
|
|
139
|
+
:type data: CHAP.pipeline.PipelineData
|
|
140
|
+
:param filename: The name of the directory to write the archive
|
|
141
|
+
files to.
|
|
140
142
|
:type filename: str
|
|
141
|
-
:return:
|
|
143
|
+
:return: The achived data
|
|
142
144
|
:rtype: bytes
|
|
143
145
|
"""
|
|
144
146
|
# System modules
|
|
@@ -153,86 +155,179 @@ class ExtractArchiveWriter(Writer):
|
|
|
153
155
|
return data
|
|
154
156
|
|
|
155
157
|
|
|
158
|
+
class FileTreeWriter(Writer):
|
|
159
|
+
"""Writer for a file tree in NeXus format"""
|
|
160
|
+
def write(self, data, outputdir, force_overwrite=False):
|
|
161
|
+
"""Write a NeXus format object contained in `data` to a
|
|
162
|
+
directory tree stuctured like the NeXus tree.
|
|
163
|
+
|
|
164
|
+
:param data: The data to write to disk.
|
|
165
|
+
:type data: CHAP.pipeline.PipelineData
|
|
166
|
+
:param outputdir: The name of the directory to write to.
|
|
167
|
+
:type outputdir: str
|
|
168
|
+
:param force_overwrite: Flag to allow data to be overwritten
|
|
169
|
+
if it already exists, defaults to `False`.
|
|
170
|
+
:type force_overwrite: bool, optional
|
|
171
|
+
:raises RuntimeError: If `filename` already exists and
|
|
172
|
+
`force_overwrite` is `False`.
|
|
173
|
+
:return: The data written to disk.
|
|
174
|
+
:rtype: Union[nexusformat.nexus.NXroot,
|
|
175
|
+
nexusformat.nexus.NXentry]
|
|
176
|
+
"""
|
|
177
|
+
# Third party modules
|
|
178
|
+
from nexusformat.nexus import (
|
|
179
|
+
NXentry,
|
|
180
|
+
NXroot,
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
data = self.unwrap_pipelinedata(data)[-1]
|
|
184
|
+
if isinstance(data, NXroot):
|
|
185
|
+
if 'default' in data.attrs:
|
|
186
|
+
nxentry = data[data.attrs['default']]
|
|
187
|
+
else:
|
|
188
|
+
nxentry = [v for v in data.values()
|
|
189
|
+
if isinstance(data, NXentry)]
|
|
190
|
+
if len(nxentry) == 1:
|
|
191
|
+
nxentry = nxentry[0]
|
|
192
|
+
else:
|
|
193
|
+
raise TypeError('Cannot write object of type '
|
|
194
|
+
f'{type(data).__name__} as a file tree '
|
|
195
|
+
'to disk.')
|
|
196
|
+
elif isinstance(data, NXentry):
|
|
197
|
+
nxentry = data
|
|
198
|
+
else:
|
|
199
|
+
raise TypeError('Cannot write object of type '
|
|
200
|
+
f'{type(data).__name__} as a file tree to disk.')
|
|
201
|
+
|
|
202
|
+
write_filetree(nxentry, outputdir, force_overwrite)
|
|
203
|
+
|
|
204
|
+
return data
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
class MatplotlibAnimationWriter(Writer):
|
|
208
|
+
"""Writer for saving matplotlib animations."""
|
|
209
|
+
def write(self, data, filename, fps=1):
|
|
210
|
+
"""Write the matplotlib.animation.ArtistAnimation object
|
|
211
|
+
contained in `data` to file.
|
|
212
|
+
|
|
213
|
+
:param data: The matplotlib animation.
|
|
214
|
+
:type data: CHAP.pipeline.PipelineData
|
|
215
|
+
:param filename: The name of the file to write to.
|
|
216
|
+
:type filename: str
|
|
217
|
+
:param fps: Movie frame rate (frames per second),
|
|
218
|
+
defaults to `1`
|
|
219
|
+
:type fps: int, optional
|
|
220
|
+
:return: The original animation.
|
|
221
|
+
:rtype: matplotlib.animation.ArtistAnimation
|
|
222
|
+
"""
|
|
223
|
+
data = self.unwrap_pipelinedata(data)[-1]
|
|
224
|
+
extension = os_path.splitext(filename)[1]
|
|
225
|
+
if not extension:
|
|
226
|
+
data.save(f'{filename}.gif', fps=fps)
|
|
227
|
+
elif extension in '.gif':
|
|
228
|
+
data.save(filename, fps=fps)
|
|
229
|
+
elif extension == '.mp4':
|
|
230
|
+
data.save(filename, writer='ffmpeg', fps=fps)
|
|
231
|
+
|
|
232
|
+
return data
|
|
233
|
+
|
|
234
|
+
|
|
156
235
|
class MatplotlibFigureWriter(Writer):
|
|
157
236
|
"""Writer for saving matplotlib figures to image files."""
|
|
158
237
|
def write(self, data, filename, savefig_kw={}, force_overwrite=False):
|
|
159
|
-
"""Write the matplotlib.
|
|
160
|
-
|
|
238
|
+
"""Write the matplotlib.figure.Figure contained in `data` to
|
|
239
|
+
file.
|
|
161
240
|
|
|
162
|
-
:param data:
|
|
241
|
+
:param data: The matplotlib figure
|
|
163
242
|
:type data: CHAP.pipeline.PipelineData
|
|
164
|
-
:param filename: name of the file to write to.
|
|
165
|
-
:
|
|
166
|
-
|
|
243
|
+
:param filename: The name of the file to write to.
|
|
244
|
+
:type filename: str
|
|
245
|
+
:param savefig_kw: Keyword args to pass to
|
|
246
|
+
matplotlib.figure.Figure.savefig, defaults to {}.
|
|
167
247
|
:type savefig_kw: dict, optional
|
|
168
|
-
:param force_overwrite:
|
|
169
|
-
overwritten
|
|
170
|
-
:
|
|
248
|
+
:param force_overwrite: Flag to allow data in `filename` to be
|
|
249
|
+
overwritten if it already exists, defaults to `False`.
|
|
250
|
+
:type force_overwrite: bool, optional
|
|
251
|
+
:raises RuntimeError: If `filename` already exists and
|
|
252
|
+
`force_overwrite` is `False`.
|
|
253
|
+
:return: The original figure object
|
|
254
|
+
:rtype: matplotlib.figure.Figure
|
|
171
255
|
"""
|
|
172
256
|
data = self.unwrap_pipelinedata(data)[-1]
|
|
173
257
|
write_matplotlibfigure(data, filename, force_overwrite)
|
|
258
|
+
|
|
174
259
|
return data
|
|
175
260
|
|
|
176
261
|
|
|
177
262
|
class NexusWriter(Writer):
|
|
178
263
|
"""Writer for NeXus files from `NXobject`-s"""
|
|
179
264
|
def write(self, data, filename, force_overwrite=False):
|
|
180
|
-
"""Write `data` to
|
|
181
|
-
|
|
182
|
-
:param data:
|
|
183
|
-
:type data:
|
|
184
|
-
:param filename: name of the file to write to.
|
|
185
|
-
:param force_overwrite:
|
|
186
|
-
overwritten
|
|
187
|
-
:
|
|
265
|
+
"""Write the NeXus object contained in `data` to file.
|
|
266
|
+
|
|
267
|
+
:param data: The data to write to file.
|
|
268
|
+
:type data: CHAP.pipeline.PipelineData
|
|
269
|
+
:param filename: The name of the file to write to.
|
|
270
|
+
:param force_overwrite: Flag to allow data in `filename` to be
|
|
271
|
+
overwritten if it already exists, defaults to `False`.
|
|
272
|
+
:type force_overwrite: bool, optional
|
|
273
|
+
:raises RuntimeError: If `filename` already exists and
|
|
274
|
+
`force_overwrite` is `False`.
|
|
275
|
+
:return: The data written to file.
|
|
276
|
+
:rtype: nexusformat.nexus.NXobject
|
|
188
277
|
"""
|
|
189
278
|
data = self.unwrap_pipelinedata(data)[-1]
|
|
190
279
|
write_nexus(data, filename, force_overwrite)
|
|
280
|
+
|
|
191
281
|
return data
|
|
192
282
|
|
|
193
283
|
|
|
194
284
|
class TXTWriter(Writer):
|
|
195
|
-
"""Writer for plain text files from string or
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
:type data: str, tuple, list
|
|
203
|
-
:param filename: name of the file to write to.
|
|
285
|
+
"""Writer for plain text files from string or tuples or lists of
|
|
286
|
+
strings."""
|
|
287
|
+
def write(self, data, filename, append=False, force_overwrite=False):
|
|
288
|
+
"""Write a string or tuple or list of strings contained in
|
|
289
|
+
`data` to file.
|
|
290
|
+
|
|
291
|
+
:param data: The data to write to disk.
|
|
292
|
+
:type data: str, tuple[str], list[str]
|
|
293
|
+
:param filename: The name of the file to write to.
|
|
204
294
|
:type filename: str
|
|
205
|
-
:param
|
|
206
|
-
|
|
207
|
-
:type
|
|
208
|
-
:
|
|
209
|
-
`
|
|
210
|
-
:
|
|
295
|
+
:param append: Flag to allow data in `filename` to be
|
|
296
|
+
be appended, defaults to `False`.
|
|
297
|
+
:type append: bool, optional
|
|
298
|
+
:param force_overwrite: Flag to allow data in `filename` to be
|
|
299
|
+
overwritten if it already exists, defaults to `False`.
|
|
300
|
+
:type force_overwrite: bool, optional
|
|
301
|
+
:raises TypeError: If the object contained in `data` is not a
|
|
302
|
+
`str`, `tuple[str]` or `list[str]`.
|
|
303
|
+
:raises RuntimeError: If `filename` already exists and
|
|
211
304
|
`force_overwrite` is `False`.
|
|
212
|
-
:return:
|
|
213
|
-
:rtype: str, tuple, list
|
|
305
|
+
:return: The data written to file.
|
|
306
|
+
:rtype: str, tuple[str], list[str]
|
|
214
307
|
"""
|
|
215
308
|
data = self.unwrap_pipelinedata(data)[-1]
|
|
216
309
|
write_txt(data, filename, force_overwrite, append)
|
|
310
|
+
|
|
217
311
|
return data
|
|
218
312
|
|
|
219
313
|
|
|
220
314
|
class YAMLWriter(Writer):
|
|
221
315
|
"""Writer for YAML files from `dict`-s"""
|
|
222
316
|
def write(self, data, filename, force_overwrite=False):
|
|
223
|
-
"""
|
|
317
|
+
"""Write the dictionary contained in `data` to file.
|
|
224
318
|
|
|
225
|
-
:param data:
|
|
319
|
+
:param data: The data to write to file.
|
|
226
320
|
:type data: dict
|
|
227
|
-
:param filename: name of the file to write to.
|
|
321
|
+
:param filename: The name of the file to write to.
|
|
228
322
|
:type filename: str
|
|
229
|
-
:param force_overwrite:
|
|
230
|
-
overwritten if it already exists
|
|
231
|
-
:type force_overwrite: bool
|
|
232
|
-
:raises TypeError:
|
|
233
|
-
|
|
323
|
+
:param force_overwrite: Flag to allow data in `filename` to be
|
|
324
|
+
overwritten if it already exists, defaults to `False`.
|
|
325
|
+
:type force_overwrite: bool, optional
|
|
326
|
+
:raises TypeError: If the object contained in `data` is not a
|
|
327
|
+
`dict`.
|
|
328
|
+
:raises RuntimeError: If `filename` already exists and
|
|
234
329
|
`force_overwrite` is `False`.
|
|
235
|
-
:return:
|
|
330
|
+
:return: The data written to file.
|
|
236
331
|
:rtype: dict
|
|
237
332
|
"""
|
|
238
333
|
data = self.unwrap_pipelinedata(data)[-1]
|
|
@@ -240,47 +335,8 @@ class YAMLWriter(Writer):
|
|
|
240
335
|
return data
|
|
241
336
|
|
|
242
337
|
|
|
243
|
-
class FileTreeWriter(Writer):
|
|
244
|
-
"""Writer for a file tree in NeXus format"""
|
|
245
|
-
def write(self, data, outputdir, force_overwrite=False):
|
|
246
|
-
"""Write `data` to a NeXus file
|
|
247
|
-
|
|
248
|
-
:param data: the data to write to disk.
|
|
249
|
-
:type data: Union[nexusformat.nexus.NXroot,
|
|
250
|
-
nexusformat.nexus.NXentry]
|
|
251
|
-
:param force_overwrite: flag to allow data to be overwritten,
|
|
252
|
-
if it already exists.
|
|
253
|
-
:return: the original input data
|
|
254
|
-
"""
|
|
255
|
-
# Third party modules
|
|
256
|
-
from nexusformat.nexus import (
|
|
257
|
-
NXentry,
|
|
258
|
-
NXroot,
|
|
259
|
-
)
|
|
260
|
-
|
|
261
|
-
data = self.unwrap_pipelinedata(data)[-1]
|
|
262
|
-
if isinstance(data, NXroot):
|
|
263
|
-
if 'default' in data.attrs:
|
|
264
|
-
nxentry = data[data.attrs['default']]
|
|
265
|
-
else:
|
|
266
|
-
nxentry = [v for v in data.values()
|
|
267
|
-
if isinstance(data, NXentry)]
|
|
268
|
-
if len(nxentry) == 1:
|
|
269
|
-
nxentry = nxentry[0]
|
|
270
|
-
else:
|
|
271
|
-
raise TypeError('Cannot write object of type '
|
|
272
|
-
f'{type(data).__name__} as a file tree '
|
|
273
|
-
'to disk.')
|
|
274
|
-
elif isinstance(data, NXentry):
|
|
275
|
-
nxentry = data
|
|
276
|
-
else:
|
|
277
|
-
raise TypeError('Cannot write object of type '
|
|
278
|
-
f'{type(data).__name__} as a file tree to disk.')
|
|
279
|
-
|
|
280
|
-
write_filetree(nxentry, outputdir, force_overwrite)
|
|
281
|
-
return data
|
|
282
|
-
|
|
283
|
-
|
|
284
338
|
if __name__ == '__main__':
|
|
339
|
+
# Local modules
|
|
285
340
|
from CHAP.writer import main
|
|
341
|
+
|
|
286
342
|
main()
|
CHAP/tomo/models.py
CHANGED
|
@@ -46,7 +46,8 @@ class TomoReduceConfig(BaseModel):
|
|
|
46
46
|
Class representing the configuration for the tomography image
|
|
47
47
|
reduction processor.
|
|
48
48
|
|
|
49
|
-
:ivar img_row_bounds: Detector image bounds in the row-direction
|
|
49
|
+
:ivar img_row_bounds: Detector image bounds in the row-direction
|
|
50
|
+
(ignored for id1a3 and id3a).
|
|
50
51
|
:type img_row_bounds: list[int], optional
|
|
51
52
|
:ivar delta_theta: Rotation angle increment in image reduction
|
|
52
53
|
in degrees.
|
|
@@ -70,12 +71,12 @@ class TomoFindCenterConfig(BaseModel):
|
|
|
70
71
|
:ivar center_offsets: Centers at the center finding row indices in
|
|
71
72
|
pixels.
|
|
72
73
|
:type center_offsets: list[float, float], optional
|
|
73
|
-
:ivar
|
|
74
|
-
in pixels
|
|
75
|
-
:type
|
|
76
|
-
:ivar
|
|
77
|
-
in pixels
|
|
78
|
-
:type
|
|
74
|
+
:ivar center_offset_min: Minimum value of center_offset in center
|
|
75
|
+
axis finding search in pixels.
|
|
76
|
+
:type center_offset_min: float, optional
|
|
77
|
+
:ivar center_offset_max: Maximum value of center_offset in center
|
|
78
|
+
axis finding search in pixels.
|
|
79
|
+
:type center_offset_max: float, optional
|
|
79
80
|
:ivar gaussian_sigma: Standard deviation for the Gaussian filter
|
|
80
81
|
applied to image reconstruction visualizations, defaults to no
|
|
81
82
|
filtering performed.
|
|
@@ -90,8 +91,8 @@ class TomoFindCenterConfig(BaseModel):
|
|
|
90
91
|
center_offsets: Optional[conlist(
|
|
91
92
|
item_type=confloat(allow_inf_nan=False),
|
|
92
93
|
min_items=2, max_items=2)]
|
|
93
|
-
|
|
94
|
-
|
|
94
|
+
center_offset_min: Optional[confloat(allow_inf_nan=False)]
|
|
95
|
+
center_offset_max: Optional[confloat(allow_inf_nan=False)]
|
|
95
96
|
gaussian_sigma: Optional[confloat(ge=0, allow_inf_nan=False)]
|
|
96
97
|
ring_width: Optional[confloat(ge=0, allow_inf_nan=False)]
|
|
97
98
|
|