daily pastebin goal
83%
SHARE
TWEET

Untitled

a guest May 17th, 2018 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. Created on Fri May 11 15:26:05 2018
  5.  
  6. @author: sommars1
  7. """
  8.  
  9. from mne.datasets import sample
  10. from mne.io import read_raw_fif, RawArray
  11. from mne import create_info
  12.  
  13. from mne.io.meas_info import _merge_dict_values
  14.  
  15. import numpy as np
  16.  
  17. data_path = sample.data_path()
  18. fname_raw = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif'
  19.  
  20. raw = read_raw_fif(fname_raw, preload=True)
  21.  
  22. new_ch_raw = RawArray(
  23.             np.zeros([1, raw._data.shape[1]]),
  24.             create_info(ch_names=['NEW_CH'],
  25.                         sfreq=raw.info['sfreq'], ch_types=['ecg']),
  26.             first_samp=raw.first_samp)
  27. ignore = ['ch_names', 'chs', 'nchan', 'bads']
  28. for k, v in raw.info.items():
  29.     if k not in ignore:
  30.         new_ch_raw.info[k] = v
  31.  
  32. print('Hpi results in raw ' + str(len(raw.info['hpi_results'])) + ' item(s)')        
  33. print('Hpi results in new_ch_raw ' +  \
  34.       str(len(new_ch_raw.info['hpi_results'])) + ' item(s)')  
  35.  
  36. ## Bug is triggered here!
  37. # In the info structure of the new data some fields, i.e. hpi_results,
  38. # hpi_meas, are duplicated
  39. new_raw = raw.add_channels([new_ch_raw])
  40. print('Hpi results in new_ch_raw ' +  \
  41.       str(len(new_raw.info['hpi_results'])) + ' item(s)')  
  42.  
  43. # The problem seems to be in _merge_dict_values (called by _merge_info), which
  44. # seems not to handle properly a list of dictionary, as shown by the following
  45. # toy example .
  46. info1 = {'field1': 2, 'field2': [{'subf':3, 'subf2':4}]}
  47. info2 = {'field1': 2, 'field2': [{'subf':3, 'subf2':4}]}
  48.  
  49. merged_info = dict()
  50. fields = ['field1', 'field2']
  51. for k in fields:
  52.     merged_info[k] = _merge_dict_values([info1, info2], k)
  53.  
  54. print(' ')
  55. print('Toy example:')
  56. print(merged_info)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top