def mask_to_limits(a, limits, inclusive):
lower_limit, upper_limit = limits<EOL>lower_include, upper_include = inclusive<EOL>am = ma.MaskedArray(a)<EOL>if lower_limit is not None:<EOL><INDENT>if lower_include:<EOL><INDENT>am = ma.masked_less(am, lower_limit)<EOL><DEDENT>else:<EOL><INDENT>am = ma.masked_less_equal(am, lower_limit)<EOL><DEDENT><DEDENT>if upper_limit is not None:<EOL><INDENT>if upper_include:<EOL><INDENT>am = ma.masked_greater(am, upper_limit)<EOL><DEDENT>else:<EOL><INDENT>am = ma.masked_greater_equal(am, upper_limit)<EOL><DEDENT><DEDENT>if am.count() == <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return am<EOL>
Mask an array for values outside of given limits.

    This is primarily a utility function.

    Parameters
    ----------
    a : array
    limits : (float or None, float or None)
        A tuple consisting of the (lower limit, upper limit).  Values in the
        input array less than the lower limit or greater than the upper limit
        will be masked out. None implies no limit.
    inclusive : (bool, bool)
        A tuple consisting of the (lower flag, upper flag).  These flags
        determine whether values exactly equal to lower or upper are allowed.

    Returns
    -------
    A MaskedArray.

    Raises
    ------
    A ValueError if there are no values within the given limits.