Skip to content

MRG ADD set_channels_type function RM parts from rename_channels - #1932

Merged
larsoner merged 18 commits into
mne-tools:masterfrom
teonbrooks:define_sensor
Apr 14, 2015
Merged

larsoner merged 18 commits into
mne-tools:masterfrom
teonbrooks:define_sensor

Conversation

@teonbrooks

Copy link
Copy Markdown
Member

Currently this removes the tuple ability to resign channel type from rename_channels.

This functionality has been moved to the define_sensors function.

addresses issue #1909

@teonbrooks
teonbrooks force-pushed the define_sensor branch 3 times, most recently from 1880943 to 4f64db5 Compare April 6, 2015 22:13
@agramfort

Copy link
Copy Markdown
Member

does this break any existing code?

@teonbrooks

Copy link
Copy Markdown
Member Author

partly. rename_channels is fine for the renaming, but I removed the tuple
support. Should we keep this and provide a depr warning to use
define_sensor function?

-teon

On Tue, Apr 7, 2015 at 12:45 AM, Alexandre Gramfort <
[email protected]> wrote:

does this break any existing code?

—
Reply to this email directly or view it on GitHub
#1932 (comment).

@agramfort

agramfort commented Apr 6, 2015 via email

Copy link
Copy Markdown
Member

@teonbrooks
teonbrooks force-pushed the define_sensor branch 7 times, most recently from 5d92381 to f9458e5 Compare April 7, 2015 12:39
@teonbrooks teonbrooks changed the title WIP ADD define_sensor function RM parts from rename MRG ADD define_sensor function RM parts from rename Apr 7, 2015
@teonbrooks

Copy link
Copy Markdown
Member Author

A proper deprecation warning is given and now it does not break any existing code.

Comment thread mne/channels/channels.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.

Is this all we need? What about the units field? My gut feeling tells me this is incomplete.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I can include it and any other fields. I just extracted the part of the
sensor type renaming that was part of the rename_channels. Can you think of
any other fields that might be useful to consider?

-teon

On Tue, Apr 7, 2015 at 2:55 PM, Denis A. Engemann [email protected]
wrote:

In mne/channels/channels.py
#1932 (comment):

  •              'syst': FIFF.FIFFV_SYST_CH}
    
  • ch_names = info['ch_names']
  • first check and assemble clean mappings of index and name

  • for ch_name, ch_type in mapping.items():
  •    if ch_name not in ch_names:
    
  •        raise ValueError("This channel name (%s) doesn't exist in info."
    
  •                         % ch_name)
    
  •    c_ind = ch_names.index(ch_name)
    
  •    if ch_type not in human2fiff:
    
  •        raise ValueError('This function cannot change to this '
    
  •                         'channel type: %s.' % ch_type)
    
  • Set sensor type

  •    info['chs'][c_ind]['kind'] = human2fiff[ch_type]
    

Is this all we need? What about the units field? My gut feeling tells me
this is incomplete.

—
Reply to this email directly or view it on GitHub
https://github.com/mne-tools/mne-python/pull/1932/files#r27874459.

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 think that's it. We have a different function for setting positions.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

also, I went through and listed all possible ch types. I didn't see a
reason to restrict which one could be used.

-teon

On Tue, Apr 7, 2015 at 3:05 PM, Denis A. Engemann [email protected]
wrote:

In mne/channels/channels.py
#1932 (comment):

  •              'syst': FIFF.FIFFV_SYST_CH}
    
  • ch_names = info['ch_names']
  • first check and assemble clean mappings of index and name

  • for ch_name, ch_type in mapping.items():
  •    if ch_name not in ch_names:
    
  •        raise ValueError("This channel name (%s) doesn't exist in info."
    
  •                         % ch_name)
    
  •    c_ind = ch_names.index(ch_name)
    
  •    if ch_type not in human2fiff:
    
  •        raise ValueError('This function cannot change to this '
    
  •                         'channel type: %s.' % ch_type)
    
  • Set sensor type

  •    info['chs'][c_ind]['kind'] = human2fiff[ch_type]
    

I think that's it. We have a different function for setting positions.

—
Reply to this email directly or view it on GitHub
https://github.com/mne-tools/mne-python/pull/1932/files#r27875156.

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'm not sure I can follow you. What do you mean?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

