Skip to content

Raise ValueError if TFR freqs <= 0#6169

Merged
agramfort merged 33 commits intomne-tools:masterfrom
DiGyt:raise_freq0_error
Apr 20, 2019
Merged

Raise ValueError if TFR freqs <= 0#6169
agramfort merged 33 commits intomne-tools:masterfrom
DiGyt:raise_freq0_error

Conversation

@DiGyt
Copy link
Copy Markdown
Contributor

@DiGyt DiGyt commented Apr 18, 2019

Raise a ValueError for invalid frequencies passed into tfr_morlet and tfr_multitaper, according to #5708

Additional information

Raise a ValueError "all computed frequencies in freqs must be greater than 0." if the freqs passed to mne/time_frequency/tfr.py::morlet and mne/time_frequency/tfr.py::_make_dpss are <= 0.

Note:
Used np.any([f <= 0 for f in freqs]) instead of np.any(freqs <= 0) to also handle simple lists.

DiGyt and others added 30 commits March 23, 2019 15:54
Enable import the function _freq_mask from .numerics
Added _freq_mask function equivalent to _time_mask function, but for frequency
Added tests for _freq_mask
Enables frequency cropping with tfr.crop(fmin, fmax) for TFR objects
Enhanced test_crop to also test for frequency cropping.
fixed floating point issues in utils.numerics._freq_mask
Updated docstring for BaseTFR.crop to show fmin/fmax params
fixed floating point error in _freq_mask
Adapted test_freq_mask to error fix in freq_mask
Adapted docstring for version in BaseTFR.crop
Removed Debugging notes from test_crop
# Conflicts:
#	mne/time_frequency/tfr.py
correct spacing
Fixed some code for flake8
Added changes to whats_new.rst
Fixed update to whats_new.rst
eliminated merge conflicts in mne.utils.__init__.py

Also edited test_freq_mask and test_time_mask mne.utils.tests.test_numerics to find errors more explicitely.
changed code format and error message.
-Removed sfreq=None argument default from mne/utils/numerics.py::_freq_mask
-Adapted relevant tests and methods accordingly
-Introduced raise(ValueError) When sfreq=None
-Introduced tests for sfreq=None case
- _time_mask or _freq_mask are only called, if they were defined in crop()
- _time_mask, _freq_mask were changed back to save time & mem
# Conflicts:
#	mne/utils/__init__.py
corrected merge conflicts with mne/utils/__init__.py
corrected ```_time_mask``` and ```_freq_mask``` conditions in ```_BaseTFR.crop()```
# Conflicts:
#	mne/time_frequency/tests/test_tfr.py
#	mne/time_frequency/tfr.py
#	mne/utils/__init__.py
Make multitaper and morlet raise a value error if freqs include a frequency <= 0.

Signed-off-by: Dirk Gütlin <dirk.guetlin@stud.sbg.ac.at>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 18, 2019

Codecov Report

Merging #6169 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #6169      +/-   ##
==========================================
+ Coverage   89.01%   89.01%   +<.01%     
==========================================
  Files         410      410              
  Lines       73869    73883      +14     
  Branches    12253    12255       +2     
==========================================
+ Hits        65752    65766      +14     
  Misses       5222     5222              
  Partials     2895     2895

@agramfort
Copy link
Copy Markdown
Member

agramfort commented Apr 18, 2019 via email

convert freqs in morlet and _make_dpss to np.array for faster computation

Signed-off-by: Dirk Gütlin <dirk.guetlin@stud.sbg.ac.at>
changed error statements for invalid frequencies passed in mne/time_frequency/tfr.py ::morlet and ::_make_dpss

Signed-off-by: Dirk Gütlin <dirk.guetlin@stud.sbg.ac.at>
@cbrnr
Copy link
Copy Markdown
Contributor

cbrnr commented Apr 19, 2019

It's good that there is an error message, but I still don't know if these wavelet-based methods cannot compute the power at DC or if this is just the case in our implementation.

@DiGyt
Copy link
Copy Markdown
Contributor Author

DiGyt commented Apr 19, 2019

It's good that there is an error message, but I still don't know if these wavelet-based methods cannot compute the power at DC or if this is just the case in our implementation.

Oh yes, sorry! I will work on this and do another PR if i find a convenient way. Would that be okay?

@cbrnr
Copy link
Copy Markdown
Contributor

cbrnr commented Apr 19, 2019

Sure!

@agramfort agramfort merged commit 69dbf4b into mne-tools:master Apr 20, 2019
@agramfort
Copy link
Copy Markdown
Member

thx @DiGyt

massich pushed a commit to massich/mne-python that referenced this pull request Apr 23, 2019
* Added import _freq_mask

Enable import the function _freq_mask from .numerics

* Added _freq_mask function

Added _freq_mask function equivalent to _time_mask function, but for frequency

* Added tests for _freq_mask

Added tests for _freq_mask

* Added frequency cropping args to BaseTFR class

Enables frequency cropping with tfr.crop(fmin, fmax) for TFR objects

* Enhanced test_crop

Enhanced test_crop to also test for frequency cropping.

* updated documentation for BaseTFR.crop function,
fixed floating point issues in utils.numerics._freq_mask

* Updated docstring for BaseTFR.crop

Updated docstring for BaseTFR.crop to show fmin/fmax params

