Skip to content

Commit cb3756c

Browse files
authored
Merge pull request #208 from DiamondLightSource/flatsdarks_scaler
normalisation method parameters for scaling flats/darks
2 parents 5a028a3 + fb2340f commit cb3756c

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

httomolibgpu/prep/normalize.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def normalize(
4343
data: cp.ndarray,
4444
flats: cp.ndarray,
4545
darks: cp.ndarray,
46+
flats_multiplier: float = 1.0,
47+
darks_multiplier: float = 1.0,
4648
cutoff: float = 10.0,
4749
minus_log: bool = True,
4850
nonnegativity: bool = False,
@@ -60,13 +62,17 @@ def normalize(
6062
3D flat field data as a CuPy array.
6163
darks : cp.ndarray
6264
3D dark field data as a CuPy array.
63-
cutoff : float, optional
65+
flats_multiplier: float
66+
A multiplier to apply to flats, can work as an intensity compensation constant.
67+
darks_multiplier: float
68+
A multiplier to apply to darks, can work as an intensity compensation constant.
69+
cutoff : float
6470
Permitted maximum value for the normalised data.
65-
minus_log : bool, optional
71+
minus_log : bool
6672
Apply negative log to the normalised data.
67-
nonnegativity : bool, optional
73+
nonnegativity : bool
6874
Remove negative values in the normalised data.
69-
remove_nans : bool, optional
75+
remove_nans : bool
7076
Remove NaN and Inf values in the normalised data.
7177
7278
Returns
@@ -82,6 +88,9 @@ def normalize(
8288
mean(darks, axis=0, dtype=float32, out=dark0)
8389
mean(flats, axis=0, dtype=float32, out=flat0)
8490

91+
dark0 *= darks_multiplier
92+
flat0 *= flats_multiplier
93+
8594
kernel_name = "normalisation"
8695
kernel = r"""
8796
float denom = float(flats) - float(darks);

tests/test_prep/test_normalize.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,26 @@ def test_normalize(data, flats, darks, ensure_clean_memory):
3535
assert data_normalize.flags.c_contiguous
3636

3737

38+
def test_normalize_scale(data, flats, darks, ensure_clean_memory):
39+
# --- testing normalize ---#
40+
data_normalize = normalize(
41+
cp.copy(data),
42+
flats,
43+
darks,
44+
flats_multiplier=10.0,
45+
darks_multiplier=10.0,
46+
minus_log=True,
47+
).get()
48+
49+
assert data_normalize.dtype == np.float32
50+
51+
assert_allclose(np.mean(data_normalize), 2.5918312, rtol=1e-06)
52+
assert_allclose(np.mean(data_normalize, axis=(1, 2)).sum(), 466.5298, rtol=1e-06)
53+
assert_allclose(np.median(data_normalize), 2.3198225, rtol=1e-06)
54+
assert_allclose(np.std(data_normalize), 0.5243825, rtol=1e-06)
55+
assert data_normalize.flags.c_contiguous
56+
57+
3858
@pytest.mark.perf
3959
def test_normalize_performance(ensure_clean_memory):
4060
# Note: low/high and size values taken from sample2_medium.yaml real run

0 commit comments

Comments
 (0)