-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduction process: effective-instrument geometry.
At the end of the reduction process, the instrument associated with each output workspace is modified. A new _effective_ instrument is substituted for each workspace. This instrument has the same number of pixels as there are group-ids, and the location of each pixel is set to the mean location of the _unmasked_ original pixels participating in that pixel group. By implication, this substitution results in there being one pixel per spectrum in the output workspaces. This commit includes the following changes: * A new `EffectiveInstrumentRecipe` implemented as a subrecipe called by `ReductionRecipe` for each grouping; * Modifications to `LocalDataService.writeReductionData` to use updated Mantid algorithms, now allowing limited I/O of programmatically-generated instruments; * Modification of `ReductionIngredients` to include the _unmasked_ `PixelGroup`s; * Modification of `SousChef.prepReductionIngredients` to prepare the _unmasked_ `PixelGroup`s; * Modification of existing unit tests, and implementation of new unit tests to verify the new subrecipe's execution. Associated with this PR are three Mantid PRs, including changes to the `EditInstrumentGeometry`, `SaveNexusESS`, and `LoadNexusProcessed` algorithms.
- Loading branch information
Kort Travis
committed
Dec 3, 2024
1 parent
b628382
commit 28cc34f
Showing
29 changed files
with
1,201 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/snapred/backend/dao/ingredients/EffectiveInstrumentIngredients.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from pydantic import BaseModel, ConfigDict | ||
|
||
from snapred.backend.dao.state.PixelGroup import PixelGroup | ||
|
||
|
||
class EffectiveInstrumentIngredients(BaseModel): | ||
unmaskedPixelGroup: PixelGroup | ||
|
||
model_config = ConfigDict( | ||
extra="forbid", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
from typing import Any, Dict, List, Tuple | ||
|
||
import numpy as np | ||
|
||
from snapred.backend.dao.ingredients import EffectiveInstrumentIngredients as Ingredients | ||
from snapred.backend.error.AlgorithmException import AlgorithmException | ||
from snapred.backend.log.logger import snapredLogger | ||
from snapred.backend.recipe.Recipe import Recipe | ||
from snapred.meta.decorators.Singleton import Singleton | ||
from snapred.meta.mantid.WorkspaceNameGenerator import WorkspaceName | ||
|
||
logger = snapredLogger.getLogger(__name__) | ||
|
||
Pallet = Tuple[Ingredients, Dict[str, str]] | ||
|
||
|
||
@Singleton | ||
class EffectiveInstrumentRecipe(Recipe[Ingredients]): | ||
def unbagGroceries(self, groceries: Dict[str, Any]): | ||
self.inputWS = groceries["inputWorkspace"] | ||
self.outputWS = groceries.get("outputWorkspace", groceries["inputWorkspace"]) | ||
|
||
def chopIngredients(self, ingredients): | ||
self.unmaskedPixelGroup = ingredients.unmaskedPixelGroup | ||
|
||
def queueAlgos(self): | ||
""" | ||
Queues up the processing algorithms for the recipe. | ||
Requires: unbagged groceries. | ||
""" | ||
# `EditInstrumentGeometry` modifies in-place, so we need to clone if a distinct output workspace is required. | ||
if self.outputWS != self.inputWS: | ||
self.mantidSnapper.CloneWorkspace( | ||
"Clone workspace for reduced instrument", OutputWorkspace=self.outputWS, InputWorkspace=self.inputWS | ||
) | ||
self.mantidSnapper.EditInstrumentGeometry( | ||
f"Editing instrument geometry for grouping '{self.unmaskedPixelGroup.focusGroup.name}'", | ||
Workspace=self.outputWS, | ||
# TODO: Mantid defect: allow SI units here! | ||
L2=self.unmaskedPixelGroup.L2, | ||
Polar=np.rad2deg(self.unmaskedPixelGroup.twoTheta), | ||
Azimuthal=np.rad2deg(self.unmaskedPixelGroup.azimuth), | ||
# | ||
InstrumentName=f"SNAP_{self.unmaskedPixelGroup.focusGroup.name}", | ||
) | ||
|
||
def validateInputs(self, ingredients: Ingredients, groceries: Dict[str, WorkspaceName]): | ||
pass | ||
|
||
def execute(self): | ||
""" | ||
Final step in a recipe, executes the queued algorithms. | ||
Requires: queued algorithms. | ||
""" | ||
try: | ||
self.mantidSnapper.executeQueue() | ||
except AlgorithmException as e: | ||
errorString = str(e) | ||
raise RuntimeError(errorString) from e | ||
|
||
def cook(self, ingredients, groceries: Dict[str, str]) -> Dict[str, Any]: | ||
""" | ||
Main interface method for the recipe. | ||
Given the ingredients and groceries, it prepares, executes and returns the final workspace. | ||
""" | ||
self.prep(ingredients, groceries) | ||
self.execute() | ||
return self.outputWS | ||
|
||
def cater(self, shipment: List[Pallet]) -> List[Dict[str, Any]]: | ||
""" | ||
A secondary interface method for the recipe. | ||
It is a batched version of cook. | ||
Given a shipment of ingredients and groceries, it prepares, executes and returns the final workspaces. | ||
""" | ||
output = [] | ||
for ingredients, grocery in shipment: | ||
self.prep(ingredients, grocery) | ||
output.append(self.outputWS) | ||
self.execute() | ||
return output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.