Skip to content

RIQ Utils

M pynasonde.vipir.riq.utils — low-level helpers for null-terminated strings, phase unwrapping, and index parity.

pynasonde.vipir.riq.utils

Utility helpers for processing VIPIR RIQ (raw IQ) records.

This module bundles a few small helpers that are shared across the RIQ parsers and datatypes:

  • odd / even check integer parity without treating zero as odd.
  • trim_null and len_trim_null handle null-terminated strings that appear in VIPIR binary structures.
  • unwrap keeps phase angles within the [-pi, pi] interval so downstream routines can reason about angular differences coherently.

unwrap(phase)

Unwrap radian phase to the range [-PI, PI].

Parameters:

Name Type Description Default
phase

float Input phase in radians.

required

Returns:

Type Description

Unwrapped phase.

Source code in pynasonde/vipir/riq/utils.py
def unwrap(phase):
    """
    Unwrap radian phase to the range [-PI, PI].

    Parameters:
        phase: float
            Input phase in radians.

    Returns:
        Unwrapped phase.
    """
    if abs(phase) <= math.pi:
        return phase
    elif phase > math.pi:
        return phase - 2 * math.pi
    elif phase < -math.pi:
        return phase + 2 * math.pi
    else:
        return math.nan  # Error case

len_trim_null(string)

Get the length of the string after stripping null characters.

Parameters:

Name Type Description Default
string

str Input string to evaluate.

required

Returns:

Type Description

Length of the string after nulls are stripped.

Source code in pynasonde/vipir/riq/utils.py
def len_trim_null(string):
    """
    Get the length of the string after stripping null characters.

    Parameters:
        string: str
            Input string to evaluate.

    Returns:
        Length of the string after nulls are stripped.
    """
    return len(trim_null(string))

trim_null(string)

Remove null characters (ASCII 0) from the string.

Parameters:

Name Type Description Default
string

str Input string to trim.

required

Returns:

Type Description

Trimmed string with null characters replaced by spaces.

Source code in pynasonde/vipir/riq/utils.py
def trim_null(string):
    """
    Remove null characters (ASCII 0) from the string.

    Parameters:
        string: str
            Input string to trim.

    Returns:
        Trimmed string with null characters replaced by spaces.
    """
    return string.replace("\x00", "").strip()

even(i)

Determine if the argument is even. Zero is considered even.

Parameters:

Name Type Description Default
i

int Integer to check for evenness.

required

Returns:

Type Description

True if even, False if odd.

Source code in pynasonde/vipir/riq/utils.py
def even(i):
    """
    Determine if the argument is even. Zero is considered even.

    Parameters:
        i: int
            Integer to check for evenness.

    Returns:
        True if even, False if odd.
    """
    return i % 2 == 0

odd(i)

Determine if the argument is odd. Zero is considered even.

Parameters:

Name Type Description Default
i

int Integer to check for oddness.

required

Returns:

Type Description

True if odd, False if even.

Source code in pynasonde/vipir/riq/utils.py
def odd(i):
    """
    Determine if the argument is odd. Zero is considered even.

    Parameters:
        i: int
            Integer to check for oddness.

    Returns:
        True if odd, False if even.
    """
    return i % 2 != 0