Skip to content

Commit 55c5238

Browse files
authored
Merge pull request #2721 from EdgarGF93/missingwedge_new_threshold
method missing wedge percentile
2 parents 1a0dd84 + 93b19bb commit 55c5238

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/pyFAI/integrator/fiber.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,15 @@ def integrate2d_fiber(self, data,
445445

446446
empty = self._empty
447447
if use_missing_wedge:
448-
missing_wedge_mask = get_missing_wedge_mask(res2d, threshold_bins=kwargs.get("missing_wedge_threshold_bins", None))
448+
# Mask by percentile or by threshold bins
449+
missing_wedge_percentile = kwargs.get("missing_wedge_percentile")
450+
if missing_wedge_percentile:
451+
missing_wedge_mask = get_missing_wedge_mask_by_percentile(result=res2d, percentile=missing_wedge_percentile)
452+
else:
453+
missing_wedge_mask = get_missing_wedge_mask(res2d, threshold_bins=kwargs.get("missing_wedge_threshold_bins", None))
449454
intensity[missing_wedge_mask] = empty
450455
sum_signal[missing_wedge_mask] = empty
456+
sum_normalization[missing_wedge_mask] = empty
451457
count[missing_wedge_mask] = 0
452458
sum_normalization[missing_wedge_mask] = empty
453459
if sum_normalization2 is not None:
@@ -593,3 +599,11 @@ def get_missing_wedge_threshold(intensity:numpy.ndarray, threshold_bins=None) ->
593599
threshold_bins = threshold_bins or max(intensity.shape)
594600
counts, bin = numpy.histogram(intensity.ravel(), bins=threshold_bins)
595601
return bin[counts.argmax()] / 2
602+
603+
def get_missing_wedge_mask_by_percentile(result: Integrate2dFiberResult, percentile=20) -> numpy.ndarray:
604+
"""Calculate a mask for the missing wedge based on the percentage of bins of result.count array falling into the missing wedge.
605+
606+
:param result: Integrate2DFiberResult, the return of a FiberIntegrator.integrate2d_grazing_incidence
607+
:param percentile: float (0 -> 100), upper limit of bins to filter out of the result.count array
608+
"""
609+
return result.count < numpy.percentile(result.count, percentile)

0 commit comments

Comments
 (0)