comyx.utils#

Package Summary#

Functions#

db2pow(→ NDArrayFloat)

Convert power in decibels to watts.

dbm2pow(→ NDArrayFloat)

Convert decibels relative to 1 milliwatt to watts.

ensure_list(→ List[Any])

Ensure that the argument is a list of desired length.

generate_seed(→ int)

Generate a seed from an identifier.

get_distance(→ float)

Calculate the Euclidean distance between two points.

inverse_qfunc(→ NDArrayFloat)

Inverse Q function.

laguerre(→ Union[float, NDArrayFloat])

Compute the Laguerre polynomial.

pow2db(→ NDArraySigned)

Convert power in watts to decibels.

pow2dbm(→ NDArraySigned)

Convert power in watts to decibels relative to 1 milliwatt.

qfunc(→ NDArrayFloat)

Compute the Q function.

rolling_mean(→ NDArrayFloat)

Compute the rolling mean of a curve.

wrap_to_2pi(→ NDArrayFloat)

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

Reference#

comyx.utils.db2pow(db: float | NDArrayFloat) NDArrayFloat[source]#

Convert power in decibels to watts.

Parameters:

db – Power in decibels.

Returns:

Power in watts.

comyx.utils.dbm2pow(dbm: float | NDArrayFloat) NDArrayFloat[source]#

Convert decibels relative to 1 milliwatt to watts.

Parameters:

dbm – Power in decibels relative to 1 milliwatt.

Returns:

Power in watts.

comyx.utils.ensure_list(arg, length) List[Any][source]#

Ensure that the argument is a list of desired length.

Parameters:
  • arg – The argument to check.

  • length – The desired length of the list.

Returns:

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

comyx.utils.generate_seed(identifier: str) int[source]#

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.

Parameters:

identifier – The identifier to hash.

Returns:

A seed for random number generation.

comyx.utils.get_distance(pt1: List[Any], pt2: List[Any]) float[source]#

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
Parameters:
  • pt1 – The first point.

  • pt2 – The second point.

Returns:

The Euclidean distance between the two points.

comyx.utils.inverse_qfunc(x: float | NDArrayFloat) NDArrayFloat[source]#

Inverse Q function.

Parameters:

x – Input to the inverse Q function.

Returns:

Inverse Q function computed at x.

comyx.utils.laguerre(x: float | NDArrayFloat, n: float) float | NDArrayFloat[source]#

Compute the Laguerre polynomial.

Parameters:
  • x – Input to the Laguerre polynomial.

  • n – The order of the Laguerre polynomial.

Returns:

Laguerre polynomial computed at x and order n.

comyx.utils.pow2db(power: float | NDArrayFloat) NDArraySigned[source]#

Convert power in watts to decibels.

Parameters:

power – Power in watts.

Returns:

Power in decibels.

comyx.utils.pow2dbm(power: float | NDArrayFloat) NDArraySigned[source]#

Convert power in watts to decibels relative to 1 milliwatt.

Parameters:

pow – Power in watts.

Returns:

Power in decibels relative to 1 milliwatt.

comyx.utils.qfunc(x: float | NDArrayFloat) NDArrayFloat[source]#

Compute the Q function.

Parameters:

x – Input to the Q function.

Returns:

Q function computed at x.

comyx.utils.rolling_mean(data: NDArrayFloat, window_size: int) NDArrayFloat[source]#

Compute the rolling mean of a curve.

Parameters:
  • data – The curve to filter.

  • window_size – The size of the window.

Returns:

Data list with the rolling mean applied.

comyx.utils.wrap_to_2pi(theta: NDArrayFloat) NDArrayFloat[source]#

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

Parameters:

theta – The angle to wrap.

Returns:

The wrapped angle.