From f4ff5a0fbe1d136effd7724edf90eba57171c243 Mon Sep 17 00:00:00 2001 From: mguthriem Date: Fri, 25 Apr 2025 16:51:40 -0400 Subject: [PATCH 1/2] prototype that applies any swiss cheese mask found in the ADS --- .../recipe/PreprocessReductionRecipe.py | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/snapred/backend/recipe/PreprocessReductionRecipe.py b/src/snapred/backend/recipe/PreprocessReductionRecipe.py index 9608cddec..6553513dc 100644 --- a/src/snapred/backend/recipe/PreprocessReductionRecipe.py +++ b/src/snapred/backend/recipe/PreprocessReductionRecipe.py @@ -1,4 +1,5 @@ from typing import Any, Dict, List, Set, Tuple +from mantid.simpleapi import mtd from snapred.backend.dao.ingredients import PreprocessReductionIngredients as Ingredients from snapred.backend.log.logger import snapredLogger @@ -32,6 +33,21 @@ def unbagGroceries(self, groceries: Dict[str, Any]): self.diffcalWs = groceries.get("diffcalWorkspace", "") self.outputWs = groceries.get("outputWorkspace", groceries["inputWorkspace"]) + def findMaskBinsTableWorkspaces(self): + """ + Locates bin Mask workspaces on the basis of their names and creates a list of these + """ + + self.binMasks = [] + for ws in mtd.getObjectNames(): + if "maskBins_" in ws: + self.binMasks.append(ws) + print(f"{len(self.binMasks)} binMasks were found in ADS") + if len(self.binMasks) >= 1: + self.hasBinMasks = True + else: + self.hasBinMasks = False + def queueAlgos(self): """ Queues up the processing algorithms for the recipe. @@ -52,6 +68,36 @@ def queueAlgos(self): CalibrationWorkspace=self.diffcalWs, ) + #check if any bin masks exist + self.findMaskBinsTableWorkspaces() + #apply bin Masks if they were found + if self.hasBinMasks: + for mask in self.binMasks: + #extract units from ws name (table workspaces don't have logs) + maskUnits = mask.split('_')[-1] + #ensure units of workspace match + self.mantidSnapper.ConvertUnits( + f"Converting units to match Bin Mask with units of {maskUnits}", + InputWorkspace=self.outputWs, + Target = maskUnits, + OutputWorkspace=self.outputWs + ) + #mask bins + self.mantidSnapper.MaskBinsFromTable( + "Masking bins...", + InputWorkspace=self.outputWs, + MaskingInformation=mask, + OutputWorkspace=self.outputWs + ) + + # convert to tof if needed + self.mantidSnapper.ConvertUnits( + "Converting to TOF...", + InputWorkspace=self.outputWs, + Target="TOF", + OutputWorkspace=self.outputWs, + ) + def cook(self, ingredients: Ingredients, groceries: Dict[str, str]) -> Dict[str, Any]: """ Main interface method for the recipe. From 9f1b3d72067846ae6fdddfd9e45f63b9c77b1eeb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 25 Apr 2025 21:33:10 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../recipe/PreprocessReductionRecipe.py | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/snapred/backend/recipe/PreprocessReductionRecipe.py b/src/snapred/backend/recipe/PreprocessReductionRecipe.py index 6553513dc..af588aa59 100644 --- a/src/snapred/backend/recipe/PreprocessReductionRecipe.py +++ b/src/snapred/backend/recipe/PreprocessReductionRecipe.py @@ -1,4 +1,5 @@ from typing import Any, Dict, List, Set, Tuple + from mantid.simpleapi import mtd from snapred.backend.dao.ingredients import PreprocessReductionIngredients as Ingredients @@ -47,7 +48,7 @@ def findMaskBinsTableWorkspaces(self): self.hasBinMasks = True else: self.hasBinMasks = False - + def queueAlgos(self): """ Queues up the processing algorithms for the recipe. @@ -68,26 +69,26 @@ def queueAlgos(self): CalibrationWorkspace=self.diffcalWs, ) - #check if any bin masks exist + # check if any bin masks exist self.findMaskBinsTableWorkspaces() - #apply bin Masks if they were found + # apply bin Masks if they were found if self.hasBinMasks: for mask in self.binMasks: - #extract units from ws name (table workspaces don't have logs) - maskUnits = mask.split('_')[-1] - #ensure units of workspace match + # extract units from ws name (table workspaces don't have logs) + maskUnits = mask.split("_")[-1] + # ensure units of workspace match self.mantidSnapper.ConvertUnits( f"Converting units to match Bin Mask with units of {maskUnits}", InputWorkspace=self.outputWs, - Target = maskUnits, - OutputWorkspace=self.outputWs + Target=maskUnits, + OutputWorkspace=self.outputWs, ) - #mask bins + # mask bins self.mantidSnapper.MaskBinsFromTable( "Masking bins...", InputWorkspace=self.outputWs, MaskingInformation=mask, - OutputWorkspace=self.outputWs + OutputWorkspace=self.outputWs, ) # convert to tof if needed