mirror of
https://github.com/bec-project/ophyd_devices.git
synced 2025-06-13 14:57:14 +02:00
fix: sim_monitor negative readback fixed
This commit is contained in:
@ -453,12 +453,12 @@ class SimulatedDataMonitor(SimulatedDataBase):
|
|||||||
int: Value with added noise.
|
int: Value with added noise.
|
||||||
"""
|
"""
|
||||||
if noise == NoiseType.POISSON:
|
if noise == NoiseType.POISSON:
|
||||||
v = np.random.poisson(v)
|
v = np.ceil(np.random.poisson(v)).astype(int)
|
||||||
return v
|
return v
|
||||||
elif noise == NoiseType.UNIFORM:
|
elif noise == NoiseType.UNIFORM:
|
||||||
noise = np.ceil(np.random.uniform(0, 1) * noise_multiplier).astype(int)
|
noise = np.ceil(np.random.uniform(0, 1) * noise_multiplier).astype(int)
|
||||||
v += noise * (np.random.randint(0, 2) * 2 - 1)
|
v += noise * (np.random.randint(0, 2) * 2 - 1)
|
||||||
return v
|
return v if v > 0 else 0
|
||||||
return v
|
return v
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,11 +39,27 @@ def test_monitor__init__(monitor):
|
|||||||
assert isinstance(monitor, BECDevice)
|
assert isinstance(monitor, BECDevice)
|
||||||
|
|
||||||
|
|
||||||
def test_monitor_readback(monitor):
|
@pytest.mark.parametrize("center", [-10, 0, 10])
|
||||||
|
def test_monitor_readback(monitor, center):
|
||||||
"""Test the readback method of SimMonitor."""
|
"""Test the readback method of SimMonitor."""
|
||||||
for model_name in monitor.sim.sim_get_models():
|
for model_name in monitor.sim.sim_get_models():
|
||||||
monitor.sim.sim_select_model(model_name)
|
monitor.sim.sim_select_model(model_name)
|
||||||
|
monitor.sim.sim_params["noise_multipler"] = 10
|
||||||
|
if "c" in monitor.sim.sim_params:
|
||||||
|
monitor.sim.sim_params["c"] = center
|
||||||
|
elif "center" in monitor.sim.sim_params:
|
||||||
|
monitor.sim.sim_params["center"] = center
|
||||||
assert isinstance(monitor.read()[monitor.name]["value"], monitor.BIT_DEPTH)
|
assert isinstance(monitor.read()[monitor.name]["value"], monitor.BIT_DEPTH)
|
||||||
|
expected_value = monitor.sim._model.eval(monitor.sim._model_params, x=0)
|
||||||
|
print(expected_value, monitor.read()[monitor.name]["value"])
|
||||||
|
tolerance = (
|
||||||
|
monitor.sim.sim_params["noise_multipler"] + 1
|
||||||
|
) # due to ceiling in calculation, but maximum +1int
|
||||||
|
assert np.isclose(
|
||||||
|
monitor.read()[monitor.name]["value"],
|
||||||
|
expected_value,
|
||||||
|
atol=monitor.sim.sim_params["noise_multipler"] + 1,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_camera__init__(camera):
|
def test_camera__init__(camera):
|
||||||
|
Reference in New Issue
Block a user