mn.time_frequency.tfr_array_stockwell

External Email - Use Caution

Hello,

I'm reading in an EDF (not FIF) file and would like to compute the
Stockwell Transform for a single channel using
time_frequency.tfr_array_stockwell as
described at
https://mne.tools/stable/generated/mne.time_frequency.tfr_array_stockwell.html?highlight=mne%20time_frequency%20tfr_stockwell
.

It says that the last dimension of my data is time. I'm not sure what that
means, but I interpret it to be that, for a single channel, the first
column consists of signal readings and the second consists of corresponding
times.

Here's what I've tried for the first channel of my signal, which is 10
minutes long with sampling frequency 200

import numpy as np
import mne as mn

raw=mn.io.read_raw_edf('/Users/fishbacp/Desktop/EEG_file.edf', preload=True)
Fs=raw.info['sfreq']

data,times=raw[:,:]
signal=np.array([data[0,:],times]).T #Creates a number_of_times -by- 2
array, whose second column consists of times.

min_freq=5
max_freq=100

st_power, itc, freqs=mn.time_frequency.tfr_array_stockwell(signal,
Fs,fmin=min_freq,fmax=max_freq)

This results in the following error:

line 172, in tfr_array_stockwell
    n_out = data.shape[2] // decim + bool(data.shape[2] % decim)
IndexError: tuple index out of range

I gather that I'm not interpreting how my input signal should be formatted.

Thanks for any assistance you can provide.

Paul F.

External Email - Use Caution

hi Paul,

try:

import numpy as np
import mne

raw = mne.io.read_raw_edf('/Users/fishbacp/Desktop/EEG_file.edf', preload=True)
Fs = raw.info['sfreq']
data, times=raw[:, :]
signal = data[[0]]
min_freq = 5
max_freq = 100
st_power, itc, freqs = mne.time_frequency.tfr_array_stockwell(signal,
Fs, fmin=min_freq, fmax=max_freq)

External Email - Use Caution

Hi Alex,

Thanks so much for responding to my message. I tried what you suggested,
but I'm still getting an error:

raw=mn.io.read_raw_edf('/Users/fishbacp/Desktop/11.edf', preload=True)
Fs=raw.info['sfreq']

data,times=raw[:,:]
print('data: '+str(data.shape)) #This indicates the data shape is
46-by-123200, which makes sense for my recording: 46 channels, 10 minute
time length, and sampling frequency 200 Hz.

signal = data[[0]]
print('signal: '+str(signal.shape)) # This produces 1-by-123200 for this
channel
min_freq = 5
max_freq = 100
st_power, itc, freqs = mn.time_frequency.tfr_array_stockwell(signal,Fs,
fmin=min_freq, fmax=max_freq)

This is the error message:

Traceback (most recent call last):
  File "/Users/fishbacp/Desktop/Python_Sabbatical/plot_stockwell.py", line
145, in <module>
    st_power, itc, freqs = mn.time_frequency.tfr_array_stockwell(signal,Fs,
fmin=min_freq, fmax=max_freq)
  File
"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mne/time_frequency/_stockwell.py",
line 172, in tfr_array_stockwell
    n_out = data.shape[2] // decim + bool(data.shape[2] % decim)
IndexError: tuple index out of range

Lines-171-173 in the script, located at
https://github.com/mne-tools/mne-python/blob/maint/0.20/mne/time_frequency/_stockwell.py#L101-L199
are
as follows:

[image: image.png]

I don't see how data.shape[2] could even be defined if data lacks a third
dimension.

I'm not wed to using this implementation of the stockwell transform. I
tried it first because I enjoy using MNE, but if you know of other good
implementations, I would enjoy hearing about them.

Many, many thanks.

Best,

Paul

External Email - Use Caution

For now you can work around it by doing `data = data[np.newaxis]` to make
it of shape `(n_epochs, n_channels, n_times)` (which appears to be what the
function actually wants). Can you open an issue on the MNE-Python issue
tracker so that we don't forget to fix this? It should really just operate
along the last dimension and not assume that's 2.

Eric

        External Email - Use Caution

Hi Alex,

Thanks so much for responding to my message. I tried what you suggested,
but I'm still getting an error:

raw=mn.io.read_raw_edf('/Users/fishbacp/Desktop/11.edf', preload=True)
Fs=raw.info['sfreq']

