diff --git a/src/snapred/backend/recipe/PreprocessReductionRecipe.py b/src/snapred/backend/recipe/PreprocessReductionRecipe.py index 9608cddec..af588aa59 100644 --- a/src/snapred/backend/recipe/PreprocessReductionRecipe.py +++ b/src/snapred/backend/recipe/PreprocessReductionRecipe.py @@ -1,5 +1,7 @@ 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 from snapred.backend.recipe.Recipe import Recipe @@ -32,6 +34,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 +69,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.