コード例 #1
0
    def readSortedRecord(self, fid, pointer, channelList=None):
        """ reads record, only one channel group per datagroup

        Parameters
        ----------------
        fid : float
            file identifier
        pointer
            position in file of data block beginning
        channelList : list of str, optional
            list of channel to read

        Returns
        -----------
        rec : numpy recarray
            contains a matrix of raw data in a recarray (attributes corresponding to channel name)

        Notes
        --------
        If channelList is None, read data using numpy.core.records.fromfile that is rather quick.
        However, in case of large file, you can use channelList to load only interesting channels or
        only one channel on demand, but be aware it might be much slower.

        """
        fid.seek(pointer)
        if channelList is None:  # reads all, quickest but memory consuming
            return fromfile(fid, dtype=self.numpyDataRecordFormat, shape=self.numberOfRecords, names=self.dataRecordName)
        else:  # reads only some channels from a sorted data block
            # memory efficient but takes time
            if len(list(set(channelList) & set(self.channelNames))) > 0:  # are channelList in this dataGroup
                # check if master channel is in the list
                if not self.master['name'] in channelList:
                    channelList.append(self.master['name'])  # adds master channel
                rec = {}
                recChan = []
                numpyDataRecordFormat = []
                for channel in channelList:  # initialise data structure
                    rec[channel] = 0
                for channel in self:  # list of recordChannels from channelList
                    if channel.name in channelList:
                        recChan.append(channel)
                        numpyDataRecordFormat.append(channel.RecordFormat)
                rec = zeros((self.numberOfRecords, ), dtype=numpyDataRecordFormat)
                recordLength = self.recordIDsize + self.recordLength
                for r in range(self.numberOfRecords):  # for each record,
                    buf = fid.read(recordLength)
                    for channel in recChan:
                        rec[channel.name][r] = channel.CFormat.unpack(buf[channel.posBeg:channel.posEnd])[0]
                return rec.view(recarray)
コード例 #2
0
ファイル: mdf3reader.py プロジェクト: kkreplin/mdfreader
    def readSortedRecord(self, fid, pointer, channelList=None):
        """ reads record, only one channel group per datagroup

        Parameters
        ----------------
        fid : float
            file identifier
        pointer
            position in file of data block beginning
        channelList : list of str, optional
            list of channel to read

        Returns
        -----------
        rec : numpy recarray
            contains a matrix of raw data in a recarray (attributes corresponding to channel name)

        Notes
        --------
        If channelList is None, read data using numpy.core.records.fromfile that is rather quick.
        However, in case of large file, you can use channelList to load only interesting channels or
        only one channel on demand, but be aware it might be much slower.

        """
        fid.seek(pointer)
        if channelList is None:  # reads all, quickest but memory consuming
            return fromfile(fid, dtype=self.numpyDataRecordFormat, shape=self.numberOfRecords, names=self.dataRecordName)
        else:  # reads only some channels from a sorted data block
            # memory efficient but takes time
            if len(list(set(channelList) & set(self.channelNames))) > 0:  # are channelList in this dataGroup
                # check if master channel is in the list
                if not self.master['name'] in channelList:
                    channelList.append(self.master['name'])  # adds master channel
                rec = {}
                recChan = []
                numpyDataRecordFormat = []
                for channel in channelList:  # initialise data structure
                    rec[channel] = 0
                for channel in self:  # list of recordChannels from channelList
                    if channel.name in channelList:
                        recChan.append(channel)
                        numpyDataRecordFormat.append(channel.RecordFormat)
                rec = zeros((self.numberOfRecords, ), dtype=numpyDataRecordFormat)
                recordLength = self.recordIDsize + self.recordLength
                for r in range(self.numberOfRecords):  # for each record,
                    buf = fid.read(recordLength)
                    for channel in recChan:
                        rec[channel.name][r] = channel.CFormat.unpack(buf[channel.posBeg:channel.posEnd])[0]
                return rec.view(recarray)
コード例 #3
0
 def header(self):
     from cPickle import load, dump
     if not hasattr(self, '_header'):
         h = fromfile(self.tsq, tsq_dtype)
         self._header = h[h['type'] == 0x8101] # keep EVTYPE_STREAM only
     return self._header