data,times=raw[:,:]
print('data: '+str(data.shape)) #This indicates the data shape is
46-by-123200, which makes sense for my recording: 46 channels, 10 minute
time length, and sampling frequency 200 Hz.

signal = data[[0]]
print('signal: '+str(signal.shape)) # This produces 1-by-123200 for
this channel
min_freq = 5
max_freq = 100
st_power, itc, freqs = mn.time_frequency.tfr_array_stockwell(signal,Fs,
fmin=min_freq, fmax=max_freq)

This is the error message:

Traceback (most recent call last):
  File "/Users/fishbacp/Desktop/Python_Sabbatical/plot_stockwell.py", line
145, in <module>
    st_power, itc, freqs =
mn.time_frequency.tfr_array_stockwell(signal,Fs, fmin=min_freq,
fmax=max_freq)
  File
"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mne/time_frequency/_stockwell.py",
line 172, in tfr_array_stockwell
    n_out = data.shape[2] // decim + bool(data.shape[2] % decim)
IndexError: tuple index out of range

Lines-171-173 in the script, located at
https://github.com/mne-tools/mne-python/blob/maint/0.20/mne/time_frequency/_stockwell.py#L101-L199 are
as follows:

[image: image.png]

I don't see how data.shape[2] could even be defined if data lacks a third
dimension.

I'm not wed to using this implementation of the stockwell transform. I
tried it first because I enjoy using MNE, but if you know of other good
implementations, I would enjoy hearing about them.

Many, many thanks.

Best,

Paul

        External Email - Use Caution

hi Paul,

try:

import numpy as np
import mne

raw = mne.io.read_raw_edf('/Users/fishbacp/Desktop/EEG_file.edf',
preload=True)
Fs = raw.info['sfreq']
data, times=raw[:, :]
signal = data[[0]]
min_freq = 5
max_freq = 100
st_power, itc, freqs = mne.time_frequency.tfr_array_stockwell(signal,
Fs, fmin=min_freq, fmax=max_freq)

--

signal must be a 2d array with dimensions: channel x time

Alex

_______________________________________________
Mne_analysis mailing list
Mne_analysis at nmr.mgh.harvard.edu
Mne_analysis Info Page

--
Professor of Mathematics, Grand Valley State University

Department of Mathematics (MAK C-2-408)
Grand Valley State University
1 Campus Dr.
Allendale, MI 49401
fishbacp at mail.gvsu.edu
616.331.2040
616.331.3120 (fax)
_______________________________________________
Mne_analysis mailing list
Mne_analysis at nmr.mgh.harvard.edu
Mne_analysis Info Page

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20200709/98ed298d/attachment-0001.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 27673 bytes
Desc: not available
Url : http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20200709/98ed298d/attachment-0001.png

External Email - Use Caution

Thanks again. Now, a different message appears:

Warning (from warnings module):
  File "/Users/fishbacp/Desktop/Python_Sabbatical/plot_stockwell.py", line
188
    st_power, itc, freqs = mn.time_frequency.tfr_array_stockwell(signal,Fs,
fmin=min_freq, fmax=max_freq)
RuntimeWarning: The input signal is shorter (123200) than "n_fft" (131072).
Applying zero padding.

This warning message comes from the function, _check_input_st.

I looked at this function separately and, while n_times is correct, n_fft
is larger, even if I simply use the default value
in mn.time_frequency.tfr_array_stockwell.

Eventually, mn.time_frequency.tfr_array_stockwell runs and I return to the
shell (in Idle); however I inserted a line to print st_power and freqs,
which came back empty

Paul

External Email - Use Caution

Looks like stockwell is internally only meant to work on 3D arrays. I've
opened a pull request to fix the checks:

https://github.com/mne-tools/mne-python/pull/7996

In your case you should be able to get something useful by passing a 3D
array like signal[np.newaxis]. The power and frequencies should not be
empty. If they are, please open an issue with a little snippet of code we
can use to reproduce the problem.

Eric

        External Email - Use Caution

Thanks again. Now, a different message appears:

Warning (from warnings module):
  File "/Users/fishbacp/Desktop/Python_Sabbatical/plot_stockwell.py", line
188
    st_power, itc, freqs =
mn.time_frequency.tfr_array_stockwell(signal,Fs, fmin=min_freq,
fmax=max_freq)
RuntimeWarning: The input signal is shorter (123200) than "n_fft"
(131072). Applying zero padding.

