Skip to content

Commit

Permalink
Simulation.add_noise uses self.random as default
Browse files Browse the repository at this point in the history
  • Loading branch information
paganol committed Nov 20, 2024
1 parent dd4c0bf commit 3597369
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/source/map_scanning.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
2 changes: 1 addition & 1 deletion docs/source/noise.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
11 changes: 7 additions & 4 deletions litebird_sim/simulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 3597369

Please sign in to comment.