{"action":"created","comment":{"url":"https://api.github.com/repos/mne-tools/mne-python/pulls/comments/32171529","id":32171529,"diff_hunk":"@@ -445,11 +466,55 @@ def fit_dipole(evoked, cov, bem, trans=None, n_jobs=1, verbose=None):\n     \"\"\"\n     # This could eventually be adapted to work with other inputs, these\n     # are what is needed:\n+\n+    evoked = evoked.copy()\n+\n+    # Determine if a list of projectors has an average EEG ref\n+    if \"eeg\" in evoked and not _has_eeg_average_ref_proj(evoked.info['projs']):\n+        raise ValueError('EEG average reference is mandatory for dipole '\n+                         'fitting.')\n+    else:\n+        # Determine if the 'Average EEG reference' projector is active.\n+        for proj in evoked.info['projs']:\n+            if (proj['desc'] == 'Average EEG reference' or\n+                    proj['kind'] == FIFF.FIFFV_MNE_PROJ_ITEM_EEG_AVREF):\n+                idx_eeg_average_proj = evoked.info['projs'].index(proj)\n+\n+        if not evoked.info['projs'][idx_eeg_average_proj]['active']:\n+\n+            # if it is not active, we need to apply only this projector\n+            # to the data.\n+\n+            # Currently it is only possible to apply all projectors\n+            # to the data, but we need to apply only one. To achieve\n+            # this we are going to use the following hack:\n+\n+            # - Remove the eeg_average_ref_proj and save the rest of\n+            # the projectors\n+            evoked.info['projs'].pop(idx_eeg_average_proj)\n+            projs = evoked.info['projs']\n+\n+            # - Once the projectors have been saved, remove all of them from\n+            # evoke.info\n+            evoked.info['projs'] = []\n+\n+            # - Make an eeg_average_ref_proj and apply it to the data\n+            avg_proj = make_eeg_average_ref_proj(evoked.info)\n+            evoked.add_proj([avg_proj])\n+            evoked.apply_proj()\n+\n+            # - Append this new projector to the previously saved\n+            # projectors, and stored them into evoked.info['projs']\n+            evoked.info['projs'] = projs + evoked.info['projs']","path":"mne/dipole.py","position":150,"original_position":150,"commit_id":"cc61948234fdb4c9b7d3e011f5a08da1860a0196","original_commit_id":"cc61948234fdb4c9b7d3e011f5a08da1860a0196","user":{"login":"agramfort","id":161052,"avatar_url":"https://avatars.githubusercontent.com/u/161052?v=3","gravatar_id":"","url":"https://api.github.com/users/agramfort","html_url":"https://github.com/agramfort","followers_url":"https://api.github.com/users/agramfort/followers","following_url":"https://api.github.com/users/agramfort/following{/other_user}","gists_url":"https://api.github.com/users/agramfort/gists{/gist_id}","starred_url":"https://api.github.com/users/agramfort/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agramfort/subscriptions","organizations_url":"https://api.github.com/users/agramfort/orgs","repos_url":"https://api.github.com/users/agramfort/repos","events_url":"https://api.github.com/users/agramfort/events{/privacy}","received_events_url":"https://api.github.com/users/agramfort/received_events","type":"User","site_admin":false},"body":"see https://github.com/mne-tools/mne-python/issues/2197","created_at":"2015-06-10T22:00:27Z","updated_at":"2015-06-10T22:00:27Z","html_url":"https://github.com/mne-tools/mne-python/pull/2196#discussion_r32171529","pull_request_url":"https://api.github.com/repos/mne-tools/mne-python/pulls/2196","_links":{"self":{"href":"https://api.github.com/repos/mne-tools/mne-python/pulls/comments/32171529"},"html":{"href":"https://github.com/mne-tools/mne-python/pull/2196#discussion_r32171529"},"pull_request":{"href":"https://api.github.com/repos/mne-tools/mne-python/pulls/2196"}}},"pull_request":{"url":"https://api.github.com/repos/mne-tools/mne-python/pulls/2196","id":37408494,"html_url":"https://github.com/mne-tools/mne-python/pull/2196","diff_url":"https://github.com/mne-tools/mne-python/pull/2196.diff","patch_url":"https://github.com/mne-tools/mne-python/pull/2196.patch","issue_url":"https://api.github.com/repos/mne-tools/mne-python/issues/2196","number":2196,"state":"open","locked":false,"title":"[MRG] Min distance fit dipole","user":{"login":"agramfort","id":161052,"avatar_url":"https://avatars.githubusercontent.com/u/161052?v=3","gravatar_id":"","url":"https://api.github.com/users/agramfort","html_url":"https://github.com/agramfort","followers_url":"https://api.github.com/users/agramfort/followers","following_url":"https://api.github.com/users/agramfort/following{/other_user}","gists_url":"https://api.github.com/users/agramfort/gists{/gist_id}","starred_url":"https://api.github.com/users/agramfort/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agramfort/subscriptions","organizations_url":"https://api.github.com/users/agramfort/orgs","repos_url":"https://api.github.com/users/agramfort/repos","events_url":"https://api.github.com/users/agramfort/events{/privacy}","received_events_url":"https://api.github.com/users/agramfort/received_events","type":"User","site_admin":false},"body":"taking over #2155","created_at":"2015-06-10T21:49:41Z","updated_at":"2015-06-10T22:00:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"979a1216e13677dec48427ae6cb4e7be3d77121b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mne-tools/mne-python/pulls/2196/commits","review_comments_url":"https://api.github.com/repos/mne-tools/mne-python/pulls/2196/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/2196/comments","statuses_url":"https://api.github.com/repos/mne-tools/mne-python/statuses/cc61948234fdb4c9b7d3e011f5a08da1860a0196","head":{"label":"agramfort:min-distance-fit-dipole","ref":"min-distance-fit-dipole","sha":"cc61948234fdb4c9b7d3e011f5a08da1860a0196","user":{"login":"agramfort","id":161052,"avatar_url":"https://avatars.githubusercontent.com/u/161052?v=3","gravatar_id":"","url":"https://api.github.com/users/agramfort","html_url":"https://github.com/agramfort","followers_url":"https://api.github.com/users/agramfort/followers","following_url":"https://api.github.com/users/agramfort/following{/other_user}","gists_url":"https://api.github.com/users/agramfort/gists{/gist_id}","starred_url":"https://api.github.com/users/agramfort/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agramfort/subscriptions","organizations_url":"https://api.github.com/users/agramfort/orgs","repos_url":"https://api.github.com/users/agramfort/repos","events_url":"https://api.github.com/users/agramfort/events{/privacy}","received_events_url":"https://api.github.com/users/agramfort/received_events","type":"User","site_admin":false},"repo":{"id":2202093,"name":"mne-python","full_name":"agramfort/mne-python","owner":{"login":"agramfort","id":161052,"avatar_url":"https://avatars.githubusercontent.com/u/161052?v=3","gravatar_id":"","url":"https://api.github.com/users/agramfort","html_url":"https://github.com/agramfort","followers_url":"https://api.github.com/users/agramfort/followers","following_url":"https://api.github.com/users/agramfort/following{/other_user}","gists_url":"https://api.github.com/users/agramfort/gists{/gist_id}","starred_url":"https://api.github.com/users/agramfort/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agramfort/subscriptions","organizations_url":"https://api.github.com/users/agramfort/orgs","repos_url":"https://api.github.com/users/agramfort/repos","events_url":"https://api.github.com/users/agramfort/events{/privacy}","received_events_url":"https://api.github.com/users/agramfort/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/agramfort/mne-python","description":"MNE scripting with Python","fork":true,"url":"https://api.github.com/repos/agramfort/mne-python","forks_url":"https://api.github.com/repos/agramfort/mne-python/forks","keys_url":"https://api.github.com/repos/agramfort/mne-python/keys{/key_id}","collaborators_url":"https://api.github.com/repos/agramfort/mne-python/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/agramfort/mne-python/teams","hooks_url":"https://api.github.com/repos/agramfort/mne-python/hooks","issue_events_url":"https://api.github.com/repos/agramfort/mne-python/issues/events{/number}","events_url":"https://api.github.com/repos/agramfort/mne-python/events","assignees_url":"https://api.github.com/repos/agramfort/mne-python/assignees{/user}","branches_url":"https://api.github.com/repos/agramfort/mne-python/branches{/branch}","tags_url":"https://api.github.com/repos/agramfort/mne-python/tags","blobs_url":"https://api.github.com/repos/agramfort/mne-python/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/agramfort/mne-python/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/agramfort/mne-python/git/refs{/sha}","trees_url":"https://api.github.com/repos/agramfort/mne-python/git/trees{/sha}","statuses_url":"https://api.github.com/repos/agramfort/mne-python/statuses/{sha}","languages_url":"https://api.github.com/repos/agramfort/mne-python/languages","stargazers_url":"https://api.github.com/repos/agramfort/mne-python/stargazers","contributors_url":"https://api.github.com/repos/agramfort/mne-python/contributors","subscribers_url":"https://api.github.com/repos/agramfort/mne-python/subscribers","subscription_url":"https://api.github.com/repos/agramfort/mne-python/subscription","commits_url":"https://api.github.com/repos/agramfort/mne-python/commits{/sha}","git_commits_url":"https://api.github.com/repos/agramfort/mne-python/git/commits{/sha}","comments_url":"https://api.github.com/repos/agramfort/mne-python/comments{/number}","issue_comment_url":"https://api.github.com/repos/agramfort/mne-python/issues/comments{/number}","contents_url":"https://api.github.com/repos/agramfort/mne-python/contents/{+path}","compare_url":"https://api.github.com/repos/agramfort/mne-python/compare/{base}...{head}","merges_url":"https://api.github.com/repos/agramfort/mne-python/merges","archive_url":"https://api.github.com/repos/agramfort/mne-python/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/agramfort/mne-python/downloads","issues_url":"https://api.github.com/repos/agramfort/mne-python/issues{/number}","pulls_url":"https://api.github.com/repos/agramfort/mne-python/pulls{/number}","milestones_url":"https://api.github.com/repos/agramfort/mne-python/milestones{/number}","notifications_url":"https://api.github.com/repos/agramfort/mne-python/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/agramfort/mne-python/labels{/name}","releases_url":"https://api.github.com/repos/agramfort/mne-python/releases{/id}","created_at":"2011-08-13T15:44:42Z","updated_at":"2015-02-21T16:37:42Z","pushed_at":"2015-06-10T21:52:29Z","git_url":"git://github.com/agramfort/mne-python.git","ssh_url":"git@github.com:agramfort/mne-python.git","clone_url":"https://github.com/agramfort/mne-python.git","svn_url":"https://github.com/agramfort/mne-python","homepage":"http://martinos.org/mne","size":80092,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"mne-tools:master","ref":"master","sha":"ed811dc83aeeb9c3dbca53b3090f8fad55399691","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-06-03T18:06:57Z","pushed_at":"2015-06-10T21:52:30Z","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":178813,"stargazers_count":129,"watchers_count":129,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":125,"mirror_url":null,"open_issues_count":152,"forks":125,"open_issues":152,"watchers":129,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mne-tools/mne-python/pulls/2196"},"html":{"href":"https://github.com/mne-tools/mne-python/pull/2196"},"issue":{"href":"https://api.github.com/repos/mne-tools/mne-python/issues/2196"},"comments":{"href":"https://api.github.com/repos/mne-tools/mne-python/issues/2196/comments"},"review_comments":{"href":"https://api.github.com/repos/mne-tools/mne-python/pulls/2196/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/2196/commits"},"statuses":{"href":"https://api.github.com/repos/mne-tools/mne-python/statuses/cc61948234fdb4c9b7d3e011f5a08da1860a0196"}}}}