<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def selection_std(populations, low=None, high=None, n_std_low=2.5, n_std_high=2.5, scale='logicle'):
 """ Select populations if most of their elements are between two values. This function selects populations from `populations` if their means are more than `n_std_low` standard deviations greater than `low` and `n_std_high` standard deviations lower than `high`. Optionally, all elements in `populations` can be rescaled as specified by the `scale` argument before calculating means and standard deviations. Parameters populations : list of 1D arrays or 1-channel FCSData objects Populations to select or discard. low, high : int or float Low and high thresholds. Required if the elements in `populations` are numpy arrays. If not specified, and the elements in `populations` are FCSData objects, use 1.5% and 98.5% of the range in ``populations[0].range``. n_std_low, n_std_high : float, optional Number of standard deviations from `low` and `high`, respectively, that a population's mean has to be closer than to be discarded. scale : str, optional Rescaling applied to `populations` before calculating means and standard deviations. Can be either ``linear`` (no rescaling), ``log``, or ``logicle``. Returns ------- selected_mask : boolean array Flags indicating whether a population has been selected. """


    # Generate scaling functions
    if scale == 'linear':
        # Identity function
        sf = lambda x: x
    elif scale == 'log':
        sf = np.log10
    elif scale == 'logicle':
        # We need a transformation from "data value" to "display scale"
        # units. To do so, we use an inverse logicle transformation.
        t = FlowCal.plot._LogicleTransform(data=populations[0],
                                           channel=0).inverted()
        sf = lambda x: t.transform_non_affine(x, mask_out_of_range=False)
    else:
        raise ValueError("scale {} not supported".format(scale))

    # If thresholds were provided, apply scaling function. Else, obtain and
    # rescale thresholds from range.
    if low is None:
        if hasattr(populations[0], 'hist_bins'):
            # Obtain default thresholds from range
            r = populations[0].range(channels=0)
            # If using log scale and the lower limit is non-positive, change to
            # a very small positive number.
            # The machine epsilon `eps` is the smallest number such that
            # `1.0 + eps != eps`. For a 64-bit floating point, `eps ~= 1e-15`.
            if scale == 'log' and r[0] <= 0:
                r[0] = 1e-15
            low = sf(r[0]) + 0.015*(sf(r[1]) - sf(r[0]))
        else:
            raise TypeError("argument 'low' not specified")
    else:
        low = sf(low)
    if high is None:
        if hasattr(populations[0], 'hist_bins'):
            # Obtain default thresholds from range
            r = populations[0].range(channels=0)
            # If using log scale and the lower limit is non-positive, change to
            # a very small positive number.
            # The machine epsilon `eps` is the smallest number such that
            # `1.0 + eps != eps`. For a 64-bit floating point, `eps ~= 1e-15`.
            if scale == 'log' and r[0] <= 0:
                r[0] = 1e-15
            high = sf(r[0]) + 0.985*(sf(r[1]) - sf(r[0]))
        else:
            raise TypeError("argument 'high' not specified")
    else:
        high = sf(high)

    # Copy events
    for i in range(len(populations)):
        populations[i] = populations[i].copy()

    # For log scaling, logarithm of zero and negatives is undefined. Therefore,
    # saturate any non-positives to a small positive value.
    # The machine epsilon `eps` is the smallest number such that
    # `1.0 + eps != eps`. For a 64-bit floating point, `eps ~= 1e-15`.
    if scale == 'log':
        for p in populations:
            p[p < 1e-15] = 1e-15

    # Rescale events
    for i in range(len(populations)):
        populations[i] = sf(populations[i])

    # Calculate means and standard deviations
    pop_mean = np.array([FlowCal.stats.mean(p) for p in populations])
    pop_std = np.array([FlowCal.stats.std(p) for p in populations])

    # Some populations, especially the highest ones when they are near
    # saturation, tend to aggregate mostly on one bin and give a standard
    # deviation of almost zero. This is an effect of the finite bin resolution
    # and probably gives a bad estimate of the standard deviation. We choose
    # to be conservative and overestimate the standard deviation in these
    # cases. Therefore, we set the minimum standard deviation to 0.005.
    min_std = 0.005
    pop_std[pop_std < min_std] = min_std

    # Return populations that don't cross either threshold
    selected_mask = np.logical_and(
        (pop_mean - n_std_low*pop_std) > low,
        (pop_mean + n_std_high*pop_std) < high)
    return selected_mask