Skip to content

Commit

Permalink
Add sans phi limits rule to rundetection
Browse files Browse the repository at this point in the history
  • Loading branch information
Pasarus committed Jan 21, 2025
1 parent 87fb1ef commit f267822
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
5 changes: 5 additions & 0 deletions rundetection/rules/common_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ def verify(self, job_request: JobRequest) -> None:
job_request.additional_values["slice_wavs"] = self._value


class SansPhiLimits(Rule[str]):
def verify(self, job_request: JobRequest) -> None:
job_request.additional_values["phi_limits"] = self._value


class MolSpecStitchRule(Rule[bool]):
"""
Enables Tosca, Osiris, and Iris Run stitching
Expand Down
11 changes: 10 additions & 1 deletion rundetection/rules/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@

from typing import Any

from rundetection.rules.common_rules import CheckIfScatterSANS, EnabledRule, MolSpecStitchRule, SansSliceWavs
from rundetection.rules.common_rules import (
CheckIfScatterSANS,
EnabledRule,
MolSpecStitchRule,
SansPhiLimits,
SansSliceWavs,
)
from rundetection.rules.inter_rules import InterStitchRule
from rundetection.rules.iris_rules import IrisCalibrationRule, IrisReductionRule
from rundetection.rules.loq_rules import LoqFindFiles, LoqUserFile
Expand Down Expand Up @@ -65,6 +71,9 @@ def rule_factory(key_: str, value: T) -> Rule[Any]: # noqa: C901, PLR0911, PLR0
case "loquserfile":
if isinstance(value, str):
return LoqUserFile(value)
case "sansphilimits":
if isinstance(value, str):
return SansPhiLimits(value)
case "sansslicewavs":
if isinstance(value, str):
return SansSliceWavs(value)
Expand Down
21 changes: 19 additions & 2 deletions test/rules/test_common_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@
import pytest

from rundetection.ingestion.ingest import JobRequest
from rundetection.rules.common_rules import CheckIfScatterSANS, EnabledRule, SansSliceWavs, is_y_within_5_percent_of_x
from rundetection.rules.common_rules import (
CheckIfScatterSANS,
EnabledRule,
SansPhiLimits,
SansSliceWavs,
is_y_within_5_percent_of_x,
)


@pytest.fixture
@pytest.fixture()
def job_request():
"""
job_request Fixture
Expand Down Expand Up @@ -100,5 +106,16 @@ def test_sans_slice_wavs_rule_when_not_enabled(job_request) -> None:
assert job_request.additional_values["slice_wavs"] == "[1.0, 2.0, 3.0, 4.0]"


def test_sans_phi_limit_rule_when_not_enabled(job_request) -> None:
"""
Test verify method will return expected value
:param job_request: JobRequest fixture
:return: None
"""
rule = SansPhiLimits("[(1.0, 2.0), (3.0, 4.0)]")
rule.verify(job_request)
assert job_request.additional_values["phi_limits"] == "[(1.0, 2.0), (3.0, 4.0)]"


if __name__ == "__main__":
unittest.main()
10 changes: 9 additions & 1 deletion test/rules/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@

import pytest

from rundetection.rules.common_rules import CheckIfScatterSANS, EnabledRule, MolSpecStitchRule
from rundetection.rules.common_rules import (
CheckIfScatterSANS,
EnabledRule,
MolSpecStitchRule,
SansPhiLimits,
SansSliceWavs,
)
from rundetection.rules.factory import rule_factory
from rundetection.rules.inter_rules import InterStitchRule
from rundetection.rules.iris_rules import IrisCalibrationRule, IrisReductionRule
Expand Down Expand Up @@ -51,6 +57,8 @@ def assert_correct_rule(name: str, value: Any, rule_type: type[Rule]):
("checkifscattersans", True, CheckIfScatterSANS),
("loquserfile", "loquserfile.toml", LoqUserFile),
("loqfindfiles", True, LoqFindFiles),
("sansphilimits", "[(1.0, 2.0), (3.0, 4.0)]", SansPhiLimits),
("sansslicewavs", "[2.7, 3.7, 4.7, 5.7, 6.7, 8.7, 10.5]", SansSliceWavs),
("irisreduction", True, IrisReductionRule),
("iriscalibration", {"002": "00148587", "004": "00148587"}, IrisCalibrationRule),
],
Expand Down
3 changes: 2 additions & 1 deletion test/test_data/specifications/loq_specification.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"checkifscattersans": true,
"loqfindfiles": true,
"loquserfile": "USER_LOQ_244A_M3_Changer_Loq_MERGED_log.toml",
"sansslicewavs": "[2.7, 3.7, 4.7, 5.7, 6.7, 8.7, 10.5]"
"sansslicewavs": "[2.7, 3.7, 4.7, 5.7, 6.7, 8.7, 10.5]",
"sansphilimits": "[(-30, 30), (60, 120)]"
}

0 comments on commit f267822

Please sign in to comment.