본문 바로가기
Brain Engineering/MNE Python

[MNE-Python] 내부 데이터 수정

by goatlab 2022. 3. 22.
728x90
반응형
SMALL

MNE-Python의 많은 데이터 객체 (Raw, Epochs, Evoked 등)에는 데이터를 제자리에서 (선택적 또는 의무적으로) 수정하는 메서드가 있다. 이는 계산을 수행하는 데 필요한 컴퓨터 메모리의 양을 줄이기 때문에 큰 데이터 세트로 작업할 때 유리할 수 있다. 그러나 이러한 상황이 발생하고 있다는 사실을 인지하지 못하면 예기치 않은 결과가 발생할 수 있다. 내부 처리의 몇 가지 예와 이를 방지하는 방법과 시기를 제공한다.

 

import os
import mne

sample_data_folder = mne.datasets.sample.data_path()
sample_data_raw_file = os.path.join(sample_data_folder, 'MEG', 'sample',
                                    'sample_audvis_raw.fif')
# the preload flag loads the data into memory now
raw = mne.io.read_raw_fif(sample_data_raw_file, preload=True)
raw.crop(tmax=10.)  # raw.crop() always happens in-place
---
Opening raw data file /home/circleci/mne_data/MNE-sample-data/MEG/sample/sample_audvis_raw.fif...
    Read a total of 3 projection items:
        PCA-v1 (1 x 102)  idle
        PCA-v2 (1 x 102)  idle
        PCA-v3 (1 x 102)  idle
    Range : 25800 ... 192599 =     42.956 ...   320.670 secs
Ready.
Reading 0 ... 166799  =      0.000 ...   277.714 secs...

 

Signal processing

 

대부분의 MNE-Python 데이터 객체에는 고, 저, 대역 통과 필터 (filter), 대역 정지 필터 (notch_filter), 힐베르트 변환 (apply_hilbert), 심지어 임의 또는 사용자 정의 함수 (apply_function)를 사용한다. 일반적으로 항상 제자리에서 데이터를 수정하므로 비교를 위해 처리되지 않은 데이터를 보존하려면 먼저 복사본을 만들어야 한다.

 

original_raw = raw.copy()
raw.apply_hilbert()
print(f'original data type was {original_raw.get_data().dtype}, after '
      f'apply_hilbert the data type changed to {raw.get_data().dtype}.')
---
out : original data type was float64, after apply_hilbert the data type changed to complex128.

 

Channel picking

 

데이터가 제자리에서 수정되는 또 다른 방법 그룹은 채널 선택 방법이다.

 

print(f'original data had {original_raw.info["nchan"]} channels.')
original_raw.pick('eeg')  # selects only the EEG channels
print(f'after picking, it has {original_raw.info["nchan"]} channels.')
---
original data had 376 channels.
Removing projector <Projection | PCA-v1, active : False, n_channels : 102>
Removing projector <Projection | PCA-v2, active : False, n_channels : 102>
Removing projector <Projection | PCA-v3, active : False, n_channels : 102>
after picking, it has 60 channels.

 

The copy parameter

 

copy처리 전후의 데이터 비교를 용이하게 하는 방법을 사용하는 예를 보면 특정 MNE-Python 함수를 사용할 때는 필요하지 않는다. 함수 매개변수에는 데이터의 수정된 복사본 반환 또는 내부 작동을 지정할 수 있는 함수 매개변수가 있기 때문이다. 예를 들어, 그러한 기능 중 하나이다.

 

rereferenced_raw, ref_data = mne.set_eeg_reference(original_raw, ['EEG 003'],
                                                   copy=True)
fig_orig = original_raw.plot()
fig_reref = rereferenced_raw.plot()

 

https://mne.tools/stable/auto_tutorials/intro/15_inplace.html#sphx-glr-auto-tutorials-intro-15-inplace-py

 

Modifying data in-place — MNE 1.0.0 documentation

Many of MNE-Python’s data objects (Raw, Epochs, Evoked, etc) have methods that modify the data in-place (either optionally or obligatorily). This can be advantageous when working with large datasets because it reduces the amount of computer memory needed

mne.tools

 

728x90
반응형
LIST