From 91f7796693a2879987281a367c1d85cae0ef966a Mon Sep 17 00:00:00 2001 From: Meghdad Yazdi Date: Fri, 9 Jan 2026 15:23:00 +0000 Subject: [PATCH 1/2] add dinamic maks for integration --- azint/azint.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/azint/azint.py b/azint/azint.py index f784e2f..b9d49b4 100644 --- a/azint/azint.py +++ b/azint/azint.py @@ -247,7 +247,9 @@ def __init__(self, def integrate(self, - img: np.ndarray) -> tuple[np.ndarray, np.ndarray]: + img: np.ndarray, + mask=None) -> tuple[np.ndarray, np.ndarray] \ + | tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]: """ Performs azimuthal integration on the input image. @@ -257,6 +259,7 @@ def integrate(self, Args: img (ndarray): Input image to be integrated. Must match expected input size. + mask (ndarray or str, optional): Mask array or path to mask file. Pixels marked with 1 will be excluded from the integration. Returns: tuple: @@ -272,6 +275,22 @@ def integrate(self, if img.size != self.input_size: raise RuntimeError('Size of image is wrong!\nExpected %d\nActual size %d' %(self.input_size, img.size)) + + if mask is not None: + if not isinstance(mask, np.ndarray): + if mask is not None: + if mask == '': + mask = None + else: + fname = mask + self.mask_path = fname + ending = os.path.splitext(fname)[1] + if ending == '.npy': + mask = np.load(fname) + else: + mask = fabio.open(fname).data + self.mask = mask + if self.mask is None: norm = self.norm else: From e08112f804ae4bd479df3de992ff69b3bbb8cbfa Mon Sep 17 00:00:00 2001 From: Meghdad Yazdi Date: Fri, 9 Jan 2026 15:23:59 +0000 Subject: [PATCH 2/2] fix "RuntimeWarning: invalid value encountered in sqrt" issue #11 --- azint/azint.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/azint/azint.py b/azint/azint.py index b9d49b4..713d788 100644 --- a/azint/azint.py +++ b/azint/azint.py @@ -306,7 +306,8 @@ def integrate(self, errors_2d = None if self.error_model: # poisson error model - errors = np.sqrt(self.sparse_matrix.spmv_corrected2(img)).reshape(self.output_shape) + sparse = np.clip(self.sparse_matrix.spmv_corrected2(img), a_min=0, a_max=None) + errors = np.sqrt(sparse).reshape(self.output_shape) if self.normalized: errors = np.divide(errors, norm, out=np.zeros_like(errors), where=norm!=0.0)