From ef61cfc941a22122d0e23e28f73fa2f2f4ab5fdb Mon Sep 17 00:00:00 2001 From: Johannes Kasimir Date: Tue, 22 Oct 2024 10:19:39 +0200 Subject: [PATCH] fix: silence warnings explicitly in the tests and in the notebook --- docs/user-guide/amor/amor-reduction.ipynb | 8 ++++++- docs/user-guide/amor/compare-to-eos.ipynb | 10 +++++++-- src/ess/amor/load.py | 27 ----------------------- tests/amor/pipeline_test.py | 4 ++++ 4 files changed, 19 insertions(+), 30 deletions(-) diff --git a/docs/user-guide/amor/amor-reduction.ipynb b/docs/user-guide/amor/amor-reduction.ipynb index 04115d19..e4fea6c9 100644 --- a/docs/user-guide/amor/amor-reduction.ipynb +++ b/docs/user-guide/amor/amor-reduction.ipynb @@ -24,11 +24,17 @@ "metadata": {}, "outputs": [], "source": [ + "import warnings\n", "import scipp as sc\n", "from ess import amor\n", "from ess.amor import data # noqa: F401\n", "from ess.reflectometry.types import *\n", - "from ess.amor.types import *" + "from ess.amor.types import *\n", + "\n", + "# The files used in this tutorial have some issues that makes scippnexus\n", + "# raise warnings when loading them. To avoid noise in the notebook the warnings are silenced.\n", + "warnings.filterwarnings('ignore', 'Failed to convert .* into a transformation')\n", + "warnings.filterwarnings('ignore', 'Invalid transformation, missing attribute')" ] }, { diff --git a/docs/user-guide/amor/compare-to-eos.ipynb b/docs/user-guide/amor/compare-to-eos.ipynb index a159bad3..c814ea6f 100644 --- a/docs/user-guide/amor/compare-to-eos.ipynb +++ b/docs/user-guide/amor/compare-to-eos.ipynb @@ -18,6 +18,7 @@ "metadata": {}, "outputs": [], "source": [ + "import warnings\n", "import orsopy\n", "import matplotlib.pyplot as plt\n", "\n", @@ -26,7 +27,12 @@ "from ess import amor\n", "from ess.amor import data # noqa: F401\n", "from ess.reflectometry.types import *\n", - "from ess.amor.types import ChopperPhase" + "from ess.amor.types import ChopperPhase\n", + "\n", + "# The files used in this tutorial have some issues that makes scippnexus\n", + "# raise warnings when loading them. To avoid noise in the notebook the warnings are silenced.\n", + "warnings.filterwarnings('ignore', 'Failed to convert .* into a transformation')\n", + "warnings.filterwarnings('ignore', 'Invalid transformation, missing attribute')" ] }, { @@ -225,7 +231,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.13" + "version": "3.10.14" } }, "nbformat": 4, diff --git a/src/ess/amor/load.py b/src/ess/amor/load.py index bae84d3d..bc0cbcb2 100644 --- a/src/ess/amor/load.py +++ b/src/ess/amor/load.py @@ -1,8 +1,5 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright (c) 2023 Scipp contributors (https://github.com/scipp) -import warnings -from functools import wraps - import scipp as sc from ..reflectometry.load import load_nx @@ -26,33 +23,12 @@ ) -def ignore_amor_warnings(func): - @wraps(func) - def wrapped(*args, **kwargs): - with warnings.catch_warnings(): - warnings.filterwarnings( - 'ignore', - category=UserWarning, - message=r'Failed to convert .* into a transformation', - ) - warnings.filterwarnings( - 'ignore', - category=UserWarning, - message='Invalid transformation, missing attribute', - ) - return func(*args, **kwargs) - - return wrapped - - -@ignore_amor_warnings def load_detector( file_path: Filename[RunType], detector_name: NeXusDetectorName[RunType] ) -> LoadedNeXusDetector[RunType]: return next(load_nx(file_path, f"NXentry/NXinstrument/{detector_name}")) -@ignore_amor_warnings def load_events( detector: LoadedNeXusDetector[RunType], detector_rotation: DetectorRotation[RunType] ) -> RawDetectorData[RunType]: @@ -130,7 +106,6 @@ def compute_tof( return ReducibleDetectorData[RunType](data) -@ignore_amor_warnings def amor_chopper(f: Filename[RunType]) -> RawChopper[RunType]: return next(load_nx(f, "NXentry/NXinstrument/NXdisk_chopper")) @@ -163,7 +138,6 @@ def load_amor_ch_frequency(ch: RawChopper[RunType]) -> ChopperFrequency[RunType] raise ValueError("No unit was found for the chopper frequency") -@ignore_amor_warnings def load_amor_sample_rotation(fp: Filename[RunType]) -> SampleRotation[RunType]: (mu,) = load_nx(fp, "NXentry/NXinstrument/master_parameters/mu") # Jochens Amor code reads the first value of this log @@ -172,7 +146,6 @@ def load_amor_sample_rotation(fp: Filename[RunType]) -> SampleRotation[RunType]: return sc.scalar(mu['value'].data['dim_1', 0]['time', 0].value, unit='deg') -@ignore_amor_warnings def load_amor_detector_rotation(fp: Filename[RunType]) -> DetectorRotation[RunType]: (nu,) = load_nx(fp, "NXentry/NXinstrument/master_parameters/nu") # Jochens Amor code reads the first value of this log diff --git a/tests/amor/pipeline_test.py b/tests/amor/pipeline_test.py index 410f1ccb..24fd5bfc 100644 --- a/tests/amor/pipeline_test.py +++ b/tests/amor/pipeline_test.py @@ -56,12 +56,16 @@ def amor_pipeline() -> sciline.Pipeline: return pl +@pytest.mark.filterwarnings("ignore:Failed to convert .* into a transformation") +@pytest.mark.filterwarnings("ignore:Invalid transformation, missing attribute") def test_run_data_pipeline(amor_pipeline: sciline.Pipeline): res = amor_pipeline.compute(ReflectivityOverQ) assert "Q" in res.coords assert "Q_resolution" in res.coords +@pytest.mark.filterwarnings("ignore:Failed to convert .* into a transformation") +@pytest.mark.filterwarnings("ignore:Invalid transformation, missing attribute") def test_run_full_pipeline(amor_pipeline: sciline.Pipeline): res = amor_pipeline.compute(orso.OrsoIofQDataset) assert res.info.data_source.experiment.instrument == "Amor"