Skip to content

Commit

Permalink
Undefined variables in SNIPModule methods
Browse files Browse the repository at this point in the history
  • Loading branch information
woutdenolf committed May 26, 2021
1 parent a955132 commit 5b3b7d5
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions PyMca5/PyMcaMath/SNIPModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ def getSpectrumBackground(spectrum, width, roi_min=None, roi_max=None, smoothing
getSnip1DBackground = getSpectrumBackground

def subtractSnip1DBackgroundFromStack(stack, width, roi_min=None, roi_max=None, smoothing=1):
if roi_min is None:
roi_min = 0
if roi_max is None:
roi_max = len(spectrum)
mcaIndex = -1
if hasattr(stack, "info") and hasattr(stack, "data"):
data = stack.data
Expand All @@ -61,6 +57,12 @@ def subtractSnip1DBackgroundFromStack(stack, width, roi_min=None, roi_max=None,
data = stack
if not isinstance(data, numpy.ndarray):
raise TypeError("This Plugin only supports numpy arrays")

if roi_min is None:
roi_min = 0
if roi_max is None:
roi_max = data.shape[mcaIndex]

oldShape = data.shape
if mcaIndex in [-1, len(data.shape)-1]:
data.shape = -1, oldShape[-1]
Expand All @@ -84,10 +86,6 @@ def subtractSnip1DBackgroundFromStack(stack, width, roi_min=None, roi_max=None,
return

def replaceStackWithSnip1DBackground(stack, width, roi_min=None, roi_max=None, smoothing=1):
if roi_min is None:
roi_min = 0
if roi_max is None:
roi_max = len(spectrum)
mcaIndex = -1
if hasattr(stack, "info") and hasattr(stack, "data"):
data = stack.data
Expand All @@ -96,6 +94,12 @@ def replaceStackWithSnip1DBackground(stack, width, roi_min=None, roi_max=None,
data = stack
if not isinstance(data, numpy.ndarray):
raise TypeError("This Plugin only supports numpy arrays")

if roi_min is None:
roi_min = 0
if roi_max is None:
roi_max = data.shape[mcaIndex]

oldShape = data.shape
if mcaIndex in [-1, len(data.shape)-1]:
data.shape = -1, oldShape[-1]
Expand Down Expand Up @@ -137,10 +141,6 @@ def subtractSnip2DBackgroundFromStack(stack, width, roi_min=None, roi_max=None,
"""
index is the dimension used to index the images
"""
if roi_min is None:
roi_min = (0, 0)
if roi_max is None:
roi_max = image.shape
if hasattr(stack, "info") and hasattr(stack, "data"):
data = stack.data
if index is None:
Expand All @@ -151,6 +151,12 @@ def subtractSnip2DBackgroundFromStack(stack, width, roi_min=None, roi_max=None,
index = 2
if not isinstance(data, numpy.ndarray):
raise TypeError("This Plugin only supports numpy arrays")

if roi_min is None:
roi_min = (0, 0)
if roi_max is None:
roi_max = tuple(data.shape[i] for i in range(3) if i != index)

shape = data.shape
if index == 0:
if (roi_min[0] > 0) or (roi_min[1] > 0):
Expand Down

0 comments on commit 5b3b7d5

Please sign in to comment.