def writeSamples(self, data_list, digital = False):
        """
        Writes physical samples (uV, mA, Ohm) from data belonging to all signals
        The physical samples will be converted to digital samples using the values
        of physical maximum, physical minimum, digital maximum and digital minimum.
        if the samplefrequency of all signals are equal, then the data could be
        saved into a matrix with the size (N,signals) If the samplefrequency
        is different, then sample_freq is a vector containing all the different
        samplefrequencys. The data is saved as list. Each list entry contains
        a vector with the data of one signal.
        
        If digital is True, digital signals (as directly from the ADC) will be expected.
        (e.g. int16 from 0 to 2048)

        All parameters must be already written into the bdf/edf-file.
        """


        if (len(data_list) != len(self.channels)):
            raise WrongInputSize(len(data_list))
            
        if digital:
            if any([not np.issubdtype(a.dtype, np.integer) for a in data_list]):
                raise TypeError('Digital = True requires all signals in int')


        ind = []
        notAtEnd = True
        for i in np.arange(len(data_list)):
            ind.append(0)

        sampleLength = 0
        sampleRates = np.zeros(len(data_list), dtype=np.int)
        for i in np.arange(len(data_list)):
            sampleRates[i] = self.channels[i]['sample_rate']
            if (np.size(data_list[i]) < ind[i] + self.channels[i]['sample_rate']):
                notAtEnd = False
            sampleLength += self.channels[i]['sample_rate']

        dataOfOneSecond = np.array([], dtype=np.int if digital else None)

        while notAtEnd:
            # dataOfOneSecondInd = 0
            del dataOfOneSecond
            dataOfOneSecond = np.array([], dtype=np.int if digital else None)
            for i in np.arange(len(data_list)):
                # dataOfOneSecond[dataOfOneSecondInd:dataOfOneSecondInd+self.channels[i]['sample_rate']] = data_list[i].ravel()[int(ind[i]):int(ind[i]+self.channels[i]['sample_rate'])]
                dataOfOneSecond = np.append(dataOfOneSecond,data_list[i].ravel()[int(ind[i]):int(ind[i]+sampleRates[i])])
                # self.writePhysicalSamples(data_list[i].ravel()[int(ind[i]):int(ind[i]+self.channels[i]['sample_rate'])])
                ind[i] += sampleRates[i]
                # dataOfOneSecondInd += sampleRates[i]
            if digital:
                self.blockWriteDigitalSamples(dataOfOneSecond)   
            else:
                self.blockWritePhysicalSamples(dataOfOneSecond)
                
            for i in np.arange(len(data_list)):
                if (np.size(data_list[i]) < ind[i] + sampleRates[i]):
                    notAtEnd = False

        # dataOfOneSecondInd = 0
        for i in np.arange(len(data_list)):
            lastSamples = np.zeros(sampleRates[i], dtype=np.int if digital else None)
            lastSampleInd = int(np.max(data_list[i].shape) - ind[i])
            lastSampleInd = int(np.min((lastSampleInd,sampleRates[i])))
            if lastSampleInd > 0:
                lastSamples[:lastSampleInd] = data_list[i].ravel()[-lastSampleInd:]
                # dataOfOneSecond[dataOfOneSecondInd:dataOfOneSecondInd+self.channels[i]['sample_rate']] = lastSamples
                # dataOfOneSecondInd += self.channels[i]['sample_rate']
                if digital:
                    self.writeDigitalSamples(lastSamples)   
                else:
                    self.writePhysicalSamples(lastSamples)
def writeSamples ( self , data_list , digital = False ) : if ( len ( data_list ) != len ( self . channels ) ) : raise WrongInputSize ( len ( data_list ) ) if digital : if any ( [ not np . issubdtype ( a . dtype , np . integer ) for a in data_list ] ) : raise TypeError ( 'Digital = True requires all signals in int' ) ind = [ ] notAtEnd = True for i in np . arange ( len ( data_list ) ) : ind . append ( 0 ) sampleLength = 0 sampleRates = np . zeros ( len ( data_list ) , dtype = np . int ) for i in np . arange ( len ( data_list ) ) : sampleRates [ i ] = self . channels [ i ] [ 'sample_rate' ] if ( np . size ( data_list [ i ] ) < ind [ i ] + self . channels [ i ] [ 'sample_rate' ] ) : notAtEnd = False sampleLength += self . channels [ i ] [ 'sample_rate' ] dataOfOneSecond = np . array ( [ ] , dtype = np . int if digital else None ) while notAtEnd : del dataOfOneSecond dataOfOneSecond = np . array ( [ ] , dtype = np . int if digital else None ) for i in np . arange ( len ( data_list ) ) : dataOfOneSecond = np . append ( dataOfOneSecond , data_list [ i ] . ravel ( ) [ int ( ind [ i ] ) : int ( ind [ i ] + sampleRates [ i ] ) ] ) ind [ i ] += sampleRates [ i ] if digital : self . blockWriteDigitalSamples ( dataOfOneSecond ) else : self . blockWritePhysicalSamples ( dataOfOneSecond ) for i in np . arange ( len ( data_list ) ) : if ( np . size ( data_list [ i ] ) < ind [ i ] + sampleRates [ i ] ) : notAtEnd = False for i in np . arange ( len ( data_list ) ) : lastSamples = np . zeros ( sampleRates [ i ] , dtype = np . int if digital else None ) lastSampleInd = int ( np . max ( data_list [ i ] . shape ) - ind [ i ] ) lastSampleInd = int ( np . min ( ( lastSampleInd , sampleRates [ i ] ) ) ) if lastSampleInd > 0 : lastSamples [ : lastSampleInd ] = data_list [ i ] . ravel ( ) [ - lastSampleInd : ] if digital : self . writeDigitalSamples ( lastSamples ) else : self . writePhysicalSamples ( lastSamples )
Writes physical samples (uV, mA, Ohm) from data belonging to all signals
        The physical samples will be converted to digital samples using the values
        of physical maximum, physical minimum, digital maximum and digital minimum.
        if the samplefrequency of all signals are equal, then the data could be
        saved into a matrix with the size (N,signals) If the samplefrequency
        is different, then sample_freq is a vector containing all the different
        samplefrequencys. The data is saved as list. Each list entry contains
        a vector with the data of one signal.
        
        If digital is True, digital signals (as directly from the ADC) will be expected.
        (e.g. int16 from 0 to 2048)

        All parameters must be already written into the bdf/edf-file.