Skip to content

Conversation

@drammock
Copy link
Member

@drammock drammock commented Oct 4, 2022

closes #11091

after reading through the TFR code, to me it seems that #10978 introduced a mistake. Specifically, the changed coef here:

if dB:
data = 20 * np.log10(data)

is only appropriate for complex data (which have been converted to real-valued amplitude a few lines above). Data that is already real-valued will be power, not amplitude, and so should have coef 10 not 20 in the dB conversion.

My only hesitation is the case of avg_power_itc where the data will be complex, but the complex part is ITC, so it seems like the test of if np.iscomplexobj is too coarse here:

if np.iscomplexobj(data):
data = np.sqrt((data * data.conj()).real)

...and data in the form avg_power_itc needs to be special-cased to simply discard the imaginary part and get treated like the (non-complex) power cases. @alexrockhill @agramfort @larsoner since you three authored/reviewed #10978 can you confirm that I'm interpreting the code correctly here and that what I've said makes sense?

@drammock
Copy link
Member Author

drammock commented Oct 5, 2022

data in the form avg_power_itc needs to be special-cased to simply discard the imaginary part and get treated like the (non-complex) power cases.

I was wrong about this. They're only combined as power + 1j * ITC internally and temporarily. By the time we're plotting, the real & imag parts have been split into separate (real-valued) TFR objects.

(so the np.iscomplexobj test is sufficient)

@drammock drammock marked this pull request as ready for review October 5, 2022 15:11
@larsoner
Copy link
Member

larsoner commented Oct 5, 2022

compat/old is unhappy:

_____________________________ test_dB_computation ______________________________
mne/time_frequency/tests/test_tfr.py:574: in test_dB_computation
    quadmesh1 = fig1.axes[0].collections[0]._mapped_colors
E   AttributeError: 'QuadMesh' object has no attribute '_mapped_colors'

maybe just wrap with if hasattr ?

@larsoner larsoner added this to the 1.2 milestone Oct 5, 2022
@larsoner larsoner enabled auto-merge (squash) October 5, 2022 18:13
@larsoner
Copy link
Member

larsoner commented Oct 5, 2022

Thanks in advance @drammock , marking for auto merge

@larsoner larsoner merged commit 4aed3f7 into mne-tools:main Oct 5, 2022
larsoner added a commit to larsoner/mne-python that referenced this pull request Oct 11, 2022
* upstream/main: (64 commits)
  MAINT: Better check (mne-tools#11229)
  MAINT: Fix link and update instantiation note (mne-tools#11228)
  BUG: Add estimated fiducials when missing / assumed head coords (mne-tools#11212)
  Fix tfr db (mne-tools#11223)
  MAINT: Update link (mne-tools#11222)
  add CPGRL doc section (mne-tools#11216)
  Don't insert superfluous newlines in subprocess log messages (mne-tools#11219)
  purge _get_args helper func (mne-tools#11215)
  Standardize topomap args (mne-tools#11123)
  MAINT: Ensure no datasets are downloaded in tests (mne-tools#11213)
  MAINT: Fix Cirrus caching (mne-tools#11211)
  Fix mesh display in tutorial (mne-tools#11200)
  MAINT: Add arm64 CI using CirrusCI (mne-tools#11209)
  Fix spatial colors (mne-tools#11201)
  MAINT: Fix CircleCI error (mne-tools#11205) [circle deploy]
  Add regression-based approach to removing EOG artifacts (mne-tools#11046)
  [DOC, MRG] Minor documentation improvements and remove glossary entry for array-like (mne-tools#11207)
  Fix `include_tmax` not considered in `mne.io.Raw.crop` to check `tmax` in bounds (mne-tools#11204)
  MAINT: Fix notebook backend (mne-tools#11206)
  MRG: Fix displayed Raw duration in Jupyter notebook (mne-tools#11203)
  ...
@drammock drammock deleted the fix-tfr-db branch March 21, 2023 13:38
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.

Wrong dB normalization for TFR plots

2 participants