Skip to content

Commit

Permalink
Change the default behavior of Simulation.add_noise() (#349)
Browse files Browse the repository at this point in the history
* Simulation.add_noise uses self.random as default

* CHANGELOG updated
  • Loading branch information
paganol authored Nov 21, 2024
1 parent e7b14ea commit 210cd82
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@

- Make the code compatible with Python 3.12 [#332](https://github.com/litebird/litebird_sim/pull/332)

- plot_fp.py which visualizes focal plane and `DetectorInfo` is implemented.
- plot_fp.py which visualizes focal plane and `DetectorInfo` is implemented.
Also it can generate a dector list file by clicking visualized detectors.
The function is executable by: `python -m litebird_sim.plot_fp` [#345](https://github.com/litebird/litebird_sim/pull/345)

- Simulation.add_noise() uses self.random as default random number generator [#349](https://github.com/litebird/litebird_sim/pull/349)

# Version 0.13.0

- **Breaking change**: new API for pointing computation [#319](https://github.com/litebird/litebird_sim/pull/319). Here is a in-depth list of all the breaking changes in this PR:
Expand Down
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 210cd82

Please sign in to comment.