@exporter.export
@preprocess_xarray
@units.wraps(('=A', '=B'), ('=A', '=B', '=B'))
def find_intersections(x, a, b, direction='all', log_x=False):
    "Calculate the best estimate of intersection.\n\n    Calculates the best estimates of the intersection of two y-value\n    data sets that share a common x-value set.\n\n    Parameters\n    ----------\n    x : array-like\n        1-dimensional array of numeric x-values\n    a : array-like\n        1-dimensional array of y-values for line 1\n    b : array-like\n        1-dimensional array of y-values for line 2\n    direction : string, optional\n        specifies direction of crossing. 'all', 'increasing' (a becoming greater than b),\n        or 'decreasing' (b becoming greater than a). Defaults to 'all'.\n    log_x : bool, optional\n        Use logarithmic interpolation along the `x` axis (i.e. for finding intersections\n        in pressure coordinates). Default is False.\n\n    Returns\n    -------\n        A tuple (x, y) of array-like with the x and y coordinates of the\n        intersections of the lines.\n\n    "
    if (log_x is True):
        x = np.log(x)
    nearest_idx = nearest_intersection_idx(a, b)
    next_idx = (nearest_idx + 1)
    sign_change = np.sign((a[next_idx] - b[next_idx]))
    (_, x0) = _next_non_masked_element(x, nearest_idx)
    (_, x1) = _next_non_masked_element(x, next_idx)
    (_, a0) = _next_non_masked_element(a, nearest_idx)
    (_, a1) = _next_non_masked_element(a, next_idx)
    (_, b0) = _next_non_masked_element(b, nearest_idx)
    (_, b1) = _next_non_masked_element(b, next_idx)
    delta_y0 = (a0 - b0)
    delta_y1 = (a1 - b1)
    intersect_x = (((delta_y1 * x0) - (delta_y0 * x1)) / (delta_y1 - delta_y0))
    intersect_y = ((((intersect_x - x0) / (x1 - x0)) * (a1 - a0)) + a0)
    if (len(intersect_x) == 0):
        return (intersect_x, intersect_y)
    if (log_x is True):
        intersect_x = np.exp(intersect_x)
    duplicate_mask = (np.ediff1d(intersect_x, to_end=1) != 0)
    if (direction == 'increasing'):
        mask = (sign_change > 0)
    elif (direction == 'decreasing'):
        mask = (sign_change < 0)
    elif (direction == 'all'):
        return (intersect_x[duplicate_mask], intersect_y[duplicate_mask])
    else:
        raise ValueError('Unknown option for direction: {0}'.format(str(direction)))
    return (intersect_x[(mask & duplicate_mask)], intersect_y[(mask & duplicate_mask)])
Calculate the best estimate of intersection.

Calculates the best estimates of the intersection of two y-value
data sets that share a common x-value set.

Parameters
----------
x : array-like
    1-dimensional array of numeric x-values
a : array-like
    1-dimensional array of y-values for line 1
b : array-like
    1-dimensional array of y-values for line 2
direction : string, optional
    specifies direction of crossing. 'all', 'increasing' (a becoming greater than b),
    or 'decreasing' (b becoming greater than a). Defaults to 'all'.
log_x : bool, optional
    Use logarithmic interpolation along the `x` axis (i.e. for finding intersections
    in pressure coordinates). Default is False.

Returns
-------
    A tuple (x, y) of array-like with the x and y coordinates of the
    intersections of the lines.
@exporter.export
@preprocess_xarray
@units.wraps(('=A', '=B'), ('=A', '=B', '=B'))
def find_intersections(x, a, b, direction='all', log_x=False):
    "Calculate the best estimate of intersection.\n\n    Calculates the best estimates of the intersection of two y-value\n    data sets that share a common x-value set.\n\n    Parameters\n    ----------\n    x : array-like\n        1-dimensional array of numeric x-values\n    a : array-like\n        1-dimensional array of y-values for line 1\n    b : array-like\n        1-dimensional array of y-values for line 2\n    direction : string, optional\n        specifies direction of crossing. 'all', 'increasing' (a becoming greater than b),\n        or 'decreasing' (b becoming greater than a). Defaults to 'all'.\n    log_x : bool, optional\n        Use logarithmic interpolation along the `x` axis (i.e. for finding intersections\n        in pressure coordinates). Default is False.\n\n    Returns\n    -------\n        A tuple (x, y) of array-like with the x and y coordinates of the\n        intersections of the lines.\n\n    "
    if (log_x is True):
        x = np.log(x)
    nearest_idx = nearest_intersection_idx(a, b)
    next_idx = (nearest_idx + 1)
    sign_change = np.sign((a[next_idx] - b[next_idx]))
    (_, x0) = _next_non_masked_element(x, nearest_idx)
    (_, x1) = _next_non_masked_element(x, next_idx)
    (_, a0) = _next_non_masked_element(a, nearest_idx)
    (_, a1) = _next_non_masked_element(a, next_idx)
    (_, b0) = _next_non_masked_element(b, nearest_idx)
    (_, b1) = _next_non_masked_element(b, next_idx)
    delta_y0 = (a0 - b0)
    delta_y1 = (a1 - b1)
    intersect_x = (((delta_y1 * x0) - (delta_y0 * x1)) / (delta_y1 - delta_y0))
    intersect_y = ((((intersect_x - x0) / (x1 - x0)) * (a1 - a0)) + a0)
    if (len(intersect_x) == 0):
        return (intersect_x, intersect_y)
    if (log_x is True):
        intersect_x = np.exp(intersect_x)
    duplicate_mask = (np.ediff1d(intersect_x, to_end=1) != 0)
    if (direction == 'increasing'):
        mask = (sign_change > 0)
    elif (direction == 'decreasing'):
        mask = (sign_change < 0)
    elif (direction == 'all'):
        return (intersect_x[duplicate_mask], intersect_y[duplicate_mask])
    else:
        raise ValueError('Unknown option for direction: {0}'.format(str(direction)))
    return (intersect_x[(mask & duplicate_mask)], intersect_y[(mask & duplicate_mask)])