Skip to content

Conversation

@jaeilepp
Copy link
Contributor

@jaeilepp jaeilepp commented May 31, 2016

Closes #3107
closes #3281
For most parts I had no idea what I was doing, but it seems to give similar results.

mne/bem.py Outdated
trans[3][3] = 1.
trans = Transform(FIFF.FIFFV_COORD_UNKNOWN, FIFF.FIFFV_COORD_MRI, trans)
surf_out = transform_surface_to(surf_in, FIFF.FIFFV_COORD_MRI, trans)
write_surface(fname_out, surf_out['rr'], surf_out['tris'])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here I saved 'tris', but there is also 'use_tris'. What's the difference?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can you base the changes on the C code?

This is basically a copy paste of the c-code apart from the calls to the existing python functions. I suppose they do the same thing.

Copy link
Member

Choose a reason for hiding this comment

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

Okay cool, that should work (especially if you unit-test against files processed by both Python and C)

Copy link
Member

Choose a reason for hiding this comment

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

Now that I look again, I don't think this file should actually write out the result, just return it. Better separation of functionality to have the write_surface called afterward.

@codecov-io
Copy link

codecov-io commented May 31, 2016

Current coverage is 77.80%

Merging #3273 into master will decrease coverage by 8.66%

@@             master      #3273   diff @@
==========================================
  Files           335        335           
  Lines         57322      57440    +118   
  Methods           0          0           
  Messages          0          0           
  Branches       8715       8733     +18   
==========================================
- Hits          49567      44692   -4875   
- Misses         5132      10634   +5502   
+ Partials       2623       2114    -509   

Sunburst

Powered by Codecov. Last updated by ea83b84...0196b28

mne/bem.py Outdated
from .surface import _read_surface_geom, write_surface
header = _get_mgz_header(T1_mgz)
surf_in = _read_surface_geom(fname_in)
surf_in['coord_frame'] = FIFF.FIFFV_COORD_MRI
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 this is FIFFV_COORD_UNKNOWN in the c-code, but it throws an error in python.

Copy link
Member

Choose a reason for hiding this comment

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

I think this is actually more correct as it is in MRI coords anyway (right?)

Copy link
Member

Choose a reason for hiding this comment

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

actually looking below I think it isn't MRI coords...

Copy link
Member

Choose a reason for hiding this comment

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

i.e. it shuold be FIFFV_COORD_UNKNOWN and there must be some bug below

@agramfort
Copy link
Member

how does the output compare with the output of the C code?

@jaeilepp
Copy link
Contributor Author

jaeilepp commented Jun 1, 2016

The results look similar, but I'm not sure if it's even transforming anything for the data I have. Trying to set up a proper c-environment now so I can isolate stuff better.

@jaeilepp
Copy link
Contributor Author

jaeilepp commented Jun 2, 2016

Okay, Now that I've actually been able to debug the c-code, I realize that most of this is unnecessary. What confuses me now is the --replacegeom parameter that is fed to the c-function. AFAIK, it only updates the tags from the T1.mgz. There isn't really much documentation on the tags (see https://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/MghFormat) and our sample data doesn't seem to have any significant information available. Do you think it would be okay to leave out the tag updating and just do the same as leaving out the --mghmri and --replacegeom params? AFAIK the tag information isn't even used in python code elsewhere.

@agramfort
Copy link
Member

agramfort commented Jun 2, 2016 via email

@larsoner
Copy link
Member

larsoner commented Jun 2, 2016 via email

@jaeilepp
Copy link
Contributor Author

jaeilepp commented Jun 7, 2016

So what do we want to do with metadata in nipy/nibabel#456? Maybe just add a read_metadata option to read_surface and metadata option to write_surface.

@agramfort
Copy link
Member

agramfort commented Jun 7, 2016 via email

@jaeilepp
Copy link
Contributor Author

jaeilepp commented Jun 7, 2016

Why is mne-python not using nibabel for reading the surfaces? I see the only difference is basically NEW_QUAD_MAGIC. Couldn't that be added to nibabel?

@larsoner
Copy link
Member

larsoner commented Jun 7, 2016

Avoiding a dependency IIRC

@agramfort
Copy link
Member

agramfort commented Jun 7, 2016 via email

mne/surface.py Outdated

import numpy as np
from scipy.sparse import coo_matrix, csr_matrix, eye as speye
import nibabel as nib
Copy link
Member

Choose a reason for hiding this comment

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

nest this import we don't want a new hard dependency

@jaeilepp
Copy link
Contributor Author

I noticed that make_flash_bem isn't tested on travis since it is classified as ultra_slow. Maybe it could be classified by as slow by not converting the images first.
So I was thinking of

  1. precomputing flash5.mgz and adding it to the testing data (running time on my computer ca. 2 mins) or
  2. precomputing flash5.mgz and flash5_reg.mgz and adding to them to testing data (running time some seconds, no slow tag).
    Wdyt?

mne/bem.py Outdated
Path to SUBJECTS_DIR if it is not set in the environment.
flash_path : str | None
Path to the flash images. If None (default), the current folder is
used.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ended up adding this to reduce the amount of magic with this function.

Copy link
Member

Choose a reason for hiding this comment

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

so not in mri/bem/flash anymore?

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 actually using the current folder before. Now we could default to the correct place, but is mri/bem/flash really the correct folder and not /mri/flash/parameter_maps? I can't find mri/bem/flash anywhere on my data.

Copy link
Member

Choose a reason for hiding this comment

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

@larsoner
Copy link
Member

Anything you can do to make a test not ultra_slow without compromising it too much is worthwhile. It would be nice to be able to do nosetests mne/tests/test_bem.py again without having it hang forever. So +1 for option (2) from me



@ultra_slow_test
@requires_mne
Copy link
Member

Choose a reason for hiding this comment

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

yeah :)

