|
12 | 12 | ) |
13 | 13 | from ess.imaging.normalize import ( |
14 | 14 | BackgroundImage, |
| 15 | + BackgroundPixelThreshold, |
| 16 | + CleansedOpenBeamImage, |
| 17 | + CleansedSampleImages, |
15 | 18 | DarkCurrentImage, |
16 | 19 | NormalizedSampleImages, |
17 | 20 | OpenBeamImage, |
| 21 | + SamplePixelThreshold, |
18 | 22 | ScaleFactor, |
| 23 | + apply_threshold_to_background_image, |
19 | 24 | apply_threshold_to_sample_images, |
20 | 25 | average_dark_current_images, |
21 | 26 | average_open_beam_images, |
@@ -171,12 +176,50 @@ def test_cleanse_sample_images( |
171 | 176 | ) |
172 | 177 |
|
173 | 178 |
|
| 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 | + |
174 | 219 | def test_normalize_negative_scale_factor_raises( |
175 | 220 | sample_images: SampleImageStacksWithLogs, |
176 | 221 | dark_current_image: DarkCurrentImage, |
177 | 222 | ) -> None: |
178 | | - from ess.imaging.normalize import SamplePixelThreshold |
179 | | - |
180 | 223 | cleansed_sample_image = apply_threshold_to_sample_images( |
181 | 224 | cleanse_sample_images(sample_images, dark_current_image), |
182 | 225 | SamplePixelThreshold(sc.scalar(0.0, unit="counts")), |
|
0 commit comments