diff --git a/docs/source/map_scanning.rst b/docs/source/map_scanning.rst index 8f7424ab..d82cdb58 100644 --- a/docs/source/map_scanning.rst +++ b/docs/source/map_scanning.rst @@ -174,7 +174,7 @@ transparent: sim.fill_tods(sky_signal) - sim.add_noise(noise_type='white', random=sim.random) + sim.add_noise(noise_type='white') for i in range(5): print(f"{sim.observations[0].tod[0][i]:.5e}") diff --git a/docs/source/noise.rst b/docs/source/noise.rst index 5cc86214..0b7c376f 100644 --- a/docs/source/noise.rst +++ b/docs/source/noise.rst @@ -241,7 +241,7 @@ the interface is simplified. sim.create_observations(detectors=det) - sim.add_noise(noise_type='one_over_f', random=sim.random) + sim.add_noise(noise_type='one_over_f') for i in range(5): print(f"{sim.observations[0].tod[0][i]:.5e}") diff --git a/litebird_sim/simulations.py b/litebird_sim/simulations.py index 5085cac1..883c50c2 100644 --- a/litebird_sim/simulations.py +++ b/litebird_sim/simulations.py @@ -1548,7 +1548,7 @@ def apply_quadratic_nonlin( @_profile def add_noise( self, - random: np.random.Generator, + random: Union[np.random.Generator, None] = None, noise_type: str = "one_over_f", component: str = "tod", append_to_report: bool = True, @@ -1558,11 +1558,14 @@ def add_noise( This method must be called after having set the instrument, the list of detectors to simulate through calls to :meth:`.set_instrument` and :meth:`.add_detector`. - The parameter `random` must be specified and must be a random number - generator thatimplements the ``normal`` method. You should typically - use the `random` field of a :class:`.Simulation` object for this. + The parameter `random` can be specified as a random number + generator that implements the ``normal`` method. As default it uses + the `random` field of a :class:`.Simulation` object for this. """ + if random is None: + random = self.random + add_noise_to_observations( observations=self.observations, noise_type=noise_type,