Skip to content

Commit

Permalink
Support stacks of images
Browse files Browse the repository at this point in the history
  • Loading branch information
vasole committed Sep 26, 2023
1 parent 44c91f8 commit 95b9b04
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions PyMca5/PyMcaPlugins/NNMAStackPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ def calculate(self):
mcaIndex = stack.info.get('McaIndex')
shape = stack.data.shape
stack = None
if mcaIndex not in [-1, len(shape) - 1]:
raise IndexError("NNMA does not support stacks of images yet")
if mcaIndex not in [0, -1, len(shape) - 1]:
raise IndexError("NNMA only support stacks of images or spectra")
return
if self.configurationWidget is None:
self.configurationWidget = NNMAParametersDialog(None, regions=True)
Expand Down Expand Up @@ -225,9 +225,23 @@ def actualCalculation(self):
self._status.setText(text)

oldShape = stack.data.shape
result = function(stack, **ddict)
if stack.data.shape != oldShape:
stack.data.shape = oldShape
mcaIndex = stack.info.get('McaIndex')
if mcaIndex == 0:
# image stack. We need a copy
_logger.info("NNMAStackPlugin converting to stack of spectra")
data = numpy.zeros(oldShape[1:] + oldShape[0:1], dtype=numpy.float32)
data.shape = -1, oldShape[0]
for i in range(oldShape[0]):
tmpData = stack.data[i]
tmpData.shape = -1
data[:, i] = tmpData
data.shape = oldShape[1:] + oldShape[0:1]
result = function(data, **ddict)
data = None
else:
result = function(stack, **ddict)
if stack.data.shape != oldShape:
stack.data.shape = oldShape
return result

def threadFinished(self):
Expand Down

0 comments on commit 95b9b04

Please sign in to comment.