diff --git a/src/toolbox_scs/detectors/hrixs.py b/src/toolbox_scs/detectors/hrixs.py index cb8c8f27920dd5c769de70331c57eeae1cb8c44d..c143833a0954cc8eee03d49625c67ba73dc4f987 100644 --- a/src/toolbox_scs/detectors/hrixs.py +++ b/src/toolbox_scs/detectors/hrixs.py @@ -250,24 +250,6 @@ def parabola(x, a, b, c=0): return (a * x + b) * x + c -def integrate(image, factor=FACTOR, range=RANGE, curvature=(CURVE_A, CURVE_B)): - x = np.arange(image.shape[1])[None, :] - y = np.arange(image.shape[0])[:, None] - ys = factor * (y - parabola(x, curvature[1], curvature[0])) - ysf = np.floor(ys) - rang = (factor * range[0], factor * range[1]) - bins = rang[1] - rang[0] - lhy, lhx = np.histogram(ysf.ravel(), bins=bins, range=rang, - weights=((ys - ysf) * image).ravel()) - rhy, rhx = np.histogram((ysf + 1).ravel(), bins=bins, range=rang, - weights=(((ysf + 1) - ys) * image).ravel()) - lvy, lvx = np.histogram(ysf.ravel(), bins=bins, range=rang, - weights=(ys - ysf).ravel()) - rvy, rvx = np.histogram((ysf + 1).ravel(), bins=bins, range=rang, - weights=((ysf + 1) - ys).ravel()) - return (lhy + rhy) / (lvy + rvy) - - class hRIXS: """The hRIXS analysis, especially curvature correction @@ -489,14 +471,26 @@ class hRIXS: data = h.integrate(data) # create spectrum by summing pixels data.spectrum[0, :].plot() # plot the spectrum of the first image """ - bins = self.Y_RANGE.stop - self.Y_RANGE.start - ret = np.zeros((len(data["hRIXS_det"]), bins - 20)) + bins = self.Y_RANGE.stop - self.Y_RANGE.start - 20 + ret = np.zeros((len(data["hRIXS_det"]), bins)) for image, r in zip(data["hRIXS_det"], ret): if self.USE_DARK: image = image - self.dark_image - r[:] = integrate(image.values[self.X_RANGE, self.Y_RANGE].T, - factor=1, range=(10, bins - 10), - curvature=(self.CURVE_A, self.CURVE_B)) + image = image.values[self.X_RANGE, self.Y_RANGE].T + x = np.arange(image.shape[1])[None, :] + y = np.arange(image.shape[0])[:, None] + ys = (y - parabola(x, self.CURVE_B, self.CURVE_A)) + ysf = np.floor(ys) + rang = (10, bins + 10) + lhy, lhx = np.histogram(ysf.ravel(), bins=bins, range=rang, + weights=((ys - ysf) * image).ravel()) + rhy, rhx = np.histogram((ysf + 1).ravel(), bins=bins, range=rang, + weights=(((ysf + 1) - ys) * image).ravel()) + lvy, lvx = np.histogram(ysf.ravel(), bins=bins, range=rang, + weights=(ys - ysf).ravel()) + rvy, rvx = np.histogram((ysf + 1).ravel(), bins=bins, range=rang, + weights=((ysf + 1) - ys).ravel()) + r[:] = (lhy + rhy) / (lvy + rvy) data = data.assign_coords( energy=np.arange(self.Y_RANGE.start + 10, self.Y_RANGE.stop - 10) * self.ENERGY_SLOPE + self.ENERGY_INTERCEPT)