if you look at the human2fiff dict, I listed all the possible channel types. Before in the rename_channels, you weren't able to rename to EEG, now, you're able to change to any channel type.

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.

Ah ok yes! So we can also map those types to physical units. Then we're good I think.

@teonbrooks
teonbrooks force-pushed the define_sensor branch 2 times, most recently from 8eff861 to 8f800f6 Compare April 7, 2015 15:34
@dgwakeman

Copy link
Copy Markdown
Contributor

There will be a lot more to define as well. The coil geometry (plus how detailed it is: some coils have more precision to their geometry measurements, which MNE takes advantage of). It may be easier to break it into parts and add them one PR at a time.
One simple one that does mne.rename_channels, and has all the checks and warnings that the current mne.rename_channels has.
Then slowly adjust the warnings/checks with subsequent PRs.

Like next add the ability for EEG adding to dig
then magnetometers (adding geometry etc.)
then axial gradiometers
then planar gradiometers

@dengemann

Copy link
Copy Markdown
Member

The coil geometry (plus how detailed it is: some coils have more precision to their geometry measurements, which MNE takes advantage of).

But this is all stored in lookup files, if you point the constants to the right system type the MNE internals will take care of the detailed mapping. I don't see this function as a way to setup new coil types from scratch.

@dgwakeman

Copy link
Copy Markdown
Contributor

Why would you ever need to change the type of the sensors, it is in your file? Changing the type from a mag to a grad for example is crazy dangerous if you aren't going in and updating all those fields?

