<s> import os <EOL> import os . path as op <EOL> import numpy as np <EOL> from scipy import sparse <EOL> from . . externals . six import string_types <EOL> from . . utils import verbose , logger , warn , _check_copy_dep <EOL> from . . io . pick import ( channel_type , pick_info , pick_types , <EOL> _check_excludes_includes , _PICK_TYPES_KEYS ) <EOL> from . . io . constants import FIFF <EOL> def _get_meg_system ( info ) : <EOL> """<STR_LIT>""" <EOL> system = '<STR_LIT>' <EOL> for ch in info [ '<STR_LIT>' ] : <EOL> if ch [ '<STR_LIT>' ] == FIFF . FIFFV_MEG_CH : <EOL> coil_type = ch [ '<STR_LIT>' ] & <NUM_LIT> <EOL> if coil_type == FIFF . FIFFV_COIL_NM_122 : <EOL> system = '<STR_LIT>' <EOL> break <EOL> elif coil_type // <NUM_LIT:1000> == <NUM_LIT:3> : <EOL> system = '<STR_LIT>' <EOL> break <EOL> elif ( coil_type == FIFF . FIFFV_COIL_MAGNES_MAG or <EOL> coil_type == FIFF . FIFFV_COIL_MAGNES_GRAD ) : <EOL> nmag = np . sum ( [ c [ '<STR_LIT>' ] == FIFF . FIFFV_MEG_CH <EOL> for c in info [ '<STR_LIT>' ] ] ) <EOL> system = '<STR_LIT>' if nmag > <NUM_LIT> else '<STR_LIT>' <EOL> break <EOL> elif coil_type == FIFF . FIFFV_COIL_CTF_GRAD : <EOL> system = '<STR_LIT>' <EOL> break <EOL> elif coil_type == FIFF . FIFFV_COIL_KIT_GRAD : <EOL> system = '<STR_LIT>' <EOL> break <EOL> elif coil_type == FIFF . FIFFV_COIL_BABY_GRAD : <EOL> system = '<STR_LIT>' <EOL> break <EOL> return system <EOL> def _contains_ch_type ( info , ch_type ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( ch_type , string_types ) : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( actual_class = type ( ch_type ) ) ) <EOL> meg_extras = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> valid_channel_types = sorted ( [ key for key in _PICK_TYPES_KEYS <EOL> if key != '<STR_LIT>' ] + meg_extras ) <EOL> if ch_type not in valid_channel_types : <EOL> raise ValueError ( '<STR_LIT>' <EOL> % ( valid_channel_types , ch_type ) ) <EOL> if info is None : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( ch_type , ) ) <EOL> return ch_type in [ channel_type ( info , ii ) for ii in range ( info [ '<STR_LIT>' ] ) ] <EOL> def _get_ch_type ( inst , ch_type ) : <EOL> """<STR_LIT>""" <EOL> if ch_type is None : <EOL> for type_ in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if type_ in inst : <EOL> ch_type = type_ <EOL> break <EOL> else : <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> return ch_type <EOL> @ verbose <EOL> def equalize_channels ( candidates , verbose = None ) : <EOL> """<STR_LIT>""" <EOL> from . . io . base import _BaseRaw <EOL> from . . epochs import _BaseEpochs <EOL> from . . evoked import Evoked <EOL> from . . time_frequency import AverageTFR <EOL> if not all ( isinstance ( c , ( _BaseRaw , _BaseEpochs , Evoked , AverageTFR ) ) <EOL> for c in candidates ) : <EOL> valid = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> raise ValueError ( '<STR_LIT>' + '<STR_LIT>' . join ( valid ) ) <EOL> chan_max_idx = np . argmax ( [ c . info [ '<STR_LIT>' ] for c in candidates ] ) <EOL> chan_template = candidates [ chan_max_idx ] . ch_names <EOL> logger . info ( '<STR_LIT>' ) <EOL> channels = [ set ( c . ch_names ) for c in candidates ] <EOL> common_channels = set ( chan_template ) . intersection ( * channels ) <EOL> dropped = list ( ) <EOL> for c in candidates : <EOL> drop_them = list ( set ( c . ch_names ) - common_channels ) <EOL> if drop_them : <EOL> c . drop_channels ( drop_them ) <EOL> dropped . extend ( drop_them ) <EOL> if dropped : <EOL> dropped = list ( set ( dropped ) ) <EOL> logger . info ( '<STR_LIT>' % dropped ) <EOL> else : <EOL> logger . info ( '<STR_LIT>' ) <EOL> class ContainsMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> def __contains__ ( self , ch_type ) : <EOL> """<STR_LIT>""" <EOL> if ch_type == '<STR_LIT>' : <EOL> has_ch_type = ( _contains_ch_type ( self . info , '<STR_LIT>' ) or <EOL> _contains_ch_type ( self . info , '<STR_LIT>' ) ) <EOL> else : <EOL> has_ch_type = _contains_ch_type ( self . info , ch_type ) <EOL> return has_ch_type <EOL> _human2fiff = { '<STR_LIT>' : FIFF . FIFFV_ECG_CH , <EOL> '<STR_LIT>' : FIFF . FIFFV_EEG_CH , <EOL> '<STR_LIT>' : FIFF . FIFFV_EMG_CH , <EOL> '<STR_LIT>' : FIFF . FIFFV_EOG_CH , <EOL> '<STR_LIT>' : FIFF . FIFFV_EXCI_CH , <EOL> '<STR_LIT>' : FIFF . FIFFV_IAS_CH , <EOL> '<STR_LIT>' : FIFF . FIFFV_MISC_CH , <EOL> '<STR_LIT>' : FIFF . FIFFV_RESP_CH , <EOL> '<STR_LIT>' : FIFF . FIFFV_SEEG_CH , <EOL> '<STR_LIT>' : FIFF . FIFFV_STIM_CH , <EOL> '<STR_LIT>' : FIFF . FIFFV_SYST_CH , <EOL> '<STR_LIT>' : FIFF . FIFFV_BIO_CH , <EOL> '<STR_LIT>' : FIFF . FIFFV_ECOG_CH } <EOL> _human2unit = { '<STR_LIT>' : FIFF . FIFF_UNIT_V , <EOL> '<STR_LIT>' : FIFF . FIFF_UNIT_V , <EOL> '<STR_LIT>' : FIFF . FIFF_UNIT_V , <EOL> '<STR_LIT>' : FIFF . FIFF_UNIT_V , <EOL> '<STR_LIT>' : FIFF . FIFF_UNIT_NONE , <EOL> '<STR_LIT>' : FIFF . FIFF_UNIT_NONE , <EOL> '<STR_LIT>' : FIFF . FIFF_UNIT_V , <EOL> '<STR_LIT>' : FIFF . FIFF_UNIT_NONE , <EOL> '<STR_LIT>' : FIFF . FIFF_UNIT_V , <EOL> '<STR_LIT>' : FIFF . FIFF_UNIT_NONE , <EOL> '<STR_LIT>' : FIFF . FIFF_UNIT_NONE , <EOL> '<STR_LIT>' : FIFF . FIFF_UNIT_V , <EOL> '<STR_LIT>' : FIFF . FIFF_UNIT_V } <EOL> _unit2human = { FIFF . FIFF_UNIT_V : '<STR_LIT>' , <EOL> FIFF . FIFF_UNIT_T : '<STR_LIT:T>' , <EOL> FIFF . FIFF_UNIT_T_M : '<STR_LIT>' , <EOL> FIFF . FIFF_UNIT_NONE : '<STR_LIT>' } <EOL> def _check_set ( ch , projs , ch_type ) : <EOL> """<STR_LIT>""" <EOL> new_kind = _human2fiff [ ch_type ] <EOL> if ch [ '<STR_LIT>' ] != new_kind : <EOL> for proj in projs : <EOL> if ch [ '<STR_LIT>' ] in proj [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] : <EOL> raise RuntimeError ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> % ( ch [ '<STR_LIT>' ] , proj [ '<STR_LIT>' ] ) ) <EOL> ch [ '<STR_LIT>' ] = new_kind <EOL> class SetChannelsMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> def _get_channel_positions ( self , picks = None ) : <EOL> """<STR_LIT>""" <EOL> if picks is None : <EOL> picks = pick_types ( self . info , meg = True , eeg = True ) <EOL> chs = self . info [ '<STR_LIT>' ] <EOL> pos = np . array ( [ chs [ k ] [ '<STR_LIT>' ] [ : <NUM_LIT:3> ] for k in picks ] ) <EOL> n_zero = np . sum ( np . sum ( np . abs ( pos ) , axis = <NUM_LIT:1> ) == <NUM_LIT:0> ) <EOL> if n_zero > <NUM_LIT:1> : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( n_zero ) ) <EOL> return pos <EOL> def _set_channel_positions ( self , pos , names ) : <EOL> """<STR_LIT>""" <EOL> if len ( pos ) != len ( names ) : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> pos = np . asarray ( pos , dtype = np . float ) <EOL> if pos . shape [ - <NUM_LIT:1> ] != <NUM_LIT:3> or pos . ndim != <NUM_LIT:2> : <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( pos . shape , ) ) <EOL> raise ValueError ( msg ) <EOL> for name , p in zip ( names , pos ) : <EOL> if name in self . ch_names : <EOL> idx = self . ch_names . index ( name ) <EOL> self . info [ '<STR_LIT>' ] [ idx ] [ '<STR_LIT>' ] [ : <NUM_LIT:3> ] = p <EOL> else : <EOL> msg = ( '<STR_LIT>' <EOL> % name ) <EOL> raise ValueError ( msg ) <EOL> def set_channel_types ( self , mapping ) : <EOL> """<STR_LIT>""" <EOL> ch_names = self . info [ '<STR_LIT>' ] <EOL> for ch_name , ch_type in mapping . items ( ) : <EOL> if ch_name not in ch_names : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" % ch_name ) <EOL> c_ind = ch_names . index ( ch_name ) <EOL> if ch_type not in _human2fiff : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> % ( ch_type , <EOL> "<STR_LIT:U+002CU+0020>" . join ( sorted ( _human2unit . keys ( ) ) ) ) ) <EOL> _check_set ( self . info [ '<STR_LIT>' ] [ c_ind ] , self . info [ '<STR_LIT>' ] , ch_type ) <EOL> unit_old = self . info [ '<STR_LIT>' ] [ c_ind ] [ '<STR_LIT>' ] <EOL> unit_new = _human2unit [ ch_type ] <EOL> if unit_old not in _unit2human : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( ch_name , unit_old ) ) <EOL> if unit_old != _human2unit [ ch_type ] : <EOL> warn ( "<STR_LIT>" <EOL> % ( ch_name , _unit2human [ unit_old ] , _unit2human [ unit_new ] ) ) <EOL> self . info [ '<STR_LIT>' ] [ c_ind ] [ '<STR_LIT>' ] = _human2unit [ ch_type ] <EOL> if ch_type in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> self . info [ '<STR_LIT>' ] [ c_ind ] [ '<STR_LIT>' ] = FIFF . FIFFV_COIL_EEG <EOL> else : <EOL> self . info [ '<STR_LIT>' ] [ c_ind ] [ '<STR_LIT>' ] = FIFF . FIFFV_COIL_NONE <EOL> def rename_channels ( self , mapping ) : <EOL> """<STR_LIT>""" <EOL> rename_channels ( self . info , mapping ) <EOL> @ verbose <EOL> def set_montage ( self , montage , verbose = None ) : <EOL> """<STR_LIT>""" <EOL> from . montage import _set_montage <EOL> _set_montage ( self . info , montage ) <EOL> def plot_sensors ( self , kind = '<STR_LIT>' , ch_type = None , title = None , <EOL> show_names = False , show = True ) : <EOL> """<STR_LIT>""" <EOL> from . . viz . utils import plot_sensors <EOL> return plot_sensors ( self . info , kind = kind , ch_type = ch_type , title = title , <EOL> show_names = show_names , show = show ) <EOL> class UpdateChannelsMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> def pick_types ( self , meg = True , eeg = False , stim = False , eog = False , <EOL> ecg = False , emg = False , ref_meg = '<STR_LIT>' , misc = False , <EOL> resp = False , chpi = False , exci = False , ias = False , syst = False , <EOL> seeg = False , bio = False , ecog = False , include = [ ] , <EOL> exclude = '<STR_LIT>' , selection = None , copy = None ) : <EOL> """<STR_LIT>""" <EOL> inst = _check_copy_dep ( self , copy ) <EOL> idx = pick_types ( <EOL> self . info , meg = meg , eeg = eeg , stim = stim , eog = eog , ecg = ecg , emg = emg , <EOL> ref_meg = ref_meg , misc = misc , resp = resp , chpi = chpi , exci = exci , <EOL> ias = ias , syst = syst , seeg = seeg , bio = bio , ecog = ecog , include = include , <EOL> exclude = exclude , selection = selection ) <EOL> inst . _pick_drop_channels ( idx ) <EOL> return inst <EOL> def pick_channels ( self , ch_names , copy = None ) : <EOL> """<STR_LIT>""" <EOL> inst = _check_copy_dep ( self , copy ) <EOL> _check_excludes_includes ( ch_names ) <EOL> idx = [ inst . ch_names . index ( c ) for c in ch_names if c in inst . ch_names ] <EOL> inst . _pick_drop_channels ( idx ) <EOL> return inst <EOL> def drop_channels ( self , ch_names , copy = None ) : <EOL> """<STR_LIT>""" <EOL> inst = _check_copy_dep ( self , copy ) <EOL> bad_idx = [ inst . ch_names . index ( c ) for c in ch_names <EOL> if c in inst . ch_names ] <EOL> idx = np . setdiff1d ( np . arange ( len ( inst . ch_names ) ) , bad_idx ) <EOL> inst . _pick_drop_channels ( idx ) <EOL> return inst <EOL> def _pick_drop_channels ( self , idx ) : <EOL> from . . io . base import _BaseRaw <EOL> from . . epochs import _BaseEpochs <EOL> from . . evoked import Evoked <EOL> from . . time_frequency import AverageTFR <EOL> if isinstance ( self , ( _BaseRaw , _BaseEpochs ) ) : <EOL> if not self . preload : <EOL> raise RuntimeError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def inst_has ( attr ) : <EOL> return getattr ( self , attr , None ) is not None <EOL> if inst_has ( '<STR_LIT>' ) : <EOL> self . picks = self . picks [ idx ] <EOL> if inst_has ( '<STR_LIT>' ) : <EOL> self . _cals = self . _cals [ idx ] <EOL> pick_info ( self . info , idx , copy = False ) <EOL> if inst_has ( '<STR_LIT>' ) : <EOL> self . _projector = self . _projector [ idx ] [ : , idx ] <EOL> if isinstance ( self , _BaseRaw ) and inst_has ( '<STR_LIT>' ) : <EOL> self . _data = self . _data . take ( idx , axis = <NUM_LIT:0> ) <EOL> elif isinstance ( self , _BaseEpochs ) and inst_has ( '<STR_LIT>' ) : <EOL> self . _data = self . _data . take ( idx , axis = <NUM_LIT:1> ) <EOL> elif isinstance ( self , AverageTFR ) and inst_has ( '<STR_LIT:data>' ) : <EOL> self . data = self . data . take ( idx , axis = <NUM_LIT:0> ) <EOL> elif isinstance ( self , Evoked ) : <EOL> self . data = self . data . take ( idx , axis = <NUM_LIT:0> ) <EOL> def add_channels ( self , add_list , copy = None ) : <EOL> """<STR_LIT>""" <EOL> out = _check_copy_dep ( self , copy ) <EOL> from . . io import _BaseRaw , _merge_info <EOL> from . . epochs import _BaseEpochs <EOL> if not isinstance ( add_list , ( list , tuple ) ) : <EOL> raise AssertionError ( '<STR_LIT>' ) <EOL> if isinstance ( self , ( _BaseRaw , _BaseEpochs ) ) : <EOL> if not all ( [ inst . preload for inst in add_list ] + [ self . preload ] ) : <EOL> raise AssertionError ( '<STR_LIT>' ) <EOL> data_name = '<STR_LIT>' <EOL> if isinstance ( self , _BaseRaw ) : <EOL> con_axis = <NUM_LIT:0> <EOL> comp_class = _BaseRaw <EOL> elif isinstance ( self , _BaseEpochs ) : <EOL> con_axis = <NUM_LIT:1> <EOL> comp_class = _BaseEpochs <EOL> else : <EOL> data_name = '<STR_LIT:data>' <EOL> con_axis = <NUM_LIT:0> <EOL> comp_class = type ( self ) <EOL> if not all ( isinstance ( inst , comp_class ) for inst in add_list ) : <EOL> raise AssertionError ( '<STR_LIT>' ) <EOL> data = [ getattr ( inst , data_name ) for inst in [ self ] + add_list ] <EOL> compare_axes = [ i for i in range ( data [ <NUM_LIT:0> ] . ndim ) if i != con_axis ] <EOL> shapes = np . array ( [ dat . shape for dat in data ] ) [ : , compare_axes ] <EOL> if not ( ( shapes [ <NUM_LIT:0> ] - shapes ) == <NUM_LIT:0> ) . all ( ) : <EOL> raise AssertionError ( '<STR_LIT>' ) <EOL> data = np . concatenate ( data , axis = con_axis ) <EOL> infos = [ self . info ] + [ inst . info for inst in add_list ] <EOL> new_info = _merge_info ( infos ) <EOL> setattr ( out , data_name , data ) <EOL> out . info = new_info <EOL> if isinstance ( self , _BaseRaw ) : <EOL> out . _cals = np . concatenate ( [ getattr ( inst , '<STR_LIT>' ) <EOL> for inst in [ self ] + add_list ] ) <EOL> return out <EOL> class InterpolationMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> def interpolate_bads ( self , reset_bads = True , mode = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> from . interpolation import _interpolate_bads_eeg , _interpolate_bads_meg <EOL> if getattr ( self , '<STR_LIT>' , None ) is False : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> _interpolate_bads_eeg ( self ) <EOL> _interpolate_bads_meg ( self , mode = mode ) <EOL> if reset_bads is True : <EOL> self . info [ '<STR_LIT>' ] = [ ] <EOL> return self <EOL> def rename_channels ( info , mapping ) : <EOL> """<STR_LIT>""" <EOL> info . _check_consistency ( ) <EOL> bads = list ( info [ '<STR_LIT>' ] ) <EOL> ch_names = list ( info [ '<STR_LIT>' ] ) <EOL> if isinstance ( mapping , dict ) : <EOL> orig_names = sorted ( list ( mapping . keys ( ) ) ) <EOL> missing = [ orig_name not in ch_names for orig_name in orig_names ] <EOL> if any ( missing ) : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT:%s>" % np . array ( orig_names ) [ np . array ( missing ) ] ) <EOL> new_names = [ ( ch_names . index ( ch_name ) , new_name ) <EOL> for ch_name , new_name in mapping . items ( ) ] <EOL> elif callable ( mapping ) : <EOL> new_names = [ ( ci , mapping ( ch_name ) ) <EOL> for ci , ch_name in enumerate ( ch_names ) ] <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' <EOL> % ( type ( mapping ) , ) ) <EOL> if any ( not isinstance ( new_name [ <NUM_LIT:1> ] , string_types ) <EOL> for new_name in new_names ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> for c_ind , new_name in new_names : <EOL> for bi , bad in enumerate ( bads ) : <EOL> if bad == ch_names [ c_ind ] : <EOL> bads [ bi ] = new_name <EOL> ch_names [ c_ind ] = new_name <EOL> if len ( ch_names ) != len ( np . unique ( ch_names ) ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> info [ '<STR_LIT>' ] = bads <EOL> for ch , ch_name in zip ( info [ '<STR_LIT>' ] , ch_names ) : <EOL> ch [ '<STR_LIT>' ] = ch_name <EOL> info . _update_redundant ( ) <EOL> info . _check_consistency ( ) <EOL> def _recursive_flatten ( cell , dtype ) : <EOL> """<STR_LIT>""" <EOL> while not isinstance ( cell [ <NUM_LIT:0> ] , dtype ) : <EOL> cell = [ c for d in cell for c in d ] <EOL> return cell <EOL> def read_ch_connectivity ( fname , picks = None ) : <EOL> """<STR_LIT>""" <EOL> from scipy . io import loadmat <EOL> if not op . isabs ( fname ) : <EOL> templates_dir = op . realpath ( op . join ( op . dirname ( __file__ ) , <EOL> '<STR_LIT:data>' , '<STR_LIT>' ) ) <EOL> templates = os . listdir ( templates_dir ) <EOL> for f in templates : <EOL> if f == fname : <EOL> break <EOL> if f == fname + '<STR_LIT>' : <EOL> fname += '<STR_LIT>' <EOL> break <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( fname ) ) <EOL> fname = op . join ( templates_dir , fname ) <EOL> nb = loadmat ( fname ) [ '<STR_LIT>' ] <EOL> ch_names = _recursive_flatten ( nb [ '<STR_LIT:label>' ] , string_types ) <EOL> neighbors = [ _recursive_flatten ( c , string_types ) for c in <EOL> nb [ '<STR_LIT>' ] . flatten ( ) ] <EOL> assert len ( ch_names ) == len ( neighbors ) <EOL> if picks is not None : <EOL> if max ( picks ) >= len ( ch_names ) : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> . format ( max ( picks ) , len ( ch_names ) ) ) <EOL> connectivity = _ch_neighbor_connectivity ( ch_names , neighbors ) <EOL> if picks is not None : <EOL> connectivity = connectivity [ picks ] [ : , picks ] <EOL> ch_names = [ ch_names [ p ] for p in picks ] <EOL> return connectivity , ch_names <EOL> def _ch_neighbor_connectivity ( ch_names , neighbors ) : <EOL> """<STR_LIT>""" <EOL> if len ( ch_names ) != len ( neighbors ) : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> set_neighbors = set ( [ c for d in neighbors for c in d ] ) <EOL> rest = set ( ch_names ) - set_neighbors <EOL> if len ( rest ) > <NUM_LIT:0> : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> for neigh in neighbors : <EOL> if ( not isinstance ( neigh , list ) and <EOL> not all ( isinstance ( c , string_types ) for c in neigh ) ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> ch_connectivity = np . eye ( len ( ch_names ) , dtype = bool ) <EOL> for ii , neigbs in enumerate ( neighbors ) : <EOL> ch_connectivity [ ii , [ ch_names . index ( i ) for i in neigbs ] ] = True <EOL> ch_connectivity = sparse . csr_matrix ( ch_connectivity ) <EOL> return ch_connectivity <EOL> def fix_mag_coil_types ( info ) : <EOL> """<STR_LIT>""" <EOL> old_mag_inds = _get_T1T2_mag_inds ( info ) <EOL> for ii in old_mag_inds : <EOL> info [ '<STR_LIT>' ] [ ii ] [ '<STR_LIT>' ] = FIFF . FIFFV_COIL_VV_MAG_T3 <EOL> logger . info ( '<STR_LIT>' % <EOL> ( len ( old_mag_inds ) , len ( pick_types ( info , meg = '<STR_LIT>' ) ) ) ) <EOL> info . _check_consistency ( ) <EOL> def _get_T1T2_mag_inds ( info ) : <EOL> """<STR_LIT>""" <EOL> picks = pick_types ( info , meg = '<STR_LIT>' ) <EOL> old_mag_inds = [ ] <EOL> for ii in picks : <EOL> ch = info [ '<STR_LIT>' ] [ ii ] <EOL> if ch [ '<STR_LIT>' ] in ( FIFF . FIFFV_COIL_VV_MAG_T1 , <EOL> FIFF . FIFFV_COIL_VV_MAG_T2 ) : <EOL> old_mag_inds . append ( ii ) <EOL> return old_mag_inds </s>
