﻿# Copyright 2014-2016 The ODL development group
#
# This file is part of ODL.
#
# ODL is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ODL is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ODL.  If not, see <http://www.gnu.org/licenses/>.

"""Functions to create noise samples of different distributions."""

# Imports for common Python 2/3 codebase
from __future__ import print_function, division, absolute_import
from future import standard_library
standard_library.install_aliases()

import numpy as np


__all__ = ('white_noise',)


def white_noise(space):
    """Standard gaussian noise in space, pointwise N(0, 1).

    """
    values = np.random.randn(*space.shape)
    return space.element(values)


if __name__ == '__main__':
    # Show the phantoms
    import odl

    discr = odl.uniform_discr([-1, -1], [1, 1], [300, 300])
    white_noise(discr).show('white_noise')

    # Run also the doctests
    # pylint: disable=wrong-import-position
    from odl.util.testutils import run_doctests
    run_doctests()

@@ -975,16 +975,32 @@
 _noise',
+ 'poisson_noise'
 )%0A%0A%0Adef 
@@ -1088,66 +1088,1043 @@
     
-%22%22%22%0A    values = np.random.randn(*space.shape)%0A    return 
+Parameters%0A    ----------%0A    space : %60FnBase%60%0A        The space that the noise should be created in%0A%0A    Returns%0A    -------%0A    white_noise : %60%60space%60%60 element%0A%0A    See Also%0A    --------%0A    poisson_noise%0A    numpy.random.randn%0A    %22%22%22%0A    values = np.random.randn(*space.shape)%0A    return space.element(values)%0A%0A%0Adef poisson_noise(intensity):%0A    %22%22%22Poisson distributed noise with given intensity.%0A%0A    Parameters%0A    ----------%0A    intensity : %60FnBase%60%0A        The intensity (usually called lambda) parameter of the noise.%0A%0A    Returns%0A    -------%0A    poisson_noise : %60%60intensity.space%60%60 element%0A        Poisson distributed random variable.%0A%0A    Notes%0A    -----%0A    The probability density function for value :math:%60k%60 and intensity%0A    :math:%60%5C%5Clambda%60 is given by:%0A%0A    .. math::%0A        %5C%5Cfrac%7B%5C%5Clambda%5Ek e%5E%7B-%5C%5Clambda%7D%7D%7Bk!%7D%0A%0A    Note that the function only takes integer values.%0A%0A    See Also%0A    --------%0A    white_noise%0A    numpy.random.poisson%0A    %22%22%22%0A    values = np.random.poisson(intensity.asarray())%0A    return intensity.
 spac

Add poisson_noise, closes #629