arte/time_series/time_series.py
def interpolate_missing_data(self, data):
        '''
        Interpolate missing data.

        Parameters
        ----------
        data: ndarray
            the original data

        Returns
        -------
        ndarray
            the interpolated array

        Raises
        ------
        ValueError
            if the frame counter first dimension does not have the same length
            as the data first dimension.
        '''
        counter = self.get_original_counter()
        if isinstance(counter, NotAvailable):
            return NotAvailable()

        if data.shape[0] != counter.shape[0]:
            raise ValueError('Shape mismatch between frame counter and data:'
                              + ' - Data: %s' % str(data.shape)
                              + ' - Counter: %s' % str(counter.shape))

        self._counter = self._interpolate_counter()

        # No interpolation done
        if len(self._counter) == len(self.get_original_counter()):
            return data

        new_data = np.zeros((self._counter.shape[0], data.shape[1]))

        # Normalize original counter to unsigned integer with unitary steps,
        # keeping the gaps. It makes easier to use the counter as
        # slice indexes, which must be integers.
        step = np.median(np.diff(counter))
        mycounter = np.round((counter - min(counter)) / step).astype(np.uint32)
        deltas = np.diff(mycounter)
        jumps = np.where(deltas > 1)[0]

        # Data before the first jump
        new_data[:jumps[0] + 1] = data[:jumps[0] + 1]

        shift = 0
        jump_idx = np.concatenate((jumps, [len(new_data)]))

        for j, nextj in pairwise(jump_idx):
            n_interp = deltas[j]
            gap = n_interp - 1
            interp = np.outer(np.arange(0, n_interp),
                              (data[j + 1] - data[j]) / n_interp) + data[j]

            # Interpolated data
            new_data[shift+j : shift+j+n_interp] = interp

            # Original data up to the next jump
            new_data[shift+j+n_interp: shift+nextj+n_interp] = data[j+1:nextj+1]

            # Keep track of how much data has been inserted in new_data
            shift += gap

        return new_data

        Interpolate missing data.

        Parameters
        ----------
        data: ndarray
            the original data

        Returns
        -------
        ndarray
            the interpolated array

        Raises
        ------
        ValueError
            if the frame counter first dimension does not have the same length
            as the data first dimension.
        
Interpolate missing data.
Parameters

ndarray
the original data

Returns

ndarray
the interpolated array

Raises

ValueError
if the frame counter first dimension does not have the same length
as the data first dimension.
Interpolate missing data . Parameters ndarray the original data Returns ndarray the interpolated array Raises ValueError if the frame counter first dimension does not have the same length as the data first dimension .
def interpolate_missing_data(self, data):
        counter = self.get_original_counter()
        if isinstance(counter, NotAvailable):
            return NotAvailable()
        if data.shape[0] != counter.shape[0]:
            raise ValueError('Shape mismatch between frame counter and data:'
                              + ' - Data: %s' % str(data.shape)
                              + ' - Counter: %s' % str(counter.shape))
        self._counter = self._interpolate_counter()
        if len(self._counter) == len(self.get_original_counter()):
            return data
        new_data = np.zeros((self._counter.shape[0], data.shape[1]))
        step = np.median(np.diff(counter))
        mycounter = np.round((counter - min(counter)) / step).astype(np.uint32)
        deltas = np.diff(mycounter)
        jumps = np.where(deltas > 1)[0]
        new_data[:jumps[0] + 1] = data[:jumps[0] + 1]
        shift = 0
        jump_idx = np.concatenate((jumps, [len(new_data)]))
        for j, nextj in pairwise(jump_idx):
            n_interp = deltas[j]
            gap = n_interp - 1
            interp = np.outer(np.arange(0, n_interp),
                              (data[j + 1] - data[j]) / n_interp) + data[j]
            new_data[shift+j : shift+j+n_interp] = interp
            new_data[shift+j+n_interp: shift+nextj+n_interp] = data[j+1:nextj+1]
            shift += gap
        return new_data
def interpolate_missing_data ( self , data ) : counter = self . get_original_counter ( ) if isinstance ( counter , NotAvailable ) : return NotAvailable ( ) if data . shape [ 0 ] != counter . shape [ 0 ] : raise ValueError ( 'Shape mismatch between frame counter and data:' + ' - Data: %s' % str ( data . shape ) + ' - Counter: %s' % str ( counter . shape ) ) self . _counter = self . _interpolate_counter ( ) if len ( self . _counter ) == len ( self . get_original_counter ( ) ) : return data new_data = np . zeros ( ( self . _counter . shape [ 0 ] , data . shape [ 1 ] ) ) step = np . median ( np . diff ( counter ) ) mycounter = np . round ( ( counter - min ( counter ) ) / step ) . astype ( np . uint32 ) deltas = np . diff ( mycounter ) jumps = np . where ( deltas > 1 ) [ 0 ] new_data [ : jumps [ 0 ] + 1 ] = data [ : jumps [ 0 ] + 1 ] shift = 0 jump_idx = np . concatenate ( ( jumps , [ len ( new_data ) ] ) ) for j , nextj in pairwise ( jump_idx ) : n_interp = deltas [ j ] gap = n_interp - 1 interp = np . outer ( np . arange ( 0 , n_interp ) , ( data [ j + 1 ] - data [ j ] ) / n_interp ) + data [ j ] new_data [ shift + j : shift + j + n_interp ] = interp new_data [ shift + j + n_interp : shift + nextj + n_interp ] = data [ j + 1 : nextj + 1 ] shift += gap return new_data
Interpolate missing data.
Interpolate missing data .
'''
        Interpolate missing data.

        Parameters
        ----------
        data: ndarray
            the original data

        Returns
        -------
        ndarray
            the interpolated array

        Raises
        ------
        ValueError
            if the frame counter first dimension does not have the same length
            as the data first dimension.
        ''' # No interpolation done # Normalize original counter to unsigned integer with unitary steps, # keeping the gaps. It makes easier to use the counter as # slice indexes, which must be integers. # Data before the first jump # Interpolated data # Original data up to the next jump # Keep track of how much data has been inserted in new_data
self
data