* Fixed _freq_mask

fixed floating point error in _freq_mask

* Adapted test_freq_mask to function changes

Adapted test_freq_mask to error fix in freq_mask

* Adapted docstring BaseTFR.crop

Adapted docstring for version in BaseTFR.crop

* Removed Debugging notes

Removed Debugging notes from test_crop

* correct spacing

correct spacing

* Fixed code format
Fixed some code for flake8

* Updated whats_new.rst
Added changes to whats_new.rst

* Updated whats_new.rst
Fixed update to whats_new.rst

* Eliminated Conflicts with master
eliminated merge conflicts in mne.utils.__init__.py

Also edited test_freq_mask and test_time_mask mne.utils.tests.test_numerics to find errors more explicitely.

* fixed flake8 probs

* changed _time/_freq_mask code style
changed code format and error message.

* Removed sfreq=None from _freq_mask
-Removed sfreq=None argument default from mne/utils/numerics.py::_freq_mask
-Adapted relevant tests and methods accordingly

* Removed support for sfreq=None from _freq_mask
-Introduced raise(ValueError) When sfreq=None
-Introduced tests for sfreq=None case

* Made _BaseTFR.crop omit mask if not defined.
- _time_mask or _freq_mask are only called, if they were defined in crop()
- _time_mask, _freq_mask were changed back to save time & mem

* corrected new merge conflicts once again

corrected merge conflicts with mne/utils/__init__.py

* corrected conditions in _BaseTFR.crop

corrected ```_time_mask``` and ```_freq_mask``` conditions in ```_BaseTFR.crop()```

* Make TFR raise value error for freqs <= 0

Make multitaper and morlet raise a value error if freqs include a frequency <= 0.

Signed-off-by: Dirk Gütlin <dirk.guetlin@stud.sbg.ac.at>

* convert freqs in morlet and _make_dpss to np.array

convert freqs in morlet and _make_dpss to np.array for faster computation

Signed-off-by: Dirk Gütlin <dirk.guetlin@stud.sbg.ac.at>

* changed error statements

changed error statements for invalid frequencies passed in mne/time_frequency/tfr.py ::morlet and ::_make_dpss

Signed-off-by: Dirk Gütlin <dirk.guetlin@stud.sbg.ac.at>
jeythekey pushed a commit to jeythekey/mne-python that referenced this pull request Apr 27, 2019
* Added import _freq_mask

Enable import the function _freq_mask from .numerics

* Added _freq_mask function

Added _freq_mask function equivalent to _time_mask function, but for frequency

* Added tests for _freq_mask

Added tests for _freq_mask

* Added frequency cropping args to BaseTFR class

Enables frequency cropping with tfr.crop(fmin, fmax) for TFR objects

* Enhanced test_crop

Enhanced test_crop to also test for frequency cropping.

* updated documentation for BaseTFR.crop function,
fixed floating point issues in utils.numerics._freq_mask

* Updated docstring for BaseTFR.crop

Updated docstring for BaseTFR.crop to show fmin/fmax params

* Fixed _freq_mask

fixed floating point error in _freq_mask

* Adapted test_freq_mask to function changes

Adapted test_freq_mask to error fix in freq_mask

* Adapted docstring BaseTFR.crop

Adapted docstring for version in BaseTFR.crop

* Removed Debugging notes

Removed Debugging notes from test_crop

* correct spacing

correct spacing

* Fixed code format
Fixed some code for flake8

* Updated whats_new.rst
Added changes to whats_new.rst

* Updated whats_new.rst
Fixed update to whats_new.rst

* Eliminated Conflicts with master
eliminated merge conflicts in mne.utils.__init__.py

Also edited test_freq_mask and test_time_mask mne.utils.tests.test_numerics to find errors more explicitely.

* fixed flake8 probs

* changed _time/_freq_mask code style
changed code format and error message.

* Removed sfreq=None from _freq_mask
-Removed sfreq=None argument default from mne/utils/numerics.py::_freq_mask
-Adapted relevant tests and methods accordingly

* Removed support for sfreq=None from _freq_mask
-Introduced raise(ValueError) When sfreq=None
-Introduced tests for sfreq=None case

* Made _BaseTFR.crop omit mask if not defined.
- _time_mask or _freq_mask are only called, if they were defined in crop()
- _time_mask, _freq_mask were changed back to save time & mem

* corrected new merge conflicts once again

corrected merge conflicts with mne/utils/__init__.py

* corrected conditions in _BaseTFR.crop

corrected ```_time_mask``` and ```_freq_mask``` conditions in ```_BaseTFR.crop()```

* Make TFR raise value error for freqs <= 0

Make multitaper and morlet raise a value error if freqs include a frequency <= 0.

Signed-off-by: Dirk Gütlin <dirk.guetlin@stud.sbg.ac.at>

* convert freqs in morlet and _make_dpss to np.array

convert freqs in morlet and _make_dpss to np.array for faster computation

Signed-off-by: Dirk Gütlin <dirk.guetlin@stud.sbg.ac.at>

* changed error statements

changed error statements for invalid frequencies passed in mne/time_frequency/tfr.py ::morlet and ::_make_dpss

Signed-off-by: Dirk Gütlin <dirk.guetlin@stud.sbg.ac.at>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants