{"action":"created","comment":{"url":"https://api.github.com/repos/nipy/dipy/pulls/comments/26442002","id":26442002,"diff_hunk":"@@ -798,3 +839,114 @@ def auto_response(gtab, data, roi_center=None, roi_radius=10, fa_thr=0.7,\n         return response, ratio, indices[0].size\n \n     return response, ratio\n+\n+\n+def recursive_response(gtab, data, mask=None, sh_order=8, peak_thr=0.01,\n+                       init_fa=0.08, init_trace=0.0021, iter=8,\n+                       convergence=0.001, parallel=True,\n+                       sphere=default_sphere):\n+    \"\"\" Recursive calibration of response function using peak threshold\n+\n+    Parameters\n+    ----------\n+    gtab : GradientTable\n+    data : ndarray\n+        diffusion data\n+    mask : ndarray\n+        mask for recursive calibration, for example a white matter mask. It has\n+        shape `data.shape[0:3]` and dtype=bool.\n+    sh_order : int\n+        maximal spherical harmonics order\n+    peak_thr : float\n+        peak threshold, how large the second peak can be relative to the first\n+        peak in order to call it a single fiber population [1]\n+    init_fa : float\n+        FA of the initial 'fat' response function (tensor)\n+    init_trace : float\n+        trace of the initial 'fat' response function (tensor)\n+    iter : int\n+        maximum number of iterations for calibration\n+    convergence : float\n+        convergence criterion, maximum relative change of SH coefficients\n+    sphere : Sphere\n+        The sphere used for peak finding.\n+\n+    Returns\n+    -------\n+    response : ndarray\n+        response function in SH coefficients\n+\n+    Notes\n+    -----\n+    In CSD there is an important pre-processing step: the estimation of the\n+    fiber response function. Using an FA threshold is not a very robust method.\n+    It is dependent on the dataset (non-informed used subjectivity), and still\n+    depends on the diffusion tensor (FA and first eigenvector),\n+    which has low accuracy at high b-value. This function recursively\n+    calibrates the response function, for more information see [1].\n+\n+    References\n+    ----------\n+    .. [1] Tax, C.M.W., et al. NeuroImage 2014. Recursive calibration of\n+           the fiber response function for spherical deconvolution of\n+           diffusion MRI data.\n+    \"\"\"\n+    S0 = 1\n+    evals = fa_trace_to_lambdas(init_fa, init_trace)\n+    res_obj = (evals, S0)\n+\n+    if mask is None:\n+        data = data.reshape(-1, data.shape[-1])\n+    else:\n+        data = data[mask]\n+\n+    n = np.arange(0, sh_order + 1, 2)\n+    where_dwi = lazy_index(~gtab.b0s_mask)\n+    response_p = np.ones(len(n))\n+\n+    for num_it in range(1, iter):\n+        r_sh_all = np.zeros(len(n))\n+        csd_model = ConstrainedSphericalDeconvModel(gtab, res_obj,","path":"dipy/reconst/csdeconv.py","position":170,"original_position":170,"commit_id":"4104d8265c1a9565790a239c959c85fb96eb402c","original_commit_id":"4104d8265c1a9565790a239c959c85fb96eb402c","user":{"login":"arokem","id":118582,"avatar_url":"https://avatars.githubusercontent.com/u/118582?v=3","gravatar_id":"","url":"https://api.github.com/users/arokem","html_url":"https://github.com/arokem","followers_url":"https://api.github.com/users/arokem/followers","following_url":"https://api.github.com/users/arokem/following{/other_user}","gists_url":"https://api.github.com/users/arokem/gists{/gist_id}","starred_url":"https://api.github.com/users/arokem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arokem/subscriptions","organizations_url":"https://api.github.com/users/arokem/orgs","repos_url":"https://api.github.com/users/arokem/repos","events_url":"https://api.github.com/users/arokem/events{/privacy}","received_events_url":"https://api.github.com/users/arokem/received_events","type":"User","site_admin":false},"body":"Good catch. Apparently not.","created_at":"2015-03-14T21:38:14Z","updated_at":"2015-03-14T21:38:14Z","html_url":"https://github.com/nipy/dipy/pull/588#discussion_r26442002","pull_request_url":"https://api.github.com/repos/nipy/dipy/pulls/588","_links":{"self":{"href":"https://api.github.com/repos/nipy/dipy/pulls/comments/26442002"},"html":{"href":"https://github.com/nipy/dipy/pull/588#discussion_r26442002"},"pull_request":{"href":"https://api.github.com/repos/nipy/dipy/pulls/588"}}},"pull_request":{"url":"https://api.github.com/repos/nipy/dipy/pulls/588","id":31155509,"html_url":"https://github.com/nipy/dipy/pull/588","diff_url":"https://github.com/nipy/dipy/pull/588.diff","patch_url":"https://github.com/nipy/dipy/pull/588.patch","issue_url":"https://api.github.com/repos/nipy/dipy/issues/588","number":588,"state":"open","locked":false,"title":"Nf csd calibration","user":{"login":"MrBago","id":223219,"avatar_url":"https://avatars.githubusercontent.com/u/223219?v=3","gravatar_id":"","url":"https://api.github.com/users/MrBago","html_url":"https://github.com/MrBago","followers_url":"https://api.github.com/users/MrBago/followers","following_url":"https://api.github.com/users/MrBago/following{/other_user}","gists_url":"https://api.github.com/users/MrBago/gists{/gist_id}","starred_url":"https://api.github.com/users/MrBago/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MrBago/subscriptions","organizations_url":"https://api.github.com/users/MrBago/orgs","repos_url":"https://api.github.com/users/MrBago/repos","events_url":"https://api.github.com/users/MrBago/events{/privacy}","received_events_url":"https://api.github.com/users/MrBago/received_events","type":"User","site_admin":false},"body":"I re-based #404 to clean it up a little bit. The changes I made are:\r\n\r\n1) Took out new functions in `dipy.reconst.shm`, these functions were not being called or tested. (Did this via rebase).\r\n2) I re-worked a little bit how the SH response was being handled. Only axially symmetric SH functions are needed so we don't bother to fit all the SH functions and zero out the non-symmetric coefficients. This should improve accuracy and performance.\r\n3) Changed recursive_response to use `default_sphere`. \r\n4) Fixed issue with response_scaling being wrong when an SH response was used.\r\n\r\n@arokem  @ChantalTax can you guys look over this.","created_at":"2015-03-13T19:15:39Z","updated_at":"2015-03-14T21:38:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f5eaf5c72e7ab2e1260c225d25b5394035a48aad","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/nipy/dipy/pulls/588/commits","review_comments_url":"https://api.github.com/repos/nipy/dipy/pulls/588/comments","review_comment_url":"https://api.github.com/repos/nipy/dipy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nipy/dipy/issues/588/comments","statuses_url":"https://api.github.com/repos/nipy/dipy/statuses/4104d8265c1a9565790a239c959c85fb96eb402c","head":{"label":"MrBago:nf_csd_calibration","ref":"nf_csd_calibration","sha":"4104d8265c1a9565790a239c959c85fb96eb402c","user":{"login":"MrBago","id":223219,"avatar_url":"https://avatars.githubusercontent.com/u/223219?v=3","gravatar_id":"","url":"https://api.github.com/users/MrBago","html_url":"https://github.com/MrBago","followers_url":"https://api.github.com/users/MrBago/followers","following_url":"https://api.github.com/users/MrBago/following{/other_user}","gists_url":"https://api.github.com/users/MrBago/gists{/gist_id}","starred_url":"https://api.github.com/users/MrBago/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MrBago/subscriptions","organizations_url":"https://api.github.com/users/MrBago/orgs","repos_url":"https://api.github.com/users/MrBago/repos","events_url":"https://api.github.com/users/MrBago/events{/privacy}","received_events_url":"https://api.github.com/users/MrBago/received_events","type":"User","site_admin":false},"repo":{"id":607143,"name":"dipy","full_name":"MrBago/dipy","owner":{"login":"MrBago","id":223219,"avatar_url":"https://avatars.githubusercontent.com/u/223219?v=3","gravatar_id":"","url":"https://api.github.com/users/MrBago","html_url":"https://github.com/MrBago","followers_url":"https://api.github.com/users/MrBago/followers","following_url":"https://api.github.com/users/MrBago/following{/other_user}","gists_url":"https://api.github.com/users/MrBago/gists{/gist_id}","starred_url":"https://api.github.com/users/MrBago/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MrBago/subscriptions","organizations_url":"https://api.github.com/users/MrBago/orgs","repos_url":"https://api.github.com/users/MrBago/repos","events_url":"https://api.github.com/users/MrBago/events{/privacy}","received_events_url":"https://api.github.com/users/MrBago/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/MrBago/dipy","description":"Diffusion MR Imaging in Python","fork":true,"url":"https://api.github.com/repos/MrBago/dipy","forks_url":"https://api.github.com/repos/MrBago/dipy/forks","keys_url":"https://api.github.com/repos/MrBago/dipy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MrBago/dipy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MrBago/dipy/teams","hooks_url":"https://api.github.com/repos/MrBago/dipy/hooks","issue_events_url":"https://api.github.com/repos/MrBago/dipy/issues/events{/number}","events_url":"https://api.github.com/repos/MrBago/dipy/events","assignees_url":"https://api.github.com/repos/MrBago/dipy/assignees{/user}","branches_url":"https://api.github.com/repos/MrBago/dipy/branches{/branch}","tags_url":"https://api.github.com/repos/MrBago/dipy/tags","blobs_url":"https://api.github.com/repos/MrBago/dipy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MrBago/dipy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MrBago/dipy/git/refs{/sha}","trees_url":"https://api.github.com/repos/MrBago/dipy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MrBago/dipy/statuses/{sha}","languages_url":"https://api.github.com/repos/MrBago/dipy/languages","stargazers_url":"https://api.github.com/repos/MrBago/dipy/stargazers","contributors_url":"https://api.github.com/repos/MrBago/dipy/contributors","subscribers_url":"https://api.github.com/repos/MrBago/dipy/subscribers","subscription_url":"https://api.github.com/repos/MrBago/dipy/subscription","commits_url":"https://api.github.com/repos/MrBago/dipy/commits{/sha}","git_commits_url":"https://api.github.com/repos/MrBago/dipy/git/commits{/sha}","comments_url":"https://api.github.com/repos/MrBago/dipy/comments{/number}","issue_comment_url":"https://api.github.com/repos/MrBago/dipy/issues/comments{/number}","contents_url":"https://api.github.com/repos/MrBago/dipy/contents/{+path}","compare_url":"https://api.github.com/repos/MrBago/dipy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MrBago/dipy/merges","archive_url":"https://api.github.com/repos/MrBago/dipy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MrBago/dipy/downloads","issues_url":"https://api.github.com/repos/MrBago/dipy/issues{/number}","pulls_url":"https://api.github.com/repos/MrBago/dipy/pulls{/number}","milestones_url":"https://api.github.com/repos/MrBago/dipy/milestones{/number}","notifications_url":"https://api.github.com/repos/MrBago/dipy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MrBago/dipy/labels{/name}","releases_url":"https://api.github.com/repos/MrBago/dipy/releases{/id}","created_at":"2010-04-12T19:26:55Z","updated_at":"2014-06-19T00:21:16Z","pushed_at":"2015-03-14T04:10:35Z","git_url":"git://github.com/MrBago/dipy.git","ssh_url":"git@github.com:MrBago/dipy.git","clone_url":"https://github.com/MrBago/dipy.git","svn_url":"https://github.com/MrBago/dipy","homepage":"http://nipy.sourceforge.net/dipy","size":16213,"stargazers_count":3,"watchers_count":3,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":5,"forks":1,"open_issues":5,"watchers":3,"default_branch":"master"}},"base":{"label":"nipy:master","ref":"master","sha":"ad8098200c67bfeeafd818bb07224b900040e9d8","user":{"login":"nipy","id":233707,"avatar_url":"https://avatars.githubusercontent.com/u/233707?v=3","gravatar_id":"","url":"https://api.github.com/users/nipy","html_url":"https://github.com/nipy","followers_url":"https://api.github.com/users/nipy/followers","following_url":"https://api.github.com/users/nipy/following{/other_user}","gists_url":"https://api.github.com/users/nipy/gists{/gist_id}","starred_url":"https://api.github.com/users/nipy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nipy/subscriptions","organizations_url":"https://api.github.com/users/nipy/orgs","repos_url":"https://api.github.com/users/nipy/repos","events_url":"https://api.github.com/users/nipy/events{/privacy}","received_events_url":"https://api.github.com/users/nipy/received_events","type":"Organization","site_admin":false},"repo":{"id":505209,"name":"dipy","full_name":"nipy/dipy","owner":{"login":"nipy","id":233707,"avatar_url":"https://avatars.githubusercontent.com/u/233707?v=3","gravatar_id":"","url":"https://api.github.com/users/nipy","html_url":"https://github.com/nipy","followers_url":"https://api.github.com/users/nipy/followers","following_url":"https://api.github.com/users/nipy/following{/other_user}","gists_url":"https://api.github.com/users/nipy/gists{/gist_id}","starred_url":"https://api.github.com/users/nipy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nipy/subscriptions","organizations_url":"https://api.github.com/users/nipy/orgs","repos_url":"https://api.github.com/users/nipy/repos","events_url":"https://api.github.com/users/nipy/events{/privacy}","received_events_url":"https://api.github.com/users/nipy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nipy/dipy","description":"Diffusion MR Imaging in Python","fork":false,"url":"https://api.github.com/repos/nipy/dipy","forks_url":"https://api.github.com/repos/nipy/dipy/forks","keys_url":"https://api.github.com/repos/nipy/dipy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nipy/dipy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nipy/dipy/teams","hooks_url":"https://api.github.com/repos/nipy/dipy/hooks","issue_events_url":"https://api.github.com/repos/nipy/dipy/issues/events{/number}","events_url":"https://api.github.com/repos/nipy/dipy/events","assignees_url":"https://api.github.com/repos/nipy/dipy/assignees{/user}","branches_url":"https://api.github.com/repos/nipy/dipy/branches{/branch}","tags_url":"https://api.github.com/repos/nipy/dipy/tags","blobs_url":"https://api.github.com/repos/nipy/dipy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nipy/dipy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nipy/dipy/git/refs{/sha}","trees_url":"https://api.github.com/repos/nipy/dipy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nipy/dipy/statuses/{sha}","languages_url":"https://api.github.com/repos/nipy/dipy/languages","stargazers_url":"https://api.github.com/repos/nipy/dipy/stargazers","contributors_url":"https://api.github.com/repos/nipy/dipy/contributors","subscribers_url":"https://api.github.com/repos/nipy/dipy/subscribers","subscription_url":"https://api.github.com/repos/nipy/dipy/subscription","commits_url":"https://api.github.com/repos/nipy/dipy/commits{/sha}","git_commits_url":"https://api.github.com/repos/nipy/dipy/git/commits{/sha}","comments_url":"https://api.github.com/repos/nipy/dipy/comments{/number}","issue_comment_url":"https://api.github.com/repos/nipy/dipy/issues/comments{/number}","contents_url":"https://api.github.com/repos/nipy/dipy/contents/{+path}","compare_url":"https://api.github.com/repos/nipy/dipy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nipy/dipy/merges","archive_url":"https://api.github.com/repos/nipy/dipy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nipy/dipy/downloads","issues_url":"https://api.github.com/repos/nipy/dipy/issues{/number}","pulls_url":"https://api.github.com/repos/nipy/dipy/pulls{/number}","milestones_url":"https://api.github.com/repos/nipy/dipy/milestones{/number}","notifications_url":"https://api.github.com/repos/nipy/dipy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nipy/dipy/labels{/name}","releases_url":"https://api.github.com/repos/nipy/dipy/releases{/id}","created_at":"2010-02-06T11:43:08Z","updated_at":"2015-03-14T17:48:23Z","pushed_at":"2015-03-14T17:48:22Z","git_url":"git://github.com/nipy/dipy.git","ssh_url":"git@github.com:nipy/dipy.git","clone_url":"https://github.com/nipy/dipy.git","svn_url":"https://github.com/nipy/dipy","homepage":"http://dipy.org","size":19766,"stargazers_count":58,"watchers_count":58,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":80,"mirror_url":null,"open_issues_count":62,"forks":80,"open_issues":62,"watchers":58,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nipy/dipy/pulls/588"},"html":{"href":"https://github.com/nipy/dipy/pull/588"},"issue":{"href":"https://api.github.com/repos/nipy/dipy/issues/588"},"comments":{"href":"https://api.github.com/repos/nipy/dipy/issues/588/comments"},"review_comments":{"href":"https://api.github.com/repos/nipy/dipy/pulls/588/comments"},"review_comment":{"href":"https://api.github.com/repos/nipy/dipy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nipy/dipy/pulls/588/commits"},"statuses":{"href":"https://api.github.com/repos/nipy/dipy/statuses/4104d8265c1a9565790a239c959c85fb96eb402c"}}}}