GSEGUtils.validators

GSEGUtils.validators.validate_spherical_angles(array)

Check spherical coordinates are valid.

Acceptable ranges:

Radius: [0, +∞] Hz Angle: [-π, +π] V Angle: [0, +π]

Raises errors if not valid. No conversion is done.

Parameters:

array (Array_Nx3_Float_T) – Nx3 array with rhv column order (Radius, Horizontal Angle, Vertical Angle)

Return type:

Array_Nx3_Float_T

Raises:

TypeError – Non numpy array

GSEGUtils.validators.validate_radius(array)

Check radii are non-negative.

Parameters:

array (Array_Float_T) – Input array is independent of the distance unit

Return type:

Array_Float_T

Raises:
GSEGUtils.validators.validate_azimuth_angles(array)

Check if azimuths in range of [0, 2π]

Parameters:

array (Array_Float_T) – Array of angles in radians

Return type:

Array_Float_T

Raises:
GSEGUtils.validators.validate_horizontal_angles(array)

Check if azimuths in range of [-π, +π]

Parameters:

array (Array_Float_T) – Array of angles in radians

Return type:

Array_Float_T

Raises:
GSEGUtils.validators.validate_zenith_angles(array)

Check if zenith angles in range of [0, +π]

Parameters:

array (Array_Float_T) – Array of angles in radians

Return type:

Array_Float_T

Raises:
GSEGUtils.validators.validate_inclination_angles(array)

Check if inclination angles in range of [-π/2, +π/2]

Parameters:

array (Array_Float_T) – Array of angles in radians

Return type:

Array_Float_T

Raises:
GSEGUtils.validators.coerce_wrapped_azimuth_angles(array)

Coerces azimuth angles to be within the range [0, 2π).

Parameters:

array (Array_Float_T) – Array of azimuth angles in radians

Return type:

Array_Float_T

GSEGUtils.validators.coerce_wrapped_horizontal_angles(array)

Coerce horizontal angles to range [-π, π)

Parameters:

array (Array_Float_T) – Array of horizontal angles in radians

Return type:

Array_Float_T

GSEGUtils.validators.validate_transposed_2d_array(array, n)

Ensure an array is of MxN shape or NxM shape and transpose if necessary.

Parameters:
  • array (ArrayT) – Input array, either 1D or 2D.

  • n (int) – The expected number of columns for the 2D array.

Return type:

ArrayT

Raises:

ValueError – Unsupported shape

GSEGUtils.validators.convert_slice_to_integer_range(selection, length)

Convert a slice object to an array of integer indices.

Parameters:
  • selection (slice) – Slice object containing start, stop, and step

  • length (int) – The length of the target array associated array or sequence

Return type:

Array_Integer_T

GSEGUtils.validators.validate_in_range(value, target_min, target_max)

Check if values are within the target range.

Parameters:
  • value (ArrayT) – Input array

  • target_min (float) – Lower inclusive limit

  • target_max (float) – Upper inclusive limit

Raises:

ValueError – Values outside of range

Return type:

None

GSEGUtils.validators.normalize_min_max(array, lower, upper, target_dtype, v_min=None, v_max=None)

Normalize and scale the values in a numpy array to a specified range using min-max scaling.

The input array is initially normalized using v_min, v_max where array.min() and array.max() are the default if not set.

This is then scaled to the target range bounds of [lower, upper] and converted to the target data type.

Parameters:
  • array (ArrayT) – Input array

  • lower (float or int or np.number) – Target lower bound after normalization

  • upper (float or int or np.number) – Target upper bound after normalization

  • target_dtype (npt.DtypeLike) – Output data type

  • v_min (float or int, optional) – Minima value used for normalization. Defaults to array.min() if not provided.

  • v_max (float or int, optional) – Maxima value used for normalization. Defaults to array.max() if not provided.

Return type:

ArrayT

GSEGUtils.validators.linear_map_dtype(array, target_dtype)

Linearly map the array values to the target dtype.

This function maps the input array values based on the current datatype’s minimum and maximum supported values to those of the target datatype.

Examples

np.int8 to np.uint16

>>> input = np.array([-50, 0, 127], dtype=np.int8)
>>> linear_map_dtype(input, np.uint16)
array([20046, 32896, 65535], dtype=uint16)
Parameters:
  • array (ArrayT) – Input array

  • target_dtype (npt.DtypeLike) – Target dtype (64-bit types not supported)

Return type:

ArrayT

Raises:
  • ValueError – Dtype is 64-bit (e.g., np.float64, np.int64, np.uint64).

  • TypeError – Non-floating or integer object type passed

GSEGUtils.validators.normalize_self(array)

Normalizes an input array to the limits expected by the array’s dtype.

For floating point values, this is [0, 1] and for integer values, it is the min and max defined by np.iinfo.

Parameters:

array (ArrayT) – The input array to be normalized

Return type:

ArrayT

GSEGUtils.validators.normalize_uint8(array)

Normalize to UInt8

Parameters:

array (ArrayT)

Return type:

Array_Uint8_T

GSEGUtils.validators.normalize_uint16(array)

Normalize to UInt16

Parameters:

array (ArrayT)

Return type:

Array_Uint16_T

GSEGUtils.validators.normalize_int8(array)

Normalize to Int8

Parameters:

array (ArrayT)

Return type:

Array_Int8_T

GSEGUtils.validators.normalize_int16(array)

Normalize to Int16

Parameters:

array (ArrayT)

Return type:

Array_Int16_T

GSEGUtils.validators.normalize_int32(array)

Normalize to Int32

Parameters:

array (ArrayT)

Return type:

Array_Int32_T

GSEGUtils.validators.normalize_int64(array)

Normalize to Int64

Parameters:

array (ArrayT)

Return type:

Array_Int64_T