prep¶
A module for io and preprocessing
- cmgraph.prep.eeg_emg_alignment(eeg_fName, emg_df, sfreq_final, emg_freq, report_fName=None, start_marker=True, fir=[1, None], PREP=True, montage='standard_1020')[source]¶
This function takes .set format for eeg and txt format for emg.
- Parameters
- eeg_fNamestring
eeg_fName should be in .set form
- emg_fNamestring
emg_fName should be in .txt form
- report_fName: string
optional, default to None which will not generate a report for the reprocessing result. When reproty_fName is specified, two reports will be generated at the suggested directory including one in HTML, and one in .h5 format. The .h5 format is an edittable report.
- montage: string
The defaut montage is set to standard 1020 montage
- start_markerboolean
if start_marker is true, the segment before the first marker will be cropped, defaults to True
- fir: list
the lower and upper boundary of filter. If the boundary is set to None, then the filter become high-pass or low-pass filter.
- PREP: boolean
the EEG preprocessing pipeline process, defauts to True. It can de deactivated when set to false.
- emg_chs_selectedlist of int
the index of emg channels (columns) that are supposed to be used in further analysis, defaults to ‘all’
- Returns
- mne raw object containing aligned eeg and emg data
Notes
Make sure the eeg recording are no less than the emg recording. The current version of this function crop emg signal with respect to emg in order to keep these data aligned.
Examples
>>>eeg_fName = r’D:DataRuiJinFirstStroke11JanEEGsubj1_healthy_session1.set’ >>>emg_fName = r’D:DataRuiJinFirstStroke11JanEMGsubj1_healthy_session1.txt’ >>>emg_df = pd.read_csv(emg_fName, header = None, skiprows=3,
sep = ‘ ‘,engine = ‘python’)
>>>eeg_emg_alignment(eeg_fName,emg_df,emg_freq=1000,sfreq_final=500,report_fName=None,PREP=False)
- cmgraph.prep.emg_io(emg_fName, skiprows, sep=' ', emg_chs_selected='all')[source]¶
this function takes .txt format emg file and renders to a pandas dataframe for further processing.
- Parameters
- emg_fNamestring
emg_fName should be in .txt or in .csv form.
- emg_chs_selectedlist of int
the index of emg channels (columns) that are supposed to be used in further analysis, defaults to ‘all’
- sepstring
the seperator to be specified when reading the txt file with pandas.read_csv
- skiprowsint
rows to be skipped. This applies for data containing emg information at the begining of the data file.
- Returns
- pandas’s dataframe
Notes
The .txt file or .csv file should not have headers. If so, please use skiprow to trim them. The first column should be 0 in the emg_chs_selected parameter
Examples
>>>emg_fName = r’D:DataRuiJinFirstStroke11JanEMGsubj1_healthy_session1.txt’ >>>emg_io(emg_fName, skiprows = 3, emg_chs_selected=’all’)
- cmgraph.prep.epochs_basedon_emg(raw_hybrid, ref_emg, windowLen, step=100, threshold=0.5, report_fName=None, add_to_existed_report=False, reject_criteria={'eeg': 0.0003, 'emg': 10000000000.0}, flat_criteria={'eeg': 5e-07}, tmin=0.0, tmax=3.0, save_fName=None)[source]¶
this function takes .set format for eeg and txt format for emg.
- Parameters
- raw_hybrid: mne raw object
The raw object containing aligned eeg and emg
- ref_emg: list of string
the emg channels that the algorithm refers to. They should be channels in input raw_hybrid. The algorithm will consider ‘the length of the string’ as number of movements.
- report_fName: string
optional, default to None which will not generate a report for the epoching result. When reproty_fName is specified, two reports will be generated at the suggested directory including one in HTML, and one in .h5 format. The .h5 format is an edittable report.
- add_to_existed_report: boolean
It is supposed to be true when one wants to add the epoching report into an existed report.
- windowLen: int
rough duration estimation of the movement
- step: int
equivalent to resolution, defaults to 100
- threshold: float
the threshold should be in [0,1], represnting the quantile of the energy for all windows
- reject_criteria: dict
epochs containing eeg and emg that exceed rejection criteria will be rejected. defaults to dict(eeg=30e-5,emg=1e10)
- flat_criteria: dict
epochs containing eeg and emg whose amplitude are lower than flat criteria will be rejected. Defaults to dict(eeg=1e-6). If reject_criteria and flat_criteria are both set to None, then no epochs rejection would take place
- tmin: float
the begining of the epochs with respect to the movement onsets
- tmax: float
the end of the epochs with respect to the movement onsets
- savefName: string
the path and filename of the saving epochs. It defaults to None, that is the epochs would not be saved
- Returns
- mne epochs
See also