<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
    _Back.py

    The inverse Radon transform with non-iterative techniques.
"""

from __future__ import division

import sys

from . import _Back as back2d
from . import _Back_iterative as back2d_it
from . import _Back_3D as back3d

__all__ = back2d.__all__ + back2d_it.__all__


def art(sinogram, angles, initial=None, iterations=1,
        jmc=None, jmm=None):
    u""" Algebraic Reconstruction Technique

    The Algebraic Reconstruction Technique (ART) iteratively
    computes the inverse of the Radon transform in two dimensions.
    The reconstruction technique uses *rays* of the diameter of
    one pixel to iteratively solve the system of linear equations
    that describe the projection process. The binary weighting
    factors are

     - 1, if the center of the a pixel is within the *ray*
     - 0, else


    Parameters
    ----------
    sinogram : ndarray, shape (A,N) or (A,M,N)
        Two- or three-dimensional sinogram of line recordings. If the
        sinogram is three-dimensional, the dimension `M` iterates 
        through the slices. The rotation takes place through
        the second (y) axis.
    angles : ndarray, length A
        Angular positions of the `sinogram` in radians. The angles
        at which the sinogram slices were recorded do not have to be
        distributed equidistantly as in :func:`backproject`.
        The angles are internaly converted to modulo PI.
    initial : ndarray, shape (N,N) or (N,M,N), optional
        The initial guess for the solution.
    iterations : int
        Number of iterations to perform.
    jmc, jmm : instance of :func:`multiprocessing.Value` or `None`
        The progress of this function can be monitored with the 
        :mod:`jobmanager` package. The current step `jmc.value` is
        incremented `jmm.value` times. `jmm.value` is set at the 
        beginning.


    Returns
    -------
    out : ndarray, shape (N,N) or (N,M,N)
        The reconstructed image.


    See Also
    --------
    sart : simultaneous algebraic reconstruction technique


    Notes
    -----
    For theoretical backround, see
    <NAME>., & <NAME>.. *Principles of Computerized
    Tomographic Imaging*, SIAM, (2001)

    Sec. 7.2:
    *"ART reconstrutions usually suffer from salt and pepper noise,
    which is caused by the inconsitencies introuced in the set of
    equations by the approximations commonly used for* 
    :math:`w_{ik}` *'s."*
    """
    # This is a convenience function that wraps 2d and 3d
    # collect all arguments
    code = sys._getframe().f_code
    keys = code.co_varnames[:code.co_argcount]
    kwargs = dict()
    lcs = locals()
    for key in list(keys):
        kwargs[key] = lcs[key]

    return two_three_dim_recon(code, kwargs)


def backproject(sinogram, angles, filtering="ramp",
                padding=True, padval=0,
                jmc=None, jmm=None, verbose=0):
    u""" Backprojection with the Fourier slice theorem

    Computes the inverse of the radon transform using filtered
    backprojection.


    Parameters
    ----------
    sinogram : ndarray, shape (A,N) or (A,M,N)
        Two- or three-dimensional sinogram of line recordings. If the
        sinogram is three-dimensional, the dimension `M` iterates 
        through the slices. The rotation takes place through
        the second (y) axis.
    angles : (A,) ndarray
        Angular positions of the `sinogram` in radians equally
        distributed from zero to PI.
    filtering : {'ramp', 'shepp-logan', 'cosine', 'hamming', \
                 'hann'}, optional
        Specifies the Fourier filter. Either of

        ``ramp``
          mathematically correct reconstruction

        ``shepp-logan``

        ``cosine``

        ``hamming``

        ``hann``

    padding : bool, optional
        Pad the input data to the second next power of 2 before
        Fourier transforming. This reduces artifacts and speeds up
        the process for input image sizes that are not powers of 2.
    padval : float
        The value used for padding.
        If `padval` is `None`, then the edge values are used for
        padding (see documentation of `numpy.pad`).
    jmc, jmm : instance of :func:`multiprocessing.Value` or `None`
        The progress of this function can be monitored with the 
        :mod:`jobmanager` package. The current step `jmc.value` is
        incremented `jmm.value` times. `jmm.value` is set at the 
        beginning.
    verbose : int
        Increment to increase verbosity.


    Returns
    -------
    out : ndarray, shape (N,N) or (N,M,N)
        The reconstructed image.


    Examples
    --------
    >>> import numpy as np
    >>> from radontea import backproject
    >>> N = 5
    >>> A = 7
    >>> x = np.linspace(-N/2, N/2, N)
    >>> projection = np.exp(-x**2)
    >>> sinogram = np.tile(projection, A).reshape(A,N)
    >>> angles = np.linspace(0, np.pi, A, endpoint=False)
    >>> backproject(sinogram, angles)
    array([[ 0.03813283, -0.01972347, -0.02221885,  0.03822303,  0.01903376],
           [ 0.04033526, -0.01591647,  0.02262173,  0.04203002,  0.02123619],
           [ 0.02658797,  0.11375576,  0.41525594,  0.17170226,  0.0074889 ],
           [ 0.04008672,  0.11139209,  0.27650193,  0.16933859,  0.02098764],
           [ 0.02140445,  0.0334597 ,  0.07691547,  0.0914062 ,  0.00230537]])


    See Also
    --------
    fourier_map : implementation by Fourier interpolation
    sum : implementation by summation in real space
    """
    # This is a convenience function that wraps 2d and 3d
    # collect all arguments
    code = sys._getframe().f_code
    keys = code.co_varnames[:code.co_argcount]
    kwargs = dict()
    lcs = locals()
    for key in list(keys):
        kwargs[key] = lcs[key]
<commit_msg>doc update<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
    _Back.py

    The inverse Radon transform with non-iterative techniques.
"""

from __future__ import division

import sys

