.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples_gallery/mkh5mne/from_mkh5.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_gallery_mkh5mne_from_mkh5.py: Options for converting to mne.Raw ################################# .. GENERATED FROM PYTHON SOURCE LINES 7-9 Set up ------- .. GENERATED FROM PYTHON SOURCE LINES 9-22 .. code-block:: default import os import mne from mkpy import mkh5 from mkpy.io import mkh5mne mne.viz.set_browser_backend("matplotlib") # for docs generation # FYI conda_env = os.environ["CONDA_DEFAULT_ENV"] print("conda env", conda_env) for pkg in [mkh5, mne]: print(pkg.__name__, pkg.__version__) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none conda env env_3.8 mkpy.mkh5 0.2.7 mne 1.0.3 .. GENERATED FROM PYTHON SOURCE LINES 23-28 mkh5 data file format in a nutshell =================================== This sample mkh5 data is for a single subject in an auditory oddball paradigm with previously set epoch tables. .. GENERATED FROM PYTHON SOURCE LINES 28-31 .. code-block:: default H5_F = "../mkh5_data/sub000p3.h5" h5_data = mkh5.mkh5(H5_F) .. GENERATED FROM PYTHON SOURCE LINES 32-35 Stimulus and response events of interest have been tagged with an mkh5 codemap and stored as named epochs tables ``mkh5.set_epochs(...)``. The epochs tables are whatever was deemed useful. .. GENERATED FROM PYTHON SOURCE LINES 35-60 .. code-block:: default h5_data.get_epochs_table_names() # The epochs tables have index information about where to find the # events in the mkh5 file, the experimental variables from # the codemap, and the epoch discrete time interval specs, relative # to the current mkh5 datablock. epochs_table = h5_data.get_epochs_table("ms1500") epochs_table[ [ "epoch_id", "data_group", "dblock_path", # HDF5 data lookup info "log_evcodes", "log_ccodes", "log_flags", # event code info "tone", "stim", "accuracy", "acc_type", # codemap tags "diti_t_0", "diti_hop", "diti_len", # epoch t_0, offset, duration ] ] .. raw:: html
epoch_id data_group dblock_path log_evcodes log_ccodes log_flags tone stim accuracy acc_type diti_t_0 diti_hop diti_len
0 0 sub000 sub000/dblock_0 11 1 0 hi target correct hit 1468 -187 375
1 1 sub000 sub000/dblock_0 11 1 0 hi target correct hit 2396 -187 375
2 2 sub000 sub000/dblock_0 11 1 0 hi target correct hit 2943 -187 375
3 3 sub000 sub000/dblock_0 11 1 0 hi target correct hit 3308 -187 375
4 4 sub000 sub000/dblock_0 11 1 0 hi target correct hit 4574 -187 375
... ... ... ... ... ... ... ... ... ... ... ... ... ...
595 596 sub000 sub000/dblock_4 4 0 0 cal cal cal cal 27315 -187 375
596 597 sub000 sub000/dblock_4 2 0 0 cal cal cal cal 27444 -187 375
597 598 sub000 sub000/dblock_4 3 0 0 cal cal cal cal 27573 -187 375
598 599 sub000 sub000/dblock_4 4 0 0 cal cal cal cal 27703 -187 375
599 600 sub000 sub000/dblock_4 2 0 0 cal cal cal cal 27832 -187 375

600 rows × 13 columns



