Skip to content

Commit

Permalink
Merge pull request #2239 from mjdiff/4d_aver
Browse files Browse the repository at this point in the history
This pull request addresses issue #2221
  • Loading branch information
kif authored Aug 19, 2024
2 parents 3cda1c9 + c037dbc commit 8ab8769
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions src/pyFAI/average.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -559,10 +560,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)
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)

if self._dry_run:
image = self._fabio_class.__class__(data=data, header=header)
self._fabio_images[algorithm] = image

def get_fabio_image(self, algorithm):
Expand Down

0 comments on commit 8ab8769

Please sign in to comment.