Skip to content

Commit 9c09b1f

Browse files
committed
fix: more granular warning ignore
1 parent b5e612c commit 9c09b1f

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/ess/amor/load.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
33
import warnings
4+
from functools import wraps
45

56
import scipp as sc
67

@@ -26,15 +27,34 @@
2627
RawChopper,
2728
)
2829

29-
warnings.filterwarnings('ignore', message=r'Failed to convert .* into a transformation')
3030

31+
def ignore_amor_warnings(func):
32+
@wraps(func)
33+
def wrapped(*args, **kwargs):
34+
with warnings.catch_warnings():
35+
warnings.filterwarnings(
36+
'ignore',
37+
category=UserWarning,
38+
message=r'Failed to convert .* into a transformation',
39+
)
40+
warnings.filterwarnings(
41+
'ignore',
42+
category=UserWarning,
43+
message='Invalid transformation, missing attribute',
44+
)
45+
return func(*args, **kwargs)
3146

47+
return wrapped
48+
49+
50+
@ignore_amor_warnings
3251
def load_detector(
3352
file_path: Filename[RunType], detector_name: NeXusDetectorName[RunType]
3453
) -> LoadedNeXusDetector[RunType]:
3554
return nexus.load_detector(file_path=file_path, detector_name=detector_name)
3655

3756

57+
@ignore_amor_warnings
3858
def load_events(
3959
detector: LoadedNeXusDetector[RunType], detector_rotation: DetectorRotation[RunType]
4060
) -> RawDetectorData[RunType]:
@@ -112,6 +132,7 @@ def compute_tof(
112132
return ReducibleDetectorData[RunType](data)
113133

114134

135+
@ignore_amor_warnings
115136
def amor_chopper(f: Filename[RunType]) -> RawChopper[RunType]:
116137
return next(load_nx(f, "NXentry/NXinstrument/NXdisk_chopper"))
117138

@@ -144,6 +165,7 @@ def load_amor_ch_frequency(ch: RawChopper[RunType]) -> ChopperFrequency[RunType]
144165
raise ValueError("No unit was found for the chopper frequency")
145166

146167

168+
@ignore_amor_warnings
147169
def load_amor_sample_rotation(fp: Filename[RunType]) -> SampleRotation[RunType]:
148170
(mu,) = load_nx(fp, "NXentry/NXinstrument/master_parameters/mu")
149171
# Jochens Amor code reads the first value of this log
@@ -152,6 +174,7 @@ def load_amor_sample_rotation(fp: Filename[RunType]) -> SampleRotation[RunType]:
152174
return sc.scalar(mu['value'].data['dim_1', 0]['time', 0].value, unit='deg')
153175

154176

177+
@ignore_amor_warnings
155178
def load_amor_detector_rotation(fp: Filename[RunType]) -> DetectorRotation[RunType]:
156179
(nu,) = load_nx(fp, "NXentry/NXinstrument/master_parameters/nu")
157180
# Jochens Amor code reads the first value of this log

0 commit comments

Comments
 (0)