Skip to content

Documentation for Noise.py

Noise

GaussianPeakNoise

GaussianPeakNoise(sigma, log_space=False)

Bases: NoPeakNoise

Adds Gaussian noise to peaks

Initialises Gaussian peak noise

Parameters:

Name Type Description Default
sigma

the variance

required
log_space

whether to sample in log space

False
Source code in vimms/Noise.py
52
53
54
55
56
57
58
59
60
61
def __init__(self, sigma, log_space=False):
    """
    Initialises Gaussian peak noise

    Args:
        sigma: the variance
        log_space: whether to sample in log space
    """
    self.sigma = sigma
    self.log_space = log_space

get

get(original, ms_level)

Get peak measurement with gaussian noise applied

Parameters:

Name Type Description Default
original

original value

required
ms_level

ms level

required

Returns: peak measurement with gaussian noise applied

Source code in vimms/Noise.py
63
64
65
66
67
68
69
70
71
72
73
74
def get(self, original, ms_level):
    """
    Get peak measurement with gaussian noise applied

    Args:
        original: original value
        ms_level: ms level

    Returns: peak measurement with gaussian noise applied

    """
    return trunc_normal(original, self.sigma, self.log_space)

GaussianPeakNoiseLevelSpecific

GaussianPeakNoiseLevelSpecific(sigma_level_dict, log_space=False)

Bases: NoPeakNoise

Adds ms-level specific Gaussian noise to peaks

Create a gaussian peak noise level specific

Parameters:

Name Type Description Default
sigma_level_dict

key: level, value: sigma. ms_levels not in the dict will not have noise added allows noise to be added to oa single level, or to all levels with different sigma

required
log_space

whether to log or not

False
Source code in vimms/Noise.py
82
83
84
85
86
87
88
89
90
91
92
93
94
def __init__(self, sigma_level_dict, log_space=False):
    """
    Create a gaussian peak noise level specific

    Args:
        sigma_level_dict: key: level, value: sigma.
                          ms_levels not in the dict will not have noise added
                          allows noise to be added to oa single level, or
                          to all levels with different sigma
        log_space: whether to log or not
    """
    self.log_space = log_space
    self.sigma_level_dict = sigma_level_dict

NoPeakNoise

The base peak noise object that doesn't add any noise

get

get(original, ms_level)

Get the original value back. No noise if applied.

Parameters:

Name Type Description Default
original

The original value

required
ms_level

The ms level

required

Returns: the original value (unused)

Source code in vimms/Noise.py
33
34
35
36
37
38
39
40
41
42
43
44
def get(self, original, ms_level):
    """
    Get the original value back. No noise if applied.

    Args:
        original: The original value
        ms_level: The ms level

    Returns: the original value (unused)

    """
    return original

UniformSpikeNoise

UniformSpikeNoise(density, max_val, min_val=0, min_mz=None, max_mz=None)

A class to add uniform spike noise to the data

Create a UniformSpikeNoise class Args: density: number of spike peaks per mz unit max_val: maximum value of spike min_val: minimum value of spike min_mz: maximum m/z max_mz: minimum m/z

Source code in vimms/Noise.py
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
def __init__(self, density, max_val, min_val=0, min_mz=None, max_mz=None):
    """
    Create a UniformSpikeNoise class
    Args:
        density: number of spike peaks per mz unit
        max_val: maximum value of spike
        min_val: minimum value of spike
        min_mz: maximum m/z
        max_mz: minimum m/z
    """
    self.density = density
    self.max_val = max_val
    self.min_val = min_val
    self.min_mz = min_mz
    self.max_mz = max_mz

trunc_normal

trunc_normal(mean, sigma, log_space)

Ensures that generators never return negative mz or intensity

Parameters:

Name Type Description Default
mean

mean of gaussian distribution to sample from

required
sigma

variance of gaussian distribution to sample from

required
log_space

whether to sample in log space

required

Returns: the sampled value

Source code in vimms/Noise.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def trunc_normal(mean, sigma, log_space):
    """
    Ensures that generators never return negative mz or intensity

    Args:
        mean: mean of gaussian distribution to sample from
        sigma: variance of gaussian distribution to sample from
        log_space: whether to sample in log space

    Returns: the sampled value

    """
    s = -1
    if not log_space:
        while s < 0:
            s = np.random.normal(mean, sigma, 1)[0]
        return s
    else:
        s = np.random.normal(np.log(mean), sigma, 1)[0]
        return np.exp(s)