Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- Created on Fri May 11 15:26:05 2018
- @author: sommars1
- """
- from mne.datasets import sample
- from mne.io import read_raw_fif, RawArray
- from mne import create_info
- from mne.io.meas_info import _merge_dict_values
- import numpy as np
- data_path = sample.data_path()
- fname_raw = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif'
- raw = read_raw_fif(fname_raw, preload=True)
- new_ch_raw = RawArray(
- np.zeros([1, raw._data.shape[1]]),
- create_info(ch_names=['NEW_CH'],
- sfreq=raw.info['sfreq'], ch_types=['ecg']),
- first_samp=raw.first_samp)
- ignore = ['ch_names', 'chs', 'nchan', 'bads']
- for k, v in raw.info.items():
- if k not in ignore:
- new_ch_raw.info[k] = v
- print('Hpi results in raw ' + str(len(raw.info['hpi_results'])) + ' item(s)')
- print('Hpi results in new_ch_raw ' + \
- str(len(new_ch_raw.info['hpi_results'])) + ' item(s)')
- ## Bug is triggered here!
- # In the info structure of the new data some fields, i.e. hpi_results,
- # hpi_meas, are duplicated
- new_raw = raw.add_channels([new_ch_raw])
- print('Hpi results in new_ch_raw ' + \
- str(len(new_raw.info['hpi_results'])) + ' item(s)')
- # The problem seems to be in _merge_dict_values (called by _merge_info), which
- # seems not to handle properly a list of dictionary, as shown by the following
- # toy example .
- info1 = {'field1': 2, 'field2': [{'subf':3, 'subf2':4}]}
- info2 = {'field1': 2, 'field2': [{'subf':3, 'subf2':4}]}
- merged_info = dict()
- fields = ['field1', 'field2']
- for k in fields:
- merged_info[k] = _merge_dict_values([info1, info2], k)
- print(' ')
- print('Toy example:')
- print(merged_info)
Add Comment
Please, Sign In to add comment