示例#1
0
def add_gaussv_noise_ic(ic: IonChromatogram, scale: int, cutoff: int,
                        prop: float):
    """
    Adds noise to an ic. The noise value is drawn from a normal
    distribution, the scale of this distribution depends on the
    value of the ic at the point where the noise is being added

    :param ic: The IonChromatogram
    :type ic: pyms.IonChromatogram.IonChromatogram
    :param cutoff: The level below which the intensity of the ic at that point
        has no effect on the scale of the noise distribution
    :type cutoff: int
    :param scale: The scale of the normal distribution for ic values below the cutoff
        is modified for values above the cutoff
    :type scale: int
    :param prop: For ic values above the cutoff, the scale is multiplied by the ic
        value multiplied by prop
    :type prop: float

    :author: Sean O'Callaghan
    """

    noise = numpy.zeros(len(ic))

    i_array = ic.get_intensity_array()
    # time_list = ic.get_time_list()

    for i in range(len(ic)):
        if i_array[i] < cutoff:
            noise[i] = numpy.random.normal(0.0, scale, 1)
        else:
            noise[i] = numpy.random.normal(0.0, scale * i_array[i] * prop, 1)

    i_array_with_noise = noise + i_array
    ic.set_intensity_array(i_array_with_noise)
示例#2
0
def add_gaussc_noise_ic(ic: IonChromatogram, scale: float):
    """
    Adds noise drawn from a normal distribution with constant scale to an ion chromatogram

    :param ic: The ion Chromatogram
    :type ic: pyms.IonChromatogram.IonChromatogram
    :param scale: The scale of the normal distribution
    :type scale: float

    :author: Sean O'Callaghan
    """

    noise = numpy.random.normal(0.0, scale, (len(ic)))

    i_array_with_noise = ic.get_intensity_array() + noise
    ic.set_intensity_array(i_array_with_noise)