Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions azint/azint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -287,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)

Expand Down