Skip to content

ENH: concatenate_epochs can be more memory efficient #6758

Closed

Description

@WilliamLabCea

Hello,

I was trying to concatenate 2 epochs with mne.concatenate_epochs, but python return memory error related to numpy array.

Last_epochs_standard = mne.concatenate_epochs([epochs1,epochs2])
Loading data for 33684 events and 1688 original time points ...
Loading data for 47154 events and 1688 original time points ...
Traceback (most recent call last):
File "", line 1, in
File "/home/wvxxxx/anaconda3/envs/Nex/lib/python3.7/site-packages/mne/epochs.py", line 2723, in concatenate_epochs
add_offset=add_offset))
File "/home/wvxxxx/anaconda3/envs/Nex/lib/python3.7/site-packages/mne/epochs.py", line 2683, in _concatenate_epochs
data = np.concatenate(data, axis=0)
File "<array_function internals>", line 6, in concatenate
MemoryError: Unable to allocate array with shape (80838, 32, 1688) and data type float64

The data size is the problem with mne.concatenate. Does it have another way to proceed ?

Best.

William

Activity

  1. agramfort commented on Sep 12, 2019

    @agramfort
    SponsorMember
  2. added this to the 0.20 milestone on Sep 12, 2019
  3. larsoner commented on Sep 12, 2019

    @larsoner
    Member

    Added this to #6380 so that we can keep track of the places we want to add preload=str support in one place, closing this (but feel free to continue discussion)

  4. WilliamLabCea commented on Sep 12, 2019

    @WilliamLabCea
    Author

    Not really. I have 63Gio in my actual computer. Each epoch data are not greater than 8go size.

  5. larsoner commented on Sep 12, 2019

    @larsoner
    Member

    Each epoch data are not greater than 8go size.

    On disk they are stored in single precision (4 bytes) but in memory they are stored as double (8 bytes). So:

    >>> mne.utils.sizeof_fmt(80838 * 32 * 1688 * 8)
    '32.53 GB'
    

    And if each is preloaded to begin with, you have to double this requirement (> 64 GB).

  6. WilliamLabCea commented on Sep 12, 2019

    @WilliamLabCea
    Author

    I read already data with preload=False.

  7. larsoner commented on Sep 12, 2019

    @larsoner
    Member

    Ahh, it's probably then because our code does (effectively) epochs.get_data() and then allocates then assigns. We can probably make this a bit more efficient by iterating over the two epochs objects rather than calling get_data (which is probably what we do) so that only one epoch per time ends up in memory. This will also only work if we know len(epochs) ahead of time, which is an additional complication (for non-preloaded ones we'll need to call drop_bad on both then iterate) but could be workable.

  8. changed the title [-]MemoryError / mne.concatenate[/-] [+]ENH: concatenate_epochs can be more memory efficient[/+] on Sep 12, 2019
  9. modified the milestones: 0.20, 0.21 on Mar 4, 2020
  10. larsoner commented on Sep 1, 2020

    @larsoner
    Member

    @WilliamLabCea #8185 should hopefully fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions