tjpcov.wigner_transform
=======================

.. py:module:: tjpcov.wigner_transform


Classes
-------

.. autoapisummary::

   tjpcov.wigner_transform.WignerTransform


Functions
---------

.. autoapisummary::

   tjpcov.wigner_transform.wigner_d
   tjpcov.wigner_transform.wigner_d_parallel
   tjpcov.wigner_transform.bin_cov


Module Contents
---------------

.. py:class:: WignerTransform(theta, ell, s1_s2, ncpu=None)

   Class to compute curved sky Hankel transforms with wigner-d matrices.

   Initialize the class for the given angles, scales and spins.

   :param theta: Values of angular separation, theta, at which the Hankel
                 transform is done. Should be in radians.
   :param ell: ell values at which the Hankel transform is done. Should be
               integers
   :param s1_s2: List of spin pairs of the tracers. Each spin pair should be
                 a tuple. e.g. for 3X2 analysis, pass
                 [(0,0),(0,2),(2,2),(2,-2)].

                 (0,0): (galaxy,galaxy)
                 (0,2): (galaxy,shear). (2,0) is equivalent.
                 (2,2): (shear,shear), xi+
                 (2,-2): (shear,shear), xi-
   :param ncpu: Number of python processes to use when computing wigner-d
                matrices.


   .. py:attribute:: name
      :value: 'Wigner'



   .. py:attribute:: ell


   .. py:attribute:: grad_ell


   .. py:attribute:: norm


   .. py:attribute:: grad_theta


   .. py:attribute:: inv_norm


   .. py:attribute:: inv_wig_norm


   .. py:attribute:: wig_d


   .. py:attribute:: wig_3j


   .. py:attribute:: s1_s2s


   .. py:attribute:: theta


   .. py:attribute:: taper_f
      :value: None



   .. py:attribute:: taper_f2
      :value: None



   .. py:method:: cl_grid(ell_cl, cl, taper=False, **taper_kwargs)

      Interpolate the input C_ell.

      This is done in case the ell values of C_ell are different from the
      grid on which wigner-d matrices were computed during intialization.

      :param ell_cl: ell at which the input C_ell is computed.
      :type ell_cl: array
      :param cl: input C_ell
      :type cl: array
      :param taper: if True apply the tapering to the input C_ell. Tapering can
                    help in reducing ringing.
      :type taper: bool

      :returns: C_ell evaluated at the initialization ells.
      :rtype: array



   .. py:method:: cl_cov_grid(ell_cl, cl_cov, taper=False, **taper_kwargs)

      Interpolate the input 2D covariances.

      This is done in case in case the ell values are different from the grid
      on which wigner-d matrices were computed during intialization.

      :param ell_cl: ell at which the input covariance was computed.
      :type ell_cl: array
      :param cl: input covariance
      :type cl: array
      :param taper: if True apply the tapering to the input C_ell.
                    Tapering can help in reducing ringing.
      :type taper: bool
      :param \*\*taper_kwargs: Arguments to pass to the tapering method

      :returns: covariance evaluated at the initialization ells.
      :rtype: array



   .. py:method:: projected_covariance(ell_cl, cl_cov, s1_s2, s1_s2_cross=None, taper=False, **kwargs)

      Convert C_ell covariance to correlation function.

      This function assumes that cl_cov is 2D matrix.

      :param cl_cov: C_ell covariance matrix.
      :param ell_cl: ell values at which input C_ell is computed.
      :param s1_s2: Tuple of the spin factors of the first set of tracers. Used
                    to identify the correct wigner-d matrix to use.
      :param s1_s2_cross: Tuple of the spin factors of the second set of
                          tracers, if different from s1_s2. Used to identify the correct
                          wigner-d matrix to use.
      :param taper: if True apply the tapering to the input C_ell.
                    Tapering can help in reducing ringing.
      :type taper: bool
      :param \*\*kwargs: Arguments to pass to the tapering method

      :returns:     - theta (array): angles given at initialization
                    - cov (array): real space covariance at the given angles
      :rtype: tuple



   .. py:method:: taper(ell, large_k_lower=10, large_k_upper=100, low_k_lower=0, low_k_upper=1e-05)
      :abstractmethod:


      Apply tapering to input C_ell.

      Tapering is useful to reduce the ringing. This function uses the cosine
      function to apply the tapering. See eq. 71 in
      https://arxiv.org/pdf/2105.04548.pdf for the function and meaning of
      input parameters.

      :param ell: ell values at which input C_ell is computed.
      :param large_k_lower:
      :param large_k_upper:
      :param low_k_lower:
      :param low_k_upper:



   .. py:method:: diagonal_err(cov)

      Returns the diagonal error from the covariance.

      Useful for errorbar plots.

      :param cov: Covariance
      :type cov: array

      :returns: Diagonal errors (i.e. sqrt(diag(cov)))
      :rtype: array



.. py:function:: wigner_d(s1, s2, theta, ell, l_use_bessel=10000.0)

   Function to compute the wigner-d matrices.

   :param s1: Spin factors for the wigner-d matrix.
   :param s2: Spin factors for the wigner-d matrix.
   :param theta: Angular separation for which to compute the wigner-d matrix. The
                 matrix depends on cos(theta).
   :param ell: The spherical harmonics mode ell for which to compute the matrix.
   :param l_use_bessel: Due to numerical issues, we need to switch from wigner-d
                        matrix to bessel functions at high ell (see the note below). This
                        defines the scale at which the switch happens.

   :returns: Wigner-d matrix
   :rtype: array


.. py:function:: wigner_d_parallel(s1, s2, theta, ell, ncpu=None, l_use_bessel=10000.0)

   Compute the wigner-d matrix in parallel using multiprocessing Pool.

   This function calls the wigner-d function defined above.

   :param s1: Spin factors for the wigner-d matrix.
   :param s2: Spin factors for the wigner-d matrix.
   :param theta: Angular separation for which to compute the wigner-d matrix. The
                 matrix depends on cos(theta).
   :param ell: The spherical harmonics mode ell for which to compute the matrix.
   :param ncpu: number of processes to use for computing the matrix.
   :param l_use_bessel: Due to numerical issues, we need to switch from wigner-d
                        matrix to bessel functions at high ell (see the note below). This
                        defines the scale at which the switch happens.

   :returns: Wigner-d matrix
   :rtype: array


.. py:function:: bin_cov(r, cov, r_bins)

   Function to apply the binning operator.

   This function works on both one dimensional vectors and two dimensional
   covariance covrices.

   :param r: theta or ell values at which the un-binned vector is computed.
   :param cov: Unbinned covariance. It also works for a vector of C_ell or xi
   :param r_bins: theta or ell bins to which the values should be binned.

   :returns: Binned covariance or vector of C_ell or xi
   :rtype: array_like