In that case it isn't defining a sensor at all (read the name is wrong).
In your example you should only read the lookup file and setup the info from there, then copy things in, but to just change the definition from MAG to GRAD (I can't understand how you could do that in any kind of lookup table). I am probably missing something, which is why this project sounded very complex to me.

@dengemann

Copy link
Copy Markdown
Member

I think the idea here is to have function for what we otherwise do manually in our source code, whenever we read in files from non Neuromag systems.

@dgwakeman

Copy link
Copy Markdown
Contributor

Right, but then it should be some sort of lookup function for those data types, with safety checks.
This unlocked ability to change a sensor type from one to another is really complicated and dangerous to have available by default. Maybe this is just Dan being annoying, feel free to tell me to shutup.

@dengemann

Copy link
Copy Markdown
Member

Maybe we should just keep this function private for now.

@teonbrooks

Copy link
Copy Markdown
Member Author

it's useful for non-meg sensors. when reading eeg, everything is assumed
eeg unless otherwise specified. it might be useful to mark some
post-reading to eog, or ecg, etc. this is where this is useful. we could
remove the functionality to meg b/c currently the respective readers mark
whether channels are mag or grad or ref_meg, etc.

-teon

On Tue, Apr 7, 2015 at 6:06 PM, Denis A. Engemann [email protected]
wrote:

Maybe we should just keep this function private for now.

—
Reply to this email directly or view it on GitHub
#1932 (comment).

@dengemann

Copy link
Copy Markdown
Member

@teonlamont then make a public restricted interface and a power ful private function that can replace and unify existing io conversion code.

@teonbrooks

Copy link
Copy Markdown
Member Author

+1

-teon

On Tue, Apr 7, 2015 at 6:16 PM, Denis A. Engemann [email protected]
wrote:

@teonlamont https://github.com/teonlamont then make a public restricted
interface and a power ful private function that can replace and unify
existing io conversion code.

—
Reply to this email directly or view it on GitHub
#1932 (comment).

@teonbrooks

Copy link
Copy Markdown
Member Author

@dengemann I will do the private interface in a separate pr.

@agramfort

agramfort commented Apr 7, 2015 via email

Copy link
Copy Markdown
Member

@teonbrooks

Copy link
Copy Markdown
Member Author

I think it's ready now

@larsoner

Copy link
Copy Markdown
Member

@teonlamont I actually have problems with pyface now, too. I wonder what we both updated that makes it so that we can't build docs.

@larsoner

Copy link
Copy Markdown
Member

FYI @teonlamont even with my pyface problems, make html_dev-noplot-nodiagram still works without error for me and allows me to check the docs.

@larsoner

Copy link
Copy Markdown
Member

I don't know if docs render properly, but they render okay. I'll open an issue.

larsoner added a commit that referenced this pull request Apr 14, 2015
MRG ADD set_channels_type function RM parts from rename_channels
@larsoner
larsoner merged commit 349c839 into mne-tools:master Apr 14, 2015
@larsoner

Copy link
Copy Markdown
Member

Thanks for your patience @teonlamont

@teonbrooks
teonbrooks deleted the define_sensor branch April 14, 2015 17:19
@teonbrooks

Copy link
Copy Markdown
Member Author

ah, I didn't realize you use the make command, I was using sphinx-build .... for me, even with the command you posted, I still get pyface problems :/

@larsoner

Copy link
Copy Markdown
Member

Weird, I don't know why pyface would even be imported. What is the trace? Who is importing it? I get an error nowadays whenever I try to use mayavi.

@teonbrooks

Copy link
Copy Markdown
Member Author

here's the traceback I get:

# Sphinx version: 1.3.1
# Python version: 2.7.9 (CPython)
# Docutils version: 0.12 release
# Jinja2 version: 2.7.3
# Last messages:
#   /Applications/packages/mne-python/doc/source/generated/mne.write_label.rst:: WARNING: document isn't included in any toctree
#   /Applications/packages/mne-python/doc/source/generated/mne.write_labels_to_annot.rst:: WARNING: document isn't included in any toctree
#   /Applications/packages/mne-python/doc/source/generated/mne.write_proj.rst:: WARNING: document isn't included in any toctree
#   /Applications/packages/mne-python/doc/source/generated/mne.write_source_spaces.rst:: WARNING: document isn't included in any toctree
#   /Applications/packages/mne-python/doc/source/generated/mne.write_surface.rst:: WARNING: document isn't included in any toctree
#   /Applications/packages/mne-python/doc/source/generated/mne.write_trans.rst:: WARNING: document isn't included in any toctree
#   done
#   preparing documents...
#   done
#   writing output... [  0%] advanced_setup
# Loaded extensions:
#   sphinx.ext.autodoc (1.3.1) from /Users/teon/anaconda/lib/python2.7/site-packages/sphinx/ext/autodoc.pyc
#   numpy_ext.numpydoc (unknown version) from /Applications/packages/mne-python/doc/sphinxext/numpy_ext/numpydoc.pyc
#   flow_diagram (unknown version) from /Applications/packages/mne-python/doc/sphinxext/flow_diagram.pyc
#   sphinx.ext.pngmath (1.3.1) from /Users/teon/anaconda/lib/python2.7/site-packages/sphinx/ext/pngmath.pyc
#   sphinx.ext.autosummary (1.3.1) from /Users/teon/anaconda/lib/python2.7/site-packages/sphinx/ext/autosummary/__init__.pyc
#   alabaster (0.7.3) from /Users/teon/anaconda/lib/python2.7/site-packages/alabaster/__init__.pyc
#   gen_rst (unknown version) from /Applications/packages/mne-python/doc/sphinxext/gen_rst.pyc
Traceback (most recent call last):
  File "/Users/teon/anaconda/lib/python2.7/site-packages/sphinx/cmdline.py", line 245, in main
    app.build(opts.force_all, filenames)
  File "/Users/teon/anaconda/lib/python2.7/site-packages/sphinx/application.py", line 264, in build
    self.builder.build_update()
  File "/Users/teon/anaconda/lib/python2.7/site-packages/sphinx/builders/__init__.py", line 245, in build_update
    'out of date' % len(to_build))
  File "/Users/teon/anaconda/lib/python2.7/site-packages/sphinx/builders/__init__.py", line 316, in build
    self.write(docnames, list(updated_docnames), method)
  File "/Users/teon/anaconda/lib/python2.7/site-packages/sphinx/builders/__init__.py", line 354, in write
    self._write_serial(sorted(docnames), warnings)
  File "/Users/teon/anaconda/lib/python2.7/site-packages/sphinx/builders/__init__.py", line 362, in _write_serial
    self.write_doc(docname, doctree)
  File "/Users/teon/anaconda/lib/python2.7/site-packages/sphinx/builders/html.py", line 439, in write_doc
    self.docwriter.write(doctree, destination)
  File "/Users/teon/anaconda/lib/python2.7/site-packages/docutils/writers/__init__.py", line 80, in write
    self.translate()
  File "/Users/teon/anaconda/lib/python2.7/site-packages/sphinx/writers/html.py", line 53, in translate
    self.document.walkabout(visitor)
  File "/Users/teon/anaconda/lib/python2.7/site-packages/docutils/nodes.py", line 174, in walkabout
    if child.walkabout(visitor):
  File "/Users/teon/anaconda/lib/python2.7/site-packages/docutils/nodes.py", line 174, in walkabout
    if child.walkabout(visitor):
  File "/Users/teon/anaconda/lib/python2.7/site-packages/docutils/nodes.py", line 174, in walkabout
    if child.walkabout(visitor):
  File "/Users/teon/anaconda/lib/python2.7/site-packages/docutils/nodes.py", line 174, in walkabout
    if child.walkabout(visitor):
  File "/Users/teon/anaconda/lib/python2.7/site-packages/docutils/nodes.py", line 166, in walkabout
    visitor.dispatch_visit(self)
  File "/Users/teon/anaconda/lib/python2.7/site-packages/docutils/nodes.py", line 1882, in dispatch_visit
    return method(node)
  File "/Users/teon/anaconda/lib/python2.7/site-packages/sphinx/writers/html.py", line 720, in visit_literal_block
    HTMLTranslator.visit_literal_block(self, node)
  File "/Users/teon/anaconda/lib/python2.7/site-packages/sphinx/writers/html.py", line 331, in visit_literal_block
    **highlight_args)
  File "/Users/teon/anaconda/lib/python2.7/site-packages/sphinx/highlighting.py", line 185, in highlight_block
    hlsource = highlight(source, lexer, formatter)
  File "/Users/teon/anaconda/lib/python2.7/site-packages/pygments/__init__.py", line 87, in highlight
    return format(lex(code, lexer), formatter, outfile)
  File "/Users/teon/anaconda/lib/python2.7/site-packages/pygments/__init__.py", line 66, in format
    formatter.format(tokens, realoutfile)
  File "/Users/teon/anaconda/lib/python2.7/site-packages/pygments/formatter.py", line 95, in format
    return self.format_unencoded(tokensource, outfile)
  File "/Users/teon/anaconda/lib/python2.7/site-packages/pygments/formatters/html.py", line 838, in format_unencoded
    for t, piece in source:
  File "/Users/teon/anaconda/lib/python2.7/site-packages/pygments/formatters/html.py", line 684, in _wrap_div
    for tup in inner:
  File "/Users/teon/anaconda/lib/python2.7/site-packages/pygments/formatters/html.py", line 697, in _wrap_pre
    for tup in inner:
  File "/Users/teon/anaconda/lib/python2.7/site-packages/pygments/formatters/html.py", line 716, in _format_lines
    for ttype, value in tokensource:
  File "/Users/teon/anaconda/lib/python2.7/site-packages/pygments/filter.py", line 20, in _apply
    for token in filter_.filter(lexer, stream):
  File "/Users/teon/anaconda/lib/python2.7/site-packages/pygments/filters/__init__.py", line 194, in filter
    for ttype, value in stream:
  File "/Users/teon/anaconda/lib/python2.7/site-packages/pygments/lexer.py", line 192, in streamer
    for i, t, v in self.get_tokens_unprocessed(text):
  File "/Users/teon/anaconda/lib/python2.7/site-packages/pygments/lexers/python.py", line 386, in get_tokens_unprocessed
    pylexer.get_tokens_unprocessed(curcode)):
  File "/Users/teon/anaconda/lib/python2.7/site-packages/pygments/lexer.py", line 785, in do_insertions
    for i, t, v in tokens:
  File "/Users/teon/anaconda/lib/python2.7/site-packages/pyface/ui/qt4/code_editor/pygments_highlighter.py", line 39, in get_tokens_unprocessed
    for item in action(self, m):
TypeError: 'NoneType' object is not callable

@larsoner

Copy link
Copy Markdown
Member

Ahh, so you get it from sphinx->pygments->pyface, I get it from Mayavi somehow. Bummer.

@mainakjas

Copy link
Copy Markdown
Contributor

I think I have the same error. If @teonlamont or @Eric89GXL figure out how to solve this, do let me know.

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.

7 participants