| 1 |  |  | # Licensed under a 3-clause BSD style license - see LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | """Methods for synthetic generation of light curves.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | import logging | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | import nfft | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | import numpy as np | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | import scipy.signal as scipy_signal | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | __all__ = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |     "lc_gen_samp", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     "lc_gen_psd_nft", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     "lc_gen_ou", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     "lc_gen_psd_lombscargle", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     "lc_gen_psd_fft", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     "lc_gen_psd_c", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     "fgen_wrapper", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | log = logging.getLogger(__name__) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  | def fgen_wrapper(fgen, t, y, fgen_params): | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |     """Wrapper for all lc_gen_* functions, so as not to duplicate code.""" | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |          | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |     if fgen == "lc_gen_samp": | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |         y2 = lc_gen_samp(y) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |     elif fgen == "lc_gen_psd_fft": | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |         y2 = lc_gen_psd_fft(y) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |     elif fgen == "lc_gen_psd_nft": | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |         y2 = lc_gen_psd_nft(t, y) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |     elif fgen == "lc_gen_psd_lombscargle": | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |         y2 = lc_gen_psd_lombscargle(t, y) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |     elif fgen == "lc_gen_psd_c": | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |         y2 = lc_gen_psd_c(t, y, t) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |     elif fgen == "lc_gen_ou": | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |         if not ('theta' in fgen_params or 'mu' in fgen_params or 'sigma' in fgen_params): | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |             raise Exception("You need to set the parameters for the signal") | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |         y2 = lc_gen_ou(times=t, **fgen_params) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |     else: | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |         raise Exception(f"Unknown fgen method {fgen}") | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |          | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |     return y2 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | def lc_gen_samp(signs): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     """Generation by sampling np.random.choice with same mean and std""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     return np.random.choice(signs, signs.size) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | def lc_gen_ou(theta, mu, sigma, times, scale=None, loc=None): | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     """Generation from an OU process integrating the stochastic differential equation.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     width = 100 * times.size | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     dt = (max(times) - min(times)) / width | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     s2 = np.empty(times.size) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     s2[0] = mu  # should get it from OU.rvs()!!!! | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     for i in range(1, times.size): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         ti = times[i - 1] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         y = s2[i - 1] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         while ti < times[i]: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             y = y + dt * (theta * (mu - y) + sigma * y * np.random.randn() / np.sqrt(dt)) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             ti = ti + dt | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         s2[i] = y | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     if scale is not None: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         s2 = scale * s2 / np.std(s2) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     if loc is not None: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         s2 = s2 - np.mean(s2) + loc | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     return s2 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | def lc_gen_psd_c(ts, values, times): | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     """Generation using interpolated PSD for light curves with similar PSD, mean and std.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     f, p = scipy_signal.welch(values, nperseg=ts.size / 2) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     fp = np.linspace(min(f), max(f), times.size // 2 + 1) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     pp = np.interp(fp, f, p) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     fft = np.sqrt(2 * pp * pp.size) * np.exp(1j * 2 * np.pi * np.random.random(pp.size)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     s2 = np.fft.irfft(fft, n=values.size) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     a = values.std() / s2.std() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     b = values.mean() - a * s2.mean() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     s2 = a * s2 + b | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     return s2 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | def lc_gen_psd_fft(values): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     """Generation using Welch algorithm and the FFT, of synthetic signals with similar PSD, mean and std. | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     Generates synthetic light curves using Lomb-Scargle algorithm | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     to compute the power spectral density and the non-uniform fft | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     to generate the signal.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     # this is not valid for non-uniform times (see PSD tests for a comparison) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     f, pxx = scipy_signal.welch(values) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     # fft2 = np.sqrt(2*Pxx*Pxx.size)*np.exp(1j*2*pi*np.random.randn(Pxx.size)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     fft2 = np.sqrt(2 * pxx * pxx.size) * np.exp(1j * 2 * np.pi * np.random.random(pxx.size)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     s2 = np.fft.irfft(fft2, n=values.size) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     a = values.std() / s2.std() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     b = values.mean() - a * s2.mean() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     s2 = a * s2 + b | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     return s2 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | def lc_gen_psd_lombscargle(times, values): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     """Generation using Lomb-Scargle algorithm and the non-uniform FFT, of synthetic signals with similar PSD, mean and std. | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     Generates synthetic light curves using Lomb-Scargle algorithm | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     to compute the power spectral density and the non-uniform fft | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     to reconstruct the randomised signal.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     if values.size % 2 != 0: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         sigp = values[:-1] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         tp = times[:-1] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     else: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         sigp = values | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         tp = times | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |     offset = 1e-6 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |     n = sigp.size | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     # k = np.arange(-n/2, n/2) no bc scipy_signal.lombscargle does not support freq zero | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     k = np.linspace(-n / 2, n / 2 - 1 + offset, n) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     freqs = k / 2 / np.pi | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |     pxx = scipy_signal.lombscargle(tp, sigp, freqs) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     # build random phase to get real signal | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |     phase = np.random.random(pxx.size // 2) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |     phase = np.concatenate((-np.flip(phase), [0], phase[:-1])) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |     fft2 = np.sqrt(2 * pxx * pxx.size) * np.exp(1j * 2 * np.pi * phase) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |     s2 = ( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |         nfft.nfft((times - (times.max() + times.min()) / 2) / np.ptp(times), fft2, n, use_fft=True) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         / n | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |     ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |     # fix small deviations | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |     a = values.std() / s2.std() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |     b = values.mean() - a * s2.mean() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |     s2 = a * s2 + b | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |     s2 = np.real(s2)     | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |     s2 = np.asarray(s2, dtype=float, order='C') # workaround for some bug in scipy lombscargle... | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |      | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |     return s2 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  | def lc_gen_psd_nft(times, values): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |     """Generation using the non-uniform FFT of synthetic signals with similar PSD, mean and std. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |     Generates synthetic light curves using the non-uniform FFT to | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |     compute the power spectral density and to reconstruct the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |     randomised signal.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |     k = np.arange(-times.size // 2, times.size / 2) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |     n = k.size | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |     nft = nfft.nfft_adjoint( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |         (times - (times.max() + times.min()) / 2) / np.ptp(times), values, n, use_fft=True | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |     ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |     # build random phase to get real signal | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |     phase = np.random.random(n // 2) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |     phase = np.concatenate((-np.flip(phase), [0], phase[:-1])) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |     fft2 = np.abs(nft) * np.exp(1j * 2 * np.pi * phase) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |     s2 = ( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |         nfft.nfft((times - (times.max() + times.min()) / 2) / np.ptp(times), fft2, use_fft=True) / n | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |     ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |     s2 = np.real(s2)  # np.real to fix small imaginary part from numerical error | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |     # fix small mean, std difference from numerical error | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |     a = values.std() / s2.std() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |     b = values.mean() - a * s2.mean() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |     s2 = a * s2 + b | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 176 |  |  |     return s2 | 
            
                                                        
            
                                    
            
            
                | 177 |  |  |  |