File: mne_substitutions.py

package info (click to toggle)
python-mne 1.3.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 100,172 kB
  • sloc: python: 166,349; pascal: 3,602; javascript: 1,472; sh: 334; makefile: 236
file content (48 lines) | stat: -rw-r--r-- 1,804 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from docutils import nodes
from docutils.parsers.rst import Directive
from docutils.statemachine import StringList

from mne.defaults import DEFAULTS
from mne.io.pick import (_PICK_TYPES_DATA_DICT, _DATA_CH_TYPES_SPLIT,
                         _DATA_CH_TYPES_ORDER_DEFAULT)


class MNESubstitution(Directive):  # noqa: D101

    has_content = False
    required_arguments = 1
    final_argument_whitespace = True

    def run(self, **kwargs):  # noqa: D102
        env = self.state.document.settings.env
        if self.arguments[0] == 'data channels list':
            keys = list()
            for key in _DATA_CH_TYPES_ORDER_DEFAULT:
                if key in _DATA_CH_TYPES_SPLIT:
                    keys.append(key)
                elif key not in ('meg', 'fnirs') and \
                        _PICK_TYPES_DATA_DICT.get(key, False):
                    keys.append(key)
            rst = '- ' + '\n- '.join(
                '``%r``: **%s** (scaled by %g to plot in *%s*)'
                % (key, DEFAULTS['titles'][key], DEFAULTS['scalings'][key],
                   DEFAULTS['units'][key])
                for key in keys)
        else:
            raise self.error(
                'MNE directive unknown in %s: %r'
                % (env.doc2path(env.docname, base=None),
                   self.arguments[0],))
        node = nodes.compound(rst)  # General(Body), Element
        content = StringList(
            rst.split('\n'), parent=self.content.parent,
            parent_offset=self.content.parent_offset)
        self.state.nested_parse(content, self.content_offset, node)
        return [node]


def setup(app):  # noqa: D103
    app.add_directive('mne', MNESubstitution)
    return {'version': '0.1',
            'parallel_read_safe': True,
            'parallel_write_safe': True}