From f267822fc8a8bc96f1a4f77426aa8f8f2e7824f7 Mon Sep 17 00:00:00 2001 From: Samuel Jones Date: Tue, 21 Jan 2025 14:10:54 +0000 Subject: [PATCH] Add sans phi limits rule to rundetection --- rundetection/rules/common_rules.py | 5 +++++ rundetection/rules/factory.py | 11 +++++++++- test/rules/test_common_rules.py | 21 +++++++++++++++++-- test/rules/test_factory.py | 10 ++++++++- .../specifications/loq_specification.json | 3 ++- 5 files changed, 45 insertions(+), 5 deletions(-) diff --git a/rundetection/rules/common_rules.py b/rundetection/rules/common_rules.py index e539e87..d500ded 100644 --- a/rundetection/rules/common_rules.py +++ b/rundetection/rules/common_rules.py @@ -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 diff --git a/rundetection/rules/factory.py b/rundetection/rules/factory.py index d9f835c..6e74c94 100644 --- a/rundetection/rules/factory.py +++ b/rundetection/rules/factory.py @@ -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 @@ -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) diff --git a/test/rules/test_common_rules.py b/test/rules/test_common_rules.py index 3ababf6..b7fe041 100644 --- a/test/rules/test_common_rules.py +++ b/test/rules/test_common_rules.py @@ -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 @@ -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() diff --git a/test/rules/test_factory.py b/test/rules/test_factory.py index 85e323b..5ec9a2d 100644 --- a/test/rules/test_factory.py +++ b/test/rules/test_factory.py @@ -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 @@ -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), ], diff --git a/test/test_data/specifications/loq_specification.json b/test/test_data/specifications/loq_specification.json index 86f63ca..1c40fa1 100644 --- a/test/test_data/specifications/loq_specification.json +++ b/test/test_data/specifications/loq_specification.json @@ -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)]" }