lab/app/windfarm.py [63:115]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    def __create_dataset__(self, X, time_steps=1, step=1):
        """
        This encodes a list of readings into the correct shape
        expected by the model. It uses the concept of a sliding window
        """
        Xs = []
        for i in range(0, len(X) - time_steps, step):
            v = X[i:(i + time_steps)]
            Xs.append(v)
        return np.array(Xs)

    def __euler_from_quaternion__(self, x, y, z, w):
        """
        Convert a quaternion into euler angles (roll, pitch, yaw)
        roll is rotation around x in radians (counterclockwise)
        pitch is rotation around y in radians (counterclockwise)
        yaw is rotation around z in radians (counterclockwise)
        """
        t0 = +2.0 * (w * x + y * z)
        t1 = +1.0 - 2.0 * (x * x + y * y)
        roll_x = math.atan2(t0, t1)

        t2 = +2.0 * (w * y - z * x)
        t2 = +1.0 if t2 > +1.0 else t2
        t2 = -1.0 if t2 < -1.0 else t2
        pitch_y = math.asin(t2)

        t3 = +2.0 * (w * z + x * y)
        t4 = +1.0 - 2.0 * (y * y + z * z)
        yaw_z = math.atan2(t3, t4)

        return roll_x, pitch_y, yaw_z # in radians
        
    def __wavelet_denoise__(self, data, wavelet, noise_sigma):
        '''
        Filter accelerometer data using wavelet denoising
        Modification of F. Blanco-Silva's code at: https://goo.gl/gOQwy5
        '''

        wavelet = pywt.Wavelet(wavelet)
        levels  = min(5, (np.floor(np.log2(data.shape[0]))).astype(int))

        # Francisco's code used wavedec2 for image data
        wavelet_coeffs = pywt.wavedec(data, wavelet, level=levels)
        threshold = noise_sigma*np.sqrt(2*np.log2(data.size))

        new_wavelet_coeffs = map(lambda x: pywt.threshold(x, threshold, mode='soft'), wavelet_coeffs)

        return pywt.waverec(list(new_wavelet_coeffs), wavelet)

    def __del__(self):
        """Destructor"""
        self.halt()
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



lab/app_ggv2/windfarm.py [65:117]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    def __create_dataset__(self, X, time_steps=1, step=1):
        """
        This encodes a list of readings into the correct shape
        expected by the model. It uses the concept of a sliding window
        """
        Xs = []
        for i in range(0, len(X) - time_steps, step):
            v = X[i:(i + time_steps)]
            Xs.append(v)
        return np.array(Xs)

    def __euler_from_quaternion__(self, x, y, z, w):
        """
        Convert a quaternion into euler angles (roll, pitch, yaw)
        roll is rotation around x in radians (counterclockwise)
        pitch is rotation around y in radians (counterclockwise)
        yaw is rotation around z in radians (counterclockwise)
        """
        t0 = +2.0 * (w * x + y * z)
        t1 = +1.0 - 2.0 * (x * x + y * y)
        roll_x = math.atan2(t0, t1)

        t2 = +2.0 * (w * y - z * x)
        t2 = +1.0 if t2 > +1.0 else t2
        t2 = -1.0 if t2 < -1.0 else t2
        pitch_y = math.asin(t2)

        t3 = +2.0 * (w * z + x * y)
        t4 = +1.0 - 2.0 * (y * y + z * z)
        yaw_z = math.atan2(t3, t4)

        return roll_x, pitch_y, yaw_z # in radians
        
    def __wavelet_denoise__(self, data, wavelet, noise_sigma):
        '''
        Filter accelerometer data using wavelet denoising
        Modification of F. Blanco-Silva's code at: https://goo.gl/gOQwy5
        '''

        wavelet = pywt.Wavelet(wavelet)
        levels  = min(5, (np.floor(np.log2(data.shape[0]))).astype(int))

        # Francisco's code used wavedec2 for image data
        wavelet_coeffs = pywt.wavedec(data, wavelet, level=levels)
        threshold = noise_sigma*np.sqrt(2*np.log2(data.size))

        new_wavelet_coeffs = map(lambda x: pywt.threshold(x, threshold, mode='soft'), wavelet_coeffs)

        return pywt.waverec(list(new_wavelet_coeffs), wavelet)

    def __del__(self):
        """Destructor"""
        self.halt()
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



