credit.pol_lapdiff_filt
=======================

.. py:module:: credit.pol_lapdiff_filt


Attributes
----------

.. autoapisummary::

   credit.pol_lapdiff_filt.device


Classes
-------

.. autoapisummary::

   credit.pol_lapdiff_filt.Diffusion_and_Pole_Filter


Functions
---------

.. autoapisummary::

   credit.pol_lapdiff_filt.polfiltT
   credit.pol_lapdiff_filt.create_sigmoid_ramp_function
   credit.pol_lapdiff_filt.find_nearest


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

.. py:function:: polfiltT(D, inddo)

.. py:function:: create_sigmoid_ramp_function(array_length, ramp_length)

   Creates an array of specified length with a sigmoid ramp up and down.

   :param array_length: The length of the output array.
   :param ramp_length: The length of the ramp up and down.

   :returns: An array of the specified length with the described ramp up and down using a sigmoid function.


.. py:function:: find_nearest(array, value)

   find nearest index in array


.. py:class:: Diffusion_and_Pole_Filter(nlat, nlon, device='cpu', lmax=None, mmax=None, grid='legendre-gauss', radius=6371220.0, omega=7.292e-05, gravity=9.80616, havg=10000.0, hamp=120.0)

   A class designed to encapsulate operations related to diffusion and pole filtering
   with spherical harmonics transformations


   .. py:attribute:: nlat


   .. py:attribute:: nlon


   .. py:attribute:: device
      :value: 'cpu'



   .. py:attribute:: lmax
      :value: None



   .. py:attribute:: mmax
      :value: None



   .. py:attribute:: grid
      :value: 'legendre-gauss'



   .. py:attribute:: radius
      :value: 6371220.0



   .. py:attribute:: omega
      :value: 7.292e-05



   .. py:attribute:: gravity
      :value: 9.80616



   .. py:attribute:: havg
      :value: 10000.0



   .. py:attribute:: hamp
      :value: 120.0



   .. py:attribute:: indpol
      :value: 10



   .. py:attribute:: sigmoid


   .. py:method:: load_data(filename)


   .. py:method:: initialize_sht()

      Initialize spherical harmonics and inverse spherical harmonics transformations
      for both scalar and vector fields.



   .. py:method:: initialize_other_properties()

      Initialize additional properties required for diffusion and pole filtering,
      including latitude and longitude arrays, Laplacian operators, and Coriolis effect.



   .. py:method:: grid2spec(ugrid)

      spectral coefficients from spatial data



   .. py:method:: spec2grid(uspec)

      spatial data from spectral coefficients



   .. py:method:: vrtdivspec(ugrid)

      spatial data from spectral coefficients



   .. py:method:: getuv(vrtdivspec)

      compute wind vector from spectral coeffs of vorticity and divergence



   .. py:method:: getgrad(chispec)

      compute vector gradient on grid given complex spectral coefficients.

      :param chispec: rank 1 or 2 or 3 tensor complex array with shape

      `(ntrunc+1)*(ntrunc+2)/2 or ((ntrunc+1)*(ntrunc+2)/2,nt)` containing
      complex spherical harmonic coefficients (where ntrunc is the
      triangular truncation limit and nt is the number of spectral arrays
      to be transformed). If chispec is rank 1, nt is assumed to be 1.

      :returns: C{B{uchi, vchi}} - rank 2 or 3 numpy float32 arrays containing

      gridded zonal and meridional components of the vector gradient.
      Shapes are either (nlat,nlon) or (nlat,nlon,nt).



   .. py:method:: polefilt_lap2d_V2(U, V, substeps)

      Enhances the characteristics of a two-dimensional (2D) vector field by applying a
      combination of pole filtering and Laplacian-based correction. This function is
      designed to refine the input vector field by selectively suppressing the influence
      of specific poles and adjusting the field to better reflect physical constraints
      and properties. It achieves this through a sequence of operations in the spectral
      domain, focusing on the field's divergence, vorticity, and Laplacian characteristics.

      The process involves initial pole filtering to mitigate the effects of unwanted
      features followed by a detailed correction phase that leverages the field's
      Laplacian to enforce smoothness and continuity. The correction phase is further
      enhanced by considering the field's divergence and vorticity, ensuring that the
      final vector field adheres more closely to the expected physical behavior.

      :param U: The x-component of the velocity or vector field. This tensor should
      :type U: Tensor
      :param represent one of the two dimensions of the field:
      :param with spatial dimensions that:
      :param match those of the V component.:
      :param V: The y-component of the velocity or vector field. This tensor complements the U component
      :type V: Tensor
      :param by representing the second dimension of the field.:
      :param substeps: The number of iterations for the correction process. This parameter
      :type substeps: int
      :param controls the depth of the refinement process:
      :param with more substeps leading to a more:
      :param pronounced adjustment of the vector field.:

      :returns: A tuple containing the modified x and y components (U, V) of the
                vector field after the pole filtering and Laplacian-based correction have been applied.
                These components will have undergone adjustments to suppress specified poles and to
                refine their characteristics based on divergence, vorticity, and Laplacian considerations.
      :rtype: Tuple[Tensor, Tensor]



   .. py:method:: polefilt_lap2d_V1(T, substeps)

      Applies a pole filtering transformation followed by a Laplacian-based correction
      to a scalar in 2D space.

      The function aims to modify the scalar field to suppress
      features associated with specified poles, and to adjust the field based on
      its divergence, vorticity, and Laplacian properties through a series of
      spectral domain operations.

      :param T: scalar-component of the velocity or vector field.
      :type T: Tensor
      :param substeps: number of substeps

      :returns: The modified T components of the scalar field.
      :rtype: Tuple of Tensors



   .. py:method:: polefilt_lap2d_QV1(T, substeps)

      Applies a pole filtering transformation followed by a Laplacian-based correction
      to a scalar in 2D space.

      The function aims to modify the scalar field to suppress
      features associated with specified poles, and to adjust the field based on
      its divergence, vorticity, and Laplacian properties through a series of
      spectral domain operations.

      :param T: scalar-component of the velocity or vector field.
      :type T: Tensor
      :param ind_pol: Index/indices specifying poles for the filtering process.
      :type ind_pol: list/int

      :returns: The modified T components of the scalar field.
      :rtype: Tuple of Tensors



   .. py:method:: diff_lap2d_filt(BB2_tensor)


.. py:data:: device

