Skip to content

Commit

Permalink
small edit to add_noise
Browse files Browse the repository at this point in the history
  • Loading branch information
profxj committed Mar 30, 2016
1 parent 7f4b83e commit 5a38269
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions linetools/spectra/xspectrum1d.py
Expand Up @@ -337,7 +337,7 @@ def set_diagnostics(self):
self._wvmax = np.max(self.wavelength[gdpx])

# Add noise
def add_noise(self, seed=None, s2n=None):
def add_noise(self, seed=None, s2n=None, rstate=None):
"""Add noise to the spectrum.
Uses the uncertainty array unless s2n is specified.
Expand All @@ -349,16 +349,20 @@ def add_noise(self, seed=None, s2n=None):
s2n : float, optional
S/N per pixel for the output spectrum. If None, use the
uncertainty array.
rstate : RandomState
allows regeneration of the same noise
Returns
-------
newspec : A new XSpectrum1D with noise added
"""
# Seed
np.random.seed(seed=seed)
if rstate is None:
rstate=np.random.RandomState(seed)

# Random numbers
rand = np.random.normal(size=self.npix)
#rand = np.random.normal(size=self.npix)
rand = rstate.randn(self.npix)

# Modify the flux
if s2n is not None:
Expand Down

0 comments on commit 5a38269

Please sign in to comment.