mirror of https://github.com/silx-kit/pyFAI.git
Port new masking to Cython, 2D as well
This commit is contained in:
parent
3cf889159a
commit
4bb8a0884e
|
@ -585,21 +585,21 @@ class AzimuthalIntegrator(Geometry):
|
|||
return self.xrpd2_histogram(data=data, nbPt2Th=nbPt2Th, nbPtChi=nbPtChi,
|
||||
filename=filename, correctSolidAngle=correctSolidAngle,
|
||||
tthRange=tthRange, chiRange=chiRange, mask=mask, dummy=dummy, delta_dummy=delta_dummy)
|
||||
mask = self.makeMask(data, mask, dummy, delta_dummy)
|
||||
tth = self.twoThetaArray(data.shape)[mask]
|
||||
chi = self.chiArray(data.shape)[mask]
|
||||
dtth = self.delta2Theta(data.shape)[mask]
|
||||
dchi = self.deltaChi(data.shape)[mask]
|
||||
# mask = self.makeMask(data, mask, dummy, delta_dummy)
|
||||
tth = self.twoThetaArray(data.shape)#[mask]
|
||||
chi = self.chiArray(data.shape)#[mask]
|
||||
dtth = self.delta2Theta(data.shape)#[mask]
|
||||
dchi = self.deltaChi(data.shape)#[mask]
|
||||
if tthRange is not None:
|
||||
tthRange = tuple([numpy.deg2rad(i) for i in tthRange])
|
||||
if chiRange is not None:
|
||||
chiRange = tuple([numpy.deg2rad(i) for i in chiRange])
|
||||
if correctSolidAngle:
|
||||
data = (data / self.solidAngleArray(data.shape))[mask]
|
||||
data = (data / self.solidAngleArray(data.shape))#[mask]
|
||||
else:
|
||||
data = data[mask]
|
||||
if dummy is None:
|
||||
dummy = 0.0
|
||||
data = data#[mask]
|
||||
# if dummy is None:
|
||||
# dummy = 0.0
|
||||
I, bins2Th, binsChi, a, b = splitBBox.histoBBox2d(weights=data,
|
||||
pos0=tth,
|
||||
delta_pos0=dtth,
|
||||
|
@ -608,7 +608,9 @@ class AzimuthalIntegrator(Geometry):
|
|||
bins=(nbPt2Th, nbPtChi),
|
||||
pos0Range=tthRange,
|
||||
pos1Range=chiRange,
|
||||
dummy=dummy)
|
||||
dummy=dummy,
|
||||
delta_dummy=delta_dummy,
|
||||
mask=mask)
|
||||
bins2Th = numpy.degrees(bins2Th)
|
||||
binsChi = numpy.degrees(binsChi)
|
||||
if filename:
|
||||
|
|
2604
src/splitBBox.c
2604
src/splitBBox.c
File diff suppressed because it is too large
Load Diff
3758
src/splitBBox.html
3758
src/splitBBox.html
File diff suppressed because it is too large
Load Diff
|
@ -72,7 +72,9 @@ def histoBBox1d(numpy.ndarray weights not None,
|
|||
@param bins: number of output bins
|
||||
@param pos0Range: minimum and maximum of the 2th range
|
||||
@param pos1Range: minimum and maximum of the chi range
|
||||
@param dummy: value for bins without pixels
|
||||
@param dummy: value for bins without pixels & value of "no good" pixels
|
||||
@param delta_dummy: precision of dummy value
|
||||
@param mask: array (of int8) with masked pixels with 1 (0=not masked)
|
||||
@return 2theta, I, weighted histogram, unweighted histogram
|
||||
"""
|
||||
cdef long size = weights.size
|
||||
|
@ -82,7 +84,7 @@ def histoBBox1d(numpy.ndarray weights not None,
|
|||
cdef long bin0_max, bin0_min, bin = 0
|
||||
cdef float data, deltaR, deltaL, deltaA,p1, epsilon = 1e-10, cdummy, ddummy
|
||||
cdef float pos0_min, pos0_max, pos0_maxin, pos1_min, pos1_max, pos1_maxin, min0, max0, fbin0_min, fbin0_max
|
||||
cdef long checkpos1 = 0, check_mask = 0, check_dummy = 0
|
||||
cdef int checkpos1 = 0, check_mask = 0, check_dummy = 0
|
||||
|
||||
cdef numpy.ndarray[numpy.float32_t, ndim = 1] cdata = numpy.ascontiguousarray(weights.ravel(),dtype=numpy.float32)
|
||||
cdef numpy.ndarray[numpy.float32_t, ndim = 1] cpos0, dpos0, cpos1, dpos1,cpos0_lower, cpos0_upper
|
||||
|
@ -150,11 +152,11 @@ def histoBBox1d(numpy.ndarray weights not None,
|
|||
outPos[i] = pos0_min + (0.5 +< float > i) * delta
|
||||
|
||||
for idx in range(size):
|
||||
if (check_mask) and cmask[idx]:
|
||||
if (check_mask) and (cmask[idx]):
|
||||
continue
|
||||
|
||||
data = cdata[idx]
|
||||
if check_dummy and fabs(data-cdummy)<ddummy:
|
||||
if check_dummy and (fabs(data-cdummy)<=ddummy):
|
||||
continue
|
||||
|
||||
min0 = cpos0_lower[idx]
|
||||
|
@ -220,7 +222,9 @@ def histoBBox2d(numpy.ndarray weights not None,
|
|||
bins=(100, 36),
|
||||
pos0Range=None,
|
||||
pos1Range=None,
|
||||
float dummy=0.0):
|
||||
dummy=None,
|
||||
delta_dummy=None,
|
||||
mask=None):
|
||||
"""
|
||||
Calculate 2D histogram of pos0(tth),pos1(chi) weighted by weights
|
||||
|
||||
|
@ -235,8 +239,9 @@ def histoBBox2d(numpy.ndarray weights not None,
|
|||
@param bins: number of output bins (tth=100, chi=36 by default)
|
||||
@param pos0Range: minimum and maximum of the 2th range
|
||||
@param pos1Range: minimum and maximum of the chi range
|
||||
@param dummy: value for bins without pixels
|
||||
@return 2theta, I, weighted histogram, unweighted histogram
|
||||
@param dummy: value for bins without pixels & value of "no good" pixels
|
||||
@param delta_dummy: precision of dummy value
|
||||
@param mask: array (of int8) with masked pixels with 1 (0=not masked)
|
||||
@return I, edges0, edges1, weighted histogram(2D), unweighted histogram (2D)
|
||||
"""
|
||||
|
||||
|
@ -269,8 +274,25 @@ def histoBBox2d(numpy.ndarray weights not None,
|
|||
|
||||
cdef float min0, max0, min1, max1, deltaR, deltaL, deltaU, deltaD, deltaA, tmp, delta0, delta1
|
||||
cdef float pos0_min, pos0_max, pos1_min, pos1_max, pos0_maxin, pos1_maxin
|
||||
cdef float fbin0_min, fbin0_max, fbin1_min, fbin1_max, data, epsilon = 1e-10
|
||||
cdef float fbin0_min, fbin0_max, fbin1_min, fbin1_max, data, epsilon = 1e-10, cdummy, ddummy
|
||||
cdef long bin0_max, bin0_min, bin1_max, bin1_min
|
||||
cdef int check_mask = 0, check_dummy = 0
|
||||
cdef numpy.ndarray[numpy.int8_t, ndim = 1] cmask
|
||||
|
||||
if mask is not None:
|
||||
assert mask.size == size
|
||||
check_mask = 1
|
||||
cmask = numpy.ascontiguousarray(mask.ravel(),dtype="int8")
|
||||
|
||||
if (dummy is not None) and delta_dummy is not None:
|
||||
check_dummy = 1
|
||||
cdummy = float(dummy)
|
||||
ddummy = float(delta_dummy)
|
||||
elif (dummy is not None):
|
||||
cdummy = float(dummy)
|
||||
else:
|
||||
cdummy=0.0
|
||||
|
||||
|
||||
pos0_min=cpos0[0]
|
||||
pos0_max=cpos0[0]
|
||||
|
@ -313,6 +335,14 @@ def histoBBox2d(numpy.ndarray weights not None,
|
|||
edges1[i] = pos1_min + (0.5 + i) * delta1
|
||||
|
||||
for idx in range(size):
|
||||
|
||||
if (check_mask) and cmask[idx]:
|
||||
continue
|
||||
|
||||
data = cdata[idx]
|
||||
if (check_dummy) and (fabs(data-cdummy)<=ddummy):
|
||||
continue
|
||||
|
||||
data = cdata[idx]
|
||||
min0 = cpos0_lower[idx]
|
||||
max0 = cpos0_upper[idx]
|
||||
|
@ -415,6 +445,6 @@ def histoBBox2d(numpy.ndarray weights not None,
|
|||
if outCount[i, j] > epsilon:
|
||||
outMerge[i, j] = <float> (outData[i, j] / outCount[i, j])
|
||||
else:
|
||||
outMerge[i, j] = dummy
|
||||
outMerge[i, j] = cdummy
|
||||
return outMerge.T, edges0, edges1, outData.T, outCount.T
|
||||
|
||||
|
|
Loading…
Reference in New Issue