Diff of /doc/_includes/memory.rst [000000] .. [7f9fb8]

Switch to unified view

a b/doc/_includes/memory.rst
1
:orphan:
2
3
Memory-efficient I/O
4
====================
5
6
.. NOTE: part of this file is included in doc/overview/implementation.rst.
7
   Changes here are reflected there. If you want to link to this content, link
8
   to :ref:`memory` to link to that section of the implementation.rst
9
   page. The next line is a target for :start-after: so we can omit the title
10
   from the include:
11
   memory-begin-content
12
13
14
Preloading continuous (raw) data
15
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16
17
MNE-Python can read data on-demand using the ``preload`` option provided in
18
raw reading functions. For example::
19
20
    from mne import io
21
    from mne.datasets import sample
22
    data_path = sample.data_path()
23
    raw_fname = data_path / 'MEG' / 'sample' / 'sample_audvis_filt-0-40_raw.fif'
24
    raw = io.read_raw_fif(raw_fname, preload=False)
25
26
.. note:: Filtering, resampling and dropping or selecting channels does not
27
          work with ``preload=False``.
28
29
30
Preloading epoched data
31
~~~~~~~~~~~~~~~~~~~~~~~
32
33
Similarly, epochs can also be be read from disk on-demand. For example::
34
35
    import mne
36
    events = mne.find_events(raw)
37
    event_id, tmin, tmax = 1, -0.2, 0.5
38
    picks = mne.pick_types(raw.info, meg=True, eeg=True, stim=False, eog=True)
39
    epochs = mne.Epochs(raw, events, event_id, tmin, tmax, picks=picks,
40
                        baseline=(None, 0), reject=dict(eeg=80e-6, eog=150e-6),
41
                        preload=False)
42
43
When ``preload=False``, the epochs data is loaded from the disk on-demand. Note
44
that ``preload=False`` for epochs will work even if the ``raw`` object has been
45
loaded with ``preload=True``. Preloading is also supported for
46
:func:`mne.read_epochs`.
47
48
.. warning:: This comes with a caveat. When ``preload=False``, data rejection
49
             based on peak-to-peak thresholds is executed when the data is
50
             loaded from disk, *not* when the ``Epochs`` object is created.
51
52
To explicitly reject artifacts with ``preload=False``, use the function :func:`mne.Epochs.drop_bad`.
53
54
55
Loading data explicitly
56
~~~~~~~~~~~~~~~~~~~~~~~
57
58
To load the data if ``preload=False`` was initially selected, use the functions :func:`mne.io.Raw.load_data` and :func:`mne.Epochs.load_data`.
59
60
61
Accessing data as NumPy arrays
62
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
63
64
If you just want your raw data as a :class:`Numpy array <numpy.ndarray>` to
65
work with it in a different framework you can use slicing syntax::
66
67
    first_channel_data, times = raw[0, :]
68
    channels_3_and_4, times = raw[3:5, :]