def _get_bound_pressure_height(pressure, bound, heights=None, interpolate=True):
    'Calculate the bounding pressure and height in a layer.\n\n    Given pressure, optional heights, and a bound, return either the closest pressure/height\n    or interpolated pressure/height. If no heights are provided, a standard atmosphere\n    ([NOAA1976]_) is assumed.\n\n    Parameters\n    ----------\n    pressure : `pint.Quantity`\n        Atmospheric pressures\n    bound : `pint.Quantity`\n        Bound to retrieve (in pressure or height)\n    heights : `pint.Quantity`, optional\n        Atmospheric heights associated with the pressure levels. Defaults to using\n        heights calculated from ``pressure`` assuming a standard atmosphere.\n    interpolate : boolean, optional\n        Interpolate the bound or return the nearest. Defaults to True.\n\n    Returns\n    -------\n    `pint.Quantity`\n        The bound pressure and height.\n\n    '
    from .basic import height_to_pressure_std, pressure_to_height_std
    sort_inds = np.argsort(pressure)[::(- 1)]
    pressure = pressure[sort_inds]
    if (heights is not None):
        heights = heights[sort_inds]
    if (bound.dimensionality == {'[length]': (- 1.0), '[mass]': 1.0, '[time]': (- 2.0)}):
        if (bound in pressure):
            bound_pressure = bound
            if (heights is not None):
                bound_height = heights[(pressure == bound_pressure)]
            else:
                bound_height = pressure_to_height_std(bound_pressure)
        elif interpolate:
            bound_pressure = bound
            if (heights is not None):
                bound_height = log_interpolate_1d(bound_pressure, pressure, heights)
            else:
                bound_height = pressure_to_height_std(bound_pressure)
        else:
            idx = np.abs((pressure - bound)).argmin()
            bound_pressure = pressure[idx]
            if (heights is not None):
                bound_height = heights[idx]
            else:
                bound_height = pressure_to_height_std(bound_pressure)
    elif (bound.dimensionality == {'[length]': 1.0}):
        if (heights is not None):
            if (bound in heights):
                bound_height = bound
                bound_pressure = pressure[(heights == bound)]
            elif interpolate:
                bound_height = bound
                bound_pressure = (np.interp(np.atleast_1d(bound.m), heights.m, pressure.m).astype(result_type(bound)) * pressure.units)
            else:
                idx = np.abs((heights - bound)).argmin()
                bound_pressure = pressure[idx]
                bound_height = heights[idx]
        else:
            bound_height = bound
            bound_pressure = height_to_pressure_std(bound)
            if (not interpolate):
                idx = np.abs((pressure - bound_pressure)).argmin()
                bound_pressure = pressure[idx]
                bound_height = pressure_to_height_std(bound_pressure)
    else:
        raise ValueError('Bound must be specified in units of length or pressure.')
    if (not (_greater_or_close(bound_pressure, (np.nanmin(pressure.m) * pressure.units)) and _less_or_close(bound_pressure, (np.nanmax(pressure.m) * pressure.units)))):
        raise ValueError('Specified bound is outside pressure range.')
    if ((heights is not None) and (not (_less_or_close(bound_height, (np.nanmax(heights.m) * heights.units)) and _greater_or_close(bound_height, (np.nanmin(heights.m) * heights.units))))):
        raise ValueError('Specified bound is outside height range.')
    return (bound_pressure, bound_height)
Calculate the bounding pressure and height in a layer.

Given pressure, optional heights, and a bound, return either the closest pressure/height
or interpolated pressure/height. If no heights are provided, a standard atmosphere
([NOAA1976]_) is assumed.

Parameters
----------
pressure : `pint.Quantity`
    Atmospheric pressures
bound : `pint.Quantity`
    Bound to retrieve (in pressure or height)
heights : `pint.Quantity`, optional
    Atmospheric heights associated with the pressure levels. Defaults to using
    heights calculated from ``pressure`` assuming a standard atmosphere.
interpolate : boolean, optional
    Interpolate the bound or return the nearest. Defaults to True.

Returns
-------
`pint.Quantity`
    The bound pressure and height.
def _get_bound_pressure_height(pressure, bound, heights=None, interpolate=True):
    'Calculate the bounding pressure and height in a layer.\n\n    Given pressure, optional heights, and a bound, return either the closest pressure/height\n    or interpolated pressure/height. If no heights are provided, a standard atmosphere\n    ([NOAA1976]_) is assumed.\n\n    Parameters\n    ----------\n    pressure : `pint.Quantity`\n        Atmospheric pressures\n    bound : `pint.Quantity`\n        Bound to retrieve (in pressure or height)\n    heights : `pint.Quantity`, optional\n        Atmospheric heights associated with the pressure levels. Defaults to using\n        heights calculated from ``pressure`` assuming a standard atmosphere.\n    interpolate : boolean, optional\n        Interpolate the bound or return the nearest. Defaults to True.\n\n    Returns\n    -------\n    `pint.Quantity`\n        The bound pressure and height.\n\n    '
    from .basic import height_to_pressure_std, pressure_to_height_std
    sort_inds = np.argsort(pressure)[::(- 1)]
    pressure = pressure[sort_inds]
    if (heights is not None):
        heights = heights[sort_inds]
    if (bound.dimensionality == {'[length]': (- 1.0), '[mass]': 1.0, '[time]': (- 2.0)}):
        if (bound in pressure):
            bound_pressure = bound
            if (heights is not None):
                bound_height = heights[(pressure == bound_pressure)]
            else:
                bound_height = pressure_to_height_std(bound_pressure)
        elif interpolate:
            bound_pressure = bound
            if (heights is not None):
                bound_height = log_interpolate_1d(bound_pressure, pressure, heights)
            else:
                bound_height = pressure_to_height_std(bound_pressure)
        else:
            idx = np.abs((pressure - bound)).argmin()
            bound_pressure = pressure[idx]
            if (heights is not None):
                bound_height = heights[idx]
            else:
                bound_height = pressure_to_height_std(bound_pressure)
    elif (bound.dimensionality == {'[length]': 1.0}):
        if (heights is not None):
            if (bound in heights):
                bound_height = bound
                bound_pressure = pressure[(heights == bound)]
            elif interpolate:
                bound_height = bound
                bound_pressure = (np.interp(np.atleast_1d(bound.m), heights.m, pressure.m).astype(result_type(bound)) * pressure.units)
            else:
                idx = np.abs((heights - bound)).argmin()
                bound_pressure = pressure[idx]
                bound_height = heights[idx]
        else:
            bound_height = bound
            bound_pressure = height_to_pressure_std(bound)
            if (not interpolate):
                idx = np.abs((pressure - bound_pressure)).argmin()
                bound_pressure = pressure[idx]
                bound_height = pressure_to_height_std(bound_pressure)
    else:
        raise ValueError('Bound must be specified in units of length or pressure.')
    if (not (_greater_or_close(bound_pressure, (np.nanmin(pressure.m) * pressure.units)) and _less_or_close(bound_pressure, (np.nanmax(pressure.m) * pressure.units)))):
        raise ValueError('Specified bound is outside pressure range.')
    if ((heights is not None) and (not (_less_or_close(bound_height, (np.nanmax(heights.m) * heights.units)) and _greater_or_close(bound_height, (np.nanmin(heights.m) * heights.units))))):
        raise ValueError('Specified bound is outside height range.')
    return (bound_pressure, bound_height)