.. GENERATED FROM PYTHON SOURCE LINES 61-63 The mkh5 EEG and event channel data are stored in datablocks (HDF5 Dataset) at the end of an HDF5 "slash" path: .. GENERATED FROM PYTHON SOURCE LINES 64-67 .. code-block:: default h5_data.dblock_paths .. rst-class:: sphx-glr-script-out Out: .. code-block:: none ['sub000/dblock_0', 'sub000/dblock_1', 'sub000/dblock_2', 'sub000/dblock_3', 'sub000/dblock_4'] .. GENERATED FROM PYTHON SOURCE LINES 68-75 Electrode locations =================== Converting mkh5 to mne.Raw **requires** an mkh5 format apparatus map with the coordinate space, fiducal landmarks and electrode locations. If the appartus map was included with the YAML .yhdr when the mkh5 file was created it will be used automatically. .. GENERATED FROM PYTHON SOURCE LINES 75-78 .. code-block:: default mne_raw = mkh5mne.from_mkh5(H5_F) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none ../mkh5_data/sub000p3.h5 looking up data block paths, larger files take longer ... ok checking info, montage sub000/dblock_1 checking info, montage sub000/dblock_2 checking info, montage sub000/dblock_3 checking info, montage sub000/dblock_4 Creating RawArray with float64 data, n_channels=39, n_times=31232 Range : 0 ... 31231 = 0.000 ... 124.924 secs Ready. /usr/share/miniconda/envs/env_3.8/lib/python3.8/site-packages/mkpy/io/mkh5mne.py:1478: RuntimeWarning: Not setting positions of 5 eog channels found in montage: ['lle', 'lhz', 'HEOG', 'rle', 'rhz'] Consider setting the channel types to be of EEG/sEEG/ECoG/DBS/fNIRS using inst.set_channel_types before calling inst.set_montage, or omit these channels when creating your montage. raw_dblock.set_montage(montage) sub000/dblock_0 setting mkh5 epochs table ms100 events and metadata sub000/dblock_0 setting mkh5 epochs table ms10000 events and metadata sub000/dblock_0 setting mkh5 epochs table ms1500 events and metadata sub000/dblock_0 setting mkh5 epochs table ms3000 events and metadata Creating RawArray with float64 data, n_channels=39, n_times=32768 Range : 0 ... 32767 = 0.000 ... 131.068 secs Ready. /usr/share/miniconda/envs/env_3.8/lib/python3.8/site-packages/mkpy/io/mkh5mne.py:1478: RuntimeWarning: Not setting positions of 5 eog channels found in montage: ['lle', 'lhz', 'HEOG', 'rle', 'rhz'] Consider setting the channel types to be of EEG/sEEG/ECoG/DBS/fNIRS using inst.set_channel_types before calling inst.set_montage, or omit these channels when creating your montage. raw_dblock.set_montage(montage) sub000/dblock_1 setting mkh5 epochs table ms100 events and metadata sub000/dblock_1 setting mkh5 epochs table ms10000 events and metadata sub000/dblock_1 setting mkh5 epochs table ms1500 events and metadata sub000/dblock_1 setting mkh5 epochs table ms3000 events and metadata Creating RawArray with float64 data, n_channels=39, n_times=31744 Range : 0 ... 31743 = 0.000 ... 126.972 secs Ready. /usr/share/miniconda/envs/env_3.8/lib/python3.8/site-packages/mkpy/io/mkh5mne.py:1478: RuntimeWarning: Not setting positions of 5 eog channels found in montage: ['lle', 'lhz', 'HEOG', 'rle', 'rhz'] Consider setting the channel types to be of EEG/sEEG/ECoG/DBS/fNIRS using inst.set_channel_types before calling inst.set_montage, or omit these channels when creating your montage. raw_dblock.set_montage(montage) sub000/dblock_2 setting mkh5 epochs table ms100 events and metadata sub000/dblock_2 setting mkh5 epochs table ms10000 events and metadata sub000/dblock_2 setting mkh5 epochs table ms1500 events and metadata sub000/dblock_2 setting mkh5 epochs table ms3000 events and metadata Creating RawArray with float64 data, n_channels=39, n_times=32512 Range : 0 ... 32511 = 0.000 ... 130.044 secs Ready. /usr/share/miniconda/envs/env_3.8/lib/python3.8/site-packages/mkpy/io/mkh5mne.py:1478: RuntimeWarning: Not setting positions of 5 eog channels found in montage: ['lle', 'lhz', 'HEOG', 'rle', 'rhz'] Consider setting the channel types to be of EEG/sEEG/ECoG/DBS/fNIRS using inst.set_channel_types before calling inst.set_montage, or omit these channels when creating your montage. raw_dblock.set_montage(montage) sub000/dblock_3 setting mkh5 epochs table ms100 events and metadata sub000/dblock_3 setting mkh5 epochs table ms10000 events and metadata sub000/dblock_3 setting mkh5 epochs table ms1500 events and metadata sub000/dblock_3 setting mkh5 epochs table ms3000 events and metadata Creating RawArray with float64 data, n_channels=39, n_times=28416 Range : 0 ... 28415 = 0.000 ... 113.660 secs Ready. /usr/share/miniconda/envs/env_3.8/lib/python3.8/site-packages/mkpy/io/mkh5mne.py:1478: RuntimeWarning: Not setting positions of 5 eog channels found in montage: ['lle', 'lhz', 'HEOG', 'rle', 'rhz'] Consider setting the channel types to be of EEG/sEEG/ECoG/DBS/fNIRS using inst.set_channel_types before calling inst.set_montage, or omit these channels when creating your montage. raw_dblock.set_montage(montage) sub000/dblock_4 setting mkh5 epochs table ms100 events and metadata sub000/dblock_4 setting mkh5 epochs table ms10000 events and metadata sub000/dblock_4 setting mkh5 epochs table ms1500 events and metadata sub000/dblock_4 setting mkh5 epochs table ms3000 events and metadata EEG data marked as already having the desired reference. .. GENERATED FROM PYTHON SOURCE LINES 79-84 This sample mkh5 data file was created with coordinates for an idealized "average" head, based on 3D digitized locations. Head-shaped locations are called for when working with realistic head geometry in MNE but they don't line up exactly with circular topographic maps. .. GENERATED FROM PYTHON SOURCE LINES 85-87 .. code-block:: default _ = mne.viz.plot_sensors(mne_raw.info, sphere="auto") .. image-sg:: /examples_gallery/mkh5mne/images/sphx_glr_from_mkh5_001.png :alt: from mkh5 :srcset: /examples_gallery/mkh5mne/images/sphx_glr_from_mkh5_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 88-96 If original .yhdr did not include an apparatus map or a different set of locations is preferred, they can be specified when converting to MNE and used instead. This map overrides the original head-shaped electrode locations with spherical 3D coordinates which are unrealistic as human head geometry but line up neatly with circles for painting pretty 2D pictures. .. GENERATED FROM PYTHON SOURCE LINES 97-102 .. code-block:: default mne_raw_a = mkh5mne.from_mkh5(H5_F, apparatus_yaml="mne_32chan_xyz_spherical.yml") _ = mne.viz.plot_sensors(mne_raw_a.info) .. image-sg:: /examples_gallery/mkh5mne/images/sphx_glr_from_mkh5_002.png :alt: from mkh5 :srcset: /examples_gallery/mkh5mne/images/sphx_glr_from_mkh5_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none ../mkh5_data/sub000p3.h5 looking up data block paths, larger files take longer ... ok /usr/share/miniconda/envs/env_3.8/lib/python3.8/site-packages/mkpy/io/mkh5mne.py:1190: UserWarning: Overriding /sub000/dblock_0 with sensor locations from mne_32chan_xyz_spherical.yml warnings.warn(msg) checking info, montage sub000/dblock_1 /usr/share/miniconda/envs/env_3.8/lib/python3.8/site-packages/mkpy/io/mkh5mne.py:1190: UserWarning: Overriding /sub000/dblock_1 with sensor locations from mne_32chan_xyz_spherical.yml warnings.warn(msg) checking info, montage sub000/dblock_2 /usr/share/miniconda/envs/env_3.8/lib/python3.8/site-packages/mkpy/io/mkh5mne.py:1190: UserWarning: Overriding /sub000/dblock_2 with sensor locations from mne_32chan_xyz_spherical.yml warnings.warn(msg) checking info, montage sub000/dblock_3 /usr/share/miniconda/envs/env_3.8/lib/python3.8/site-packages/mkpy/io/mkh5mne.py:1190: UserWarning: Overriding /sub000/dblock_3 with sensor locations from mne_32chan_xyz_spherical.yml warnings.warn(msg) checking info, montage sub000/dblock_4 /usr/share/miniconda/envs/env_3.8/lib/python3.8/site-packages/mkpy/io/mkh5mne.py:1190: UserWarning: Overriding /sub000/dblock_4 with sensor locations from mne_32chan_xyz_spherical.yml warnings.warn(msg) /usr/share/miniconda/envs/env_3.8/lib/python3.8/site-packages/mkpy/io/mkh5mne.py:1190: UserWarning: Overriding /sub000/dblock_0 with sensor locations from mne_32chan_xyz_spherical.yml warnings.warn(msg) Creating RawArray with float64 data, n_channels=39, n_times=31232 Range : 0 ... 31231 = 0.000 ... 124.924 secs Ready. /usr/share/miniconda/envs/env_3.8/lib/python3.8/site-packages/mkpy/io/mkh5mne.py:1478: RuntimeWarning: Not setting position of 1 eog channel found in montage: ['HEOG'] Consider setting the channel types to be of EEG/sEEG/ECoG/DBS/fNIRS using inst.set_channel_types before calling inst.set_montage, or omit these channels when creating your montage. raw_dblock.set_montage(montage) sub000/dblock_0 setting mkh5 epochs table ms100 events and metadata sub000/dblock_0 setting mkh5 epochs table ms10000 events and metadata sub000/dblock_0 setting mkh5 epochs table ms1500 events and metadata sub000/dblock_0 setting mkh5 epochs table ms3000 events and metadata /usr/share/miniconda/envs/env_3.8/lib/python3.8/site-packages/mkpy/io/mkh5mne.py:1190: UserWarning: Overriding /sub000/dblock_1 with sensor locations from mne_32chan_xyz_spherical.yml warnings.warn(msg) Creating RawArray with float64 data, n_channels=39, n_times=32768 Range : 0 ... 32767 = 0.000 ... 131.068 secs Ready. /usr/share/miniconda/envs/env_3.8/lib/python3.8/site-packages/mkpy/io/mkh5mne.py:1478: RuntimeWarning: Not setting position of 1 eog channel found in montage: ['HEOG'] Consider setting the channel types to be of EEG/sEEG/ECoG/DBS/fNIRS using inst.set_channel_types before calling inst.set_montage, or omit these channels when creating your montage. raw_dblock.set_montage(montage) sub000/dblock_1 setting mkh5 epochs table ms100 events and metadata sub000/dblock_1 setting mkh5 epochs table ms10000 events and metadata sub000/dblock_1 setting mkh5 epochs table ms1500 events and metadata sub000/dblock_1 setting mkh5 epochs table ms3000 events and metadata /usr/share/miniconda/envs/env_3.8/lib/python3.8/site-packages/mkpy/io/mkh5mne.py:1190: UserWarning: Overriding /sub000/dblock_2 with sensor locations from mne_32chan_xyz_spherical.yml warnings.warn(msg) Creating RawArray with float64 data, n_channels=39, n_times=31744 Range : 0 ... 31743 = 0.000 ... 126.972 secs Ready. /usr/share/miniconda/envs/env_3.8/lib/python3.8/site-packages/mkpy/io/mkh5mne.py:1478: RuntimeWarning: Not setting position of 1 eog channel found in montage: ['HEOG'] Consider setting the channel types to be of EEG/sEEG/ECoG/DBS/fNIRS using inst.set_channel_types before calling inst.set_montage, or omit these channels when creating your montage. raw_dblock.set_montage(montage) sub000/dblock_2 setting mkh5 epochs table ms100 events and metadata sub000/dblock_2 setting mkh5 epochs table ms10000 events and metadata sub000/dblock_2 setting mkh5 epochs table ms1500 events and metadata sub000/dblock_2 setting mkh5 epochs table ms3000 events and metadata /usr/share/miniconda/envs/env_3.8/lib/python3.8/site-packages/mkpy/io/mkh5mne.py:1190: UserWarning: Overriding /sub000/dblock_3 with sensor locations from mne_32chan_xyz_spherical.yml warnings.warn(msg) Creating RawArray with float64 data, n_channels=39, n_times=32512 Range : 0 ... 32511 = 0.000 ... 130.044 secs Ready. /usr/share/miniconda/envs/env_3.8/lib/python3.8/site-packages/mkpy/io/mkh5mne.py:1478: RuntimeWarning: Not setting position of 1 eog channel found in montage: ['HEOG'] Consider setting the channel types to be of EEG/sEEG/ECoG/DBS/fNIRS using inst.set_channel_types before calling inst.set_montage, or omit these channels when creating your montage. raw_dblock.set_montage(montage) sub000/dblock_3 setting mkh5 epochs table ms100 events and metadata sub000/dblock_3 setting mkh5 epochs table ms10000 events and metadata sub000/dblock_3 setting mkh5 epochs table ms1500 events and metadata sub000/dblock_3 setting mkh5 epochs table ms3000 events and metadata /usr/share/miniconda/envs/env_3.8/lib/python3.8/site-packages/mkpy/io/mkh5mne.py:1190: UserWarning: Overriding /sub000/dblock_4 with sensor locations from mne_32chan_xyz_spherical.yml warnings.warn(msg) Creating RawArray with float64 data, n_channels=39, n_times=28416 Range : 0 ... 28415 = 0.000 ... 113.660 secs Ready. /usr/share/miniconda/envs/env_3.8/lib/python3.8/site-packages/mkpy/io/mkh5mne.py:1478: RuntimeWarning: Not setting position of 1 eog channel found in montage: ['HEOG'] Consider setting the channel types to be of EEG/sEEG/ECoG/DBS/fNIRS using inst.set_channel_types before calling inst.set_montage, or omit these channels when creating your montage. raw_dblock.set_montage(montage) sub000/dblock_4 setting mkh5 epochs table ms100 events and metadata sub000/dblock_4 setting mkh5 epochs table ms10000 events and metadata sub000/dblock_4 setting mkh5 epochs table ms1500 events and metadata sub000/dblock_4 setting mkh5 epochs table ms3000 events and metadata EEG data marked as already having the desired reference. .. GENERATED FROM PYTHON SOURCE LINES 103-115 Selecting which datablocks to convert to mne.Raw ================================================ By default :py:meth:`.read_raw_mkh5` converts the entire mkh5 file. The mkh5 data groups and EEG datablocks are appended in the order order returned by :py:meth:`.dblock_paths` which sorts HDF5 the HDF5 paths to data group alphabetically and preserves data block order within each group. An mkh5 file might have multiple subjects or experiments, if you don't want to make it all one mne.Raw object, you can select which data blocks to convert with ``datablock_paths=``. .. GENERATED FROM PYTHON SOURCE LINES 115-123 .. code-block:: default mne_raw_b = mkh5mne.read_raw_mkh5( H5_F, dblock_paths=["sub000/dblock_0", "sub000/dblock_1"] ) # only dblock_0 and dblock_1 appear in the Raw data mne_raw_b.annotations.description .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /usr/share/miniconda/envs/env_3.8/lib/python3.8/site-packages/mkpy/io/mkh5mne.py:1688: UserWarning: mkh5mne.read_raw_mkh5() is deprecated and will be removed in a future release, use mkh5mn3.from_mkh5() instead warnings.warn( ok checking info, montage sub000/dblock_1 Creating RawArray with float64 data, n_channels=39, n_times=31232 Range : 0 ... 31231 = 0.000 ... 124.924 secs Ready. /usr/share/miniconda/envs/env_3.8/lib/python3.8/site-packages/mkpy/io/mkh5mne.py:1478: RuntimeWarning: Not setting positions of 5 eog channels found in montage: ['lle', 'lhz', 'HEOG', 'rle', 'rhz'] Consider setting the channel types to be of EEG/sEEG/ECoG/DBS/fNIRS using inst.set_channel_types before calling inst.set_montage, or omit these channels when creating your montage. raw_dblock.set_montage(montage) sub000/dblock_0 setting mkh5 epochs table ms100 events and metadata sub000/dblock_0 setting mkh5 epochs table ms10000 events and metadata sub000/dblock_0 setting mkh5 epochs table ms1500 events and metadata sub000/dblock_0 setting mkh5 epochs table ms3000 events and metadata Creating RawArray with float64 data, n_channels=39, n_times=32768 Range : 0 ... 32767 = 0.000 ... 131.068 secs Ready. /usr/share/miniconda/envs/env_3.8/lib/python3.8/site-packages/mkpy/io/mkh5mne.py:1478: RuntimeWarning: Not setting positions of 5 eog channels found in montage: ['lle', 'lhz', 'HEOG', 'rle', 'rhz'] Consider setting the channel types to be of EEG/sEEG/ECoG/DBS/fNIRS using inst.set_channel_types before calling inst.set_montage, or omit these channels when creating your montage. raw_dblock.set_montage(montage) sub000/dblock_1 setting mkh5 epochs table ms100 events and metadata sub000/dblock_1 setting mkh5 epochs table ms10000 events and metadata sub000/dblock_1 setting mkh5 epochs table ms1500 events and metadata sub000/dblock_1 setting mkh5 epochs table ms3000 events and metadata EEG data marked as already having the desired reference. array(['sub000/dblock_0', 'sub000/dblock_1', 'BAD boundary', 'EDGE boundary'], dtype=' .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 1 minutes 28.220 seconds) .. _sphx_glr_download_examples_gallery_mkh5mne_from_mkh5.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: from_mkh5.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: from_mkh5.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_