Skip to content

Commit

Permalink
Fix position noise ignoring unit of sigma
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonHeybrock committed Feb 5, 2025
1 parent e9473d8 commit f21e22b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/ess/reduce/live/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,12 @@ def position_noise_for_cylindrical_pixel(


def gaussian_position_noise(sigma: PositionNoiseSigma) -> PositionNoise:
sigma = sigma.to(unit='m', copy=False)
size = _noise_size
position = sc.empty(sizes={'position': size}, unit='m', dtype=sc.DType.vector3)
position.values = np.random.default_rng().normal(0, sigma.value, size=(size, 3))
position.values = np.random.default_rng(seed=1234).normal(
0, sigma.value, size=(size, 3)
)
return PositionNoise(position)


Expand Down
11 changes: 11 additions & 0 deletions tests/live/raw_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
from ess.reduce.live import raw


@pytest.mark.parametrize(
'sigma',
[sc.scalar(0.01, unit='m'), sc.scalar(1.0, unit='cm'), sc.scalar(10.0, unit='mm')],
)
def test_gaussian_position_noise_is_sigma_unit_independent(sigma: sc.Variable) -> None:
sigma_m = sigma.to(unit='m')
reference = raw.gaussian_position_noise(sigma=sigma_m)
noise = raw.gaussian_position_noise(sigma=sigma)
assert sc.identical(noise, reference)


def test_clear_counts_resets_counts_to_zero() -> None:
detector_number = sc.array(dims=['pixel'], values=[1, 2, 3], unit=None)
det = raw.Detector(detector_number)
Expand Down

0 comments on commit f21e22b

Please sign in to comment.