from . import _Back as back2d
from . import _Back_iterative as back2d_it
from . import _Back_3D as back3d

__all__ = back2d.__all__ + back2d_it.__all__


def art(sinogram, angles, initial=None, iterations=1,
        jmc=None, jmm=None):
    u""" Algebraic Reconstruction Technique

    The Algebraic Reconstruction Technique (ART) iteratively
    computes the inverse of the Radon transform in two dimensions.
    The reconstruction technique uses *rays* of the diameter of
    one pixel to iteratively solve the system of linear equations
    that describe the projection process. The binary weighting
    factors are

     - 1, if the center of the a pixel is within the *ray*
     - 0, else


    Parameters
    ----------
    sinogram : ndarray, shape (A,N) or (A,M,N)
        Two- or three-dimensional sinogram of line recordings. If the
        sinogram is three-dimensional, the dimension `M` iterates 
        through the slices. The rotation takes place through
        the second (y) axis.
    angles : ndarray, length A
        Angular positions of the `sinogram` in radians. The angles
        at which the sinogram slices were recorded do not have to be
        distributed equidistantly as in :func:`backproject`.
        The angles are internaly converted to modulo PI.
    initial : ndarray, shape (N,N) or (N,M,N), optional
        The initial guess for the solution.
    iterations : int
        Number of iterations to perform.
    jmc, jmm : instance of :func:`multiprocessing.Value` or `None`
        The progress of this function can be monitored with the 
        :mod:`jobmanager` package. The current step `jmc.value` is
        incremented `jmm.value` times. `jmm.value` is set at the 
        beginning.


    Returns
    -------
    out : ndarray, shape (N,N) or (N,M,N)
        The reconstructed image.


    See Also
    --------
    sart : simultaneous algebraic reconstruction technique


    Notes
    -----
    For theoretical backround, see
    <NAME>., & <NAME>.. *Principles of Computerized
    Tomographic Imaging*, SIAM, (2001)

    Sec. 7.2:
    *"ART reconstrutions usually suffer from salt and pepper noise,
    which is caused by the inconsitencies introuced in the set of
    equations by the approximations commonly used for* 
    :math:`w_{ik}` *'s."*
    """
    # This is a convenience function that wraps 2d and 3d
    # collect all arguments
    code = sys._getframe().f_code
    keys = code.co_varnames[:code.co_argcount]
    kwargs = dict()
    lcs = locals()
    for key in list(keys):
        kwargs[key] = lcs[key]

    return two_three_dim_recon(code, kwargs)


def backproject(sinogram, angles, filtering="ramp",
                padding=True, padval=0,
                jmc=None, jmm=None, verbose=0):
    u""" Backprojection with the Fourier slice theorem

    Computes the inverse of the radon transform using filtered
    backprojection.


    Parameters
    ----------
    sinogram : ndarray, shape (A,N) or (A,M,N)
        Two- or three-dimensional sinogram of line recordings. If the
        sinogram is three-dimensional, the dimension `M` iterates 
        through the slices. The rotation takes place through
        the second (y) axis.
    angles : (A,) ndarray
        Angular positions of the `sinogram` in radians equally
        distributed from zero to PI.
    filtering : {'ramp', 'shepp-logan', 'cosine', 'hamming', \
                 'hann'}, optional
        Specifies the Fourier filter. Either of

        ``ramp``
          mathematically correct reconstruction

        ``shepp-logan``

        ``cosine``

        ``hamming``

        ``hann``

    padding : bool, optional
        Pad the input data to the second next power of 2 before
        Fourier transforming. This reduces artifacts and speeds up
        the process for input image sizes that are not powers of 2.
    padval : float
        The value used for padding.
        If `padval` is `None`, then the edge values are used for
        padding (see documentation of `numpy.pad`).
    jmc, jmm : instance of :func:`multiprocessing.Value` or `None`
        The progress of this function can be monitored with the 
        :mod:`jobmanager` package. The current step `jmc.value` is
        incremented `jmm.value` times. `jmm.value` is set at the 
        beginning.
    verbose : int
        Increment to increase verbosity.


    Returns
    -------
    out : ndarray, shape (N,N) or (N,M,N)
        The reconstructed image.


    Examples
    --------
    >>> import numpy as np
    >>> from radontea import backproject
    >>> N = 5
    >>> A = 7
    >>> x = np.linspace(-N/2, N/2, N)
    >>> projection = np.exp(-x**2)
    >>> sinogram = np.tile(projection, A).reshape(A,N)
    >>> angles = np.linspace(0, np.pi, A, endpoint=False)
    >>> backproject(sinogram, angles)
    array([[ 0.03768159, -0.02020189, -0.02287825,  0.03766525,  0.01771381],
           [ 0.03945197, -0.01662539,  0.02187192,  0.04124174,  0.0194842 ],
           [ 0.02491933,  0.11287706,  0.41412685,  0.17074419,  0.00495156],
           [ 0.03915731,  0.10966977,  0.27540441,  0.16753691,  0.01918954],
           [ 0.02052438,  0.03156967,  0.07341154,  0.08943681,  0.0005566 ]])


    See Also
    --------
    fourier_map : implementation by Fourier interpolation
    sum : implementation by summation in real space
    """
    # This is a convenience function that wraps 2d and 3d
    # collect all arguments
    code = sys._getframe().f_code
    keys = code.co_varnames[:code.co_argcount]
    kwargs = dict()
    lcs = locals()
    for key in list(keys):
        kwargs[key] = lcs[key]

{'fraction_non_alphanumeric': 0.0994589023447565, 'fraction_numerical': 0.04337370093618483, 'mean_word_length': 2.401694420099328, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1840294', 'n_tokens_mistral': 3862, 'n_tokens_neox': 3450, 'n_words': 1251}