# import a CON file In this example, we read a con file. And save these data in a epoch file and a evoked file. ```python %matplotlib qt ``` ```python import mne import matplotlib.pyplot as plt import pandas as pd import numpy as np data_path = '/Users/kevinhsu/Documents/D/000_experiment/compounding_VR/2013_megdata' # import raw CON sid = 6 confile = data_path + '/de%.3dnn.con' % sid # # /Users/kevinhsu/Documents/D/000_experiment/compounding_VR/2013_megdata/de001nn.con raw = mne.io.kit.read_raw_kit(confile, stim = [192, 193, 194], slope = '+') events = mne.find_events(raw, stim_channel='STI 014') raw.plot() ``` Extracting SQD Parameters from /Users/kevinhsu/Documents/D/000_experiment/compounding_VR/2013_megdata/de006nn.con... Creating Raw.info structure... Setting channel info structure... Creating Info structure... Current compensation grade : 0 Ready. 300 events found Event IDs: [1 4] ![](https://i.imgur.com/0kuoYUd.png) ```python # browse events: three columns [onsets, zeros, conditions] events ``` array([[ 13963, 0, 4], [ 17444, 0, 1], [ 21925, 0, 4], ... [1217254, 0, 1], [1220929, 0, 4], [1224333, 0, 1], [1227606, 0, 1], [1231091, 0, 1], [1234853, 0, 4], [1238734, 0, 1], [1241954, 0, 1], [1245831, 0, 4], [1249235, 0, 4]]) ```python kit_lay = mne.channels.layout.read_layout(data_path + '/KIT-TW-157.lout') # preload raw MEG data raw.load_data() # low pass fillter raw.filter(0, 30, phase= 'zero-double') # duration of epochs tmin = -0.1 # pre stimulis interval (in seconds) # tmax = 0.7 # post stimulus interval # # artifact rejection criteria reject = dict(mag=1.5e-12) # using strings (words) to label conditions event_id = {'words':1, 'pseudo': 4} # keep MEG channels picks = mne.pick_types(raw.info, meg= True, stim = False) # channels to use in epochs # # baseline correction baseline = (None, 0) # what to use as baseline comparison - here it's pre-stim interval # # do the actual epoching processes epochs = mne.Epochs(raw, events, event_id, tmin, tmax, proj = True, picks = picks, baseline=baseline, preload = True, reject=reject) ``` Reading 0 ... 1264999 = 0.000 ... 1264.999 secs... Filtering raw data in 1 contiguous segment Setting up low-pass filter at 30 Hz FIR filter parameters --------------------- Designing a two-pass forward and reverse, zero-phase, non-causal lowpass filter: - Windowed time-domain design (firwin) method - Hamming window with 0.0194 passband ripple and 53 dB stopband attenuation - Upper passband edge: 30.00 Hz - Upper transition bandwidth: 7.50 Hz (-12 dB cutoff frequency: 33.75 Hz) - Filter length: 441 samples (0.441 sec) 300 matching events found Applying baseline correction (mode: mean) Not setting metadata 0 projection items activated Loading data for 300 events and 801 original time points ... Rejecting epoch based on MAG : ['MEG 145'] Rejecting epoch based on MAG : ['MEG 130'] Rejecting epoch based on MAG : ['MEG 145'] Rejecting epoch based on MAG : ['MEG 131'] ... Rejecting epoch based on MAG : ['MEG 131', 'MEG 145'] Rejecting epoch based on MAG : ['MEG 130'] Rejecting epoch based on MAG : ['MEG 130', 'MEG 131'] Rejecting epoch based on MAG : ['MEG 131'] Rejecting epoch based on MAG : ['MEG 130', 'MEG 131'] 218 bad epochs dropped ```python # check results of artifact rejection drop_log = pd.DataFrame(epochs.drop_log) drop_log.to_csv('s%.3d_droplog.csv' % sid) ``` ```python # saving an epoch object into a fif file epochs.save(data_path + '/%.3dnn_raw_epo.fif' % sid, overwrite= True) # averaging evoked1 = epochs['words'].average() evoked2 = epochs['pseudo'].average() # saving multiple evoked objects into a fif file mne.write_evokeds('%.3d-ave.fif' % sid, [evoked1, evoked2]) ``` ```python evoked1.plot() ``` ![](https://i.imgur.com/vCT5IhY.png) Show MEG data ```python raw ``` <RawKIT | de006nn.con, n_channels x n_times : 257 x 1265000 (1265.0 sec), ~2.42 GB, data loaded> ```python epochs ``` <Epochs | 82 events (all good), -0.1 - 0.7 sec, baseline [None, 0], ~79.0 MB, data loaded, 'pseudo': 48 'words': 34> ```python evoked1 ``` <Evoked | 'words' (mean, N=34), [-0.1, 0.7] sec, 157 ch, ~1.3 MB> ```python evoked2 ``` <Evoked | 'pseudo' (mean, N=48), [-0.1, 0.7] sec, 157 ch, ~1.3 MB> ```python tmp = [evoked1, evoked2] colors = 'green', 'red' mne.viz.plot_evoked_topo(tmp, color = colors, title = 'LDT / lexicality', layout = kit_lay) ``` ![](https://i.imgur.com/SY3vyA3.png) ```python times = np.arange(0.05, 0.5, 0.05) evoked1.plot_topomap(times=times, ch_type='mag', time_unit='s') ``` ![](https://i.imgur.com/lA0qoCR.png) ```python ts_args = dict(gfp=True, time_unit='s') topomap_args = dict(sensors=False, time_unit='s') evoked1.plot_joint(title='Real Words', times=[.13, .20, 0.31], ts_args=ts_args, topomap_args=topomap_args) ``` ![](https://i.imgur.com/DKx4Q2J.png) ```python raw.info['ch_names'] ``` ['MEG 001', 'MEG 002', ... 'TRIGGER 006', 'TRIGGER 007', 'TRIGGER 008', ... 'MISC 031', 'MISC 032', 'STI 014']