Skip to content

Commit

Permalink
Use same API as cython
Browse files Browse the repository at this point in the history
  • Loading branch information
kif committed Nov 18, 2024
1 parent ab311d3 commit 5f61cf8
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/pyFAI/engines/CSR_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
__contact__ = "[email protected]"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__date__ = "14/11/2024"
__date__ = "18/11/2024"
__status__ = "development"

from collections.abc import Iterable
Expand Down Expand Up @@ -395,7 +395,9 @@ def medfilt(self, data, dark=None, dummy=None, delta_dummy=None,
variance=None, dark_variance=None,
flat=None, solidangle=None, polarization=None, absorption=None,
safe=True, error_model=None,
normalization_factor=1.0, quantile=0.5
normalization_factor=1.0,
quant_min=0.5,
quant_max=0.5,
):
"""
Perform a median-filter/quantile mean in azimuthal space.
Expand Down Expand Up @@ -425,17 +427,12 @@ def medfilt(self, data, dark=None, dummy=None, delta_dummy=None,
:param safe: Unused in this implementation
:param error_model: Enum or str, "azimuthal" or "poisson"
:param normalization_factor: divide raw signal by this value
:param quantile: which percentile/100 use for cutting out quantil.
can be a 2-tuple to specify a region to average out.
By default, takes the median
:param quant_min: start percentile/100 to use. Use 0.5 for the median (default). 0<=quant_min<=1
:param quant_max: stop percentile/100 to use. Use 0.5 for the median (default). 0<=quant_max<=1
:return: namedtuple with "position intensity error signal variance normalization count"
"""
if isinstance(quantile, Iterable):
q_start = min(quantile)
q_stop = max(quantile)
else:
q_stop = q_start = quantile

indptr = self._csr.indptr
indices = self._csr.indices
Expand Down Expand Up @@ -484,7 +481,7 @@ def medfilt(self, data, dark=None, dummy=None, delta_dummy=None,
upper = numpy.cumsum(tmp["norm"])
last = upper[-1]
lower = numpy.concatenate(([0],upper[:-1]))
mask = numpy.logical_and(upper>=q_start*last, lower<=q_stop*last)
mask = numpy.logical_and(upper>=quant_min*last, lower<=quant_max*last)
tmp = tmp[mask]
cnt[i] = tmp.size
signal[i] = tmp["sig"].sum(dtype=numpy.float64)
Expand Down

0 comments on commit 5f61cf8

Please sign in to comment.