{"action":"created","comment":{"url":"https://api.github.com/repos/mne-tools/mne-python/pulls/comments/34324488","id":34324488,"diff_hunk":"@@ -0,0 +1,507 @@\n+# Authors: Mark Wronkiewicz <wronk.mark@gmail.com>\n+#          Jussi Nurminen <jnu@iki.fi>\n+\n+# This code was adapted and relicensed (with BSD form) with permission from\n+# Jussi Nurminen\n+\n+# License: BSD (3-clause)\n+\n+# Equation numbers refer to Taulu and Kajola, 2005. 'Presentation of\n+# electromagnetic multichannel data: The signal space separation method,' which\n+# can be found for free online.\n+\n+# Note, there are an absurd number of different possible notations for\n+# spherical coordinates, which confounds the notation for spherical harmonics.\n+# Here, we purposefully stay away from shorthand notation in both and use\n+# explicit terms (like 'azimuth' and 'polar') to avoid confusion.\n+\n+\n+from __future__ import division\n+from os import path as op\n+import numpy as np\n+from scipy.special import lpmv\n+from scipy.linalg import pinv\n+from scipy.misc import factorial as fact\n+from ..utils import logger\n+from .. import pick_types, pick_info\n+from ..io.constants import FIFF\n+from ..forward._compute_forward import _concatenate_coils\n+from ..forward._make_forward import _read_coil_defs, _create_coils\n+\n+\n+def maxwell_filter(raw, origin=(0, 0, 40), int_order=8, ext_order=3):\n+    \"\"\"Apply Maxwell filter to data using spherical harmonics.\n+\n+    Parameters\n+    ----------\n+    raw : instance of mne.io.Raw\n+        Data to be filtered\n+    origin : array-like, shape (3,)\n+        Origin of internal and external multipolar moment space in head coords\n+        and in millimeters\n+    int_order : int\n+        Order of internal component of spherical expansion\n+    ext_order : int\n+        Order of external component of spherical expansion\n+\n+    Returns\n+    -------\n+    raw_sss : instance of mne.io.Raw\n+        The raw data with Maxwell filtering applied\n+    \"\"\"\n+\n+    # TODO: Exclude 'bads' in multipolar moment calc, add back during\n+    # reconstruction\n+    assert (raw.info['bads'] == [], 'Maxwell filter does not yet handle bad '\n+            'channels.')\n+\n+    # Read coil definitions from file\n+    coil_def_file = op.join(op.split(__file__)[0], '..', 'data',\n+                            'coil_def_Elekta.dat')\n+    all_coils, meg_info = _make_coils(raw.info, accurate=True,\n+                                      coil_def=coil_def_file)\n+\n+    # Create coil list and pick MEG channels\n+    picks = [raw.info['ch_names'].index(coil['chname'])\n+             for coil in all_coils]\n+    coils = [all_coils[ci] for ci in picks]\n+    raw.pick_channels(coil['chname'] for coil in coils)\n+\n+    data, times = raw[picks, :]\n+\n+    # Magnetometers (with coil_class == 1.0) must be scaled by 100 to improve\n+    # numerical stability as they have different scales than gradiometers\n+    coil_scale = np.ones(len(picks))\n+    coil_scale[np.array([coil['coil_class'] == 1.0 for coil in coils])] = 100.","path":"mne/preprocessing/maxwell.py","position":75,"original_position":75,"commit_id":"56200e8ca6a8cef886c2438b768b016659aad551","original_commit_id":"56200e8ca6a8cef886c2438b768b016659aad551","user":{"login":"Eric89GXL","id":2365790,"avatar_url":"https://avatars.githubusercontent.com/u/2365790?v=3","gravatar_id":"","url":"https://api.github.com/users/Eric89GXL","html_url":"https://github.com/Eric89GXL","followers_url":"https://api.github.com/users/Eric89GXL/followers","following_url":"https://api.github.com/users/Eric89GXL/following{/other_user}","gists_url":"https://api.github.com/users/Eric89GXL/gists{/gist_id}","starred_url":"https://api.github.com/users/Eric89GXL/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Eric89GXL/subscriptions","organizations_url":"https://api.github.com/users/Eric89GXL/orgs","repos_url":"https://api.github.com/users/Eric89GXL/repos","events_url":"https://api.github.com/users/Eric89GXL/events{/privacy}","received_events_url":"https://api.github.com/users/Eric89GXL/received_events","type":"User","site_admin":false},"body":"(i.e., to match what MaxFilter does to some extent)","created_at":"2015-07-10T02:50:16Z","updated_at":"2015-07-10T02:50:16Z","html_url":"https://github.com/mne-tools/mne-python/pull/2115#discussion_r34324488","pull_request_url":"https://api.github.com/repos/mne-tools/mne-python/pulls/2115","_links":{"self":{"href":"https://api.github.com/repos/mne-tools/mne-python/pulls/comments/34324488"},"html":{"href":"https://github.com/mne-tools/mne-python/pull/2115#discussion_r34324488"},"pull_request":{"href":"https://api.github.com/repos/mne-tools/mne-python/pulls/2115"}}},"pull_request":{"url":"https://api.github.com/repos/mne-tools/mne-python/pulls/2115","id":35686142,"html_url":"https://github.com/mne-tools/mne-python/pull/2115","diff_url":"https://github.com/mne-tools/mne-python/pull/2115.diff","patch_url":"https://github.com/mne-tools/mne-python/pull/2115.patch","issue_url":"https://api.github.com/repos/mne-tools/mne-python/issues/2115","number":2115,"state":"open","locked":false,"title":"WIP: SSS Maxwell (for GSoC)","user":{"login":"wronk","id":5296721,"avatar_url":"https://avatars.githubusercontent.com/u/5296721?v=3","gravatar_id":"","url":"https://api.github.com/users/wronk","html_url":"https://github.com/wronk","followers_url":"https://api.github.com/users/wronk/followers","following_url":"https://api.github.com/users/wronk/following{/other_user}","gists_url":"https://api.github.com/users/wronk/gists{/gist_id}","starred_url":"https://api.github.com/users/wronk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wronk/subscriptions","organizations_url":"https://api.github.com/users/wronk/orgs","repos_url":"https://api.github.com/users/wronk/repos","events_url":"https://api.github.com/users/wronk/events{/privacy}","received_events_url":"https://api.github.com/users/wronk/received_events","type":"User","site_admin":false},"body":"This PR is for my Google Summer of Code project to implement the open/published parts of SSS Maxwell filtering in MNE-Python.\r\n\r\n* [x] Add new coil definitions that match Elekta's\r\n* [ ] see why travis and appveyor are not happy\r\n* [ ] Create new Maxwell filtered dataset for tests\r\n* [ ] tell us how long it takes to run the tests\r\n* [ ] check test coverage with nosetests coverage plugin and tell us how good it is for the new code.\r\n* [ ] add information about filtering to `info` like MaxFilter does\r\n* [ ] change type to not be `maxshield` after filtering\r\n...","created_at":"2015-05-19T00:22:12Z","updated_at":"2015-07-10T02:50:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"54702458ee45e6ddd70c8b721a6485b7716efec0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mne-tools/mne-python/pulls/2115/commits","review_comments_url":"https://api.github.com/repos/mne-tools/mne-python/pulls/2115/comments","review_comment_url":"https://api.github.com/repos/mne-tools/mne-python/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mne-tools/mne-python/issues/2115/comments","statuses_url":"https://api.github.com/repos/mne-tools/mne-python/statuses/56200e8ca6a8cef886c2438b768b016659aad551","head":{"label":"wronk:sss_maxwell","ref":"sss_maxwell","sha":"56200e8ca6a8cef886c2438b768b016659aad551","user":{"login":"wronk","id":5296721,"avatar_url":"https://avatars.githubusercontent.com/u/5296721?v=3","gravatar_id":"","url":"https://api.github.com/users/wronk","html_url":"https://github.com/wronk","followers_url":"https://api.github.com/users/wronk/followers","following_url":"https://api.github.com/users/wronk/following{/other_user}","gists_url":"https://api.github.com/users/wronk/gists{/gist_id}","starred_url":"https://api.github.com/users/wronk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wronk/subscriptions","organizations_url":"https://api.github.com/users/wronk/orgs","repos_url":"https://api.github.com/users/wronk/repos","events_url":"https://api.github.com/users/wronk/events{/privacy}","received_events_url":"https://api.github.com/users/wronk/received_events","type":"User","site_admin":false},"repo":{"id":12385398,"name":"mne-python","full_name":"wronk/mne-python","owner":{"login":"wronk","id":5296721,"avatar_url":"https://avatars.githubusercontent.com/u/5296721?v=3","gravatar_id":"","url":"https://api.github.com/users/wronk","html_url":"https://github.com/wronk","followers_url":"https://api.github.com/users/wronk/followers","following_url":"https://api.github.com/users/wronk/following{/other_user}","gists_url":"https://api.github.com/users/wronk/gists{/gist_id}","starred_url":"https://api.github.com/users/wronk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wronk/subscriptions","organizations_url":"https://api.github.com/users/wronk/orgs","repos_url":"https://api.github.com/users/wronk/repos","events_url":"https://api.github.com/users/wronk/events{/privacy}","received_events_url":"https://api.github.com/users/wronk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/wronk/mne-python","description":"MNE : Magnetoencephalography (MEG) and Electroencephalography (EEG) in Python","fork":true,"url":"https://api.github.com/repos/wronk/mne-python","forks_url":"https://api.github.com/repos/wronk/mne-python/forks","keys_url":"https://api.github.com/repos/wronk/mne-python/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wronk/mne-python/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wronk/mne-python/teams","hooks_url":"https://api.github.com/repos/wronk/mne-python/hooks","issue_events_url":"https://api.github.com/repos/wronk/mne-python/issues/events{/number}","events_url":"https://api.github.com/repos/wronk/mne-python/events","assignees_url":"https://api.github.com/repos/wronk/mne-python/assignees{/user}","branches_url":"https://api.github.com/repos/wronk/mne-python/branches{/branch}","tags_url":"https://api.github.com/repos/wronk/mne-python/tags","blobs_url":"https://api.github.com/repos/wronk/mne-python/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wronk/mne-python/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wronk/mne-python/git/refs{/sha}","trees_url":"https://api.github.com/repos/wronk/mne-python/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wronk/mne-python/statuses/{sha}","languages_url":"https://api.github.com/repos/wronk/mne-python/languages","stargazers_url":"https://api.github.com/repos/wronk/mne-python/stargazers","contributors_url":"https://api.github.com/repos/wronk/mne-python/contributors","subscribers_url":"https://api.github.com/repos/wronk/mne-python/subscribers","subscription_url":"https://api.github.com/repos/wronk/mne-python/subscription","commits_url":"https://api.github.com/repos/wronk/mne-python/commits{/sha}","git_commits_url":"https://api.github.com/repos/wronk/mne-python/git/commits{/sha}","comments_url":"https://api.github.com/repos/wronk/mne-python/comments{/number}","issue_comment_url":"https://api.github.com/repos/wronk/mne-python/issues/comments{/number}","contents_url":"https://api.github.com/repos/wronk/mne-python/contents/{+path}","compare_url":"https://api.github.com/repos/wronk/mne-python/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wronk/mne-python/merges","archive_url":"https://api.github.com/repos/wronk/mne-python/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wronk/mne-python/downloads","issues_url":"https://api.github.com/repos/wronk/mne-python/issues{/number}","pulls_url":"https://api.github.com/repos/wronk/mne-python/pulls{/number}","milestones_url":"https://api.github.com/repos/wronk/mne-python/milestones{/number}","notifications_url":"https://api.github.com/repos/wronk/mne-python/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wronk/mne-python/labels{/name}","releases_url":"https://api.github.com/repos/wronk/mne-python/releases{/id}","created_at":"2013-08-26T17:36:28Z","updated_at":"2015-05-07T21:22:18Z","pushed_at":"2015-07-09T22:23:55Z","git_url":"git://github.com/wronk/mne-python.git","ssh_url":"git@github.com:wronk/mne-python.git","clone_url":"https://github.com/wronk/mne-python.git","svn_url":"https://github.com/wronk/mne-python","homepage":"http://martinos.org/mne/","size":77332,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mne-tools:master","ref":"master","sha":"e2498e1d01ac4a31430ba74102cce5e085901519","user":{"login":"mne-tools","id":583875,"avatar_url":"https://avatars.githubusercontent.com/u/583875?v=3","gravatar_id":"","url":"https://api.github.com/users/mne-tools","html_url":"https://github.com/mne-tools","followers_url":"https://api.github.com/users/mne-tools/followers","following_url":"https://api.github.com/users/mne-tools/following{/other_user}","gists_url":"https://api.github.com/users/mne-tools/gists{/gist_id}","starred_url":"https://api.github.com/users/mne-tools/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mne-tools/subscriptions","organizations_url":"https://api.github.com/users/mne-tools/orgs","repos_url":"https://api.github.com/users/mne-tools/repos","events_url":"https://api.github.com/users/mne-tools/events{/privacy}","received_events_url":"https://api.github.com/users/mne-tools/received_events","type":"Organization","site_admin":false},"repo":{"id":1301584,"name":"mne-python","full_name":"mne-tools/mne-python","owner":{"login":"mne-tools","id":583875,"avatar_url":"https://avatars.githubusercontent.com/u/583875?v=3","gravatar_id":"","url":"https://api.github.com/users/mne-tools","html_url":"https://github.com/mne-tools","followers_url":"https://api.github.com/users/mne-tools/followers","following_url":"https://api.github.com/users/mne-tools/following{/other_user}","gists_url":"https://api.github.com/users/mne-tools/gists{/gist_id}","starred_url":"https://api.github.com/users/mne-tools/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mne-tools/subscriptions","organizations_url":"https://api.github.com/users/mne-tools/orgs","repos_url":"https://api.github.com/users/mne-tools/repos","events_url":"https://api.github.com/users/mne-tools/events{/privacy}","received_events_url":"https://api.github.com/users/mne-tools/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mne-tools/mne-python","description":"MNE : Magnetoencephalography (MEG) and Electroencephalography (EEG) in Python","fork":false,"url":"https://api.github.com/repos/mne-tools/mne-python","forks_url":"https://api.github.com/repos/mne-tools/mne-python/forks","keys_url":"https://api.github.com/repos/mne-tools/mne-python/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mne-tools/mne-python/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mne-tools/mne-python/teams","hooks_url":"https://api.github.com/repos/mne-tools/mne-python/hooks","issue_events_url":"https://api.github.com/repos/mne-tools/mne-python/issues/events{/number}","events_url":"https://api.github.com/repos/mne-tools/mne-python/events","assignees_url":"https://api.github.com/repos/mne-tools/mne-python/assignees{/user}","branches_url":"https://api.github.com/repos/mne-tools/mne-python/branches{/branch}","tags_url":"https://api.github.com/repos/mne-tools/mne-python/tags","blobs_url":"https://api.github.com/repos/mne-tools/mne-python/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mne-tools/mne-python/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mne-tools/mne-python/git/refs{/sha}","trees_url":"https://api.github.com/repos/mne-tools/mne-python/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mne-tools/mne-python/statuses/{sha}","languages_url":"https://api.github.com/repos/mne-tools/mne-python/languages","stargazers_url":"https://api.github.com/repos/mne-tools/mne-python/stargazers","contributors_url":"https://api.github.com/repos/mne-tools/mne-python/contributors","subscribers_url":"https://api.github.com/repos/mne-tools/mne-python/subscribers","subscription_url":"https://api.github.com/repos/mne-tools/mne-python/subscription","commits_url":"https://api.github.com/repos/mne-tools/mne-python/commits{/sha}","git_commits_url":"https://api.github.com/repos/mne-tools/mne-python/git/commits{/sha}","comments_url":"https://api.github.com/repos/mne-tools/mne-python/comments{/number}","issue_comment_url":"https://api.github.com/repos/mne-tools/mne-python/issues/comments{/number}","contents_url":"https://api.github.com/repos/mne-tools/mne-python/contents/{+path}","compare_url":"https://api.github.com/repos/mne-tools/mne-python/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mne-tools/mne-python/merges","archive_url":"https://api.github.com/repos/mne-tools/mne-python/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mne-tools/mne-python/downloads","issues_url":"https://api.github.com/repos/mne-tools/mne-python/issues{/number}","pulls_url":"https://api.github.com/repos/mne-tools/mne-python/pulls{/number}","milestones_url":"https://api.github.com/repos/mne-tools/mne-python/milestones{/number}","notifications_url":"https://api.github.com/repos/mne-tools/mne-python/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mne-tools/mne-python/labels{/name}","releases_url":"https://api.github.com/repos/mne-tools/mne-python/releases{/id}","created_at":"2011-01-28T03:31:13Z","updated_at":"2015-07-08T04:33:01Z","pushed_at":"2015-07-09T22:33:51Z","git_url":"git://github.com/mne-tools/mne-python.git","ssh_url":"git@github.com:mne-tools/mne-python.git","clone_url":"https://github.com/mne-tools/mne-python.git","svn_url":"https://github.com/mne-tools/mne-python","homepage":"http://martinos.org/mne/","size":179021,"stargazers_count":137,"watchers_count":137,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":128,"mirror_url":null,"open_issues_count":175,"forks":128,"open_issues":175,"watchers":137,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mne-tools/mne-python/pulls/2115"},"html":{"href":"https://github.com/mne-tools/mne-python/pull/2115"},"issue":{"href":"https://api.github.com/repos/mne-tools/mne-python/issues/2115"},"comments":{"href":"https://api.github.com/repos/mne-tools/mne-python/issues/2115/comments"},"review_comments":{"href":"https://api.github.com/repos/mne-tools/mne-python/pulls/2115/comments"},"review_comment":{"href":"https://api.github.com/repos/mne-tools/mne-python/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mne-tools/mne-python/pulls/2115/commits"},"statuses":{"href":"https://api.github.com/repos/mne-tools/mne-python/statuses/56200e8ca6a8cef886c2438b768b016659aad551"}}}}