From ed801319cf7aaa16e3125cd24c0d1a6860f22c70 Mon Sep 17 00:00:00 2001 From: acorrao <95718914+AdamCorrao@users.noreply.github.com> Date: Fri, 12 Apr 2024 12:03:26 -0400 Subject: [PATCH] fix: normalize then bkg sub --- pdf_agents/agents.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pdf_agents/agents.py b/pdf_agents/agents.py index 19f13b4..0c5cea6 100644 --- a/pdf_agents/agents.py +++ b/pdf_agents/agents.py @@ -102,8 +102,6 @@ def measurement_plan(self, point: ArrayLike) -> Tuple[str, List, Dict]: def unpack_run(self, run) -> Tuple[Union[float, ArrayLike], Union[float, ArrayLike]]: """Subtracts background and returns motor positions and data""" y = run.primary.data[self.data_key].read().flatten() - if self.background is not None: - y = y - self.background[1] ordinate = np.array(run.primary.data[self.roi_key]).flatten() if self.norm_region is not None: @@ -127,11 +125,16 @@ def unpack_run(self, run) -> Tuple[Union[float, ArrayLike], Union[float, ArrayLi if len(np.where(self.background[0] > self.norm_region[1])[0]) else None ) - scale_factor = np.sum(self.background[1][bkg_idx_min:bkg_idx_max]) / np.sum(y[idx_min:idx_max]) + + scale_bkg = 1 / np.sum(self.background[1][bkg_idx_min:bkg_idx_max]) + scale_y = 1 / np.sum(y[idx_min:idx_max]) + else: - scale_factor = 1 + scale_bkg = 1 + scale_y = 1 - y = y * scale_factor + if self.background is not None: + y = (y * scale_y) - (self.background[1] * scale_bkg) if self.roi is not None: ordinate = np.array(run.primary.data[self.roi_key]).flatten()