<s> """<STR_LIT>""" <EOL> from os import SEEK_CUR , path as op <EOL> from struct import unpack <EOL> import time <EOL> import numpy as np <EOL> from scipy import linalg <EOL> from . . pick import pick_types <EOL> from ... coreg import fit_matched_points , _decimate_points <EOL> from ... utils import verbose , logger , warn <EOL> from ... transforms import ( apply_trans , als_ras_trans , als_ras_trans_mm , <EOL> get_ras_to_neuromag_trans , Transform ) <EOL> from . . base import _BaseRaw <EOL> from . . utils import _mult_cal_one <EOL> from ... epochs import _BaseEpochs <EOL> from . . constants import FIFF <EOL> from . . meas_info import _empty_info , _read_dig_points , _make_dig_points <EOL> from . constants import KIT , KIT_CONSTANTS , SYSNAMES <EOL> from . coreg import read_mrk <EOL> from ... externals . six import string_types <EOL> from ... event import read_events <EOL> class RawKIT ( _BaseRaw ) : <EOL> """<STR_LIT>""" <EOL> @ verbose <EOL> def __init__ ( self , input_fname , mrk = None , elp = None , hsp = None , stim = '<STR_LIT:>>' , <EOL> slope = '<STR_LIT:->' , stimthresh = <NUM_LIT:1> , preload = False , stim_code = '<STR_LIT>' , <EOL> verbose = None ) : <EOL> logger . info ( '<STR_LIT>' % input_fname ) <EOL> input_fname = op . abspath ( input_fname ) <EOL> self . preload = False <EOL> logger . info ( '<STR_LIT>' ) <EOL> info , kit_info = get_kit_info ( input_fname ) <EOL> kit_info [ '<STR_LIT>' ] = slope <EOL> kit_info [ '<STR_LIT>' ] = stimthresh <EOL> if kit_info [ '<STR_LIT>' ] != <NUM_LIT:1> : <EOL> err = '<STR_LIT>' <EOL> raise TypeError ( err ) <EOL> logger . info ( '<STR_LIT>' ) <EOL> last_samps = [ kit_info [ '<STR_LIT>' ] - <NUM_LIT:1> ] <EOL> self . _raw_extras = [ kit_info ] <EOL> self . _set_stimchannels ( info , stim , stim_code ) <EOL> super ( RawKIT , self ) . __init__ ( <EOL> info , preload , last_samps = last_samps , filenames = [ input_fname ] , <EOL> raw_extras = self . _raw_extras , verbose = verbose ) <EOL> if isinstance ( mrk , list ) : <EOL> mrk = [ read_mrk ( marker ) if isinstance ( marker , string_types ) <EOL> else marker for marker in mrk ] <EOL> mrk = np . mean ( mrk , axis = <NUM_LIT:0> ) <EOL> if mrk is not None and elp is not None and hsp is not None : <EOL> dig_points , dev_head_t = _set_dig_kit ( mrk , elp , hsp ) <EOL> self . info [ '<STR_LIT>' ] = dig_points <EOL> self . info [ '<STR_LIT>' ] = dev_head_t <EOL> elif mrk is not None or elp is not None or hsp is not None : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> logger . info ( '<STR_LIT>' ) <EOL> def read_stim_ch ( self , buffer_size = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> buffer_size = int ( buffer_size ) <EOL> start = int ( self . first_samp ) <EOL> stop = int ( self . last_samp + <NUM_LIT:1> ) <EOL> pick = pick_types ( self . info , meg = False , ref_meg = False , <EOL> stim = True , exclude = [ ] ) <EOL> stim_ch = np . empty ( ( <NUM_LIT:1> , stop ) , dtype = np . int ) <EOL> for b_start in range ( start , stop , buffer_size ) : <EOL> b_stop = b_start + buffer_size <EOL> x = self [ pick , b_start : b_stop ] [ <NUM_LIT:0> ] <EOL> stim_ch [ : , b_start : b_start + x . shape [ <NUM_LIT:1> ] ] = x <EOL> return stim_ch <EOL> def _set_stimchannels ( self , info , stim , stim_code ) : <EOL> """<STR_LIT>""" <EOL> if stim_code not in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> raise ValueError ( "<STR_LIT>" <EOL> % stim_code ) <EOL> if stim is not None : <EOL> if isinstance ( stim , str ) : <EOL> picks = pick_types ( info , meg = False , ref_meg = False , <EOL> misc = True , exclude = [ ] ) [ : <NUM_LIT:8> ] <EOL> if stim == '<STR_LIT:<>' : <EOL> stim = picks [ : : - <NUM_LIT:1> ] <EOL> elif stim == '<STR_LIT:>>' : <EOL> stim = picks <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" % str ( stim ) ) <EOL> elif np . max ( stim ) >= self . _raw_extras [ <NUM_LIT:0> ] [ '<STR_LIT>' ] : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> % ( np . max ( stim ) , <EOL> self . _raw_extras [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) ) <EOL> nchan = self . _raw_extras [ <NUM_LIT:0> ] [ '<STR_LIT>' ] + <NUM_LIT:1> <EOL> ch_name = '<STR_LIT>' <EOL> chan_info = { } <EOL> chan_info [ '<STR_LIT>' ] = KIT . CALIB_FACTOR <EOL> chan_info [ '<STR_LIT>' ] = nchan <EOL> chan_info [ '<STR_LIT>' ] = nchan <EOL> chan_info [ '<STR_LIT>' ] = <NUM_LIT:1.0> <EOL> chan_info [ '<STR_LIT>' ] = FIFF . FIFF_UNIT_NONE <EOL> chan_info [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> chan_info [ '<STR_LIT>' ] = ch_name <EOL> chan_info [ '<STR_LIT>' ] = FIFF . FIFFV_COIL_NONE <EOL> chan_info [ '<STR_LIT>' ] = np . zeros ( <NUM_LIT:12> ) <EOL> chan_info [ '<STR_LIT>' ] = FIFF . FIFFV_STIM_CH <EOL> info [ '<STR_LIT>' ] . append ( chan_info ) <EOL> info . _update_redundant ( ) <EOL> if self . preload : <EOL> err = "<STR_LIT>" <EOL> raise NotImplementedError ( err ) <EOL> self . _raw_extras [ <NUM_LIT:0> ] [ '<STR_LIT>' ] = stim <EOL> self . _raw_extras [ <NUM_LIT:0> ] [ '<STR_LIT>' ] = stim_code <EOL> @ verbose <EOL> def _read_segment_file ( self , data , idx , fi , start , stop , cals , mult ) : <EOL> """<STR_LIT>""" <EOL> nchan = self . _raw_extras [ fi ] [ '<STR_LIT>' ] <EOL> data_left = ( stop - start ) * nchan <EOL> n_sens = self . _raw_extras [ fi ] [ '<STR_LIT>' ] <EOL> sensor_gain = self . _raw_extras [ fi ] [ '<STR_LIT>' ] . copy ( ) <EOL> sensor_gain [ : n_sens ] = ( sensor_gain [ : n_sens ] / <EOL> self . _raw_extras [ fi ] [ '<STR_LIT>' ] ) <EOL> conv_factor = np . array ( ( KIT . VOLTAGE_RANGE / <EOL> self . _raw_extras [ fi ] [ '<STR_LIT>' ] ) * <EOL> sensor_gain ) <EOL> n_bytes = <NUM_LIT:2> <EOL> blk_size = min ( data_left , ( <NUM_LIT> // n_bytes // nchan ) * nchan ) <EOL> with open ( self . _filenames [ fi ] , '<STR_LIT:rb>' , buffering = <NUM_LIT:0> ) as fid : <EOL> data_offset = KIT . RAW_OFFSET <EOL> fid . seek ( data_offset ) <EOL> data_offset = unpack ( '<STR_LIT:i>' , fid . read ( KIT . INT ) ) [ <NUM_LIT:0> ] <EOL> pointer = start * nchan * KIT . SHORT <EOL> fid . seek ( data_offset + pointer ) <EOL> for blk_start in np . arange ( <NUM_LIT:0> , data_left , blk_size ) // nchan : <EOL> blk_size = min ( blk_size , data_left - blk_start * nchan ) <EOL> block = np . fromfile ( fid , dtype = '<STR_LIT:h>' , count = blk_size ) <EOL> block = block . reshape ( nchan , - <NUM_LIT:1> , order = '<STR_LIT:F>' ) . astype ( float ) <EOL> blk_stop = blk_start + block . shape [ <NUM_LIT:1> ] <EOL> data_view = data [ : , blk_start : blk_stop ] <EOL> block *= conv_factor [ : , np . newaxis ] <EOL> if self . _raw_extras [ fi ] [ '<STR_LIT>' ] is not None : <EOL> trig_chs = block [ self . _raw_extras [ fi ] [ '<STR_LIT>' ] , : ] <EOL> if self . _raw_extras [ fi ] [ '<STR_LIT>' ] == '<STR_LIT:+>' : <EOL> trig_chs = trig_chs > self . _raw_extras [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> elif self . _raw_extras [ fi ] [ '<STR_LIT>' ] == '<STR_LIT:->' : <EOL> trig_chs = trig_chs < self . _raw_extras [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if self . _raw_extras [ <NUM_LIT:0> ] [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> ntrigchan = len ( self . _raw_extras [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> trig_vals = np . array ( <NUM_LIT:2> ** np . arange ( ntrigchan ) , <EOL> ndmin = <NUM_LIT:2> ) . T <EOL> else : <EOL> trig_vals = np . reshape ( self . _raw_extras [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , <EOL> ( - <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> trig_chs = trig_chs * trig_vals <EOL> stim_ch = np . array ( trig_chs . sum ( axis = <NUM_LIT:0> ) , ndmin = <NUM_LIT:2> ) <EOL> block = np . vstack ( ( block , stim_ch ) ) <EOL> _mult_cal_one ( data_view , block , idx , None , mult ) <EOL> class EpochsKIT ( _BaseEpochs ) : <EOL> """<STR_LIT>""" <EOL> @ verbose <EOL> def __init__ ( self , input_fname , events , event_id = None , tmin = <NUM_LIT:0> , <EOL> baseline = None , reject = None , flat = None , reject_tmin = None , <EOL> reject_tmax = None , mrk = None , elp = None , hsp = None , verbose = None ) : <EOL> if isinstance ( events , string_types ) : <EOL> events = read_events ( events ) <EOL> if isinstance ( mrk , list ) : <EOL> mrk = [ read_mrk ( marker ) if isinstance ( marker , string_types ) <EOL> else marker for marker in mrk ] <EOL> mrk = np . mean ( mrk , axis = <NUM_LIT:0> ) <EOL> if ( mrk is not None and elp is not None and hsp is not None ) : <EOL> dig_points , dev_head_t = _set_dig_kit ( mrk , elp , hsp ) <EOL> self . info [ '<STR_LIT>' ] = dig_points <EOL> self . info [ '<STR_LIT>' ] = dev_head_t <EOL> elif ( mrk is not None or elp is not None or hsp is not None ) : <EOL> err = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> raise ValueError ( err ) <EOL> logger . info ( '<STR_LIT>' % input_fname ) <EOL> input_fname = op . abspath ( input_fname ) <EOL> self . info , kit_info = get_kit_info ( input_fname ) <EOL> self . _raw_extras = [ kit_info ] <EOL> if len ( events ) != self . _raw_extras [ <NUM_LIT:0> ] [ '<STR_LIT>' ] : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if self . _raw_extras [ <NUM_LIT:0> ] [ '<STR_LIT>' ] == <NUM_LIT:3> : <EOL> self . _raw_extras [ <NUM_LIT:0> ] [ '<STR_LIT>' ] = KIT . RAW_OFFSET <EOL> self . _raw_extras [ <NUM_LIT:0> ] [ '<STR_LIT>' ] = KIT . INT <EOL> self . _raw_extras [ <NUM_LIT:0> ] [ '<STR_LIT>' ] = '<STR_LIT:h>' <EOL> else : <EOL> err = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> raise TypeError ( err ) <EOL> if event_id is None : <EOL> event_id = dict ( ( str ( e ) , int ( e ) ) for e in np . unique ( events [ : , <NUM_LIT:2> ] ) ) <EOL> for key , val in event_id . items ( ) : <EOL> if val not in events [ : , <NUM_LIT:2> ] : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( key , val ) ) <EOL> self . _filename = input_fname <EOL> data = self . _read_kit_data ( ) <EOL> assert data . shape == ( self . _raw_extras [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , <EOL> self . info [ '<STR_LIT>' ] , <EOL> self . _raw_extras [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> tmax = ( ( data . shape [ <NUM_LIT:2> ] - <NUM_LIT:1> ) / self . info [ '<STR_LIT>' ] ) + tmin <EOL> super ( EpochsKIT , self ) . __init__ ( self . info , data , events , event_id , <EOL> tmin , tmax , baseline , <EOL> reject = reject , flat = flat , <EOL> reject_tmin = reject_tmin , <EOL> reject_tmax = reject_tmax , <EOL> verbose = verbose ) <EOL> logger . info ( '<STR_LIT>' ) <EOL> def _read_kit_data ( self ) : <EOL> """<STR_LIT>""" <EOL> epoch_length = self . _raw_extras [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> n_epochs = self . _raw_extras [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> n_samples = self . _raw_extras [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> with open ( self . _filename , '<STR_LIT:rb>' , buffering = <NUM_LIT:0> ) as fid : <EOL> data_offset = self . _raw_extras [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> dtype = self . _raw_extras [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> fid . seek ( data_offset ) <EOL> data_offset = unpack ( '<STR_LIT:i>' , fid . read ( KIT . INT ) ) [ <NUM_LIT:0> ] <EOL> nchan = self . _raw_extras [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> count = n_samples * nchan <EOL> fid . seek ( data_offset ) <EOL> data = np . fromfile ( fid , dtype = dtype , count = count ) <EOL> data = data . reshape ( ( n_samples , nchan ) ) <EOL> n_sens = self . _raw_extras [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> sensor_gain = np . copy ( self . _raw_extras [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> sensor_gain [ : n_sens ] = ( sensor_gain [ : n_sens ] / <EOL> self . _raw_extras [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> conv_factor = np . array ( ( KIT . VOLTAGE_RANGE / <EOL> self . _raw_extras [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) * <EOL> sensor_gain , ndmin = <NUM_LIT:2> ) <EOL> data = conv_factor * data <EOL> data = data . T <EOL> data = data . reshape ( ( nchan , n_epochs , epoch_length ) ) <EOL> data = data . transpose ( ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:2> ) ) <EOL> return data <EOL> def _set_dig_kit ( mrk , elp , hsp ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( hsp , string_types ) : <EOL> hsp = _read_dig_points ( hsp ) <EOL> n_pts = len ( hsp ) <EOL> if n_pts > KIT . DIG_POINTS : <EOL> hsp = _decimate_points ( hsp , res = <NUM_LIT:5> ) <EOL> n_new = len ( hsp ) <EOL> warn ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" . format ( <EOL> n_in = n_pts , n_rec = KIT . DIG_POINTS , n_new = n_new ) ) <EOL> if isinstance ( elp , string_types ) : <EOL> elp_points = _read_dig_points ( elp ) <EOL> if len ( elp_points ) != <NUM_LIT:8> : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( elp , elp_points . shape ) ) <EOL> elp = elp_points <EOL> elif len ( elp ) != <NUM_LIT:8> : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( elp . shape , ) ) <EOL> if isinstance ( mrk , string_types ) : <EOL> mrk = read_mrk ( mrk ) <EOL> hsp = apply_trans ( als_ras_trans_mm , hsp ) <EOL> elp = apply_trans ( als_ras_trans_mm , elp ) <EOL> mrk = apply_trans ( als_ras_trans , mrk ) <EOL> nasion , lpa , rpa = elp [ : <NUM_LIT:3> ] <EOL> nmtrans = get_ras_to_neuromag_trans ( nasion , lpa , rpa ) <EOL> elp = apply_trans ( nmtrans , elp ) <EOL> hsp = apply_trans ( nmtrans , hsp ) <EOL> trans = fit_matched_points ( tgt_pts = elp [ <NUM_LIT:3> : ] , src_pts = mrk , out = '<STR_LIT>' ) <EOL> nasion , lpa , rpa = elp [ : <NUM_LIT:3> ] <EOL> elp = elp [ <NUM_LIT:3> : ] <EOL> dig_points = _make_dig_points ( nasion , lpa , rpa , elp , hsp ) <EOL> dev_head_t = Transform ( '<STR_LIT>' , '<STR_LIT>' , trans ) <EOL> return dig_points , dev_head_t <EOL> def get_kit_info ( rawfile ) : <EOL> """<STR_LIT>""" <EOL> sqd = dict ( ) <EOL> sqd [ '<STR_LIT>' ] = rawfile <EOL> with open ( rawfile , '<STR_LIT:rb>' , buffering = <NUM_LIT:0> ) as fid : <EOL> fid . seek ( KIT . BASIC_INFO ) <EOL> basic_offset = unpack ( '<STR_LIT:i>' , fid . read ( KIT . INT ) ) [ <NUM_LIT:0> ] <EOL> fid . seek ( basic_offset ) <EOL> fid . seek ( KIT . INT * <NUM_LIT:2> , SEEK_CUR ) <EOL> sysid = unpack ( '<STR_LIT:i>' , fid . read ( KIT . INT ) ) [ <NUM_LIT:0> ] <EOL> sysname = unpack ( '<STR_LIT>' , fid . read ( KIT . STRING ) ) <EOL> sysname = sysname [ <NUM_LIT:0> ] . decode ( ) . split ( '<STR_LIT:\n>' ) [ <NUM_LIT:0> ] <EOL> if sysid not in KIT_CONSTANTS : <EOL> raise NotImplementedError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( sysname , sysid ) ) <EOL> KIT_SYS = KIT_CONSTANTS [ sysid ] <EOL> if sysid in SYSNAMES : <EOL> if sysname != SYSNAMES [ sysid ] : <EOL> warn ( "<STR_LIT>" <EOL> % ( rawfile , sysname , SYSNAMES [ sysid ] ) ) <EOL> fid . seek ( KIT . STRING , SEEK_CUR ) <EOL> sqd [ '<STR_LIT>' ] = unpack ( '<STR_LIT:i>' , fid . read ( KIT . INT ) ) [ <NUM_LIT:0> ] <EOL> fid . seek ( KIT_SYS . CHAN_LOC_OFFSET ) <EOL> chan_offset = unpack ( '<STR_LIT:i>' , fid . read ( KIT . INT ) ) [ <NUM_LIT:0> ] <EOL> chan_size = unpack ( '<STR_LIT:i>' , fid . read ( KIT . INT ) ) [ <NUM_LIT:0> ] <EOL> fid . seek ( chan_offset ) <EOL> sensors = [ ] <EOL> for i in range ( KIT_SYS . N_SENS ) : <EOL> fid . seek ( chan_offset + chan_size * i ) <EOL> sens_type = unpack ( '<STR_LIT:i>' , fid . read ( KIT . INT ) ) [ <NUM_LIT:0> ] <EOL> if sens_type == <NUM_LIT:1> : <EOL> sensors . append ( np . fromfile ( fid , dtype = '<STR_LIT:d>' , count = <NUM_LIT:6> ) ) <EOL> elif sens_type == <NUM_LIT:2> : <EOL> sensors . append ( np . fromfile ( fid , dtype = '<STR_LIT:d>' , count = <NUM_LIT:7> ) ) <EOL> elif sens_type == <NUM_LIT:3> : <EOL> sensors . append ( np . fromfile ( fid , dtype = '<STR_LIT:d>' , count = <NUM_LIT:9> ) ) <EOL> elif sens_type == <NUM_LIT> : <EOL> sensors . append ( np . zeros ( <NUM_LIT:7> ) ) <EOL> sqd [ '<STR_LIT:i>' ] = sens_type <EOL> sqd [ '<STR_LIT>' ] = np . array ( sensors ) <EOL> fid . seek ( KIT_SYS . AMPLIFIER_INFO ) <EOL> amp_offset = unpack ( '<STR_LIT:i>' , fid . read ( KIT_SYS . INT ) ) [ <NUM_LIT:0> ] <EOL> fid . seek ( amp_offset ) <EOL> amp_data = unpack ( '<STR_LIT:i>' , fid . read ( KIT_SYS . INT ) ) [ <NUM_LIT:0> ] <EOL> gain1 = KIT_SYS . GAINS [ ( KIT_SYS . GAIN1_MASK & amp_data ) >> <EOL> KIT_SYS . GAIN1_BIT ] <EOL> gain2 = KIT_SYS . GAINS [ ( KIT_SYS . GAIN2_MASK & amp_data ) >> <EOL> KIT_SYS . GAIN2_BIT ] <EOL> if KIT_SYS . GAIN3_BIT : <EOL> gain3 = KIT_SYS . GAINS [ ( KIT_SYS . GAIN3_MASK & amp_data ) >> <EOL> KIT_SYS . GAIN3_BIT ] <EOL> sqd [ '<STR_LIT>' ] = gain1 * gain2 * gain3 <EOL> else : <EOL> sqd [ '<STR_LIT>' ] = gain1 * gain2 <EOL> sqd [ '<STR_LIT>' ] = KIT_SYS . LPFS [ ( KIT_SYS . LPF_MASK & amp_data ) >> <EOL> KIT_SYS . LPF_BIT ] <EOL> sqd [ '<STR_LIT>' ] = KIT_SYS . HPFS [ ( KIT_SYS . HPF_MASK & amp_data ) >> <EOL> KIT_SYS . HPF_BIT ] <EOL> sqd [ '<STR_LIT>' ] = KIT_SYS . BEFS [ ( KIT_SYS . BEF_MASK & amp_data ) >> <EOL> KIT_SYS . BEF_BIT ] <EOL> fid . seek ( KIT_SYS . CHAN_SENS ) <EOL> sens_offset = unpack ( '<STR_LIT:i>' , fid . read ( KIT_SYS . INT ) ) [ <NUM_LIT:0> ] <EOL> fid . seek ( sens_offset ) <EOL> sens = np . fromfile ( fid , dtype = '<STR_LIT:d>' , count = sqd [ '<STR_LIT>' ] * <NUM_LIT:2> ) <EOL> sens . shape = ( sqd [ '<STR_LIT>' ] , <NUM_LIT:2> ) <EOL> sqd [ '<STR_LIT>' ] = np . ones ( KIT_SYS . NCHAN ) <EOL> sqd [ '<STR_LIT>' ] [ : KIT_SYS . N_SENS ] = sens [ : KIT_SYS . N_SENS , <NUM_LIT:1> ] <EOL> fid . seek ( KIT_SYS . SAMPLE_INFO ) <EOL> acqcond_offset = unpack ( '<STR_LIT:i>' , fid . read ( KIT_SYS . INT ) ) [ <NUM_LIT:0> ] <EOL> fid . seek ( acqcond_offset ) <EOL> acq_type = unpack ( '<STR_LIT:i>' , fid . read ( KIT_SYS . INT ) ) [ <NUM_LIT:0> ] <EOL> sqd [ '<STR_LIT>' ] = unpack ( '<STR_LIT:d>' , fid . read ( KIT_SYS . DOUBLE ) ) [ <NUM_LIT:0> ] <EOL> if acq_type == <NUM_LIT:1> : <EOL> fid . read ( KIT_SYS . INT ) <EOL> sqd [ '<STR_LIT>' ] = unpack ( '<STR_LIT:i>' , fid . read ( KIT_SYS . INT ) ) [ <NUM_LIT:0> ] <EOL> elif acq_type == <NUM_LIT:2> or acq_type == <NUM_LIT:3> : <EOL> sqd [ '<STR_LIT>' ] = unpack ( '<STR_LIT:i>' , fid . read ( KIT_SYS . INT ) ) [ <NUM_LIT:0> ] <EOL> sqd [ '<STR_LIT>' ] = unpack ( '<STR_LIT:i>' , fid . read ( KIT_SYS . INT ) ) [ <NUM_LIT:0> ] <EOL> sqd [ '<STR_LIT>' ] = unpack ( '<STR_LIT:i>' , fid . read ( KIT_SYS . INT ) ) [ <NUM_LIT:0> ] <EOL> sqd [ '<STR_LIT>' ] = unpack ( '<STR_LIT:i>' , fid . read ( KIT_SYS . INT ) ) [ <NUM_LIT:0> ] <EOL> sqd [ '<STR_LIT>' ] = sqd [ '<STR_LIT>' ] * sqd [ '<STR_LIT>' ] <EOL> else : <EOL> err = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> raise TypeError ( err ) <EOL> sqd [ '<STR_LIT>' ] = KIT_SYS . N_SENS <EOL> sqd [ '<STR_LIT>' ] = KIT_SYS . NMEGCHAN <EOL> sqd [ '<STR_LIT>' ] = KIT_SYS . NMISCCHAN <EOL> sqd [ '<STR_LIT>' ] = KIT_SYS . DYNAMIC_RANGE <EOL> sqd [ '<STR_LIT>' ] = acq_type <EOL> info = _empty_info ( float ( sqd [ '<STR_LIT>' ] ) ) <EOL> info . update ( meas_date = int ( time . time ( ) ) , lowpass = sqd [ '<STR_LIT>' ] , <EOL> highpass = sqd [ '<STR_LIT>' ] , filename = rawfile , <EOL> buffer_size_sec = <NUM_LIT:1.> ) <EOL> logger . info ( '<STR_LIT>' ) <EOL> ch_names = { } <EOL> ch_names [ '<STR_LIT>' ] = [ '<STR_LIT>' % ch for ch <EOL> in range ( <NUM_LIT:1> , sqd [ '<STR_LIT>' ] + <NUM_LIT:1> ) ] <EOL> ch_names [ '<STR_LIT>' ] = [ '<STR_LIT>' % ch for ch <EOL> in range ( <NUM_LIT:1> , sqd [ '<STR_LIT>' ] + <NUM_LIT:1> ) ] <EOL> locs = sqd [ '<STR_LIT>' ] <EOL> chan_locs = apply_trans ( als_ras_trans , locs [ : , : <NUM_LIT:3> ] ) <EOL> chan_angles = locs [ : , <NUM_LIT:3> : ] <EOL> info [ '<STR_LIT>' ] = [ ] <EOL> for idx , ch_info in enumerate ( zip ( ch_names [ '<STR_LIT>' ] , chan_locs , <EOL> chan_angles ) , <NUM_LIT:1> ) : <EOL> ch_name , ch_loc , ch_angles = ch_info <EOL> chan_info = { } <EOL> chan_info [ '<STR_LIT>' ] = KIT . CALIB_FACTOR <EOL> chan_info [ '<STR_LIT>' ] = idx <EOL> chan_info [ '<STR_LIT>' ] = idx <EOL> chan_info [ '<STR_LIT>' ] = KIT . RANGE <EOL> chan_info [ '<STR_LIT>' ] = KIT . UNIT_MUL <EOL> chan_info [ '<STR_LIT>' ] = ch_name <EOL> chan_info [ '<STR_LIT>' ] = FIFF . FIFF_UNIT_T <EOL> chan_info [ '<STR_LIT>' ] = FIFF . FIFFV_COORD_DEVICE <EOL> if idx <= sqd [ '<STR_LIT>' ] : <EOL> chan_info [ '<STR_LIT>' ] = FIFF . FIFFV_COIL_KIT_GRAD <EOL> chan_info [ '<STR_LIT>' ] = FIFF . FIFFV_MEG_CH <EOL> else : <EOL> chan_info [ '<STR_LIT>' ] = FIFF . FIFFV_COIL_KIT_REF_MAG <EOL> chan_info [ '<STR_LIT>' ] = FIFF . FIFFV_REF_MEG_CH <EOL> ch_angles = np . radians ( ch_angles ) <EOL> x = np . sin ( ch_angles [ <NUM_LIT:0> ] ) * np . cos ( ch_angles [ <NUM_LIT:1> ] ) <EOL> y = np . sin ( ch_angles [ <NUM_LIT:0> ] ) * np . sin ( ch_angles [ <NUM_LIT:1> ] ) <EOL> z = np . cos ( ch_angles [ <NUM_LIT:0> ] ) <EOL> vec_z = np . array ( [ x , y , z ] ) <EOL> length = linalg . norm ( vec_z ) <EOL> vec_z /= length <EOL> vec_x = np . zeros ( vec_z . size , dtype = np . float ) <EOL> if vec_z [ <NUM_LIT:1> ] < vec_z [ <NUM_LIT:2> ] : <EOL> if vec_z [ <NUM_LIT:0> ] < vec_z [ <NUM_LIT:1> ] : <EOL> vec_x [ <NUM_LIT:0> ] = <NUM_LIT:1.0> <EOL> else : <EOL> vec_x [ <NUM_LIT:1> ] = <NUM_LIT:1.0> <EOL> elif vec_z [ <NUM_LIT:0> ] < vec_z [ <NUM_LIT:2> ] : <EOL> vec_x [ <NUM_LIT:0> ] = <NUM_LIT:1.0> <EOL> else : <EOL> vec_x [ <NUM_LIT:2> ] = <NUM_LIT:1.0> <EOL> vec_x -= np . sum ( vec_x * vec_z ) * vec_z <EOL> length = linalg . norm ( vec_x ) <EOL> vec_x /= length <EOL> vec_y = np . cross ( vec_z , vec_x ) <EOL> vecs = np . vstack ( ( vec_x , vec_y , vec_z ) ) <EOL> vecs = apply_trans ( als_ras_trans , vecs ) <EOL> chan_info [ '<STR_LIT>' ] = np . vstack ( ( ch_loc , vecs ) ) . ravel ( ) <EOL> info [ '<STR_LIT>' ] . append ( chan_info ) <EOL> for idy , ch_name in enumerate ( ch_names [ '<STR_LIT>' ] , <EOL> sqd [ '<STR_LIT>' ] + <NUM_LIT:1> ) : <EOL> chan_info = { } <EOL> chan_info [ '<STR_LIT>' ] = KIT . CALIB_FACTOR <EOL> chan_info [ '<STR_LIT>' ] = idy <EOL> chan_info [ '<STR_LIT>' ] = idy <EOL> chan_info [ '<STR_LIT>' ] = <NUM_LIT:1.0> <EOL> chan_info [ '<STR_LIT>' ] = FIFF . FIFF_UNIT_V <EOL> chan_info [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> chan_info [ '<STR_LIT>' ] = ch_name <EOL> chan_info [ '<STR_LIT>' ] = FIFF . FIFFV_COIL_NONE <EOL> chan_info [ '<STR_LIT>' ] = np . zeros ( <NUM_LIT:12> ) <EOL> chan_info [ '<STR_LIT>' ] = FIFF . FIFFV_MISC_CH <EOL> info [ '<STR_LIT>' ] . append ( chan_info ) <EOL> info . _update_redundant ( ) <EOL> return info , sqd <EOL> def read_raw_kit ( input_fname , mrk = None , elp = None , hsp = None , stim = '<STR_LIT:>>' , <EOL> slope = '<STR_LIT:->' , stimthresh = <NUM_LIT:1> , preload = False , stim_code = '<STR_LIT>' , <EOL> verbose = None ) : <EOL> """<STR_LIT>""" <EOL> return RawKIT ( input_fname = input_fname , mrk = mrk , elp = elp , hsp = hsp , <EOL> stim = stim , slope = slope , stimthresh = stimthresh , <EOL> preload = preload , stim_code = stim_code , verbose = verbose ) <EOL> def read_epochs_kit ( input_fname , events , event_id = None , <EOL> mrk = None , elp = None , hsp = None , verbose = None ) : <EOL> """<STR_LIT>""" <EOL> epochs = EpochsKIT ( input_fname = input_fname , events = events , <EOL> event_id = event_id , mrk = mrk , elp = elp , hsp = hsp , <EOL> verbose = verbose ) <EOL> return epochs </s>
