Initial processing¶
UML diagrams presenting the flow of the analysis for each module are available here: https://github.com/ANCPLabOldenburg/MEG-QC-code/tree/main/diagrams
- meg_qc.calculation.initial_meg_qc.Epoch_meg(epoching_params, data: Raw)[source]¶
Epoch MEG data based on the parameters provided in the config file.
- Parameters:
epoching_params (dict) – Dictionary with parameters for epoching.
data (mne.io.Raw) – MEG data to be epoched.
- Returns:
dict_epochs_mg – Dictionary with epochs for each channel type: mag, grad.
- Return type:
dict
- meg_qc.calculation.initial_meg_qc.add_3d_ch_locations(raw, channels_objs)[source]¶
Add channel locations to the MEG channels objects.
- Parameters:
raw (mne.io.Raw) – MEG data.
channels_objs (dict) – Dictionary with MEG channels.
- Returns:
channels_objs – Dictionary with MEG channels with added locations.
- Return type:
dict
- meg_qc.calculation.initial_meg_qc.assign_channels_properties(channels_short: dict, meg_system: str)[source]¶
Assign lobe area to each channel according to the lobe area dictionary + the color for plotting + channel location.
Can later try to make this function a method of the MEG_channels class. At the moment not possible because it needs to know the total number of channels to figure which meg system to use for locations. And MEG_channels class is created for each channel separately.
- Parameters:
channels (dict) – dict with channels names like: {‘mag’: […], ‘grad’: […]}
meg_system (str) – CTF, Triux, None…
- Returns:
channels_objs (dict) – Dictionary with channel names for each channel type: mag, grad. Each channel has assigned lobe area and color for plotting + channel location.
lobes_color_coding_str (str) – A string with information about the color coding of the lobes.
- meg_qc.calculation.initial_meg_qc.change_ch_type_CTF(raw, channels)[source]¶
For CTF data channels types and units need to be chnaged from mag to grad.
- Parameters:
channels (dict) – dict with ch names separated by mag and grad
- Returns:
channels – dict with ch names separated by mag and grad UPDATED
- Return type:
dict
- meg_qc.calculation.initial_meg_qc.check_chosen_ch_types(m_or_g_chosen: List, channels_objs: dict)[source]¶
Check if the channels which the user gave in config file to analize actually present in the data set.
- Parameters:
m_or_g_chosen (list) – List with channel types to analize: mag, grad. These are theones the user chose.
channels_objs (dict) – Dictionary with channel names for each channel type: mag, grad. These are the ones present in the data set.
- Returns:
m_or_g_chosen (list) – List with channel types to analize: mag, grad.
m_or_g_skipped_str (str) – String with information about which channel types were skipped.
- meg_qc.calculation.initial_meg_qc.choose_channels(raw: Raw)[source]¶
Separate channels by ‘mag’ and ‘grad’. Done this way, because pick() or pick_types() sometimes gets wrong results, especialy for CTF data.
- Parameters:
raw (mne.io.Raw) – MEG data
- Returns:
channels – dict with ch names separated by mag and grad
- Return type:
dict
- meg_qc.calculation.initial_meg_qc.chs_dict_to_csv(chs_by_lobe: dict, file_name_prefix: str)[source]¶
Convert dictionary with channels objects to a data frame and save it as a csv file.
- Parameters:
chs_by_lobe (dict) – Dictionary with channel objects for each channel type: mag, grad. And by lobe. Each obj hold info about the channel name, lobe area and color code, locations and (in the future) pther info, like: if it has noise of any sort.
file_name_prefix (str) – Prefix for the file name. Example: ‘Sensors’ will result in file name ‘Sensors.csv’.
- Returns:
df_deriv – List with data frames with sensors info.
- Return type:
list
- meg_qc.calculation.initial_meg_qc.get_all_config_params(config_file_path: str)[source]¶
Parse all the parameters from config and put into a python dictionary divided by sections. Parsing approach can be changed here, which will not affect working of other fucntions.
- Parameters:
config_file_path (str) – The path to the config file.
- Returns:
all_qc_params – A dictionary with all the parameters from the config file.
- Return type:
dict
- meg_qc.calculation.initial_meg_qc.get_internal_config_params(config_file_name: str)[source]¶
Parse all the parameters from config and put into a python dictionary divided by sections. Parsing approach can be changed here, which will not affect working of other fucntions. These are interanl parameters, NOT to be changed by the user.
- Parameters:
config_file_name (str) – The name of the config file.
- Returns:
internal_qc_params – A dictionary with all the parameters.
- Return type:
dict
- meg_qc.calculation.initial_meg_qc.initial_processing(default_settings: dict, filtering_settings: dict, epoching_params: dict, file_path: str)[source]¶
Here all the initial actions needed to analyse MEG data are done:
read fif file,
separate mags and grads names into 2 lists,
crop the data if needed,
filter and downsample the data,
epoch the data.
- Parameters:
default_settings (dict) – Dictionary with default settings for MEG QC.
filtering_settings (dict) – Dictionary with parameters for filtering.
epoching_params (dict) – Dictionary with parameters for epoching.
file_path (str) – Path to the fif file with MEG data.
- Returns:
dict_epochs_mg (dict) – Dictionary with epochs for each channel type: mag, grad.
chs_by_lobe (dict) – Dictionary with channel objects for each channel type: mag, grad. And by lobe. Each obj hold info about the channel name, lobe area and color code, locations and (in the future) pther info, like: if it has noise of any sort.
channels (dict) – Dictionary with channel names for each channel type: mag, grad.
raw_crop_filtered (mne.io.Raw) – Filtered and cropped MEG data.
raw_crop_filtered_resampled (mne.io.Raw) – Filtered, cropped and resampled MEG data.
raw_cropped (mne.io.Raw) – Cropped MEG data.
raw (mne.io.Raw) – MEG data.
info_derivs (list) – List with QC_derivative objects with MNE info object.
shielding_str (str) – String with information about active shielding.
epoching_str (str) – String with information about epoching.
sensors_derivs (list) – List with data frames with sensors info.
m_or_g_chosen (list) – List with channel types to analize: mag, grad.
m_or_g_skipped_str (str) – String with information about which channel types were skipped.
lobes_color_coding_str (str) – String with information about color coding for lobes.
resample_str (str) – String with information about resampling.
- meg_qc.calculation.initial_meg_qc.load_data(file_path)[source]¶
Load MEG data from a file. It can be a CTF data or a FIF file.
- Parameters:
file_path (str) – Path to the fif file with MEG data.
- Returns:
raw (mne.io.Raw) – MEG data.
shielding_str (str) – String with information about active shielding.