Skip to content
Snippets Groups Projects
Commit 919a4e77 authored by Johannes Niskanen's avatar Johannes Niskanen
Browse files

jhns_centroid'.

parent 4fed0c4a
No related branches found
No related tags found
2 merge requests!196Commented and changed centroid function.,!188P2866 updates
......@@ -392,60 +392,8 @@ class hRIXS:
self.CURVE_B, self.CURVE_A, *_ = args
return self.CURVE_A, self.CURVE_B
def centroid(self, data, bins=None, return_hits=False):
if bins is None:
bins = self.BINS
hit_x = []
hit_y = []
hits = []
ret = np.zeros((len(data["hRIXS_det"]), bins))
for image, r in zip(data["hRIXS_det"], ret):
use_image = image.to_numpy()
if self.USE_DARK_MASK:
use_image[self.dark_mask] = np.mean(use_image[self.MASK_AVG_Y,
self.MASK_AVG_X], (0, 1))
if self.USE_DARK:
use_image = use_image - self.dark_im_array_m
else:
if self.USE_DARK:
use_image = use_image - self.dark_im_array
c = centroid(
use_image[self.X_RANGE, self.Y_RANGE].T,
threshold=self.THRESHOLD,
std_threshold=self.STD_THRESHOLD,
curvature=(self.CURVE_A, self.CURVE_B))
if not len(c):
continue
rc = np.array(c)
if return_hits:
hit_x.append(rc[:, 0])
hit_y.append(rc[:, 1])
hits.append(rc)
hy, hx = np.histogram(
rc[:, 0], bins=bins,
range=(0, self.Y_RANGE.stop - self.Y_RANGE.start))
r[:] = hy
data = data.assign_coords(
energy=np.linspace(self.Y_RANGE.start, self.Y_RANGE.stop, bins)
* self.ENERGY_SLOPE + self.ENERGY_INTERCEPT)
#**********************************************
# If hits were requested, assign them to data
#**********************************************
if return_hits:
data = data.assign(hits=(("trainId"), hits),
xhits=(("trainId"), hit_x),
yhits=(("trainId"), hit_y))
#**********************************************
# Always assign the spectrum to data
#**********************************************
data = data.assign(spectrum=(("trainId", "energy"), ret))
return data
def centroid_jhns(self, data, bins=None, return_hits=False):
#*************************************************************
# Carry out hit finding on data and bin them in grid
# Allows for
......
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