ewoksid27 0.0.1a0__tar.gz

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.
@@ -0,0 +1,20 @@
1
+ # MIT License
2
+
3
+ **Copyright (c) 2026 European Synchrotron Radiation Facility**
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,138 @@
1
+ Metadata-Version: 2.4
2
+ Name: ewoksid27
3
+ Version: 0.0.1a0
4
+ Summary: An Ewoks project
5
+ Author-email: ESRF <dau-pydev@esrf.fr>
6
+ License: # MIT License
7
+
8
+ **Copyright (c) 2026 European Synchrotron Radiation Facility**
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
11
+ this software and associated documentation files (the "Software"), to deal in
12
+ the Software without restriction, including without limitation the rights to
13
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
14
+ the Software, and to permit persons to whom the Software is furnished to do so,
15
+ subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
22
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
23
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+
27
+ Project-URL: Homepage, https://gitlab.esrf.fr/workflow/ewoksapps/ewoksid27/
28
+ Project-URL: Documentation, https://ewoksid27.readthedocs.io/
29
+ Project-URL: Repository, https://gitlab.esrf.fr/workflow/ewoksapps/ewoksid27/
30
+ Project-URL: Issues, https://gitlab.esrf.fr/workflow/ewoksapps/ewoksid27/issues
31
+ Project-URL: Changelog, https://gitlab.esrf.fr/workflow/ewoksapps/ewoksid27/-/blob/main/CHANGELOG.md
32
+ Keywords: ewoks
33
+ Classifier: Intended Audience :: Science/Research
34
+ Classifier: License :: OSI Approved :: MIT License
35
+ Classifier: Programming Language :: Python :: 3
36
+ Requires-Python: >=3.10
37
+ Description-Content-Type: text/markdown
38
+ License-File: LICENSE.md
39
+ Requires-Dist: ewokscore
40
+ Requires-Dist: ewoksxrpd
41
+ Requires-Dist: pydantic>=2
42
+ Provides-Extra: test
43
+ Requires-Dist: pytest>=7; extra == "test"
44
+ Provides-Extra: dev
45
+ Requires-Dist: ewoksid27[test]; extra == "dev"
46
+ Requires-Dist: ruff; extra == "dev"
47
+ Provides-Extra: doc
48
+ Requires-Dist: ewoksid27[test]; extra == "doc"
49
+ Requires-Dist: sphinx>=4.5; extra == "doc"
50
+ Requires-Dist: sphinx-autodoc-typehints>=1.16; extra == "doc"
51
+ Requires-Dist: pydata-sphinx-theme; extra == "doc"
52
+ Requires-Dist: sphinx-copybutton; extra == "doc"
53
+ Requires-Dist: ewokssphinx>=2.0; extra == "doc"
54
+ Dynamic: license-file
55
+
56
+ # ewoksid27
57
+
58
+ Ewoks tasks and workflows for ID27 data processing.
59
+
60
+ ## Multigeometry integration
61
+
62
+ The packaged `src/ewoksid27/workflows/multigeometry.json` workflow runs:
63
+
64
+ `PrepareMultiGeometryImages → Integrate1DMultiGeometry → SaveNexusIntegrated`
65
+
66
+ The integration output also feeds `ewoksxrpd.tasks.ascii.SaveAsciiPattern1D`.
67
+ Set `save_ascii.filename` to the ASCII destination. It writes radial and intensity
68
+ columns, plus intensity errors when available, with units and integration settings
69
+ in the header.
70
+
71
+ Preparation averages the frames within each scan, flips vertically, multiplies
72
+ by an optional correction map, then sums repeated scans separately for each
73
+ geometry in float64. Each group corresponds to one detector y position. The
74
+ correction map is flipped as well; masks must already be in calibration
75
+ coordinates. Scan inputs may be 2D images or 3D `(frames, height, width)` stacks,
76
+ as arrays or data URLs. Set `flip_vertical=False` if images and correction maps already
77
+ match the calibration orientation.
78
+
79
+ ```python
80
+ from importlib.resources import files
81
+ from ewokscore import execute_graph
82
+
83
+ workflow = files("ewoksid27") / "workflows" / "multigeometry.json"
84
+ execute_graph(
85
+ str(workflow),
86
+ inputs=[
87
+ {
88
+ "id": "prepare",
89
+ "name": "image_groups",
90
+ "value": [
91
+ ["center1.h5::/image", "center2.h5::/image"],
92
+ ["border1.h5::/image", "border2.h5::/image"],
93
+ ],
94
+ },
95
+ {
96
+ "id": "prepare",
97
+ "name": "correction_map",
98
+ "value": "correction.npy",
99
+ },
100
+ {
101
+ "id": "integrate",
102
+ "name": "poni_files",
103
+ "value": ["center.poni", "border.poni"],
104
+ },
105
+ {
106
+ "id": "integrate",
107
+ "name": "masks",
108
+ "value": ["center.mask", "border.mask"],
109
+ },
110
+ {
111
+ "id": "integrate",
112
+ "name": "integration_options",
113
+ "value": {
114
+ "nbpt_rad": 500,
115
+ "unit": "q_A^-1",
116
+ "radial_range_min": 0.9,
117
+ "radial_range_max": 17.5,
118
+ "polarization_factor": 0.99,
119
+ },
120
+ },
121
+ {"id": "save", "name": "url", "value": "patterns.h5::/sample"},
122
+ {"id": "save_ascii", "name": "filename", "value": "patterns/sample.dat"},
123
+ ],
124
+ )
125
+ ```
126
+
127
+ Image groups, PONI files and masks use the same geometry order. The correction
128
+ map multiplies the signal, unlike a divisive flatfield. Exposure/monitor scaling
129
+ and uncertainty propagation through preparation are not inferred. Geometry
130
+ integration is sequential by default (`threadpoolsize=0`).
131
+
132
+ Blissoda should submit the workflow once all scans in a collection are complete.
133
+ Run the same workflow for backgrounds, saving to a separate entry. Background
134
+ subtraction can be added downstream; it is not part of this workflow.
135
+
136
+ ## Documentation
137
+
138
+ https://ewoksid27.readthedocs.io/
@@ -0,0 +1,83 @@
1
+ # ewoksid27
2
+
3
+ Ewoks tasks and workflows for ID27 data processing.
4
+
5
+ ## Multigeometry integration
6
+
7
+ The packaged `src/ewoksid27/workflows/multigeometry.json` workflow runs:
8
+
9
+ `PrepareMultiGeometryImages → Integrate1DMultiGeometry → SaveNexusIntegrated`
10
+
11
+ The integration output also feeds `ewoksxrpd.tasks.ascii.SaveAsciiPattern1D`.
12
+ Set `save_ascii.filename` to the ASCII destination. It writes radial and intensity
13
+ columns, plus intensity errors when available, with units and integration settings
14
+ in the header.
15
+
16
+ Preparation averages the frames within each scan, flips vertically, multiplies
17
+ by an optional correction map, then sums repeated scans separately for each
18
+ geometry in float64. Each group corresponds to one detector y position. The
19
+ correction map is flipped as well; masks must already be in calibration
20
+ coordinates. Scan inputs may be 2D images or 3D `(frames, height, width)` stacks,
21
+ as arrays or data URLs. Set `flip_vertical=False` if images and correction maps already
22
+ match the calibration orientation.
23
+
24
+ ```python
25
+ from importlib.resources import files
26
+ from ewokscore import execute_graph
27
+
28
+ workflow = files("ewoksid27") / "workflows" / "multigeometry.json"
29
+ execute_graph(
30
+ str(workflow),
31
+ inputs=[
32
+ {
33
+ "id": "prepare",
34
+ "name": "image_groups",
35
+ "value": [
36
+ ["center1.h5::/image", "center2.h5::/image"],
37
+ ["border1.h5::/image", "border2.h5::/image"],
38
+ ],
39
+ },
40
+ {
41
+ "id": "prepare",
42
+ "name": "correction_map",
43
+ "value": "correction.npy",
44
+ },
45
+ {
46
+ "id": "integrate",
47
+ "name": "poni_files",
48
+ "value": ["center.poni", "border.poni"],
49
+ },
50
+ {
51
+ "id": "integrate",
52
+ "name": "masks",
53
+ "value": ["center.mask", "border.mask"],
54
+ },
55
+ {
56
+ "id": "integrate",
57
+ "name": "integration_options",
58
+ "value": {
59
+ "nbpt_rad": 500,
60
+ "unit": "q_A^-1",
61
+ "radial_range_min": 0.9,
62
+ "radial_range_max": 17.5,
63
+ "polarization_factor": 0.99,
64
+ },
65
+ },
66
+ {"id": "save", "name": "url", "value": "patterns.h5::/sample"},
67
+ {"id": "save_ascii", "name": "filename", "value": "patterns/sample.dat"},
68
+ ],
69
+ )
70
+ ```
71
+
72
+ Image groups, PONI files and masks use the same geometry order. The correction
73
+ map multiplies the signal, unlike a divisive flatfield. Exposure/monitor scaling
74
+ and uncertainty propagation through preparation are not inferred. Geometry
75
+ integration is sequential by default (`threadpoolsize=0`).
76
+
77
+ Blissoda should submit the workflow once all scans in a collection are complete.
78
+ Run the same workflow for backgrounds, saving to a separate entry. Background
79
+ subtraction can be added downstream; it is not part of this workflow.
80
+
81
+ ## Documentation
82
+
83
+ https://ewoksid27.readthedocs.io/
@@ -0,0 +1,82 @@
1
+ [build-system]
2
+ requires = [
3
+ "setuptools>=61",
4
+ ]
5
+ build-backend = "setuptools.build_meta"
6
+
7
+ [project]
8
+ name = "ewoksid27"
9
+ version = "0.0.1-alpha"
10
+ keywords = [
11
+ "ewoks"
12
+ ]
13
+
14
+ authors = [{name = "ESRF", email = "dau-pydev@esrf.fr"}]
15
+ description = "An Ewoks project"
16
+ readme = {file = "README.md", content-type = "text/markdown"}
17
+ license = {file = "LICENSE.md"}
18
+ classifiers = [
19
+ "Intended Audience :: Science/Research",
20
+ "License :: OSI Approved :: MIT License",
21
+ "Programming Language :: Python :: 3",
22
+ ]
23
+ requires-python = ">=3.10"
24
+ dependencies = [
25
+ "ewokscore",
26
+ "ewoksxrpd",
27
+ "pydantic >=2",
28
+ ]
29
+
30
+ [project.urls]
31
+ Homepage = "https://gitlab.esrf.fr/workflow/ewoksapps/ewoksid27/"
32
+ Documentation = "https://ewoksid27.readthedocs.io/"
33
+ Repository = "https://gitlab.esrf.fr/workflow/ewoksapps/ewoksid27/"
34
+ Issues = "https://gitlab.esrf.fr/workflow/ewoksapps/ewoksid27/issues"
35
+ Changelog = "https://gitlab.esrf.fr/workflow/ewoksapps/ewoksid27/-/blob/main/CHANGELOG.md"
36
+
37
+ [project.optional-dependencies]
38
+ test = [
39
+ "pytest >=7",
40
+ ]
41
+ dev = [
42
+ "ewoksid27[test]",
43
+ "ruff",
44
+ ]
45
+ doc = [
46
+ "ewoksid27[test]",
47
+ "sphinx >=4.5",
48
+ "sphinx-autodoc-typehints >=1.16",
49
+ "pydata-sphinx-theme",
50
+ "sphinx-copybutton",
51
+ "ewokssphinx >=2.0"
52
+ ]
53
+
54
+ [tool.setuptools]
55
+ package-dir = {""= "src"}
56
+
57
+ [tool.setuptools.packages.find]
58
+ where = ["src"]
59
+ namespaces = false
60
+
61
+ [tool.setuptools.package-data]
62
+ "ewoksid27" = ["workflows/*.json"]
63
+ "ewoksid27.tests.data"= ["*/*"]
64
+
65
+ [project.entry-points."ewoks.tasks.class"]
66
+ "ewoksid27.tasks.*" = "ewoksid27"
67
+
68
+
69
+ [tool.coverage.run]
70
+ omit = [
71
+ "*/tests/*"
72
+ ]
73
+ [tool.ruff.lint]
74
+ select = ["E", "F", "I", "S"]
75
+ ignore = ["E203", "E501", "E701"]
76
+
77
+ [tool.ruff.lint.per-file-ignores]
78
+ # Ignore `S101` (assert used violations) in all test files
79
+ "*/test_*.py" = ["S101"]
80
+
81
+ [tool.ruff.lint.isort]
82
+ force-single-line = true
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
File without changes
File without changes
@@ -0,0 +1,92 @@
1
+ from pathlib import Path
2
+ from typing import Any
3
+ from typing import Dict
4
+ from typing import List
5
+ from typing import Optional
6
+ from typing import Union
7
+
8
+ import numpy
9
+ from ewokscore.model import BaseInputModel
10
+ from ewoksxrpd.tasks.data_access import TaskWithDataAccess
11
+ from ewoksxrpd.tasks.utils import integrate_utils
12
+ from ewoksxrpd.tasks.utils import pyfai_utils
13
+ from pydantic import Field
14
+ from pydantic import model_validator
15
+ from pyFAI.multi_geometry import MultiGeometry
16
+ from silx.io.url import DataUrl
17
+
18
+ ImageSource = Union[str, DataUrl, numpy.ndarray]
19
+
20
+
21
+ class Integrate1DMultiGeometryInputModel(BaseInputModel):
22
+ poni_files: List[Union[str, Path]] = Field(
23
+ min_length=1, description="PONI files in the same order as images"
24
+ )
25
+ images: List[ImageSource] = Field(
26
+ min_length=1, description="One prepared image per geometry"
27
+ )
28
+ masks: Optional[List[Optional[ImageSource]]] = Field(
29
+ default=None, description="Masks in calibration coordinates, in geometry order"
30
+ )
31
+ integration_options: Dict[str, Any] = Field(default_factory=dict)
32
+ threadpoolsize: int = Field(default=0, ge=0)
33
+
34
+ @model_validator(mode="after")
35
+ def validate_geometry_counts(self):
36
+ if len(self.images) != len(self.poni_files):
37
+ raise ValueError("Images and PONI files must have the same length")
38
+ if self.masks is not None and len(self.masks) != len(self.images):
39
+ raise ValueError("Masks must match images")
40
+ return self
41
+
42
+
43
+ class Integrate1DMultiGeometry(
44
+ TaskWithDataAccess,
45
+ input_names=["poni_files", "images"],
46
+ optional_input_names=["masks", "integration_options", "threadpoolsize"],
47
+ output_names=["info", "radial", "intensity", "intensity_error", "radial_units"],
48
+ ):
49
+ """Joint 1D integration of prepared images with ordered PONI calibrations.
50
+
51
+ Sum exposures and apply orientation/correction maps before calling this task.
52
+ Images, PONI files and masks must have identical geometry ordering.
53
+ """
54
+
55
+ def run(self):
56
+ inputs = Integrate1DMultiGeometryInputModel.model_validate(
57
+ self.get_input_values()
58
+ )
59
+ images = [self.get_image(image) for image in inputs.images]
60
+ if any(image.ndim != 2 for image in images):
61
+ raise ValueError("Each geometry requires one 2D image")
62
+ raw_options = dict(inputs.integration_options)
63
+ raw_options.setdefault("unit", "2th_deg")
64
+ geometry_options, options = (
65
+ pyfai_utils.split_multi_geom_and_integration_options(raw_options)
66
+ )
67
+ if "npt_rad" in options:
68
+ options["npt"] = options.pop("npt_rad")
69
+ if inputs.masks is not None:
70
+ masks = [
71
+ self.get_image(mask) if mask is not None else None
72
+ for mask in inputs.masks
73
+ ]
74
+ if any(
75
+ mask is not None and mask.shape != image.shape
76
+ for mask, image in zip(masks, images)
77
+ ):
78
+ raise ValueError("Mask shape must match its image")
79
+ options["lst_mask"] = masks
80
+ mg = MultiGeometry(
81
+ [str(path) for path in inputs.poni_files],
82
+ threadpoolsize=inputs.threadpoolsize,
83
+ **geometry_options,
84
+ )
85
+ result = mg.integrate1d(images, **options)
86
+ self.outputs.radial = result.radial
87
+ self.outputs.intensity = result.intensity
88
+ self.outputs.intensity_error = integrate_utils.get_intensity_error(result)
89
+ self.outputs.radial_units = result.unit.name
90
+ info = pyfai_utils.compile_integration_info(raw_options)
91
+ info["geometries"] = [pyfai_utils.ai_to_poni(ai) for ai in mg.ais]
92
+ self.outputs.info = info
@@ -0,0 +1,83 @@
1
+ from typing import List
2
+ from typing import Optional
3
+
4
+ import numpy
5
+ from ewokscore.model import BaseInputModel
6
+ from ewoksxrpd.tasks.data_access import TaskWithDataAccess
7
+ from pydantic import Field
8
+ from pydantic import model_validator
9
+
10
+ from .integrate1d_multi_geometry import ImageSource
11
+
12
+
13
+ class PrepareMultiGeometryInputModel(BaseInputModel):
14
+ image_groups: List[List[ImageSource]] = Field(
15
+ min_length=1,
16
+ description="Scan lists in geometry order; frames within each scan are averaged",
17
+ )
18
+ correction_map: Optional[ImageSource] = Field(
19
+ default=None,
20
+ description="Multiplicative correction map in raw image coordinates",
21
+ )
22
+ flip_vertical: bool = Field(
23
+ default=True,
24
+ description="Flip images and correction map for Dioptas calibration",
25
+ )
26
+
27
+ @model_validator(mode="after")
28
+ def validate_groups(self):
29
+ if any(not group for group in self.image_groups):
30
+ raise ValueError("Each geometry requires at least one exposure")
31
+ return self
32
+
33
+
34
+ class PrepareMultiGeometryImages(
35
+ TaskWithDataAccess,
36
+ input_names=["image_groups"],
37
+ optional_input_names=["correction_map", "flip_vertical"],
38
+ output_names=["images"],
39
+ ):
40
+ """Average scan frames, flip, correct, and sum scans per geometry.
41
+
42
+ Inputs are 2D images or (frames, height, width) scan stacks, as arrays or URLs.
43
+ Each scan stack is averaged over frames before correction and summation.
44
+ Averaging and summation use float64. Masks are not transformed.
45
+ Output images retain the input geometry order; no normalization is applied.
46
+ """
47
+
48
+ def run(self):
49
+ inputs = PrepareMultiGeometryInputModel.model_validate(self.get_input_values())
50
+ correction = None
51
+ if inputs.correction_map is not None:
52
+ correction = self._read_image(inputs.correction_map, inputs.flip_vertical)
53
+ images = []
54
+ for group in inputs.image_groups:
55
+ total = None
56
+ for source in group:
57
+ image = self._read_image(
58
+ source, inputs.flip_vertical, average_frames=True
59
+ )
60
+ if correction is not None:
61
+ if correction.shape != image.shape:
62
+ raise ValueError("Correction map shape must match each image")
63
+ image = image * correction
64
+ if total is None:
65
+ total = image.copy()
66
+ else:
67
+ if total.shape != image.shape:
68
+ raise ValueError(
69
+ "Exposures within a geometry must have the same shape"
70
+ )
71
+ total += image
72
+ images.append(total)
73
+ self.outputs.images = images
74
+
75
+ def _read_image(self, source, flip_vertical, average_frames=False):
76
+ image = numpy.asarray(self.get_image(source), dtype=numpy.float64)
77
+ if average_frames and image.ndim == 3:
78
+ if image.shape[0] == 0:
79
+ raise ValueError("Scan stack must contain at least one frame")
80
+ image = image.mean(axis=0, dtype=numpy.float64)
81
+ if image.ndim != 2:
82
+ raise ValueError("Expected a 2D image or, for scans, a 3D frame stack")
83
+ return image[::-1] if flip_vertical else image
File without changes
@@ -0,0 +1,181 @@
1
+ import json
2
+ from pathlib import Path
3
+
4
+ import h5py
5
+ import numpy
6
+ import pyFAI
7
+ import pytest
8
+ from ewokscore import execute_graph
9
+ from pyFAI.detectors import Detector
10
+ from pyFAI.multi_geometry import MultiGeometry
11
+
12
+ from ewoksid27.tasks.integrate1d_multi_geometry import Integrate1DMultiGeometry
13
+ from ewoksid27.tasks.prepare_multi_geometry import PrepareMultiGeometryImages
14
+
15
+
16
+ def test_prepare_images(tmp_path):
17
+ image = numpy.arange(400, dtype=numpy.uint16).reshape(20, 20)
18
+ correction = numpy.linspace(1, 2, 400).reshape(20, 20)
19
+ filename = tmp_path / "images.h5"
20
+ with h5py.File(filename, "w") as root:
21
+ root["image"] = image[numpy.newaxis]
22
+ task = PrepareMultiGeometryImages(
23
+ inputs={
24
+ "image_groups": [[f"{filename}::/image", image], [image]],
25
+ "correction_map": correction,
26
+ }
27
+ )
28
+ task.execute()
29
+ images = task.get_output_value("images")
30
+ numpy.testing.assert_allclose(images[0], 2 * image[::-1] * correction[::-1])
31
+ numpy.testing.assert_allclose(images[1], image[::-1] * correction[::-1])
32
+ assert images[0].dtype == numpy.float64
33
+ numpy.testing.assert_array_equal(image, numpy.arange(400).reshape(20, 20))
34
+
35
+
36
+ @pytest.mark.parametrize("flip_vertical", [False, True])
37
+ def test_average_scan_frames(tmp_path, flip_vertical):
38
+ # Unequal scan lengths distinguish per-scan averaging from pooling frames.
39
+ frames = numpy.arange(60, dtype=numpy.uint16).reshape(3, 4, 5)
40
+ other_frames = numpy.full((2, 4, 5), 60000, dtype=numpy.uint16)
41
+ correction = numpy.linspace(1, 2, 20).reshape(4, 5)
42
+ filename = tmp_path / "raw.h5"
43
+ with h5py.File(filename, "w") as root:
44
+ root["7.1/measurement/eiger"] = frames
45
+ task = PrepareMultiGeometryImages(
46
+ inputs={
47
+ "image_groups": [
48
+ [f"{filename}::/7.1/measurement/eiger", other_frames],
49
+ [frames],
50
+ ],
51
+ "correction_map": correction,
52
+ "flip_vertical": flip_vertical,
53
+ }
54
+ )
55
+ task.execute()
56
+ expected = frames.mean(axis=0, dtype=numpy.float64)
57
+ other = other_frames.mean(axis=0, dtype=numpy.float64)
58
+ if flip_vertical:
59
+ expected, other, correction = expected[::-1], other[::-1], correction[::-1]
60
+ images = task.get_output_value("images")
61
+ numpy.testing.assert_allclose(images[0], (expected + other) * correction)
62
+ numpy.testing.assert_allclose(images[1], expected * correction)
63
+ assert images[0].dtype == numpy.float64
64
+ numpy.testing.assert_array_equal(frames, numpy.arange(60).reshape(3, 4, 5))
65
+
66
+
67
+ @pytest.mark.parametrize(
68
+ "inputs",
69
+ [
70
+ {"image_groups": []},
71
+ {"image_groups": [[]]},
72
+ {"image_groups": [[numpy.ones((2, 2)), numpy.ones((3, 3))]]},
73
+ {"image_groups": [[numpy.ones((2, 2))]], "correction_map": numpy.ones((3, 3))},
74
+ {"image_groups": [[numpy.ones((2, 2, 2, 2))]]},
75
+ {"image_groups": [[numpy.empty((0, 2, 2))]]},
76
+ {
77
+ "image_groups": [[numpy.ones((2, 2))]],
78
+ "correction_map": numpy.ones((2, 2, 2)),
79
+ },
80
+ ],
81
+ )
82
+ def test_invalid_preparation(inputs):
83
+ with pytest.raises(RuntimeError):
84
+ PrepareMultiGeometryImages(inputs=inputs).execute()
85
+
86
+
87
+ def test_workflow(tmp_path):
88
+ paths = []
89
+ for index in range(2):
90
+ ai = pyFAI.load(
91
+ {
92
+ "dist": 0.1,
93
+ "poni1": 0.001,
94
+ "poni2": 0.001 + index * 0.001,
95
+ "wavelength": 1e-10,
96
+ "detector": Detector(pixel1=1e-4, pixel2=1e-4, max_shape=(20, 20)),
97
+ }
98
+ )
99
+ path = tmp_path / f"{index}.poni"
100
+ ai.save(str(path))
101
+ paths.append(str(path))
102
+ image = numpy.arange(400, dtype=numpy.uint16).reshape(20, 20)
103
+ correction = numpy.linspace(1, 2, 400).reshape(20, 20)
104
+ masks = [numpy.zeros((20, 20), dtype=bool), numpy.zeros((20, 20), dtype=bool)]
105
+ masks[1][:10] = True
106
+ source = tmp_path / "input.h5"
107
+ with h5py.File(source, "w") as root:
108
+ root["image"] = image
109
+ root["correction"] = correction
110
+ for index, mask in enumerate(masks):
111
+ root[f"mask{index}"] = mask
112
+ output = tmp_path / "patterns.h5"
113
+ ascii_output = tmp_path / "ascii" / "pattern.dat"
114
+ workflow = Path(__file__).resolve().parents[1] / "workflows" / "multigeometry.json"
115
+ result = execute_graph(
116
+ workflow,
117
+ inputs=[
118
+ {
119
+ "id": "prepare",
120
+ "name": "image_groups",
121
+ "value": [[f"{source}::/image", image], [image]],
122
+ },
123
+ {
124
+ "id": "prepare",
125
+ "name": "correction_map",
126
+ "value": f"{source}::/correction",
127
+ },
128
+ {"id": "integrate", "name": "poni_files", "value": paths},
129
+ {
130
+ "id": "integrate",
131
+ "name": "masks",
132
+ "value": [f"{source}::/mask0", f"{source}::/mask1"],
133
+ },
134
+ {
135
+ "id": "integrate",
136
+ "name": "integration_options",
137
+ "value": {
138
+ "nbpt_rad": 30,
139
+ "unit": "q_A^-1",
140
+ "radial_range_min": 0.01,
141
+ "radial_range_max": 0.2,
142
+ "polarization_factor": 0.99,
143
+ },
144
+ },
145
+ {"id": "save", "name": "url", "value": f"{output}::/sample"},
146
+ {"id": "save_ascii", "name": "filename", "value": str(ascii_output)},
147
+ ],
148
+ )
149
+ assert result["saved"]
150
+ corrected = image.astype(float)[::-1] * correction[::-1]
151
+ expected = MultiGeometry(
152
+ paths, unit="q_A^-1", radial_range=(0.01, 0.2), threadpoolsize=0
153
+ ).integrate1d(
154
+ [2 * corrected, corrected],
155
+ npt=30,
156
+ lst_mask=masks,
157
+ polarization_factor=0.99,
158
+ )
159
+ with h5py.File(output) as root:
160
+ data = root["sample/integrate/integrated"]
161
+ numpy.testing.assert_allclose(data["intensity"][()], expected.intensity)
162
+ numpy.testing.assert_allclose(data["q"][()], expected.radial)
163
+ assert data["q"].attrs["units"] == "A^-1"
164
+ config = json.loads(root["sample/integrate/configuration/data"][()])
165
+ assert len(config["geometries"]) == 2
166
+ ascii_data = numpy.loadtxt(ascii_output)
167
+ numpy.testing.assert_allclose(ascii_data[:, 0], expected.radial)
168
+ numpy.testing.assert_allclose(ascii_data[:, 1], expected.intensity)
169
+ assert ascii_data.shape == (30, 3)
170
+ assert numpy.isnan(ascii_data[:, 2]).all()
171
+ assert "xunits = q_A^-1" in ascii_output.read_text()
172
+
173
+
174
+ def test_invalid_geometry_counts():
175
+ with pytest.raises(RuntimeError, match="same length"):
176
+ Integrate1DMultiGeometry(
177
+ inputs={
178
+ "poni_files": ["center.poni", "border.poni"],
179
+ "images": [numpy.ones((20, 20))],
180
+ }
181
+ ).execute()
@@ -0,0 +1,103 @@
1
+ {
2
+ "directed": true,
3
+ "multigraph": false,
4
+ "graph": {
5
+ "id": "multigeometry.json",
6
+ "schema_version": "1.0"
7
+ },
8
+ "nodes": [
9
+ {
10
+ "id": "prepare",
11
+ "label": "Prepare images",
12
+ "task_type": "class",
13
+ "task_identifier": "ewoksid27.tasks.prepare_multi_geometry.PrepareMultiGeometryImages"
14
+ },
15
+ {
16
+ "id": "integrate",
17
+ "label": "Integrate geometries",
18
+ "task_type": "class",
19
+ "task_identifier": "ewoksid27.tasks.integrate1d_multi_geometry.Integrate1DMultiGeometry"
20
+ },
21
+ {
22
+ "id": "save",
23
+ "label": "Save integrated pattern",
24
+ "task_type": "class",
25
+ "task_identifier": "ewoksxrpd.tasks.nexus.SaveNexusIntegrated"
26
+ },
27
+ {
28
+ "id": "save_ascii",
29
+ "label": "Save ASCII pattern",
30
+ "task_type": "class",
31
+ "task_identifier": "ewoksxrpd.tasks.ascii.SaveAsciiPattern1D"
32
+ }
33
+ ],
34
+ "links": [
35
+ {
36
+ "source": "prepare",
37
+ "target": "integrate",
38
+ "data_mapping": [
39
+ {
40
+ "source_output": "images",
41
+ "target_input": "images"
42
+ }
43
+ ]
44
+ },
45
+ {
46
+ "source": "integrate",
47
+ "target": "save",
48
+ "data_mapping": [
49
+ {
50
+ "source_output": "info",
51
+ "target_input": "info"
52
+ },
53
+ {
54
+ "source_output": "radial",
55
+ "target_input": "radial"
56
+ },
57
+ {
58
+ "source_output": "intensity",
59
+ "target_input": "intensity"
60
+ },
61
+ {
62
+ "source_output": "intensity_error",
63
+ "target_input": "intensity_error"
64
+ },
65
+ {
66
+ "source_output": "radial_units",
67
+ "target_input": "radial_units"
68
+ }
69
+ ]
70
+ },
71
+ {
72
+ "source": "integrate",
73
+ "target": "save_ascii",
74
+ "data_mapping": [
75
+ {
76
+ "source_output": "radial",
77
+ "target_input": "x"
78
+ },
79
+ {
80
+ "source_output": "intensity",
81
+ "target_input": "y"
82
+ },
83
+ {
84
+ "source_output": "radial_units",
85
+ "target_input": "xunits"
86
+ },
87
+ {
88
+ "source_output": "intensity_error",
89
+ "target_input": "yerror"
90
+ },
91
+ {
92
+ "source_output": "info",
93
+ "target_input": "header"
94
+ }
95
+ ]
96
+ },
97
+ {
98
+ "source": "save",
99
+ "target": "save_ascii",
100
+ "data_mapping": []
101
+ }
102
+ ]
103
+ }
@@ -0,0 +1,138 @@
1
+ Metadata-Version: 2.4
2
+ Name: ewoksid27
3
+ Version: 0.0.1a0
4
+ Summary: An Ewoks project
5
+ Author-email: ESRF <dau-pydev@esrf.fr>
6
+ License: # MIT License
7
+
8
+ **Copyright (c) 2026 European Synchrotron Radiation Facility**
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
11
+ this software and associated documentation files (the "Software"), to deal in
12
+ the Software without restriction, including without limitation the rights to
13
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
14
+ the Software, and to permit persons to whom the Software is furnished to do so,
15
+ subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
22
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
23
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+
27
+ Project-URL: Homepage, https://gitlab.esrf.fr/workflow/ewoksapps/ewoksid27/
28
+ Project-URL: Documentation, https://ewoksid27.readthedocs.io/
29
+ Project-URL: Repository, https://gitlab.esrf.fr/workflow/ewoksapps/ewoksid27/
30
+ Project-URL: Issues, https://gitlab.esrf.fr/workflow/ewoksapps/ewoksid27/issues
31
+ Project-URL: Changelog, https://gitlab.esrf.fr/workflow/ewoksapps/ewoksid27/-/blob/main/CHANGELOG.md
32
+ Keywords: ewoks
33
+ Classifier: Intended Audience :: Science/Research
34
+ Classifier: License :: OSI Approved :: MIT License
35
+ Classifier: Programming Language :: Python :: 3
36
+ Requires-Python: >=3.10
37
+ Description-Content-Type: text/markdown
38
+ License-File: LICENSE.md
39
+ Requires-Dist: ewokscore
40
+ Requires-Dist: ewoksxrpd
41
+ Requires-Dist: pydantic>=2
42
+ Provides-Extra: test
43
+ Requires-Dist: pytest>=7; extra == "test"
44
+ Provides-Extra: dev
45
+ Requires-Dist: ewoksid27[test]; extra == "dev"
46
+ Requires-Dist: ruff; extra == "dev"
47
+ Provides-Extra: doc
48
+ Requires-Dist: ewoksid27[test]; extra == "doc"
49
+ Requires-Dist: sphinx>=4.5; extra == "doc"
50
+ Requires-Dist: sphinx-autodoc-typehints>=1.16; extra == "doc"
51
+ Requires-Dist: pydata-sphinx-theme; extra == "doc"
52
+ Requires-Dist: sphinx-copybutton; extra == "doc"
53
+ Requires-Dist: ewokssphinx>=2.0; extra == "doc"
54
+ Dynamic: license-file
55
+
56
+ # ewoksid27
57
+
58
+ Ewoks tasks and workflows for ID27 data processing.
59
+
60
+ ## Multigeometry integration
61
+
62
+ The packaged `src/ewoksid27/workflows/multigeometry.json` workflow runs:
63
+
64
+ `PrepareMultiGeometryImages → Integrate1DMultiGeometry → SaveNexusIntegrated`
65
+
66
+ The integration output also feeds `ewoksxrpd.tasks.ascii.SaveAsciiPattern1D`.
67
+ Set `save_ascii.filename` to the ASCII destination. It writes radial and intensity
68
+ columns, plus intensity errors when available, with units and integration settings
69
+ in the header.
70
+
71
+ Preparation averages the frames within each scan, flips vertically, multiplies
72
+ by an optional correction map, then sums repeated scans separately for each
73
+ geometry in float64. Each group corresponds to one detector y position. The
74
+ correction map is flipped as well; masks must already be in calibration
75
+ coordinates. Scan inputs may be 2D images or 3D `(frames, height, width)` stacks,
76
+ as arrays or data URLs. Set `flip_vertical=False` if images and correction maps already
77
+ match the calibration orientation.
78
+
79
+ ```python
80
+ from importlib.resources import files
81
+ from ewokscore import execute_graph
82
+
83
+ workflow = files("ewoksid27") / "workflows" / "multigeometry.json"
84
+ execute_graph(
85
+ str(workflow),
86
+ inputs=[
87
+ {
88
+ "id": "prepare",
89
+ "name": "image_groups",
90
+ "value": [
91
+ ["center1.h5::/image", "center2.h5::/image"],
92
+ ["border1.h5::/image", "border2.h5::/image"],
93
+ ],
94
+ },
95
+ {
96
+ "id": "prepare",
97
+ "name": "correction_map",
98
+ "value": "correction.npy",
99
+ },
100
+ {
101
+ "id": "integrate",
102
+ "name": "poni_files",
103
+ "value": ["center.poni", "border.poni"],
104
+ },
105
+ {
106
+ "id": "integrate",
107
+ "name": "masks",
108
+ "value": ["center.mask", "border.mask"],
109
+ },
110
+ {
111
+ "id": "integrate",
112
+ "name": "integration_options",
113
+ "value": {
114
+ "nbpt_rad": 500,
115
+ "unit": "q_A^-1",
116
+ "radial_range_min": 0.9,
117
+ "radial_range_max": 17.5,
118
+ "polarization_factor": 0.99,
119
+ },
120
+ },
121
+ {"id": "save", "name": "url", "value": "patterns.h5::/sample"},
122
+ {"id": "save_ascii", "name": "filename", "value": "patterns/sample.dat"},
123
+ ],
124
+ )
125
+ ```
126
+
127
+ Image groups, PONI files and masks use the same geometry order. The correction
128
+ map multiplies the signal, unlike a divisive flatfield. Exposure/monitor scaling
129
+ and uncertainty propagation through preparation are not inferred. Geometry
130
+ integration is sequential by default (`threadpoolsize=0`).
131
+
132
+ Blissoda should submit the workflow once all scans in a collection are complete.
133
+ Run the same workflow for backgrounds, saving to a separate entry. Background
134
+ subtraction can be added downstream; it is not part of this workflow.
135
+
136
+ ## Documentation
137
+
138
+ https://ewoksid27.readthedocs.io/
@@ -0,0 +1,16 @@
1
+ LICENSE.md
2
+ README.md
3
+ pyproject.toml
4
+ src/ewoksid27/__init__.py
5
+ src/ewoksid27.egg-info/PKG-INFO
6
+ src/ewoksid27.egg-info/SOURCES.txt
7
+ src/ewoksid27.egg-info/dependency_links.txt
8
+ src/ewoksid27.egg-info/entry_points.txt
9
+ src/ewoksid27.egg-info/requires.txt
10
+ src/ewoksid27.egg-info/top_level.txt
11
+ src/ewoksid27/tasks/__init__.py
12
+ src/ewoksid27/tasks/integrate1d_multi_geometry.py
13
+ src/ewoksid27/tasks/prepare_multi_geometry.py
14
+ src/ewoksid27/tests/__init__.py
15
+ src/ewoksid27/tests/test_multigeometry.py
16
+ src/ewoksid27/workflows/multigeometry.json
@@ -0,0 +1,2 @@
1
+ [ewoks.tasks.class]
2
+ ewoksid27.tasks.* = ewoksid27
@@ -0,0 +1,18 @@
1
+ ewokscore
2
+ ewoksxrpd
3
+ pydantic>=2
4
+
5
+ [dev]
6
+ ewoksid27[test]
7
+ ruff
8
+
9
+ [doc]
10
+ ewoksid27[test]
11
+ sphinx>=4.5
12
+ sphinx-autodoc-typehints>=1.16
13
+ pydata-sphinx-theme
14
+ sphinx-copybutton
15
+ ewokssphinx>=2.0
16
+
17
+ [test]
18
+ pytest>=7
@@ -0,0 +1 @@
1
+ ewoksid27