new: Rng customization in NoiseMeasurement

This commit is contained in:
Benoît Sierro
2023-09-12 15:39:33 +02:00
parent d261759dc0
commit e0fc7aeed4
2 changed files with 3 additions and 2 deletions

View File

@@ -16,6 +16,7 @@ class NoiseMeasurement:
psd: np.ndarray psd: np.ndarray
phase: np.ndarray | None = None phase: np.ndarray | None = None
psd_interp: interp1d = field(init=False) psd_interp: interp1d = field(init=False)
rng: np.random.Generator = field(default_factory=np.random.default_rng)
_window_functions: ClassVar[dict[str, Callable[[int], np.ndarray]]] = {} _window_functions: ClassVar[dict[str, Callable[[int], np.ndarray]]] = {}
@classmethod @classmethod
@@ -190,7 +191,7 @@ class NoiseMeasurement:
freq, spec = self.sample_spectrum(nt, dt) freq, spec = self.sample_spectrum(nt, dt)
if phase is None: if phase is None:
phase = 2 * np.pi * np.random.rand(len(freq)) phase = 2 * np.pi * self.rng.random(len(freq))
time, dt = math.irfftfreq(freq, True) time, dt = math.irfftfreq(freq, True)
amp = np.sqrt(spec) * np.exp(1j * phase) amp = np.sqrt(spec) * np.exp(1j * phase)

View File

@@ -332,7 +332,7 @@ def _bundle_external_files(params: Parameters, io: PropagationIOHandler):
existing_files = set(io.keys()) existing_files = set(io.keys())
for _, value in params.items(): for _, value in params.items():
if isinstance(value, DataFile): if isinstance(value, DataFile):
data = value.load_data() data = value.load_bytes()
value.io = io value.io = io
value.prefix = "zip" value.prefix = "zip"