Skip to content

Commit

Permalink
fix: normalize then bkg sub
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamCorrao committed Apr 12, 2024
1 parent e0b9f2e commit ed80131
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pdf_agents/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
Expand Down

0 comments on commit ed80131

Please sign in to comment.