skjerns / AutoSleepScorer

An open-source sleep stage classification Python package
GNU Affero General Public License v3.0
103 stars 22 forks source link

What is the purpose of the line np.stack([eeg]) #10

Closed balandongiv closed 5 years ago

balandongiv commented 5 years ago

Hi Simon, may I know what is the function of these lines? I had dissect to understand its purpose, but turn out no where. Appreciate if you can shed some light

Especially, the need of the pool.apply and RawArray here. I had read the documentation, but still unable to relate why you used it here.

            xx=np.stack([eeg]) # I am able to run even w/o stack
            vv=mne.create_info(1, self.sfreq, 'eeg')
            res_eeg = pool.apply_async(
                mne.io.RawArray(xx, vv, first_samp=0, verbose=0).resample,args=(100.,)) 
skjerns commented 5 years ago

1) Python is generally not good with using multiple cores. Therefore I use a multiprocessing.pool for parallel data processing (speeding things up.). In this example, I run the resampling in parallel, which makes it almost 3x faster. 2) mne.io.RawArray needs a 2D input (channels x samples). We have a 1D data series (one ExG channel). np.stack([array1d]) converts a 1D array to a 2D array. Not sure why I don't use np.reshape(data, [1, -1]), but I assume there was a reason (probably something with views and copies).