.. note::
    :class: sphx-glr-download-link-note

    Click :ref:`here <sphx_glr_download_auto_examples_plot_custom_dataset_example.py>` to download the full example code
.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_plot_custom_dataset_example.py:

Custom Dataset Example
=========================

This example shows how to convert data from X and y to a braindecode
compatible data format.


.. code-block:: default


    # Authors: Lukas Gemein <l.gemein@gmail.com>
    #
    # License: BSD (3-clause)

    import mne

    from braindecode.datasets.xy import create_from_X_y








To set up the example, we first fetch some data using mne:


.. code-block:: default


    # 5, 6, 7, 10, 13, 14 are codes for executed and imagined hands/feet
    subject_id = 22
    event_codes = [5, 6, 9, 10, 13, 14]
    # event_codes = [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]

    # This will download the files if you don't have them yet,
    # and then return the paths to the files.
    physionet_paths = mne.datasets.eegbci.load_data(
        subject_id, event_codes, update_path=False)

    # Load each of the files
    parts = [mne.io.read_raw_edf(path, preload=True, stim_channel='auto')
             for path in physionet_paths]








We take the required data, targets and additional information sampling
frequency and channel names from the loaded data. Note that this data and
information can originate from any source.


.. code-block:: default

    X = [raw.get_data() for raw in parts]
    y = event_codes
    sfreq = parts[0].info["sfreq"]
    ch_names = parts[0].info["ch_names"]








Convert to data format compatible with skorch and braindecode:


.. code-block:: default

    windows_dataset = create_from_X_y(
        X, y, drop_last_window=False, sfreq=sfreq, ch_names=ch_names,
        window_stride_samples=500,
        window_size_samples=500,
    )








.. rst-class:: sphx-glr-timing

   **Total running time of the script:** ( 0 minutes  0.828 seconds)

**Estimated memory usage:**  131 MB


.. _sphx_glr_download_auto_examples_plot_custom_dataset_example.py:


.. only :: html

 .. container:: sphx-glr-footer
    :class: sphx-glr-footer-example



  .. container:: sphx-glr-download

     :download:`Download Python source code: plot_custom_dataset_example.py <plot_custom_dataset_example.py>`



  .. container:: sphx-glr-download

     :download:`Download Jupyter notebook: plot_custom_dataset_example.ipynb <plot_custom_dataset_example.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
