New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Support exporting mne objects to xarray DataArray objects #11464
base: main
Are you sure you want to change the base?
Conversation
Ok, so far so good, test for a to_xarray sketch work. I was thinking about channel picks and handling types:
|
I have no experience with xarray so no ideas here. Maybe @drammock or @hoechenberger ? |
mne/utils/xarray.py
Outdated
|
||
if isinstance(mne_inst, Epochs): | ||
data = mne_inst.get_data() | ||
dims = ('chan', 'trial', 'time') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we call the dimension "channel"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer shorter dimension names as you use them often during various operations, but I will change the name if this would be the common preference. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we're internally consistent on questions like this. E.g., in function names sometimes we use channel
and sometimes ch
. Also when exporting to data frames, the spectrum class makes a column freq
(not frequency
). So I'm not really sure what to do WRT "channel". However, I would say that trial
is not ideal, it should be epoch
(for e.g. resting state recordings cut into sequential chunks "trial" doesn't make sense)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, yes I will definitelly change trial
to epoch
, especially that you can have multiple epochs from the same trial (for example successively presented items to remember).
not necessary, but wouldn't it avoid an extra copy operation to have
I think yes, an additional coordinate that is "parallel to" or "overlaid on" the channels coord makes sense here (not sure exactly what the right terminology is, I don't use xarray very much) |
It could lead to less characters used, for sure: evoked.to_xarray(picks=picks) vs evoked.copy().pick(picks).to_xarray(copy=False) I am still not sure, however. For operations like |
it's a good point that |
FWIW internally |
That's why the example used |
So we might need to think/plan out more deeply how all the |
IIRC I think |
The docs for Evoked claim that |
@larsoner You are right. The docs say that the import numpy as np
import mne
info = mne.create_info(list('abcd'), sfreq=250)
data = np.random.rand(4, 350)
erp = mne.EvokedArray(data, info, tmin=-0.5)
data = erp.get_data()
data[0, 0] = 23.
print(data[0, 0])
print(erp.data[0, 0]) |
(I still remember about this PR and should have some time to finish it soon) |
Adresses #7793
Part 1 of N parts:
.to_xarray()
methods toEvoked
andEpochs
objectsother mne objects will be covered in future PRs (and also maybe exporting metadata to additional xarray coords).
TODO:
picks
.to_xarray()
forEvoked
.to_xarray()
forEpochs
.to_xarray()
? (or just add "bad" channel coordinate?)