Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 3, 2024
1 parent 35c7f34 commit 8bb61d7
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/snapred/backend/data/LocalDataService.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ def writeReductionData(self, record: ReductionRecord):
# 2) For SNAPRed internal use:
# if `reduction.output.useEffectiveInstrument` is set to false in "application.yml",
# output workspaces will be saved without converting their instruments to the reduced form.
# Both of these alternatives are retained to allow some flexibility in what specifically
# Both of these alternatives are retained to allow some flexibility in what specifically
# is saved with the reduction data.
#

Expand Down
15 changes: 4 additions & 11 deletions src/snapred/backend/service/SousChef.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def prepPixelGroup(
ingredients.useLiteMode,
groupingSchema,
ingredients.calibrantSamplePath,
pixelMask
pixelMask,
)
if key not in self._pixelGroupCache:
focusGroup = self.prepFocusGroup(ingredients)
Expand All @@ -116,10 +116,7 @@ def prepPixelGroup(
self.groceryClerk.name("groupingWorkspace").fromRun(ingredients.runNumber).grouping(
focusGroup.name
).useLiteMode(ingredients.useLiteMode).add()
groceries = self.groceryService.fetchGroceryDict(
self.groceryClerk.buildDict(),
maskWorkspace=pixelMask
)
groceries = self.groceryService.fetchGroceryDict(self.groceryClerk.buildDict(), maskWorkspace=pixelMask)
data = PixelGroupingParametersCalculationRecipe().executeRecipe(pixelIngredients, groceries)

self._pixelGroupCache[key] = PixelGroup(
Expand All @@ -131,9 +128,7 @@ def prepPixelGroup(
return deepcopy(self._pixelGroupCache[key])

def prepManyPixelGroups(
self,
ingredients: FarmFreshIngredients,
pixelMask: Optional[WorkspaceName] = None
self, ingredients: FarmFreshIngredients, pixelMask: Optional[WorkspaceName] = None
) -> List[PixelGroup]:
pixelGroups = []
ingredients_ = ingredients.model_copy()
Expand Down Expand Up @@ -267,9 +262,7 @@ def _pullNormalizationRecordFFI(
return ingredients, smoothingParameter, calibrantSamplePath

def prepReductionIngredients(
self,
ingredients: FarmFreshIngredients,
combinedPixelMask: Optional[WorkspaceName] = None
self, ingredients: FarmFreshIngredients, combinedPixelMask: Optional[WorkspaceName] = None
) -> ReductionIngredients:
ingredients_ = ingredients.model_copy()
# some of the reduction ingredients MUST match those used in the calibration/normalization processes
Expand Down
1 change: 1 addition & 0 deletions src/snapred/resources/ultralite/create_ultralite_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# import mantid algorithms, numpy and matplotlib

from mantid.simpleapi import *

from snapred.backend.dao.ingredients.GroceryListItem import GroceryListItem
from snapred.backend.data.DataFactoryService import DataFactoryService
from snapred.backend.data.GroceryService import GroceryService
Expand Down
11 changes: 4 additions & 7 deletions tests/unit/backend/recipe/test_EffectiveInstrumentRecipe.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import numpy as np
from unittest import mock

from mantid.simpleapi import EditInstrumentGeometry
import numpy as np
import pytest
from util.SculleryBoy import SculleryBoy

from snapred.backend.dao.ingredients import EffectiveInstrumentIngredients as Ingredients
from snapred.backend.dao.state.FocusGroup import FocusGroup
from snapred.backend.dao.state.PixelGroup import PixelGroup
from snapred.backend.error.AlgorithmException import AlgorithmException
from snapred.backend.recipe.algorithm.Utensils import Utensils
from snapred.backend.recipe.EffectiveInstrumentRecipe import EffectiveInstrumentRecipe
from snapred.meta.Config import Resource

from util.SculleryBoy import SculleryBoy

from unittest import mock
import pytest

class TestEffectiveInstrumentRecipe:
fakeInstrumentFilePath = Resource.getPath("inputs/testInstrument/fakeSNAP_Definition.xml")
Expand Down
5 changes: 2 additions & 3 deletions tests/unit/backend/recipe/test_PreprocessReductionRecipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
LoadInstrument,
mtd,
)
from util.helpers import createCompatibleMask
from util.SculleryBoy import SculleryBoy

from snapred.backend.dao.ingredients import PreprocessReductionIngredients as Ingredients
from snapred.backend.recipe.algorithm.Utensils import Utensils
from snapred.backend.recipe.PreprocessReductionRecipe import PreprocessReductionRecipe
from snapred.meta.Config import Resource

from util.helpers import createCompatibleMask
from util.SculleryBoy import SculleryBoy


class PreprocessReductionRecipeTest(unittest.TestCase):
fakeInstrumentFilePath = Resource.getPath("inputs/testInstrument/fakeSNAP_Definition.xml")
Expand Down
9 changes: 5 additions & 4 deletions tests/unit/backend/recipe/test_ReductionRecipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import pytest
from mantid.simpleapi import CreateSingleValuedWorkspace, mtd
from util.Config_helpers import Config_override
from util.SculleryBoy import SculleryBoy

from snapred.backend.dao.ingredients import ReductionIngredients
from snapred.backend.recipe.ReductionRecipe import (
Expand All @@ -15,8 +17,6 @@
)
from snapred.meta.mantid.WorkspaceNameGenerator import WorkspaceNameGenerator as wng

from util.SculleryBoy import SculleryBoy
from util.Config_helpers import Config_override

class ReductionRecipeTest(TestCase):
sculleryBoy = SculleryBoy()
Expand Down Expand Up @@ -478,7 +478,6 @@ def test_execute(self, mockMtd):
assert recipe._deleteWorkspace.call_count == len(recipe._prepGroupingWorkspaces.return_value)
assert result["outputs"][0] == "sample_grouped"


@mock.patch("mantid.simpleapi.mtd", create=True)
def test_execute_useEffectiveInstrument(self, mockMtd):
with Config_override("reduction.output.useEffectiveInstrument", True):
Expand All @@ -491,7 +490,9 @@ def test_execute_useEffectiveInstrument(self, mockMtd):
mockGroupWorkspace.readY.return_value = [0] * 10
mockMaskworkspace.readY.return_value = [0] * 10

mockMtd.__getitem__.side_effect = lambda ws_name: mockMaskworkspace if ws_name == "mask" else mockGroupWorkspace
mockMtd.__getitem__.side_effect = (
lambda ws_name: mockMaskworkspace if ws_name == "mask" else mockGroupWorkspace
)

recipe = ReductionRecipe()
recipe.mantidSnapper = mockMantidSnapper
Expand Down
8 changes: 3 additions & 5 deletions tests/unit/backend/service/test_SousChef.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def test_prepPixelGroup_nocache(
self.ingredients.useLiteMode,
self.ingredients.focusGroup.name,
self.ingredients.calibrantSamplePath,
None
None,
)

# ensure there is no cached value
Expand Down Expand Up @@ -213,14 +213,13 @@ def test_prepPixelGroup_nocache(

@mock.patch(thisService + "PixelGroupingParametersCalculationRecipe")
def test_prepPixelGroup_cache(self, PixelGroupingParametersCalculationRecipe):

# ensure the cache is prepared
key = (
self.ingredients.runNumber,
self.ingredients.useLiteMode,
self.ingredients.focusGroup.name,
self.ingredients.calibrantSamplePath,
self.pixelMask
self.pixelMask,
)
self.instance._pixelGroupCache[key] = mock.sentinel.pixel

Expand All @@ -230,14 +229,13 @@ def test_prepPixelGroup_cache(self, PixelGroupingParametersCalculationRecipe):
assert res == self.instance._pixelGroupCache[key]

def test_prepPixelGroup_cache_not_altered(self):

# ensure the cache is prepared
key = (
self.ingredients.runNumber,
self.ingredients.useLiteMode,
self.ingredients.focusGroup.name,
self.ingredients.calibrantSamplePath,
None
None,
)
self.instance._pixelGroupCache[key] = PixelGroup.construct(timeOfFlight={"minimum": 0})

Expand Down
1 change: 1 addition & 0 deletions tests/unit/ui/workflow/test_DiffCalWorkflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
mtd,
)
from qtpy.QtWidgets import QMessageBox

from snapred.meta.mantid.FitPeaksOutput import FIT_PEAK_DIAG_SUFFIX, FitOutputEnum
from snapred.meta.pointer import create_pointer
from snapred.ui.workflow.DiffCalWorkflow import DiffCalWorkflow
Expand Down

0 comments on commit 8bb61d7

Please sign in to comment.