mirror of
https://github.com/bec-project/ophyd_devices.git
synced 2026-02-04 14:18:41 +01:00
fix: make SimulatedDataMonitor robust to inf/nan
This commit is contained in:
@@ -6,6 +6,7 @@ import time as ttime
|
||||
from abc import ABC, abstractmethod
|
||||
from collections import defaultdict
|
||||
from copy import deepcopy
|
||||
from math import copysign, isinf, isnan
|
||||
|
||||
import numpy as np
|
||||
from bec_lib import bec_logger
|
||||
@@ -72,6 +73,14 @@ DEFAULT_PARAMS_HOT_PIXEL = {
|
||||
}
|
||||
|
||||
|
||||
def _safeint(val: float) -> int:
|
||||
if isnan(val):
|
||||
return 0
|
||||
if isinf(val):
|
||||
return int(copysign(2_147_483_647, val))
|
||||
return int(val)
|
||||
|
||||
|
||||
class SimulatedDataBase(ABC):
|
||||
"""Abstract base class for simulated data.
|
||||
|
||||
@@ -429,7 +438,7 @@ class SimulatedDataMonitor(SimulatedDataBase):
|
||||
else:
|
||||
motor_pos = 0
|
||||
method = self._model
|
||||
value = int(method.eval(params=self._model_params, x=motor_pos))
|
||||
value = _safeint(method.eval(params=self._model_params, x=motor_pos))
|
||||
return self._add_noise(value, self.params["noise"], self.params["noise_multiplier"])
|
||||
|
||||
def _add_noise(self, v: int, noise: NoiseType, noise_multiplier: float) -> int:
|
||||
|
||||
Reference in New Issue
Block a user