esmvaltool/preprocessor/_derive.py
def _p_level_widths(array):
    """Create pressure level widths from an array with pressure level values.

    The array is assumed to be monotonic and the values are decreasing.

    The first element is the lower boundary (surface pressure), the last value
    is the upper boundary. Thicknesses are only calculated for the values
    between these boundaries, the returned array, therefore, contains two
    elements less.

    >>> _p_level_widths(np.array([1020, 1000, 700, 500, 5]))
    array([170., 250., 595.])

    >>> _p_level_widths(np.array([990, np.NaN, 700, 500, 5]))
    array([  0., 390., 595.])
    """
    surface_pressure = array[0]
    top_limit = array[-1]
    array = array[1:-1]

    p_level_widths = np.ones(array.shape) * np.NAN

    last_pressure_level = len(array) - 1
    for i, val in enumerate(array):
        # numba would otherwise initialise it to 0 and
        # hide bugs that would occur in raw Python
        bounds_width = np.NAN
        if np.isnan(val):
            bounds_width = 0
        else:
            # distance to lower bound
            if i == 0 or np.isnan(array[i - 1]):
                # first pressure level with value
                dist_to_lower_bound = surface_pressure - val
            else:
                dist_to_lower_bound = 0.5 * (array[i - 1] - val)

            # distance to upper bound
            if i == last_pressure_level:  # last pressure level
                dist_to_upper_bound = val - top_limit
            else:
                dist_to_upper_bound = 0.5 * (val - array[i + 1])

            # Check monotonicity - all distances must be >= 0
            if dist_to_lower_bound < 0.0 or dist_to_upper_bound < 0.0:
                raise ValueError('Pressure level value increased with height.')

            bounds_width = dist_to_lower_bound + dist_to_upper_bound

        p_level_widths[i] = bounds_width
    return p_level_widths
Create pressure level widths from an array with pressure level values.

    The array is assumed to be monotonic and the values are decreasing.

    The first element is the lower boundary (surface pressure), the last value
    is the upper boundary. Thicknesses are only calculated for the values
    between these boundaries, the returned array, therefore, contains two
    elements less.

    >>> _p_level_widths(np.array([1020, 1000, 700, 500, 5]))
    array([170., 250., 595.])

    >>> _p_level_widths(np.array([990, np.NaN, 700, 500, 5]))
    array([  0., 390., 595.])
    
Create pressure level widths from an array with pressure level values.
The array is assumed to be monotonic and the values are decreasing.

The first element is the lower boundary (surface pressure), the last value
is the upper boundary. Thicknesses are only calculated for the values
between these boundaries, the returned array, therefore, contains two
elements less.




Create pressure level widths from an array with pressure level values . The array is assumed to be monotonic and the values are decreasing . The first element is the lower boundary ( surface pressure ) the last value is the upper boundary . Thicknesses are only calculated for the values between these boundaries the returned array therefore contains two elements less .
def _p_level_widths(array):
    surface_pressure = array[0]
    top_limit = array[-1]
    array = array[1:-1]
    p_level_widths = np.ones(array.shape) * np.NAN
    last_pressure_level = len(array) - 1
    for i, val in enumerate(array):
        bounds_width = np.NAN
        if np.isnan(val):
            bounds_width = 0
        else:
            if i == 0 or np.isnan(array[i - 1]):
                dist_to_lower_bound = surface_pressure - val
            else:
                dist_to_lower_bound = 0.5 * (array[i - 1] - val)
            if i == last_pressure_level:  
                dist_to_upper_bound = val - top_limit
            else:
                dist_to_upper_bound = 0.5 * (val - array[i + 1])
            if dist_to_lower_bound < 0.0 or dist_to_upper_bound < 0.0:
                raise ValueError('Pressure level value increased with height.')
            bounds_width = dist_to_lower_bound + dist_to_upper_bound
        p_level_widths[i] = bounds_width
    return p_level_widths
def _p_level_widths ( array ) : surface_pressure = array [ 0 ] top_limit = array [ - 1 ] array = array [ 1 : - 1 ] p_level_widths = np . ones ( array . shape ) * np . NAN last_pressure_level = len ( array ) - 1 for i , val in enumerate ( array ) : bounds_width = np . NAN if np . isnan ( val ) : bounds_width = 0 else : if i == 0 or np . isnan ( array [ i - 1 ] ) : dist_to_lower_bound = surface_pressure - val else : dist_to_lower_bound = 0.5 * ( array [ i - 1 ] - val ) if i == last_pressure_level : dist_to_upper_bound = val - top_limit else : dist_to_upper_bound = 0.5 * ( val - array [ i + 1 ] ) if dist_to_lower_bound < 0.0 or dist_to_upper_bound < 0.0 : raise ValueError ( 'Pressure level value increased with height.' ) bounds_width = dist_to_lower_bound + dist_to_upper_bound p_level_widths [ i ] = bounds_width return p_level_widths
Create pressure level widths from an array with pressure level values.
Create pressure level widths from an array with pressure level values .
"""Create pressure level widths from an array with pressure level values.

    The array is assumed to be monotonic and the values are decreasing.

    The first element is the lower boundary (surface pressure), the last value
    is the upper boundary. Thicknesses are only calculated for the values
    between these boundaries, the returned array, therefore, contains two
    elements less.

    >>> _p_level_widths(np.array([1020, 1000, 700, 500, 5]))
    array([170., 250., 595.])

    >>> _p_level_widths(np.array([990, np.NaN, 700, 500, 5]))
    array([  0., 390., 595.])
    """ # numba would otherwise initialise it to 0 and # hide bugs that would occur in raw Python # distance to lower bound # first pressure level with value # distance to upper bound # last pressure level # Check monotonicity - all distances must be >= 0
array