Skip to content
Snippets Groups Projects
Commit 11218377 authored by Martin Teichmann's avatar Martin Teichmann
Browse files

using bincount instead of histogram for integration

this removes more code from the inner loop. It is more efficient,
but is it also more readable? Probably not.
parent 90631a58
1 merge request!231improve the integation code
......@@ -480,18 +480,17 @@ class hRIXS:
x = np.arange(images.shape[1])[:, None]
y = np.arange(images.shape[2])[None, :] - self.parabola(x)
quo, rem = divmod(y, 1)
quo = np.array([[[0]], [[1]]]) + quo
quo = np.array([[[0]], [[1]]]) + quo - margin
rem = rem * np.array([[[1]], [[-1]]]) + np.array([[[0]], [[1]]])
wrong = (quo < 0) | (quo >= bins - 2 * margin)
quo[wrong] = rem[wrong] = 0
quo = quo.astype(int).ravel()
for image, r in zip(images, ret):
if self.USE_DARK:
image = image - dark_image
r[:], _ = np.histogram(quo.ravel(), weights=(rem * image).ravel(),
bins=bins - 2 * margin,
range=(margin, bins - margin))
ret /= np.histogram(quo.ravel(), weights=rem.ravel(),
bins=bins - 2 * margin,
range=(margin, bins - margin))[0]
r[:] = np.bincount(quo, weights=(rem * image).ravel())
ret /= np.bincount(quo, weights=rem.ravel())
data.coords["energy"] = (
np.arange(self.Y_RANGE.start + margin, self.Y_RANGE.stop - margin)
* self.ENERGY_SLOPE + self.ENERGY_INTERCEPT)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment