Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[MRG][FIX] Fixes to examples #2990

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

Merged
merged 15 commits into from
Mar 16, 2016
Merged

[MRG][FIX] Fixes to examples #2990

merged 15 commits into from
Mar 16, 2016

Conversation

jaeilepp
Copy link
Contributor

@jaeilepp jaeilepp commented Mar 7, 2016

Noticed that with the new SPM datasets the examples are not working. See plot_spm_faces_datasets for example.
figure_1-6
figure_1-7
figure_1-8
figure_1-9
figure_1-10

@agramfort
Copy link
Member

hum... what's wrong?

@jaeilepp
Copy link
Contributor Author

jaeilepp commented Mar 7, 2016

Yeah. I can also look deeper later, but I was asking if anyone (@Eric89GXL ) has an idea...

@agramfort
Copy link
Member

agramfort commented Mar 7, 2016 via email

@larsoner
Copy link
Member

larsoner commented Mar 7, 2016

I'm not sure what the difference would be. You could try converting the files using the C tools and swap in the .fif files for the CTF ones and see if you get the same or different results.

@jaeilepp
Copy link
Contributor Author

jaeilepp commented Mar 9, 2016

Seems like with our python reader the data has some weird stuff at the start causing the events to be out of sync. This mess is not appearing with the converted fif file:
screenshot_2016-03-09_15-04-27

@larsoner
Copy link
Member

larsoner commented Mar 9, 2016

That looks like a bug. I wonder why it's not caught by the tests. Can you see if the verbose output is similar to what the C code says? CTF data has some skips, and they might not match properly. I probably won't have time to check for a while.

@jaeilepp
Copy link
Contributor Author

jaeilepp commented Mar 9, 2016

Seems that the mess at the beginning is data from the end of the recording. I see similar patterns when comparing to the end of the c converted file. You can also see the reference signal on the first channel:
screenshot_2016-03-09_15-34-28

@@ -149,13 +150,13 @@ def _read_segment_file(self, data, idx, fi, start, stop, cals, mult):
with open(self._filenames[fi], 'rb') as fid:
for bi in range(len(r_lims)):
samp_offset = (bi + trial_start_idx) * si['res4_nsamp']
n_read = min(si['n_samp'] - samp_offset, si['block_size'])
n_read = min(si['n_samp_tot'] - samp_offset, si['block_size'])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was the bug. It wasn't caught by the tests because on our testing data n_samp and n_samp_tot are equal.

Copy link
Member

Choose a reason for hiding this comment

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

no need to update a test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I said, our testing data has equal values for these. We should probably add dataset with different values. I wonder if @dengemann or someone else has nice small files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And I'm not entirely sure this is the correct solution to fix the bug. It almost looks like our python version tries to leave out some samples from the end (see https://github.com/mne-tools/mne-python/blob/master/mne/io/ctf/ctf.py#L214), but at least with our spm_faces dataset this wasn't behaving well. Maybe someone with deeper understanding of CTF format can help.

Copy link
Member

Choose a reason for hiding this comment

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

Both the Python and C versions can omit samples from the end. We do it differently from the C tools to handle a user's use case, see:

#2712

I suspect this fix will break that use case, but I'm not sure. We really do need to add some test files to figure it out.

@jaeilepp
Copy link
Contributor Author

If we are content with the ctf fix, this is ready for review/merge. It can be fixed in another PR if needed.

@jaeilepp jaeilepp changed the title [WIP][FIX] Fixes to examples [MRG][FIX] Fixes to examples Mar 10, 2016
@agramfort
Copy link
Member

I would check against brainstorm reader to make sure we read the correct number of samples and proper values of everything...

@larsoner
Copy link
Member

You'll need a rebase since I decreased mem usage in the SPM example

@jaeilepp
Copy link
Contributor Author

Come to think of it, we should probably make it throw an error if baseline is not None and mode is None to avoid people thinking they're baseline correcting when they're not. And those checks should be done in rescale.

Now this happens. It might break someone's code, but that means they've been doing it wrong all along.

To me it looks like the ctf bug fix here is the right one. Calling with system_clock='ignore' on master makes the artefacts in the beginning disappear, but it also added samples to the end, which doesn't happen with c version. With this fix, 'ignore' adds those samples too, but the artefacts aren't there either way. So judging by the behavior, the fix works.

@larsoner
Copy link
Member

larsoner commented Mar 11, 2016 via email

@jaeilepp
Copy link
Contributor Author

Okay test added. Now it just checks that samples are omitted. For data comparison, the data should be added to the dataset. I believe this is sufficient for now.
I also removed special characters from maxwell.py. They were causing failures with sphinx-gallery.
Ready for review from my end.

@larsoner
Copy link
Member

larsoner commented Mar 11, 2016 via email


# We've already clicked and exported
layout_path = op.join(op.dirname(mne.__file__), 'data', 'image')
layout_path = op.join(op.dirname(__file__), '..', '..', 'mne', 'data', 'image')
Copy link
Member

Choose a reason for hiding this comment

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

you cannot assume the example file is at a fixed place on disk. The previous option is more robust.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It fails on circle. That's why I changed it.

Copy link
Member

Choose a reason for hiding this comment

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

What's the failure? Is there some way to use the location of mne instead of the location of the example file? It really should be more robust to use the repo-location to find data files from the repo than use the example-location -- people could reasonably just download the example to their Desktop and expect it to work. Maybe we need to add mne.data_path within the repo that just points to op.join(os.abspath(__file__), 'data') or so in __init__.py.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I suspect that the gif file is not properly installed via our setup.py .... it's a bug. The example should not be changed due to this.

Copy link
Member

Choose a reason for hiding this comment

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

@agramfort
Copy link
Member

I agree with @Eric89GXL.

the bug should be fixed in sphinx-gallery.

Please open an issue there and cc me.

thx

@jaeilepp
Copy link
Contributor Author

To me allowing special characters sounds like asking for trouble. The doc builds are way too fragile to some specific versions as it is.

@agramfort
Copy link
Member

agramfort commented Mar 11, 2016 via email

@larsoner
Copy link
Member

larsoner commented Mar 11, 2016 via email

@@ -55,15 +59,12 @@ def rescale(data, times, baseline, mode='mean', copy=True, verbose=None):
data_scaled: array
Array of same shape as data after rescaling.
"""
_log_rescale(baseline, mode)
if baseline is None:
return data
Copy link
Member

Choose a reason for hiding this comment

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

This changes the previous reasonable behavior of the function -- before if copy is True then it would always return a copy, now it does in some cases and doesn't in others.

@larsoner
Copy link
Member

larsoner commented Mar 12, 2016 via email

@agramfort
Copy link
Member

let me know if we're good here.

@larsoner
Copy link
Member

This should fix sphinx-gallery:

sphinx-gallery/sphinx-gallery#106

@jaeilepp
Copy link
Contributor Author

Ready for review.


raw = io.Raw(raw_fname % 1) # Take first run
raw = io.read_raw_ctf(raw_fname % 1, preload=True) # Take first run
Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't need preload=True, if you do, we have a bug

Copy link
Member

Choose a reason for hiding this comment

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

(this will increase memory usage substantially)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops. I don't know how that got there. But in any case there is a load_data on the line below so this seems redundant.

Copy link
Member

Choose a reason for hiding this comment

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

More importantly, the load_data happens after the crop statement, which leads to memory savings

@agramfort
Copy link
Member

besides LGTM

don't forget to update what's new BUG section

@jaeilepp
Copy link
Contributor Author

I thought I had found a setting that would work with mayavi figures, but apparently I was wrong. I'll try it on another PR then.
Ready for review.

@agramfort
Copy link
Member

Great

Merge when Travis is happy

jaeilepp added a commit that referenced this pull request Mar 16, 2016
@jaeilepp jaeilepp merged commit 3e79f10 into mne-tools:master Mar 16, 2016
@jaeilepp jaeilepp deleted the fix-examples branch March 16, 2016 09:39
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