def azinrange(az, low, high):
    """Return whether azimuth is between low and high, trying to respect the
    360 deg boundary.

    We transform high so that it is in the range [low, low+360].  We then
    transform az likewise, so that the test can be done as low <= az <= high.
    In this scheme, azinrange(0, 2, 1) = True, since low, high = [2, 1] is
    interpreted as all angles between 2 and 361 degrees.

    Parameters
    ----------
    az: azimuth (deg)
    low: lower bound on azimuth (deg)
    high: upper bound on azimuth (deg)

    Returns
    -------
    Array of same shape as az, indicating if az is between low and high.
    """

    if low > high:
        high = ((high - low) % 360) + low
    az = ((az - low) % 360) + low
    return (az >= low) & (az <= high)