GSEGUtils.util

GSEGUtils.util This module provides utility functions and constants for angle conversion and numerical operations, along with an enumeration for specifying angle units.

class GSEGUtils.util.AngleUnit

Bases: StrEnum

Enumerator for angular units.

  • AngleUnit.RAD = ‘rad’

  • AngleUnit.DEGREE = ‘deg’

  • AngleUnit.GON = ‘gon’

RAD = 'rad'
DEGREE = 'deg'
GON = 'gon'
static _generate_next_value_(name, start, count, last_values)

Return the lower-cased version of the member name.

__new__(value)
GSEGUtils.util.convert_angles(values, source_unit, target_unit, out=None)

Converts an array of angles from one unit to another

Parameters:
  • values (Array_Float_T) – Array of angles to convert.

  • source_unit (AngleUnit) – Unit of the input angles

  • target_unit (AngleUnit) – Unit to convert the angles to.

  • out (Optional[Array_Float_T], default=None) – Optional output array to store the results. If provided, it must be the same shape as values.

Return type:

Array_Float_T

Notes

  • If source_unit and target_unit are the same, the function returns a copy of the input values unless out is provided, in which case it writes the result to out.

  • Supported conversions: - Radians ↔ Degrees - Radians ↔ Gradians - Degrees ↔ Gradians

Examples

Convert an array of angles from degrees to radians

>>> import numpy as np
>>> from pchandler.util import convert_angles, AngleUnit
>>> angles_deg = np.array([0, 90, 180, 360])
>>> convert_angles(angles_deg, AngleUnit.DEGREE, AngleUnit.RAD)
array([0.        , 1.57079633, 3.14159265, 6.28318531])

Convert angles from radians to gradians

>>> angles_rad = np.array([0, np.pi/2, np.pi, 2*np.pi])
>>> convert_angles(angles_rad, AngleUnit.RAD, AngleUnit.GON)
array([ 0., 100., 200., 400.])
GSEGUtils.util._rad2deg(values, out=None)

Convert radians to degrees.

Parameters:
Return type:

Array_Float_T|float|None

GSEGUtils.util._rad2gon(values, out=None)

Convert radians to gradians(gon).

Parameters:
Return type:

Array_Float_T|float|None

GSEGUtils.util._deg2rad(values, out=None)

Convert degrees to radians.

Parameters:
Return type:

Array_Float_T|float|None

GSEGUtils.util._deg2gon(values, out=None)

Convert degrees to gradians(gon).

Parameters:
Return type:

Array_Float_T|float|None

GSEGUtils.util._gon2rad(values, out=None)

Convert gradians(gon) to radians.

Parameters:
Return type:

Array_Float_T|float|None

GSEGUtils.util._gon2deg(values, out=None)

Convert gradians(gon) to degrees.

Parameters:
Return type:

Array_Float_T|float|None

GSEGUtils.util.unique_rows_fast(bin_idx)

Determine unique rows in a 2D array of integers. Returns (unique_rows, inverse_indices) exactly like np.unique(bin_idx, axis=0, return_inverse=True) but ~5–10× faster for large N.

Parameters:

bin_idx (Array_Int32_T)

Returns:

  • unique_rows (ArrayT,)

  • inverse_indices (Array_Int32_T)

Return type:

tuple[NDArray[Any, ((<class ‘numpy.int8’>, <class ‘numpy.int16’>, <class ‘numpy.int32’>, <class ‘numpy.int64’>, <class ‘numpy.int16’>, <class ‘numpy.uint8’>, <class ‘numpy.uint16’>, <class ‘numpy.uint32’>, <class ‘numpy.uint64’>, <class ‘numpy.uint16’>), (<class ‘numpy.float16’>, <class ‘numpy.float32’>, <class ‘numpy.float64’>, <class ‘numpy.float32’>, <class ‘numpy.float64’>), <class ‘numpy.bool’>)], NDArray[Any, int32]]