@agramfort
Copy link
Member

please set to MRG when comments are addressed. thx @jaeilepp was not that easy in the end ;)

mne/utils.py Outdated
'MNE_SKIP_TESTING_DATASET_TESTS',
'MNE_STIM_CHANNEL',
'MNE_USE_CUDA',
'MNE_TESTING',
Copy link
Member

Choose a reason for hiding this comment

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

We have others of the form MNE_SKIP_*, so maybe MNE_SKIP_FLASH_CALL or something would be better.

Although in this case, we want the default behavior when running nosetests mne/tests/test_bem.py to skip the FreeSurfer call, since it takes forever. Your current code will still make the call to FreeSurfer by default (although you have made AppVeyor and Travis skip it, developers will still be haunted by the slowness).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The calls to freesurfer here aren't actually that slow. It is the conversion of flash images that took a long time before. Now we have them precomputed.

@jaeilepp
Copy link
Contributor Author

This is also ready for review.

.travis.yml Outdated
python -c 'import mne; mne.datasets.testing.data_path(verbose=True)';
if [ "${DEPS}" == "full" ]; then
export FREESURFER_HOME=$(python -c 'import mne; print(mne.datasets.testing.data_path())');
export MNE_SKIP_FLASH_CALL=1;
Copy link
Member

Choose a reason for hiding this comment

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

Is this done for speed, or because Travis and AppVeyor don't have the right command-line utilities to do it?

Copy link
Member

Choose a reason for hiding this comment

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

Ahh, you replied below:

Yeah, this is to avoid the freesurfer calls.

Can you add a comment somewhere saying that it's done only to avoid a command that isn't available on CIs?

@agramfort agramfort merged commit 6be10db into mne-tools:master Jun 29, 2016
@agramfort
Copy link
Member

thanks @jaeilepp !

jona-sassenhagen added a commit to jona-sassenhagen/mne-python that referenced this pull request Jul 5, 2016
* 'master' of git://github.com/mne-tools/mne-python: (48 commits)
  FIX: Flake
  fix pep8
  [MRG] FIX Topographic plotting for KIT-UMD data (mne-tools#3349)
  QUICKFIX: logging test
  Error message for simulate evoked. (mne-tools#3372)
  Warnings for big bems. (mne-tools#3374)
  Add test for baseline correction.
  Use apply_baseline in read_evokeds.
  Makes (None, 0) the default value baseline in apply_baseline.
  [FIX] Adds apply_baseline to Evoked
  fix component inds in ica tutorial (mne-tools#3379)
  FIX: Xdawn with shuffled epochs (mne-tools#3373)
  FIX consistency:  Epochs.load_data() should always return self (mne-tools#3376)
  MRG: Build relevant examples (mne-tools#3365)
  [MRG] set vmin, vmax after smoothing in plot_epochs_image (mne-tools#3360)
  [FIX] Attempt to fix circle.
  fixing a bg plotting bug for topo plots
  Modified test and tutorial.
  [MRG] convert surface using python. (mne-tools#3273)
  [MRG] raw.plot_psd() with flat channel (mne-tools#3342)
  ...
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.

BUG: write_surface doesn't write in same reference frame as read_surface make_watershed_bem using c-tools

4 participants