This warning message comes from the function, _check_input_st.

I looked at this function separately and, while n_times is correct, n_fft
is larger, even if I simply use the default value
in mn.time_frequency.tfr_array_stockwell.

Eventually, mn.time_frequency.tfr_array_stockwell runs and I return to the
shell (in Idle); however I inserted a line to print st_power and freqs,
which came back empty

Paul

        External Email - Use Caution

For now you can work around it by doing `data = data[np.newaxis]` to make
it of shape `(n_epochs, n_channels, n_times)` (which appears to be what the
function actually wants). Can you open an issue on the MNE-Python issue
tracker so that we don't forget to fix this? It should really just operate
along the last dimension and not assume that's 2.

Eric

        External Email - Use Caution

Hi Alex,

Thanks so much for responding to my message. I tried what you suggested,
but I'm still getting an error:

raw=mn.io.read_raw_edf('/Users/fishbacp/Desktop/11.edf', preload=True)
Fs=raw.info['sfreq']

data,times=raw[:,:]
print('data: '+str(data.shape)) #This indicates the data shape is
46-by-123200, which makes sense for my recording: 46 channels, 10 minute
time length, and sampling frequency 200 Hz.

signal = data[[0]]
print('signal: '+str(signal.shape)) # This produces 1-by-123200 for
this channel
min_freq = 5
max_freq = 100
st_power, itc, freqs = mn.time_frequency.tfr_array_stockwell(signal,Fs,
fmin=min_freq, fmax=max_freq)

This is the error message:

Traceback (most recent call last):
  File "/Users/fishbacp/Desktop/Python_Sabbatical/plot_stockwell.py",
line 145, in <module>
    st_power, itc, freqs =
mn.time_frequency.tfr_array_stockwell(signal,Fs, fmin=min_freq,
fmax=max_freq)
  File
"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mne/time_frequency/_stockwell.py",
line 172, in tfr_array_stockwell
    n_out = data.shape[2] // decim + bool(data.shape[2] % decim)
IndexError: tuple index out of range

Lines-171-173 in the script, located at
https://github.com/mne-tools/mne-python/blob/maint/0.20/mne/time_frequency/_stockwell.py#L101-L199 are
as follows:

[image: image.png]

I don't see how data.shape[2] could even be defined if data lacks a
third dimension.

I'm not wed to using this implementation of the stockwell transform. I
tried it first because I enjoy using MNE, but if you know of other good
implementations, I would enjoy hearing about them.

Many, many thanks.

Best,

Paul

        External Email - Use Caution

hi Paul,

try:

import numpy as np
import mne

raw = mne.io.read_raw_edf('/Users/fishbacp/Desktop/EEG_file.edf',
preload=True)
Fs = raw.info['sfreq']
data, times=raw[:, :]
signal = data[[0]]
min_freq = 5
max_freq = 100
st_power, itc, freqs = mne.time_frequency.tfr_array_stockwell(signal,
Fs, fmin=min_freq, fmax=max_freq)

--

signal must be a 2d array with dimensions: channel x time

Alex

_______________________________________________
Mne_analysis mailing list
Mne_analysis at nmr.mgh.harvard.edu
https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis

--
Professor of Mathematics, Grand Valley State University

Department of Mathematics (MAK C-2-408)
Grand Valley State University
1 Campus Dr.
Allendale, MI 49401
fishbacp at mail.gvsu.edu
616.331.2040
616.331.3120 (fax)
_______________________________________________
Mne_analysis mailing list
Mne_analysis at nmr.mgh.harvard.edu
https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis

_______________________________________________
Mne_analysis mailing list
Mne_analysis at nmr.mgh.harvard.edu
https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis

--
Professor of Mathematics, Grand Valley State University
President, Pi Mu Epsilon National Honorary Mathematics Society, Inc.

Department of Mathematics (MAK C-2-408)
Grand Valley State University
1 Campus Dr.
Allendale, MI 49401
fishbacp at mail.gvsu.edu
616.331.2040
616.331.3120 (fax)
_______________________________________________
Mne_analysis mailing list
Mne_analysis at nmr.mgh.harvard.edu
https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20200710/46317c06/attachment-0001.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 27673 bytes
Desc: not available
Url : http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20200710/46317c06/attachment-0001.png