BEL-Public/mffpy

Adding large segment to BinWriter object

Opened this issue · 2 comments

When I attempt to add a block of signals larger than about 2000000 samples (for 256 channels) to a BinWriter object, I get this error:

---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-7-6fddd83ebbc4> in <module>
      1 B = BinWriter(sampling_rate=sr)
----> 2 B.add_block(signals.astype(np.float32))
      3 W = Writer(join('examples', 'sample.mff'))
      4 startdatetime = datetime.strptime('1984-02-18T14:00:10.000000+0100',
      5         "%Y-%m-%dT%H:%M:%S.%f%z")

~/Repositories/mffpy/mffpy/bin_writer.py in add_block(self, data, offset_us)
     99             )
    100         # Write header/data to stream, and add an epochs block
--> 101         write_header_block(self.stream, self.header)
    102         self.append(data.tobytes())
    103         self._add_block_to_epochs(num_samples, offset_us=offset_us)

~/Repositories/mffpy/mffpy/header_block.py in write_header_block(fp, hdr)
    130     """write HeaderBlock `hdr` to file pointer `fp`"""
    131     fp.write(struct.pack('4i',
--> 132                          1, hdr.header_size, hdr.block_size, hdr.num_channels))
    133     num_samples = (hdr.block_size//hdr.num_channels) // 4
    134     # Write channel offset into the data block

error: 'i' format requires -2147483648 <= number <= 2147483647

I am able to work around this error for now by splitting the signals into multiple block and adding the blocks one at a time with no gap in time between them. I run into this error often enough that it would be good to look into how we could allow adding of larger blocks of EEG to a BinWriter object.

Can this request be closed?

@jusjusjus I think this is still worth solving. Basically we can't write a block of data of a certain size. I think we should at least throw out a message stating the maximum size of a block that we can write when this error occurs.