.. :html_theme.sidebar_secondary.remove:

:py:mod:`comyx.utils`
=====================

.. py:module:: comyx.utils


Package Summary
----------------


Functions
~~~~~~~~~

.. autoapisummary::

   comyx.utils.db2pow
   comyx.utils.dbm2pow
   comyx.utils.ensure_list
   comyx.utils.generate_seed
   comyx.utils.get_distance
   comyx.utils.inverse_qfunc
   comyx.utils.laguerre
   comyx.utils.pow2db
   comyx.utils.pow2dbm
   comyx.utils.qfunc
   comyx.utils.rolling_mean
   comyx.utils.wrap_to_2pi




Reference
---------

.. py:function:: db2pow(db: Union[float, NDArrayFloat]) -> NDArrayFloat

   Convert power in decibels to watts.

   :param db: Power in decibels.

   :returns: Power in watts.


.. py:function:: dbm2pow(dbm: Union[float, NDArrayFloat]) -> NDArrayFloat

   Convert decibels relative to 1 milliwatt to watts.

   :param dbm: Power in decibels relative to 1 milliwatt.

   :returns: Power in watts.


.. py:function:: ensure_list(arg, length) -> List[Any]

   Ensure that the argument is a list of desired length.

   :param arg: The argument to check.
   :param length: The desired length of the list.

   :returns: Argument repeated length times if it is not a list, otherwise the
             argument itself.


.. py:function:: generate_seed(identifier: str) -> int

   Generate a seed from an identifier.

   Seed is generated using the MD5 hash of the identifier. The hash is then
   converted to an integer and the modulo operation is applied to ensure the
   seed fits into a 32-bit integer.

   :param identifier: The identifier to hash.

   :returns: A seed for random number generation.


.. py:function:: get_distance(pt1: List[Any], pt2: List[Any]) -> float

   Calculate the Euclidean distance between two points.

   Points must have the same dimension and be a list of length 2 or 3.

   Example usage:
       >>> get_distance([0, 0], [1, 1])
       1.4142135623730951
       >>> get_distance([0, 0, 0], [1, 1, 1])
       1.7320508075688772

   :param pt1: The first point.
   :param pt2: The second point.

   :returns: The Euclidean distance between the two points.


.. py:function:: inverse_qfunc(x: Union[float, NDArrayFloat]) -> NDArrayFloat

   Inverse Q function.

   :param x: Input to the inverse Q function.

   :returns: Inverse Q function computed at x.


.. py:function:: laguerre(x: Union[float, NDArrayFloat], n: float) -> Union[float, NDArrayFloat]

   Compute the Laguerre polynomial.

   :param x: Input to the Laguerre polynomial.
   :param n: The order of the Laguerre polynomial.

   :returns: Laguerre polynomial computed at x and order n.


.. py:function:: pow2db(power: Union[float, NDArrayFloat]) -> NDArraySigned

   Convert power in watts to decibels.

   :param power: Power in watts.

   :returns: Power in decibels.


.. py:function:: pow2dbm(power: Union[float, NDArrayFloat]) -> NDArraySigned

   Convert power in watts to decibels relative to 1 milliwatt.

   :param pow: Power in watts.

   :returns: Power in decibels relative to 1 milliwatt.


.. py:function:: qfunc(x: Union[float, NDArrayFloat]) -> NDArrayFloat

   Compute the Q function.

   :param x: Input to the Q function.

   :returns: Q function computed at x.


.. py:function:: rolling_mean(data: NDArrayFloat, window_size: int) -> NDArrayFloat

   Compute the rolling mean of a curve.

   :param data: The curve to filter.
   :param window_size: The size of the window.

   :returns: Data list with the rolling mean applied.


.. py:function:: wrap_to_2pi(theta: NDArrayFloat) -> NDArrayFloat

   Wrap an angle to the interval [0, 2 * pi].

   :param theta: The angle to wrap.

   :returns: The wrapped angle.


