Skip to content

Conversation

@eioe
Copy link
Contributor

@eioe eioe commented Mar 17, 2021

This is related to issue #7975

EpochsTFR and AverageTFR do not allow to extract data as a (pandas) data frame which in turn would be handy for export to (e.g.) R.

To build this functionality, I use the to_data_frame() method of the BaseEpochs class as template.
Major differences:

  1. TFR data is 4 dimensional.
  2. EpochsTFR did not yet have the selection attribute which should be used for the epoch index in the resulting data frame.
  3. The method in BaseEpochs gets scaled (according to the channel type) before it's written out. For TFR data this seems to be more complicated because it should also be taken into account whether any/which baselining procedure was applied to get meaningful units/scaling.

I implemented 1. and 2. EpochsTFR and AverageTFR now both inherit a to_data_framemethod from _BaseTFR which has similar way of functioning as the methods for Epochs and Evoked. Currently, I'm skipping the scaling for the TFR classes and leave it to the users to interpret/label the output as they should know best what state the data is in.

@agramfort
Copy link
Member

don't forget to add some tests

@eioe eioe marked this pull request as ready for review March 22, 2021 20:05
@eioe
Copy link
Contributor Author

eioe commented Mar 22, 2021

I updated the original post to better reflect what happened in the mean time.
Summary:

  • EpochsTFR now also has the attributes selection and drop_log (which by default it grabs from the Epochs instance that's used for the tf decomposition)
  • EpochsTFR and AvergaeTFR now have a to_data_frame_method
  • all new functionalities should be covered by tests

@eioe eioe changed the title WIP: add to_data_frame method to EpochsTFR ENH: add to_data_frame method to EpochsTFR Mar 22, 2021
@eioe eioe requested a review from britta-wstnr March 24, 2021 13:17
Copy link
Member

@drammock drammock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it took a while to get around to reviewing this. It looks good! I've made only minor tweaks/suggestions.

eioe and others added 4 commits April 6, 2021 18:58
Co-authored-by: Daniel McCloy <dan@mccloy.info>
Co-authored-by: Daniel McCloy <dan@mccloy.info>
Co-authored-by: Daniel McCloy <dan@mccloy.info>
Co-authored-by: Daniel McCloy <dan@mccloy.info>
Co-authored-by: eioe <klotzsche@cbs.mpg.de>
@drammock drammock merged commit 5ae29cd into mne-tools:main Apr 6, 2021
@drammock
Copy link
Member

drammock commented Apr 6, 2021

thanks @eioe!

vagechirkov pushed a commit to vagechirkov/mne-python that referenced this pull request Apr 6, 2021
* implement to_df method; missing selection attr

* add to_data_frame method

* Apply suggestions from code review

Co-authored-by: Britta Westner <britta.wstnr@gmail.com>

* cosmetics

* add test_to_data_frame

* fix tests _index and _time_format

* fix codespell

* fix codespell (I now learned to run flake locally)

* add selection, drop_log to EpochsTFR

* forward selection and drop_log to EpochsTFR

* assign selection and drop_log also in else case

* consistency checks

* add tests for selection, drop_log, rw epochstfr

* doc: add EpochsTFR to params of read_ write_tfrs

* add doc string for test_init_EpochsTFR

* fix doc str test

* move to_data_frame to _BaseTFR for inheritance

* extend tests

* simplify

Co-authored-by: Daniel McCloy <dan@mccloy.info>

* upgrade coding style

Co-authored-by: Daniel McCloy <dan@mccloy.info>

* shorten doc string

Co-authored-by: Daniel McCloy <dan@mccloy.info>

* shorten doc string

Co-authored-by: Daniel McCloy <dan@mccloy.info>

* Apply suggestions from code review

Co-authored-by: eioe <klotzsche@cbs.mpg.de>

Co-authored-by: Britta Westner <britta.wstnr@gmail.com>
Co-authored-by: Daniel McCloy <dan@mccloy.info>
@cbrnr
Copy link
Contributor

cbrnr commented Apr 16, 2021

Looks very nice, great job @eioe!

@eioe
Copy link
Contributor Author

eioe commented Apr 16, 2021

Thanks @cbrnr , I also open #9275 for review then.

@cbrnr
Copy link
Contributor

cbrnr commented Apr 16, 2021

Yes, still on my agenda!

larsoner added a commit that referenced this pull request Apr 26, 2021
* extend ERDS example with df method

* housekeeping for PR #9124

* rm space

* improve doc

Co-authored-by: Daniel McCloy <dan@mccloy.info>

* improve code stringency

Co-authored-by: Daniel McCloy <dan@mccloy.info>

* refactor plotting to use FacetGrid

* refactor using FacetGrid; rename file

* change filename

* test

* improve plotting

* move legend

* Update examples/time_frequency/time_frequency_erds.py

fix doc string layout

Co-authored-by: Clemens Brunner <clemens.brunner@gmail.com>

* rework text

Co-authored-by: Clemens Brunner <clemens.brunner@gmail.com>

* rework text

Co-authored-by: Clemens Brunner <clemens.brunner@gmail.com>

* fix spelling

Co-authored-by: Clemens Brunner <clemens.brunner@gmail.com>

* fix length block splitters

* add explanation for time_format=None

* change binning

* thinner violin outlines

* remove empty plots

* fix doc

Co-authored-by: Daniel McCloy <dan@mccloy.info>
Co-authored-by: Clemens Brunner <clemens.brunner@gmail.com>
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
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.

5 participants