From aecdfe3d900cbdfc173cad9c514354c2b14d91e9 Mon Sep 17 00:00:00 2001 From: Maciej Jankowski Date: Sun, 21 Jul 2024 20:09:52 +0200 Subject: [PATCH 1/6] Fixes #2221: Patch for 4D data from lima2 processed by average --- src/pyFAI/average.py | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/pyFAI/average.py b/src/pyFAI/average.py index 8760f6f9c..eb1af85bf 100644 --- a/src/pyFAI/average.py +++ b/src/pyFAI/average.py @@ -559,10 +559,36 @@ def write_reduction(self, algorithm, data): filter_parameters = algorithm.get_parameters() for name, value in filter_parameters.items(): header[name] = str(value) - image = self._fabio_class.__class__(data=data, header=header) + if not self._dry_run: - image.write(file_name) - logger.info("Wrote %s", file_name) + ##### + import os + dim = len(data.shape) + + try: + image = self._fabio_class.__class__(data=data, header=header) + image.write(f"{file_name}") + logger.info("Wrote %s", file_name) + + except: + if dim == 3: + image = self._fabio_class.__class__(data=data[0], header=header) + if hasattr(image, 'append_frame'): + for i in range(1, data.shape[0]): + image.append_frame(data=data[i]) + image.write(f"{file_name}") + logger.info("Wrote %s", file_name) + + else: + base_name, ext = os.path.splitext(file_name) + image.write(f"{base_name}_channel_0{ext}") + logger.info("Wrote %s", file_name) + for i in range(1, data.shape[0]): + image = self._fabio_class.__class__(data=data[i], header=header) + file_name=f"{base_name}_channel_{i}{ext}" + image.write(file_name) + logger.info("Wrote %s", file_name) + ##### self._fabio_images[algorithm] = image def get_fabio_image(self, algorithm): From 986c95e7fa859d1dc60cd196b7cd7613e1b53e5f Mon Sep 17 00:00:00 2001 From: Maciej Jankowski Date: Sun, 21 Jul 2024 20:19:45 +0200 Subject: [PATCH 2/6] Fixes #2221: Patch for 4D data from lima2 processed by average --- src/pyFAI/average.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pyFAI/average.py b/src/pyFAI/average.py index eb1af85bf..0b021a72b 100644 --- a/src/pyFAI/average.py +++ b/src/pyFAI/average.py @@ -561,7 +561,7 @@ def write_reduction(self, algorithm, data): header[name] = str(value) if not self._dry_run: - ##### + import os dim = len(data.shape) @@ -588,7 +588,7 @@ def write_reduction(self, algorithm, data): file_name=f"{base_name}_channel_{i}{ext}" image.write(file_name) logger.info("Wrote %s", file_name) - ##### + self._fabio_images[algorithm] = image def get_fabio_image(self, algorithm): From c78627f0f760f88ac176d445216499856f2b64e5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 21 Jul 2024 18:55:38 +0000 Subject: [PATCH 3/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/pyFAI/average.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pyFAI/average.py b/src/pyFAI/average.py index 0b021a72b..8b5676dcd 100644 --- a/src/pyFAI/average.py +++ b/src/pyFAI/average.py @@ -561,11 +561,11 @@ def write_reduction(self, algorithm, data): header[name] = str(value) if not self._dry_run: - + import os dim = len(data.shape) - try: + try: image = self._fabio_class.__class__(data=data, header=header) image.write(f"{file_name}") logger.info("Wrote %s", file_name) @@ -578,17 +578,17 @@ def write_reduction(self, algorithm, data): image.append_frame(data=data[i]) image.write(f"{file_name}") logger.info("Wrote %s", file_name) - + else: base_name, ext = os.path.splitext(file_name) image.write(f"{base_name}_channel_0{ext}") logger.info("Wrote %s", file_name) for i in range(1, data.shape[0]): - image = self._fabio_class.__class__(data=data[i], header=header) + image = self._fabio_class.__class__(data=data[i], header=header) file_name=f"{base_name}_channel_{i}{ext}" image.write(file_name) logger.info("Wrote %s", file_name) - + self._fabio_images[algorithm] = image def get_fabio_image(self, algorithm): From b661e43668e46dcd1687a8bcc43d2a22c2aafa78 Mon Sep 17 00:00:00 2001 From: Maciej Jankowski Date: Sun, 21 Jul 2024 22:05:15 +0200 Subject: [PATCH 4/6] Fixes #2221: Small fix for dry run --- src/pyFAI/average.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pyFAI/average.py b/src/pyFAI/average.py index 0b021a72b..a2a8f25eb 100644 --- a/src/pyFAI/average.py +++ b/src/pyFAI/average.py @@ -589,6 +589,8 @@ def write_reduction(self, algorithm, data): image.write(file_name) logger.info("Wrote %s", file_name) + if self._dry_run: + image = self._fabio_class.__class__(data=data, header=header) self._fabio_images[algorithm] = image def get_fabio_image(self, algorithm): From f4d3e5f57139d8d7593bcaf3024c1b622377f3e5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 21 Jul 2024 20:08:39 +0000 Subject: [PATCH 5/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/pyFAI/average.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pyFAI/average.py b/src/pyFAI/average.py index 156326f92..e44a2217c 100644 --- a/src/pyFAI/average.py +++ b/src/pyFAI/average.py @@ -588,7 +588,7 @@ def write_reduction(self, algorithm, data): file_name=f"{base_name}_channel_{i}{ext}" image.write(file_name) logger.info("Wrote %s", file_name) - + if self._dry_run: image = self._fabio_class.__class__(data=data, header=header) self._fabio_images[algorithm] = image From c037dbc2efe26aefa9c225f8b4c36d5513735c7f Mon Sep 17 00:00:00 2001 From: Maciej Jankowski Date: Sun, 21 Jul 2024 22:22:47 +0200 Subject: [PATCH 6/6] Fixes #2221: Small change --- src/pyFAI/average.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pyFAI/average.py b/src/pyFAI/average.py index e44a2217c..abc42506b 100644 --- a/src/pyFAI/average.py +++ b/src/pyFAI/average.py @@ -36,6 +36,7 @@ import numpy import fabio import weakref +import os from scipy import ndimage from scipy.interpolate import interp1d from scipy.optimize import fmin @@ -561,8 +562,6 @@ def write_reduction(self, algorithm, data): header[name] = str(value) if not self._dry_run: - - import os dim = len(data.shape) try: