Skip to content

ENH: apply_forward; compute sensor space data from source estimate - #21

Merged
agramfort merged 5 commits into
mne-tools:masterfrom
mluessi:apply_forward
Feb 8, 2012
Merged

agramfort merged 5 commits into
mne-tools:masterfrom
mluessi:apply_forward

Conversation

@mluessi

@mluessi mluessi commented Feb 2, 2012

Copy link
Copy Markdown
Contributor

This is useful, e.g., when evaluating methods or when working with surrogate data in source space.

Comment thread mne/tests/test_forward.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe you can use the tiny raw file in fiff/tests it will be faster

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread mne/forward.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what I don't really like about returning not an Evoked object is that there is no convenient way to work with such data, times, ch_names. You cannot really plot it and don't have access to measurement info to find channel type and so on. Why not passing an info parameter and eventually an evoked_template?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thats's true, the function doesn't return information such as channel types etc. My reason for having two functions (apply_forward and apply_forward_raw) was that the first doesn't require a template. So it is easier to use if one just wants to project source space data to the sensor space without wanting to store the result or visualize the channels.

How about adding a 3rd function apply_forward_evoked, which does the same thing as apply_forward_raw but for Evoked?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I had an idea during the night. Basically data, times, and ch_names are attributes of an Evoked object. The Evoked has just an extra info attribute for the measurement info. So one option is to have BaseEvoked object and an extra info param in apply_forward. If info is not None you return an Evoked and if info is None then you return a BaseEvoked object that is just a namedtuple with 3 attributes (data, times and ch_names). Makes sense?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this will make things confusing to the user. As BaseEvoked wouldn't have channel and measurement info, it wouldn't be possible to plot the sensor topography etc. Users are also likely to pass BaseEvoked to functions that expect Evoked and will be confused if it doesn't work.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ok however that would avoid having 2 different functions for simultating Evoked and plain data. What is not clear to me is what you can actually do from plain data. You would not even be able to apply an inverse operator.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

True, let's just have 2 functions, apply_forward_raw and apply_forward_evoked.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

True, let's just have 2 functions, apply_forward_raw and apply_forward_evoked.

maybe i am neat picking but if apply_inverse is not named
apply_inverse_evoked we should have apply_forward that works with an
Evoked instance… :)

@mluessi

mluessi commented Feb 6, 2012

Copy link
Copy Markdown
Contributor Author

Ok, now apply_forward returns Evoked, so it is consistent with apply_inverse.

@agramfort

Copy link
Copy Markdown
Member

one last thing before you want to kill me ... To me having a template and include, exclude parameters is a bit redundant. I would expect the output Evoked to have the same channels and the function to raise an error if a data channel in Evoked is not present in the forward. A typical use case would be to keep only the MEG channels and I don't feel it would be very convenient with include, exclude. I'd rather do first a pick_channels_evoked and then the apply_forward. I'm just trying to avoid having too many different ways to do the same thing. If you're fed up I can do it tomorrow if you want.

@mluessi

mluessi commented Feb 7, 2012

Copy link
Copy Markdown
Contributor Author

True, it is a bit redundant. At the moment, the returned Evoked/Raw object will have all the channels that are present in fwd, as the channel info is copied from there. The problem with using pick_channels_evoked is that the corresponding function doesn't exist for Raw (and it would be difficult to implement, as the data usually stays on disk).

How about we use pick_channels_forward and pick_types_forward (I can add this function)?

@agramfort

Copy link
Copy Markdown
Member

ok this makes things even simple. We had the pick forward functions
and it's the channels present in the forward that are included. So we
can get rid of include / exclude params and it works with both Evoked
and Raw. The info is used if present to complement based on channels
present in forward. If a channel is not in info we raise an exception.
ok?

@mluessi

mluessi commented Feb 7, 2012

Copy link
Copy Markdown
Contributor Author

Yes, it will be nice and clean :). Regarding raising an exception, isn't all the channel info included in fwd['chs']? At the moment I copy the channel information from there, so it should work even if a channel isn't present in the info of the template. Right?

@agramfort

Copy link
Copy Markdown
Member

Yes, it will be nice and clean :).

I like that !

Regarding raising an exception, isn't all the channel info included in fwd['chs']?

it should but you never know what users do :)

At the moment I copy the channel information from there, so it should work even if a channel isn't present in the info of the template. Right?

I think it shouldn't

@mluessi

mluessi commented Feb 7, 2012

Copy link
Copy Markdown
Contributor Author

Another attempt ;-)

@agramfort

Copy link
Copy Markdown
Member

maybe you can avoid the duplicated code in the tests and then press the green button ! thanks heaps !

agramfort added a commit that referenced this pull request Feb 8, 2012
ENH: apply_forward; compute sensor space data from source estimate
@agramfort
agramfort merged commit 57708a3 into mne-tools:master Feb 8, 2012
@agramfort

Copy link
Copy Markdown
Member

merged ! I'll polish the tests

@agramfort

Copy link
Copy Markdown
Member

done !

@mluessi

mluessi commented Feb 8, 2012

Copy link
Copy Markdown
Contributor Author

thanks

dengemann added a commit that referenced this pull request May 13, 2015
larsoner added a commit that referenced this pull request Sep 17, 2015
mikech76 pushed a commit to mikech76/mne-python that referenced this pull request Nov 30, 2026
Removing the fitted constant shifted each window by its mean (reported by
cbrnr for mnextend in mne-tools#21). Only the sinusoids are subtracted now.
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.

2 participants