Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/snapred/backend/recipe/PreprocessReductionRecipe.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -32,6 +34,21 @@
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)

Check warning on line 45 in src/snapred/backend/recipe/PreprocessReductionRecipe.py

View check run for this annotation

Codecov / codecov/patch

src/snapred/backend/recipe/PreprocessReductionRecipe.py#L45

Added line #L45 was not covered by tests
Comment on lines +42 to +45
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of inspecting the ads for a name schema we would instead want to append this to the pixelMask list on the ReductionRequest so it may be picked up by the prepCombinedMask method in ReductionService

To accomplish this you will need to:

  1. Create a new WorkspaceNameGenerator name for the swisscheese mask: A. Add another template to the application.yml B. Add another workspace type to the enum C. Add another method to the WNG itself following the naming pattern
  2. Add a new case to the prepCombinedMask method for the new workspace type you added in the previous step, probably in the same fashion as this case
  3. When you submit your reduction request, use the wng to generate the name and add it to pixelMask list on the ReductionRequest

print(f"{len(self.binMasks)} binMasks were found in ADS")
if len(self.binMasks) >= 1:
self.hasBinMasks = True

Check warning on line 48 in src/snapred/backend/recipe/PreprocessReductionRecipe.py

View check run for this annotation

Codecov / codecov/patch

src/snapred/backend/recipe/PreprocessReductionRecipe.py#L48

Added line #L48 was not covered by tests
else:
self.hasBinMasks = False

def queueAlgos(self):
"""
Queues up the processing algorithms for the recipe.
Expand All @@ -52,6 +69,36 @@
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:

Check warning on line 76 in src/snapred/backend/recipe/PreprocessReductionRecipe.py

View check run for this annotation

Codecov / codecov/patch

src/snapred/backend/recipe/PreprocessReductionRecipe.py#L76

Added line #L76 was not covered by tests
# extract units from ws name (table workspaces don't have logs)
maskUnits = mask.split("_")[-1]

Check warning on line 78 in src/snapred/backend/recipe/PreprocessReductionRecipe.py

View check run for this annotation

Codecov / codecov/patch

src/snapred/backend/recipe/PreprocessReductionRecipe.py#L78

Added line #L78 was not covered by tests
# ensure units of workspace match
self.mantidSnapper.ConvertUnits(

Check warning on line 80 in src/snapred/backend/recipe/PreprocessReductionRecipe.py

View check run for this annotation

Codecov / codecov/patch

src/snapred/backend/recipe/PreprocessReductionRecipe.py#L80

Added line #L80 was not covered by tests
f"Converting units to match Bin Mask with units of {maskUnits}",
InputWorkspace=self.outputWs,
Target=maskUnits,
OutputWorkspace=self.outputWs,
)
# mask bins
self.mantidSnapper.MaskBinsFromTable(

Check warning on line 87 in src/snapred/backend/recipe/PreprocessReductionRecipe.py

View check run for this annotation

Codecov / codecov/patch

src/snapred/backend/recipe/PreprocessReductionRecipe.py#L87

Added line #L87 was not covered by tests
"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.
Expand Down