Example #1
0
 def read_next_chunk(self, lazy):
     # Check for EOF:
     ncode_records_minus_one_buf = self._stream.read(1)
     if not ncode_records_minus_one_buf:
         return None
     # Code track (run length encoded):
     (ncode_records_minus_one, ) = struct.unpack(
         "<B", ncode_records_minus_one_buf)
     ncode_records = ncode_records_minus_one + 1
     codes = np.empty(256, np.uint16)
     cursor = 0
     for i in xrange(ncode_records):
         repeat_minus_one, code = struct.unpack("<BH", self._stream.read(3))
         codes[cursor:cursor + repeat_minus_one + 1] = code
         cursor += repeat_minus_one + 1
     assert cursor == 256
     # Data bytes (delta encoded and packed into variable-length integers):
     # Record where these start so we can find it again in get_chunk().
     self._offsets.append(self._stream.tell())
     (ncompressed_words, ) = struct.unpack("<H", self._stream.read(2))
     compressed_data = self._stream.read(ncompressed_words * 2)
     if lazy:
         data_chunk = None
     else:
         # This is the slow part of loading data:
         data_chunk = _decompress_crw_chunk(compressed_data,
                                            ncompressed_words, self._nchans)
     return codes, data_chunk
Example #2
0
File: erpss.py Project: rerpy/rerpy
 def read_next_chunk(self, lazy):
     # Check for EOF:
     ncode_records_minus_one_buf = self._stream.read(1)
     if not ncode_records_minus_one_buf:
         return None
     # Code track (run length encoded):
     (ncode_records_minus_one,) = struct.unpack("<B",
                                                ncode_records_minus_one_buf)
     ncode_records = ncode_records_minus_one + 1
     codes = np.empty(256, np.uint16)
     cursor = 0
     for i in xrange(ncode_records):
         repeat_minus_one, code = struct.unpack("<BH", self._stream.read(3))
         codes[cursor:cursor + repeat_minus_one + 1] = code
         cursor += repeat_minus_one + 1
     assert cursor == 256
     # Data bytes (delta encoded and packed into variable-length integers):
     # Record where these start so we can find it again in get_chunk().
     self._offsets.append(self._stream.tell())
     (ncompressed_words,) = struct.unpack("<H", self._stream.read(2))
     compressed_data = self._stream.read(ncompressed_words * 2)
     if lazy:
         data_chunk = None
     else:
         # This is the slow part of loading data:
         data_chunk = _decompress_crw_chunk(compressed_data,
                                            ncompressed_words,
                                            self._nchans)
     return codes, data_chunk
Example #3
0
 def get_chunk(self, chunk_number):
     self._stream.seek(self._offsets[chunk_number])
     (ncompressed_words, ) = struct.unpack("<H", self._stream.read(2))
     return _decompress_crw_chunk(self._stream.read(ncompressed_words * 2),
                                  ncompressed_words, self._nchans)
Example #4
0
File: erpss.py Project: rerpy/rerpy
 def get_chunk(self, chunk_number):
     self._stream.seek(self._offsets[chunk_number])
     (ncompressed_words,) = struct.unpack("<H", self._stream.read(2))
     return _decompress_crw_chunk(self._stream.read(ncompressed_words * 2),
                                  ncompressed_words,
                                  self._nchans)