diff --git a/src/toolbox_scs/detectors/hrixs.py b/src/toolbox_scs/detectors/hrixs.py index 6f1c23d3e1d0e548dc58981524571402ccd97592..11d409c85578bac6d720e8174acffb8882967c54 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 b919e69409ff13d48b34ce0ec814f5f607de282b..5e49db20f5436d065d773641e396bc5306e4031e 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__":