From 90631a583285d021310fb3fe5478d80ac1ae7895 Mon Sep 17 00:00:00 2001 From: Martin Teichmann <martin.teichmann@xfel.eu> Date: Tue, 13 Dec 2022 15:23:55 +0100 Subject: [PATCH] brutal simplification of integration --- src/toolbox_scs/detectors/hrixs.py | 22 ++++++++++++---------- src/toolbox_scs/test/test_hrixs.py | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/toolbox_scs/detectors/hrixs.py b/src/toolbox_scs/detectors/hrixs.py index 6f1c23d..11d409c 100644 --- a/src/toolbox_scs/detectors/hrixs.py +++ b/src/toolbox_scs/detectors/hrixs.py @@ -476,20 +476,22 @@ class hRIXS: if self.USE_DARK: dark_image = self.dark_image[self.X_RANGE, self.Y_RANGE] images = data["hRIXS_det"].values[:, self.X_RANGE, self.Y_RANGE] + x = np.arange(images.shape[1])[:, None] - energy = np.arange(images.shape[2])[None, :] - self.parabola(x) - floor, left = divmod(energy, 1) - right = 1 - left - def histo(weight): - return np.histogram(floor.ravel(), weights=weight.ravel(), - bins=bins, range=(0, bins))[0] + y = np.arange(images.shape[2])[None, :] - self.parabola(x) + quo, rem = divmod(y, 1) + quo = np.array([[[0]], [[1]]]) + quo + rem = rem * np.array([[[1]], [[-1]]]) + np.array([[[0]], [[1]]]) + for image, r in zip(images, ret): if self.USE_DARK: image = image - dark_image - r[:] = histo(left * image)[margin:-margin] - r[:] += histo(right * image)[margin-1 : -margin-1] - ret /= histo(left)[margin:-margin] \ - + histo(right)[margin-1 : -margin-1] + 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] data.coords["energy"] = ( np.arange(self.Y_RANGE.start + margin, self.Y_RANGE.stop - margin) * self.ENERGY_SLOPE + self.ENERGY_INTERCEPT) diff --git a/src/toolbox_scs/test/test_hrixs.py b/src/toolbox_scs/test/test_hrixs.py index b919e69..5e49db2 100644 --- a/src/toolbox_scs/test/test_hrixs.py +++ b/src/toolbox_scs/test/test_hrixs.py @@ -19,7 +19,7 @@ class TestHRIXS(unittest.TestCase): r = h.integrate(data) self.assertIs(r, data) self.assertEqual(data['spectrum'][1, 50].values[()], - 28517.704705882352) + 28517.704705882363) self.assertEqual(data['spectrum'][1, 50].coords['energy'], 90) if __name__ == "__main__": -- GitLab