{"action":"created","comment":{"url":"https://api.github.com/repos/mne-tools/mne-python/pulls/comments/42347692","id":42347692,"diff_hunk":"@@ -1374,3 +1375,112 @@ def tfr_multitaper(inst, freqs, n_cycles, time_bandwidth=4.0,\n         out = (out, AverageTFR(info, itc, times, freqs, nave,\n                                method='mutlitaper-itc'))\n     return out\n+\n+\n+def grand_average(all_tfr, drop_bads=True):\n+    \"\"\"Make grand average of a list TFR data\n+\n+    Selects the subset of good channels across all datasets.\n+\n+    The grand_average.nave attribute will be equal the number\n+    of datasets used to calculate the grand average.\n+\n+    Note: Grand average TFR shall not be used for source localization.\n+\n+    Parameters\n+    ----------\n+    all_tfr : list of AllTFR data\n+        The TFR datasets.\n+    drop_bads : bool\n+        If True, bad MEG and EEG channels are dropped.\n+\n+    Returns\n+    -------\n+    grand_average : AllTFR\n+        The grand average data.\n+\n+    Notes\n+    -----\n+    .. versionadded:: 0.10.0\n+    \"\"\"\n+    # check if all elements in the given list are evoked data\n+    if not all(isinstance(e, AverageTFR) for e in all_tfr):\n+        raise ValueError(\"Not all the elements in list are AllTFR data\")\n+\n+    # Copy channels to leave the original evoked datasets intact.\n+    all_tfr = [e.copy() for e in all_tfr]\n+\n+    # Interpolates if necessary\n+    if drop_bads:\n+        for tfr in all_tfr:\n+            tfr.drop_channels(tfr.info['bads'], copy=False)\n+    else:\n+        pass\n+        # implement good channel subset here somehow??\n+\n+    equalize_channels(all_tfr)  # apply equalize_channels\n+    # make grand_average object using combine_tfr\n+    grand_average = combine_tfr(all_tfr)\n+    # change the grand_average.nave to the number of Evokeds\n+    grand_average.nave = len(all_tfr)\n+    # change comment field\n+    grand_average.comment = \"Grand average (n = %d)\" % grand_average.nave\n+    return grand_average\n+\n+\n+def combine_tfr(all_tfr, weights='nave'):\n+    \"\"\"Merge TFR data\n+\n+    Data should have the same channels and the same time instants.\n+    Subtraction can be performed by passing negative weights (e.g., [1, -1]).\n+\n+    Parameters\n+    ----------\n+    all_tfr : list of TFR\n+        The tfr datasets.\n+    weights : list of float | str\n+        The weights to apply to the data of each TFR instance.\n+        Can also be ``'nave'`` to weight according to tfr.nave,\n+        or ``\"equal\"`` to use equal weighting (each weighted as ``1/N``).\n+\n+    Returns\n+    -------\n+    tfr : AllTFR\n+        The new TFR data.\n+\n+    Notes\n+    -----\n+    .. versionadded:: 0.10.0\n+    \"\"\"\n+    tfr = all_tfr[0].copy()\n+    if isinstance(weights, string_types):\n+        if weights not in ('nave', 'equal'):\n+            raise ValueError('Weights must be a list of float, or \"nave\" or '\n+                             '\"equal\"')\n+        if weights == 'nave':\n+            weights = np.array([e.nave for e in all_tfr], float)\n+            weights /= weights.sum()\n+        else:  # == 'equal'\n+            weights = [1. / len(all_tfr)] * len(all_tfr)\n+    weights = np.array(weights, float)\n+    if weights.ndim != 1 or weights.size != len(all_tfr):\n+        raise ValueError('Weights must be the same size as all_tfr')\n+\n+    ch_names = tfr.ch_names\n+    for e in all_tfr[1:]:\n+        assert e.ch_names == ch_names, ValueError(\"%s and %s do not contain \"\n+                                                  \"the same channels\"\n+                                                  % (tfr, e))\n+        assert np.max(np.abs(e.times - tfr.times)) < 1e-7, \\\n+            ValueError(\"%s and %s do not contain the same time instants\"\n+                       % (tfr, e))\n+\n+    # use union of bad channels\n+    bads = list(set(tfr.info['bads']).union(*(ev.info['bads']\n+                                              for ev in all_tfr[1:])))\n+    tfr.info['bads'] = bads\n+\n+    tfr.data = sum(w * e.data for w, e in zip(weights, all_tfr))\n+    tfr.nave = max(int(1. / sum(w ** 2 / e.nave\n+                                for w, e in zip(weights, all_tfr))), 1)","path":"mne/time_frequency/tfr.py","position":129,"original_position":129,"commit_id":"1e70e53c06ae8890cf3d5dbf048ceb7e244f0692","original_commit_id":"1e70e53c06ae8890cf3d5dbf048ceb7e244f0692","user":{"login":"jaeilepp","id":3456414,"avatar_url":"https://avatars.githubusercontent.com/u/3456414?v=3","gravatar_id":"","url":"https://api.github.com/users/jaeilepp","html_url":"https://github.com/jaeilepp","followers_url":"https://api.github.com/users/jaeilepp/followers","following_url":"https://api.github.com/users/jaeilepp/following{/other_user}","gists_url":"https://api.github.com/users/jaeilepp/gists{/gist_id}","starred_url":"https://api.github.com/users/jaeilepp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaeilepp/subscriptions","organizations_url":"https://api.github.com/users/jaeilepp/orgs","repos_url":"https://api.github.com/users/jaeilepp/repos","events_url":"https://api.github.com/users/jaeilepp/events{/privacy}","received_events_url":"https://api.github.com/users/jaeilepp/received_events","type":"User","site_admin":false},"body":"Okay, We had a chat with Alex offline. The ``grand_average`` should use ``equal`` as the method for averaging just like with evoked. Add that on line 1423.","created_at":"2015-10-19T08:45:37Z","updated_at":"2015-10-19T08:45:37Z","html_url":"https://github.com/mne-tools/mne-python/pull/2537#discussion_r42347692","pull_request_url":"https://api.github.com/repos/mne-tools/mne-python/pulls/2537","_links":{"self":{"href":"https://api.github.com/repos/mne-tools/mne-python/pulls/comments/42347692"},"html":{"href":"https://github.com/mne-tools/mne-python/pull/2537#discussion_r42347692"},"pull_request":{"href":"https://api.github.com/repos/mne-tools/mne-python/pulls/2537"}}},"pull_request":{"url":"https://api.github.com/repos/mne-tools/mne-python/pulls/2537","id":47957563,"html_url":"https://github.com/mne-tools/mne-python/pull/2537","diff_url":"https://github.com/mne-tools/mne-python/pull/2537.diff","patch_url":"https://github.com/mne-tools/mne-python/pull/2537.patch","issue_url":"https://api.github.com/repos/mne-tools/mne-python/issues/2537","number":2537,"state":"open","locked":false,"title":"WIP: Initialize tfr average","user":{"login":"jona-sassenhagen","id":4321826,"avatar_url":"https://avatars.githubusercontent.com/u/4321826?v=3","gravatar_id":"","url":"https://api.github.com/users/jona-sassenhagen","html_url":"https://github.com/jona-sassenhagen","followers_url":"https://api.github.com/users/jona-sassenhagen/followers","following_url":"https://api.github.com/users/jona-sassenhagen/following{/other_user}","gists_url":"https://api.github.com/users/jona-sassenhagen/gists{/gist_id}","starred_url":"https://api.github.com/users/jona-sassenhagen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jona-sassenhagen/subscriptions","organizations_url":"https://api.github.com/users/jona-sassenhagen/orgs","repos_url":"https://api.github.com/users/jona-sassenhagen/repos","events_url":"https://api.github.com/users/jona-sassenhagen/events{/privacy}","received_events_url":"https://api.github.com/users/jona-sassenhagen/received_events","type":"User","site_admin":false},"body":"See #2523\r\n\r\nTodo: test","created_at":"2015-10-16T20:40:52Z","updated_at":"2015-10-19T08:45:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fba84bd31bc2ea865e1160f288bf76f5414d34e8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mne-tools/mne-python/pulls/2537/commits","review_comments_url":"https://api.github.com/repos/mne-tools/mne-python/pulls/2537/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/2537/comments","statuses_url":"https://api.github.com/repos/mne-tools/mne-python/statuses/1e70e53c06ae8890cf3d5dbf048ceb7e244f0692","head":{"label":"jona-sassenhagen:patch-3","ref":"patch-3","sha":"1e70e53c06ae8890cf3d5dbf048ceb7e244f0692","user":{"login":"jona-sassenhagen","id":4321826,"avatar_url":"https://avatars.githubusercontent.com/u/4321826?v=3","gravatar_id":"","url":"https://api.github.com/users/jona-sassenhagen","html_url":"https://github.com/jona-sassenhagen","followers_url":"https://api.github.com/users/jona-sassenhagen/followers","following_url":"https://api.github.com/users/jona-sassenhagen/following{/other_user}","gists_url":"https://api.github.com/users/jona-sassenhagen/gists{/gist_id}","starred_url":"https://api.github.com/users/jona-sassenhagen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jona-sassenhagen/subscriptions","organizations_url":"https://api.github.com/users/jona-sassenhagen/orgs","repos_url":"https://api.github.com/users/jona-sassenhagen/repos","events_url":"https://api.github.com/users/jona-sassenhagen/events{/privacy}","received_events_url":"https://api.github.com/users/jona-sassenhagen/received_events","type":"User","site_admin":false},"repo":{"id":26366770,"name":"mne-python","full_name":"jona-sassenhagen/mne-python","owner":{"login":"jona-sassenhagen","id":4321826,"avatar_url":"https://avatars.githubusercontent.com/u/4321826?v=3","gravatar_id":"","url":"https://api.github.com/users/jona-sassenhagen","html_url":"https://github.com/jona-sassenhagen","followers_url":"https://api.github.com/users/jona-sassenhagen/followers","following_url":"https://api.github.com/users/jona-sassenhagen/following{/other_user}","gists_url":"https://api.github.com/users/jona-sassenhagen/gists{/gist_id}","starred_url":"https://api.github.com/users/jona-sassenhagen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jona-sassenhagen/subscriptions","organizations_url":"https://api.github.com/users/jona-sassenhagen/orgs","repos_url":"https://api.github.com/users/jona-sassenhagen/repos","events_url":"https://api.github.com/users/jona-sassenhagen/events{/privacy}","received_events_url":"https://api.github.com/users/jona-sassenhagen/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jona-sassenhagen/mne-python","description":"MNE : Magnetoencephalography (MEG) and Electroencephalography (EEG) in Python","fork":true,"url":"https://api.github.com/repos/jona-sassenhagen/mne-python","forks_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/forks","keys_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/teams","hooks_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/hooks","issue_events_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/issues/events{/number}","events_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/events","assignees_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/assignees{/user}","branches_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/branches{/branch}","tags_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/tags","blobs_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/git/refs{/sha}","trees_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/statuses/{sha}","languages_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/languages","stargazers_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/stargazers","contributors_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/contributors","subscribers_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/subscribers","subscription_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/subscription","commits_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/commits{/sha}","git_commits_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/git/commits{/sha}","comments_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/comments{/number}","issue_comment_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/issues/comments{/number}","contents_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/contents/{+path}","compare_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/merges","archive_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/downloads","issues_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/issues{/number}","pulls_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/pulls{/number}","milestones_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/milestones{/number}","notifications_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/labels{/name}","releases_url":"https://api.github.com/repos/jona-sassenhagen/mne-python/releases{/id}","created_at":"2014-11-08T16:37:16Z","updated_at":"2015-03-21T16:54:38Z","pushed_at":"2015-10-17T23:30:18Z","git_url":"git://github.com/jona-sassenhagen/mne-python.git","ssh_url":"git@github.com:jona-sassenhagen/mne-python.git","clone_url":"https://github.com/jona-sassenhagen/mne-python.git","svn_url":"https://github.com/jona-sassenhagen/mne-python","homepage":"http://martinos.org/mne/","size":83437,"stargazers_count":0,"watchers_count":0,"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":0,"default_branch":"master"}},"base":{"label":"mne-tools:master","ref":"master","sha":"dd6acfc3cc6b31d458c7a6c520924fb07b9560f5","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-10-16T15:33:35Z","pushed_at":"2015-10-17T23:30:18Z","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":183382,"stargazers_count":153,"watchers_count":153,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":142,"mirror_url":null,"open_issues_count":179,"forks":142,"open_issues":179,"watchers":153,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mne-tools/mne-python/pulls/2537"},"html":{"href":"https://github.com/mne-tools/mne-python/pull/2537"},"issue":{"href":"https://api.github.com/repos/mne-tools/mne-python/issues/2537"},"comments":{"href":"https://api.github.com/repos/mne-tools/mne-python/issues/2537/comments"},"review_comments":{"href":"https://api.github.com/repos/mne-tools/mne-python/pulls/2537/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/2537/commits"},"statuses":{"href":"https://api.github.com/repos/mne-tools/mne-python/statuses/1e70e53c06ae8890cf3d5dbf048ceb7e244f0692"}}}}