ChessAnalysisPipeline 0.0.14__py3-none-any.whl → 0.0.16__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 +1 -1
- CHAP/common/__init__.py +13 -0
- CHAP/common/models/integration.py +29 -26
- CHAP/common/models/map.py +395 -224
- CHAP/common/processor.py +1725 -93
- CHAP/common/reader.py +265 -28
- CHAP/common/writer.py +191 -18
- CHAP/edd/__init__.py +9 -2
- CHAP/edd/models.py +886 -665
- CHAP/edd/processor.py +2592 -936
- CHAP/edd/reader.py +889 -0
- CHAP/edd/utils.py +846 -292
- CHAP/foxden/__init__.py +6 -0
- CHAP/foxden/processor.py +42 -0
- CHAP/foxden/writer.py +65 -0
- CHAP/giwaxs/__init__.py +8 -0
- CHAP/giwaxs/models.py +100 -0
- CHAP/giwaxs/processor.py +520 -0
- CHAP/giwaxs/reader.py +5 -0
- CHAP/giwaxs/writer.py +5 -0
- CHAP/pipeline.py +48 -10
- CHAP/runner.py +161 -72
- CHAP/tomo/models.py +31 -29
- CHAP/tomo/processor.py +169 -118
- CHAP/utils/__init__.py +1 -0
- CHAP/utils/fit.py +1292 -1315
- CHAP/utils/general.py +411 -53
- CHAP/utils/models.py +594 -0
- CHAP/utils/parfile.py +10 -2
- ChessAnalysisPipeline-0.0.16.dist-info/LICENSE +60 -0
- {ChessAnalysisPipeline-0.0.14.dist-info → ChessAnalysisPipeline-0.0.16.dist-info}/METADATA +1 -1
- ChessAnalysisPipeline-0.0.16.dist-info/RECORD +62 -0
- {ChessAnalysisPipeline-0.0.14.dist-info → ChessAnalysisPipeline-0.0.16.dist-info}/WHEEL +1 -1
- CHAP/utils/scanparsers.py +0 -1431
- ChessAnalysisPipeline-0.0.14.dist-info/LICENSE +0 -21
- ChessAnalysisPipeline-0.0.14.dist-info/RECORD +0 -54
- {ChessAnalysisPipeline-0.0.14.dist-info → ChessAnalysisPipeline-0.0.16.dist-info}/entry_points.txt +0 -0
- {ChessAnalysisPipeline-0.0.14.dist-info → ChessAnalysisPipeline-0.0.16.dist-info}/top_level.txt +0 -0
CHAP/foxden/__init__.py
ADDED
CHAP/foxden/processor.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
#-*- coding: utf-8 -*-
|
|
3
|
+
#pylint: disable=
|
|
4
|
+
"""
|
|
5
|
+
File : processor.py
|
|
6
|
+
Author : Valentin Kuznetsov <vkuznet AT gmail dot com>
|
|
7
|
+
Description: Processor module for FOXDEN services
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
# system modules
|
|
11
|
+
from time import time
|
|
12
|
+
|
|
13
|
+
# local modules
|
|
14
|
+
from CHAP import Processor
|
|
15
|
+
from CHAP.foxden.writer import FoxdenWriter
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class FoxdenProvenanceProcessor(Processor):
|
|
19
|
+
"""A Processor to communicate with FOXDEN provenance server."""
|
|
20
|
+
# def __init__(self):
|
|
21
|
+
# self.writer = FoxdenWriter()
|
|
22
|
+
|
|
23
|
+
def process(self, data, url, dryRun=False, verbose=False):
|
|
24
|
+
"""process data API"""
|
|
25
|
+
|
|
26
|
+
t0 = time()
|
|
27
|
+
self.logger.info(f'Executing "process" with url {url} data {data} dryrun {dryRun}')
|
|
28
|
+
writer = FoxdenWriter()
|
|
29
|
+
|
|
30
|
+
# data = self.writer.write(data, url, dryRun)
|
|
31
|
+
data = writer.write(data, url, dryRun=dryRun)
|
|
32
|
+
|
|
33
|
+
self.logger.info(f'Finished "process" in {time()-t0:.3f} seconds\n')
|
|
34
|
+
|
|
35
|
+
return data
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
if __name__ == '__main__':
|
|
39
|
+
# local modules
|
|
40
|
+
from CHAP.processor import main
|
|
41
|
+
|
|
42
|
+
main()
|
CHAP/foxden/writer.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""FOXDE command line writer."""
|
|
2
|
+
|
|
3
|
+
# system modules
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
# Local modules
|
|
7
|
+
from CHAP.writer import main
|
|
8
|
+
|
|
9
|
+
class FoxdenWriter():
|
|
10
|
+
"""FOXDEN writer writes data to specific FOXDEN service
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
def write(self, data, url, method="POST", headers={}, timeout=10, dryRun=False):
|
|
14
|
+
"""Write the input data as text to a file.
|
|
15
|
+
|
|
16
|
+
:param data: input data
|
|
17
|
+
:type data: list[PipelineData]
|
|
18
|
+
:param url: url of service
|
|
19
|
+
:type url: str
|
|
20
|
+
:param method: HTTP method to use, POST for creation and PUT for update
|
|
21
|
+
:type method: str
|
|
22
|
+
:param headers: HTTP headers to use
|
|
23
|
+
:type headers: dictionary
|
|
24
|
+
:param timeout: timeout of HTTP request
|
|
25
|
+
:type timeout: str
|
|
26
|
+
:param dryRun: dryRun option to verify HTTP workflow
|
|
27
|
+
:type dryRun: boolean
|
|
28
|
+
:return: contents of the input data
|
|
29
|
+
:rtype: object
|
|
30
|
+
"""
|
|
31
|
+
import requests
|
|
32
|
+
if 'Content-Type' not in headers:
|
|
33
|
+
headers['Content-type'] = 'application/json'
|
|
34
|
+
if 'Accept' not in headers:
|
|
35
|
+
headers['Accept'] = 'application/json'
|
|
36
|
+
if dryRun:
|
|
37
|
+
print("### HTTP writer call", url, headers, data)
|
|
38
|
+
return []
|
|
39
|
+
token = ""
|
|
40
|
+
fname = os.getenv("CHESS_WRITE_TOKEN")
|
|
41
|
+
if not fname:
|
|
42
|
+
msg = f'CHESS_WRITE_TOKEN env variable is not set'
|
|
43
|
+
raise Exception(msg)
|
|
44
|
+
with open(fname, 'r') as istream:
|
|
45
|
+
token = istream.read()
|
|
46
|
+
if token:
|
|
47
|
+
headers["Authorization"] = f"Bearer {token}"
|
|
48
|
+
else:
|
|
49
|
+
msg = f'No valid write token found in CHESS_WRITE_TOKEN env variable'
|
|
50
|
+
raise Exception(msg)
|
|
51
|
+
|
|
52
|
+
# make actual HTTP request to FOXDEN service
|
|
53
|
+
if method.lower() == 'post':
|
|
54
|
+
resp = requests.post(url, headers=headers, timeout=timeout, data=data)
|
|
55
|
+
elif method.lower() == 'put':
|
|
56
|
+
resp = requests.put(url, headers=headers, timeout=timeout, data=data)
|
|
57
|
+
else:
|
|
58
|
+
msg = f"unsupporteed method {method}"
|
|
59
|
+
raise Exception(msg)
|
|
60
|
+
data = resp.content
|
|
61
|
+
return data
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
if __name__ == '__main__':
|
|
65
|
+
main()
|
CHAP/giwaxs/__init__.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"""This subpackage contains `PipelineItems` unique to GIWAXS data
|
|
2
|
+
processing workflows.
|
|
3
|
+
"""
|
|
4
|
+
# from CHAP.giwaxs.reader import
|
|
5
|
+
# from CHAP.giwaxs.processor import
|
|
6
|
+
# from CHAP.giwaxs.writer import
|
|
7
|
+
|
|
8
|
+
from CHAP.giwaxs.processor import GiwaxsConversionProcessor
|
CHAP/giwaxs/models.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# System modules
|
|
2
|
+
from functools import cache
|
|
3
|
+
import os
|
|
4
|
+
from pathlib import PosixPath
|
|
5
|
+
from typing import (
|
|
6
|
+
Optional,
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
# Third party modules
|
|
10
|
+
import numpy as np
|
|
11
|
+
from pydantic import (
|
|
12
|
+
BaseModel,
|
|
13
|
+
DirectoryPath,
|
|
14
|
+
FilePath,
|
|
15
|
+
conint,
|
|
16
|
+
conlist,
|
|
17
|
+
constr,
|
|
18
|
+
field_validator,
|
|
19
|
+
model_validator,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
# Local modules
|
|
23
|
+
from CHAP.common.models.map import MapConfig
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Detector(BaseModel):
|
|
27
|
+
"""Detector class to represent a single detector used in the
|
|
28
|
+
experiment.
|
|
29
|
+
|
|
30
|
+
:param prefix: Prefix of the detector in the SPEC file.
|
|
31
|
+
:type prefix: str
|
|
32
|
+
:param poni_file: Path to the poni file.
|
|
33
|
+
:type poni_file: str
|
|
34
|
+
"""
|
|
35
|
+
prefix: constr(strip_whitespace=True, min_length=1)
|
|
36
|
+
poni_file: FilePath
|
|
37
|
+
|
|
38
|
+
@field_validator('poni_file')
|
|
39
|
+
@classmethod
|
|
40
|
+
def validate_poni_file(cls, poni_file):
|
|
41
|
+
"""Validate the poni file by checking if it's a valid PONI
|
|
42
|
+
file.
|
|
43
|
+
|
|
44
|
+
:param poni_file: Path to the poni file.
|
|
45
|
+
:type poni_file: str
|
|
46
|
+
:raises ValueError: If poni_file is not a valid PONI file.
|
|
47
|
+
:returns: Absolute path to the poni file.
|
|
48
|
+
:rtype: str
|
|
49
|
+
"""
|
|
50
|
+
# Third party modules
|
|
51
|
+
from pyFAI import load
|
|
52
|
+
|
|
53
|
+
poni_file = os.path.abspath(poni_file)
|
|
54
|
+
try:
|
|
55
|
+
load(poni_file)
|
|
56
|
+
except Exception as exc:
|
|
57
|
+
raise ValueError(f'{poni_file} is not a valid PONI file') from exc
|
|
58
|
+
return poni_file
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class GiwaxsConversionConfig(BaseModel):
|
|
62
|
+
"""Class representing metadata required to locate GIWAXS image
|
|
63
|
+
files for a single scan to convert to q_par/q_perp coordinates.
|
|
64
|
+
|
|
65
|
+
:ivar detectors: List of detector configurations.
|
|
66
|
+
:type detectors: list[Detector]
|
|
67
|
+
:ivar scan_step_indices: Optional scan step indices to convert.
|
|
68
|
+
If not specified, all images will be converted.
|
|
69
|
+
:type scan_step_indices: Union(int, list[int], str), optional
|
|
70
|
+
:ivar save_raw_data: Save the raw data in the NeXus output,
|
|
71
|
+
default to `False`.
|
|
72
|
+
:type save_raw_data: bool, optional
|
|
73
|
+
"""
|
|
74
|
+
detectors: conlist(item_type=Detector, min_length=1)
|
|
75
|
+
scan_step_indices: Optional[
|
|
76
|
+
conlist(item_type=conint(ge=0), min_length=1)] = None
|
|
77
|
+
save_raw_data: Optional[bool] = False
|
|
78
|
+
|
|
79
|
+
@field_validator('scan_step_indices', mode='before')
|
|
80
|
+
@classmethod
|
|
81
|
+
def validate_scan_step_indices(cls, scan_step_indices):
|
|
82
|
+
"""Validate the specified list of scan step indices.
|
|
83
|
+
|
|
84
|
+
:param scan_step_indices: List of scan numbers.
|
|
85
|
+
:type scan_step_indices: list of int
|
|
86
|
+
:raises ValueError: If a specified scan number is not found in
|
|
87
|
+
the SPEC file.
|
|
88
|
+
:return: List of scan numbers.
|
|
89
|
+
:rtype: list of int
|
|
90
|
+
"""
|
|
91
|
+
if isinstance(scan_step_indices, int):
|
|
92
|
+
scan_step_indices = [scan_step_indices]
|
|
93
|
+
if isinstance(scan_step_indices, str):
|
|
94
|
+
# Local modules
|
|
95
|
+
from CHAP.utils.general import string_to_list
|
|
96
|
+
|
|
97
|
+
scan_step_indices = string_to_list(scan_step_indices)
|
|
98
|
+
|
|
99
|
+
return scan_step_indices
|
|
100
|
+
|