{"action":"created","comment":{"url":"https://api.github.com/repos/mne-tools/mne-python/pulls/comments/33875164","id":33875164,"diff_hunk":"@@ -0,0 +1,463 @@\n+import numpy as np\n+from collections import defaultdict\n+from operator import add\n+from scipy.signal import welch, lfilter\n+from scipy.stats import kurtosis\n+from functools import reduce\n+from . import find_outliers\n+from ..utils import logger\n+from ..io.pick import pick_types, channel_type\n+\n+\n+def _by_ch_type(info, picks):\n+    \"\"\"Returns lists of channel indices, grouped by channel type.\"\"\"\n+    ch_types = defaultdict(list)\n+\n+    for ch in picks:\n+        ch_types[channel_type(info, ch)].append(ch)\n+\n+    return ch_types.items()\n+\n+\n+def _hurst(x):\n+    \"\"\"Estimate Hurst exponent on a timeseries.\n+\n+    The estimation is based on the second order discrete derivative.\n+\n+    Parameters\n+    ----------\n+    x : 1D numpy array\n+        The timeseries to estimate the Hurst exponent for.\n+\n+    Returns\n+    -------\n+    h : float\n+        The estimation of the Hurst exponent for the given timeseries.\n+    \"\"\"\n+    y = np.cumsum(np.diff(x, axis=1), axis=1)\n+\n+    b1 = [1, -2, 1]\n+    b2 = [1,  0, -2, 0, 1]\n+\n+    # second order derivative\n+    y1 = lfilter(b1, 1, y, axis=1)\n+    y1 = y1[:, len(b1) - 1:-1]  # first values contain filter artifacts\n+\n+    # wider second order derivative\n+    y2 = lfilter(b2, 1, y, axis=1)\n+    y2 = y2[:, len(b2) - 1:-1]  # first values contain filter artifacts\n+\n+    s1 = np.mean(y1 ** 2, axis=1)\n+    s2 = np.mean(y2 ** 2, axis=1)\n+\n+    return 0.5 * np.log2(s2 / s1)\n+\n+\n+def _efficient_welch(data, sfreq):\n+    \"\"\"Calls scipy.signal.welch with parameters optimized for greatest speed\n+    at the expense of precision. The window is set to ~10 seconds and windows\n+    are non-overlapping.\n+\n+    Parameters\n+    ----------\n+    data : N-D numpy array\n+        The timeseries to estimate signal power for. The last dimension\n+        is presumed to be time.\n+    sfreq : float\n+        The sample rate of the timeseries.\n+\n+    Returns\n+    -------\n+    fs : 1D numpy array\n+        The frequencies for which the power spectra was calculated.\n+    ps : ND numpy array","path":"mne/preprocessing/faster.py","position":73,"original_position":73,"commit_id":"d91cc67aeac912ed08297eb15f708baf3edf5cb8","original_commit_id":"d91cc67aeac912ed08297eb15f708baf3edf5cb8","user":{"login":"mainakjas","id":3817535,"avatar_url":"https://avatars.githubusercontent.com/u/3817535?v=3","gravatar_id":"","url":"https://api.github.com/users/mainakjas","html_url":"https://github.com/mainakjas","followers_url":"https://api.github.com/users/mainakjas/followers","following_url":"https://api.github.com/users/mainakjas/following{/other_user}","gists_url":"https://api.github.com/users/mainakjas/gists{/gist_id}","starred_url":"https://api.github.com/users/mainakjas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mainakjas/subscriptions","organizations_url":"https://api.github.com/users/mainakjas/orgs","repos_url":"https://api.github.com/users/mainakjas/repos","events_url":"https://api.github.com/users/mainakjas/events{/privacy}","received_events_url":"https://api.github.com/users/mainakjas/received_events","type":"User","site_admin":false},"body":"inconsistent documentation style","created_at":"2015-07-03T17:26:10Z","updated_at":"2015-07-03T17:26:10Z","html_url":"https://github.com/mne-tools/mne-python/pull/1777#discussion_r33875164","pull_request_url":"https://api.github.com/repos/mne-tools/mne-python/pulls/1777","_links":{"self":{"href":"https://api.github.com/repos/mne-tools/mne-python/pulls/comments/33875164"},"html":{"href":"https://github.com/mne-tools/mne-python/pull/1777#discussion_r33875164"},"pull_request":{"href":"https://api.github.com/repos/mne-tools/mne-python/pulls/1777"}}},"pull_request":{"url":"https://api.github.com/repos/mne-tools/mne-python/pulls/1777","id":28726334,"html_url":"https://github.com/mne-tools/mne-python/pull/1777","diff_url":"https://github.com/mne-tools/mne-python/pull/1777.diff","patch_url":"https://github.com/mne-tools/mne-python/pull/1777.patch","issue_url":"https://api.github.com/repos/mne-tools/mne-python/issues/1777","number":1777,"state":"open","locked":false,"title":"WIP: Automatic artifact detection with FASTER","user":{"login":"wmvanvliet","id":428273,"avatar_url":"https://avatars.githubusercontent.com/u/428273?v=3","gravatar_id":"","url":"https://api.github.com/users/wmvanvliet","html_url":"https://github.com/wmvanvliet","followers_url":"https://api.github.com/users/wmvanvliet/followers","following_url":"https://api.github.com/users/wmvanvliet/following{/other_user}","gists_url":"https://api.github.com/users/wmvanvliet/gists{/gist_id}","starred_url":"https://api.github.com/users/wmvanvliet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wmvanvliet/subscriptions","organizations_url":"https://api.github.com/users/wmvanvliet/orgs","repos_url":"https://api.github.com/users/wmvanvliet/repos","events_url":"https://api.github.com/users/wmvanvliet/events{/privacy}","received_events_url":"https://api.github.com/users/wmvanvliet/received_events","type":"User","site_admin":false},"body":"The FASTER method consists of a series of algorithms designed to automatically detect various artifacts through outlier detection [1]. This PR implements the first four steps of the series:\r\n\r\n1. Detect bad MEG/EEG channels\r\n2. Detect bad epochs\r\n3. Detect bad ICA components\r\n4. Detect for each epoch, channels that are locally bad\r\n\r\nAn example is provided that takes the user through all four steps and demonstrates how to deal with the detected artifacts (bad channels can be interpolated, bad epochs can be rejected, bad ICA components can be zeroed out, ...)\r\n\r\n[1] Nolan H., Whelan R. and Reilly RB. FASTER: fully automated statistical thresholding for EEG artifact rejection. Journal of Neuroscience Methods, vol. 192, issue 1, pp. 152-162, 2010. http://doi.org/10.1016/j.jneumeth.2010.07.015\r\n","created_at":"2015-02-05T14:01:40Z","updated_at":"2015-07-03T17:26:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"736cbd7c3a01198e9e0491f9e550429cfae32618","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mne-tools/mne-python/pulls/1777/commits","review_comments_url":"https://api.github.com/repos/mne-tools/mne-python/pulls/1777/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/1777/comments","statuses_url":"https://api.github.com/repos/mne-tools/mne-python/statuses/d91cc67aeac912ed08297eb15f708baf3edf5cb8","head":{"label":"wmvanvliet:faster","ref":"faster","sha":"d91cc67aeac912ed08297eb15f708baf3edf5cb8","user":{"login":"wmvanvliet","id":428273,"avatar_url":"https://avatars.githubusercontent.com/u/428273?v=3","gravatar_id":"","url":"https://api.github.com/users/wmvanvliet","html_url":"https://github.com/wmvanvliet","followers_url":"https://api.github.com/users/wmvanvliet/followers","following_url":"https://api.github.com/users/wmvanvliet/following{/other_user}","gists_url":"https://api.github.com/users/wmvanvliet/gists{/gist_id}","starred_url":"https://api.github.com/users/wmvanvliet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wmvanvliet/subscriptions","organizations_url":"https://api.github.com/users/wmvanvliet/orgs","repos_url":"https://api.github.com/users/wmvanvliet/repos","events_url":"https://api.github.com/users/wmvanvliet/events{/privacy}","received_events_url":"https://api.github.com/users/wmvanvliet/received_events","type":"User","site_admin":false},"repo":{"id":23457160,"name":"mne-python","full_name":"wmvanvliet/mne-python","owner":{"login":"wmvanvliet","id":428273,"avatar_url":"https://avatars.githubusercontent.com/u/428273?v=3","gravatar_id":"","url":"https://api.github.com/users/wmvanvliet","html_url":"https://github.com/wmvanvliet","followers_url":"https://api.github.com/users/wmvanvliet/followers","following_url":"https://api.github.com/users/wmvanvliet/following{/other_user}","gists_url":"https://api.github.com/users/wmvanvliet/gists{/gist_id}","starred_url":"https://api.github.com/users/wmvanvliet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wmvanvliet/subscriptions","organizations_url":"https://api.github.com/users/wmvanvliet/orgs","repos_url":"https://api.github.com/users/wmvanvliet/repos","events_url":"https://api.github.com/users/wmvanvliet/events{/privacy}","received_events_url":"https://api.github.com/users/wmvanvliet/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/wmvanvliet/mne-python","description":"MNE : Magnetoencephalography (MEG) and Electroencephalography (EEG) in Python","fork":true,"url":"https://api.github.com/repos/wmvanvliet/mne-python","forks_url":"https://api.github.com/repos/wmvanvliet/mne-python/forks","keys_url":"https://api.github.com/repos/wmvanvliet/mne-python/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wmvanvliet/mne-python/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wmvanvliet/mne-python/teams","hooks_url":"https://api.github.com/repos/wmvanvliet/mne-python/hooks","issue_events_url":"https://api.github.com/repos/wmvanvliet/mne-python/issues/events{/number}","events_url":"https://api.github.com/repos/wmvanvliet/mne-python/events","assignees_url":"https://api.github.com/repos/wmvanvliet/mne-python/assignees{/user}","branches_url":"https://api.github.com/repos/wmvanvliet/mne-python/branches{/branch}","tags_url":"https://api.github.com/repos/wmvanvliet/mne-python/tags","blobs_url":"https://api.github.com/repos/wmvanvliet/mne-python/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wmvanvliet/mne-python/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wmvanvliet/mne-python/git/refs{/sha}","trees_url":"https://api.github.com/repos/wmvanvliet/mne-python/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wmvanvliet/mne-python/statuses/{sha}","languages_url":"https://api.github.com/repos/wmvanvliet/mne-python/languages","stargazers_url":"https://api.github.com/repos/wmvanvliet/mne-python/stargazers","contributors_url":"https://api.github.com/repos/wmvanvliet/mne-python/contributors","subscribers_url":"https://api.github.com/repos/wmvanvliet/mne-python/subscribers","subscription_url":"https://api.github.com/repos/wmvanvliet/mne-python/subscription","commits_url":"https://api.github.com/repos/wmvanvliet/mne-python/commits{/sha}","git_commits_url":"https://api.github.com/repos/wmvanvliet/mne-python/git/commits{/sha}","comments_url":"https://api.github.com/repos/wmvanvliet/mne-python/comments{/number}","issue_comment_url":"https://api.github.com/repos/wmvanvliet/mne-python/issues/comments{/number}","contents_url":"https://api.github.com/repos/wmvanvliet/mne-python/contents/{+path}","compare_url":"https://api.github.com/repos/wmvanvliet/mne-python/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wmvanvliet/mne-python/merges","archive_url":"https://api.github.com/repos/wmvanvliet/mne-python/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wmvanvliet/mne-python/downloads","issues_url":"https://api.github.com/repos/wmvanvliet/mne-python/issues{/number}","pulls_url":"https://api.github.com/repos/wmvanvliet/mne-python/pulls{/number}","milestones_url":"https://api.github.com/repos/wmvanvliet/mne-python/milestones{/number}","notifications_url":"https://api.github.com/repos/wmvanvliet/mne-python/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wmvanvliet/mne-python/labels{/name}","releases_url":"https://api.github.com/repos/wmvanvliet/mne-python/releases{/id}","created_at":"2014-08-29T08:06:25Z","updated_at":"2015-05-08T07:28:50Z","pushed_at":"2015-06-08T20:22:52Z","git_url":"git://github.com/wmvanvliet/mne-python.git","ssh_url":"git@github.com:wmvanvliet/mne-python.git","clone_url":"https://github.com/wmvanvliet/mne-python.git","svn_url":"https://github.com/wmvanvliet/mne-python","homepage":"http://martinos.org/mne/","size":78825,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"mne-tools:master","ref":"master","sha":"e61db28bb5ac7bf0cf280ab01e97be47068e9e6d","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-01T13:25:29Z","pushed_at":"2015-07-03T15:46:47Z","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":178886,"stargazers_count":134,"watchers_count":134,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":128,"mirror_url":null,"open_issues_count":169,"forks":128,"open_issues":169,"watchers":134,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mne-tools/mne-python/pulls/1777"},"html":{"href":"https://github.com/mne-tools/mne-python/pull/1777"},"issue":{"href":"https://api.github.com/repos/mne-tools/mne-python/issues/1777"},"comments":{"href":"https://api.github.com/repos/mne-tools/mne-python/issues/1777/comments"},"review_comments":{"href":"https://api.github.com/repos/mne-tools/mne-python/pulls/1777/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/1777/commits"},"statuses":{"href":"https://api.github.com/repos/mne-tools/mne-python/statuses/d91cc67aeac912ed08297eb15f708baf3edf5cb8"}}}}