Skip to content

Commit 58a36e0

Browse files
committed
Add tests for threshold applying step.
1 parent d7ad2b8 commit 58a36e0

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

tests/image_normalize_test.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@
1212
)
1313
from ess.imaging.normalize import (
1414
BackgroundImage,
15+
BackgroundPixelThreshold,
16+
CleansedOpenBeamImage,
17+
CleansedSampleImages,
1518
DarkCurrentImage,
1619
NormalizedSampleImages,
1720
OpenBeamImage,
21+
SamplePixelThreshold,
1822
ScaleFactor,
23+
apply_threshold_to_background_image,
1924
apply_threshold_to_sample_images,
2025
average_dark_current_images,
2126
average_open_beam_images,
@@ -171,12 +176,50 @@ def test_cleanse_sample_images(
171176
)
172177

173178

179+
def test_apply_threshold_to_sample_images() -> None:
180+
sample_images_with_negative_values = sc.DataArray(
181+
data=sc.array(
182+
dims=["time", "dim_1", "dim_2"],
183+
values=[[[2.0, 2.0], [2.0, -1.0]], [[4.0, 4.0], [4.0, -1.0]]],
184+
unit="counts",
185+
),
186+
coords={
187+
"time": sc.array(dims=["time"], values=[1, 2], unit="s"),
188+
},
189+
)
190+
threshold = sc.scalar(1.0, unit="counts")
191+
thresholded_sample_images = apply_threshold_to_sample_images(
192+
CleansedSampleImages(sample_images_with_negative_values),
193+
SamplePixelThreshold(threshold),
194+
)
195+
with pytest.raises(AssertionError, match="Arrays are not equal"):
196+
assert_identical(sample_images_with_negative_values.data.min(), threshold)
197+
assert_identical(thresholded_sample_images.data.min(), threshold)
198+
199+
200+
def test_apply_threshold_to_background_image() -> None:
201+
background_image_with_negative_values = sc.DataArray(
202+
data=sc.array(
203+
dims=["dim_1", "dim_2"],
204+
values=[[3.0, 3.0], [3.0, -1.0]],
205+
unit="counts",
206+
),
207+
coords={},
208+
)
209+
threshold = sc.scalar(1.0, unit="counts")
210+
thresholded_background_image = apply_threshold_to_background_image(
211+
CleansedOpenBeamImage(background_image_with_negative_values),
212+
BackgroundPixelThreshold(threshold),
213+
)
214+
with pytest.raises(AssertionError, match="Arrays are not equal"):
215+
assert_identical(background_image_with_negative_values.data.min(), threshold)
216+
assert_identical(thresholded_background_image.data.min(), threshold)
217+
218+
174219
def test_normalize_negative_scale_factor_raises(
175220
sample_images: SampleImageStacksWithLogs,
176221
dark_current_image: DarkCurrentImage,
177222
) -> None:
178-
from ess.imaging.normalize import SamplePixelThreshold
179-
180223
cleansed_sample_image = apply_threshold_to_sample_images(
181224
cleanse_sample_images(sample_images, dark_current_image),
182225
SamplePixelThreshold(sc.scalar(0.0, unit="counts")),

0 commit comments

Comments
 (0)