{"action":"created","comment":{"url":"https://api.github.com/repos/nipy/dipy/pulls/comments/37701157","id":37701157,"diff_hunk":"@@ -113,3 +116,169 @@ def select_random_set_of_streamlines(streamlines, select):\n     len_s = len(streamlines)\n     index = np.random.randint(0, len_s, min(select, len_s))\n     return [streamlines[i] for i in index]\n+\n+\n+def reduce_rois(rois, include):\n+    \"\"\"Reduce multiple ROIs to one inclusion and one exclusion ROI\n+\n+    Parameters\n+    ----------\n+    rois : list or ndarray\n+        A list of 3D arrays, each with shape (x, y, z) corresponding to the\n+        shape of the brain volume, or a 4D array with shape (n_rois, x, y,\n+        z). Non-zeros in each volume are considered to be within the region.\n+\n+    include: array or list\n+        A list or 1D array of boolean marking inclusion or exclusion\n+        criteria.\n+\n+    Returns\n+    -------\n+    include_roi : boolean 3D array\n+        An array marking the inclusion mask.\n+\n+    exclude_roi : boolean 3D array\n+        An array marking the exclusion mask\n+\n+    Note\n+    ----\n+    The include_roi and exclude_roi can be used to perfom the operation: \"(A\n+    or B or ...) and not (X or Y or ...)\", where A, B are inclusion regions\n+    and X, Y are exclusion regions.\n+    \"\"\"\n+    include_roi = np.zeros(rois[0].shape, dtype=bool)\n+    exclude_roi = np.zeros(rois[0].shape, dtype=bool)\n+\n+    for i in range(len(rois)):\n+        if include[i]:\n+            include_roi |= rois[i]\n+        else:\n+            exclude_roi |= rois[i]\n+\n+    return include_roi, exclude_roi\n+\n+\n+def select_by_roi(streamlines, rois, include, mode=None, affine=None,\n+                  tol=None):\n+    \"\"\"Select streamlines based on logical relations with several regions of\n+    interest (ROIs). For example, select streamlines that pass near ROI1,\n+    but only if they do not pass near ROI2.\n+\n+    Parameters\n+    ----------\n+    streamlines: list\n+        A list of candidate streamlines for selection\n+    rois: list or ndarray","path":"dipy/tracking/streamline.py","position":76,"original_position":76,"commit_id":"0065a9e87457930a413653706d7749e551f1d142","original_commit_id":"0065a9e87457930a413653706d7749e551f1d142","user":{"login":"Garyfallidis","id":134276,"avatar_url":"https://avatars.githubusercontent.com/u/134276?v=3","gravatar_id":"","url":"https://api.github.com/users/Garyfallidis","html_url":"https://github.com/Garyfallidis","followers_url":"https://api.github.com/users/Garyfallidis/followers","following_url":"https://api.github.com/users/Garyfallidis/following{/other_user}","gists_url":"https://api.github.com/users/Garyfallidis/gists{/gist_id}","starred_url":"https://api.github.com/users/Garyfallidis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Garyfallidis/subscriptions","organizations_url":"https://api.github.com/users/Garyfallidis/orgs","repos_url":"https://api.github.com/users/Garyfallidis/repos","events_url":"https://api.github.com/users/Garyfallidis/events{/privacy}","received_events_url":"https://api.github.com/users/Garyfallidis/received_events","type":"User","site_admin":false},"body":"same here","created_at":"2015-08-23T00:24:39Z","updated_at":"2015-08-23T00:24:39Z","html_url":"https://github.com/nipy/dipy/pull/635#discussion_r37701157","pull_request_url":"https://api.github.com/repos/nipy/dipy/pulls/635","_links":{"self":{"href":"https://api.github.com/repos/nipy/dipy/pulls/comments/37701157"},"html":{"href":"https://github.com/nipy/dipy/pull/635#discussion_r37701157"},"pull_request":{"href":"https://api.github.com/repos/nipy/dipy/pulls/635"}}},"pull_request":{"url":"https://api.github.com/repos/nipy/dipy/pulls/635","id":34010568,"html_url":"https://github.com/nipy/dipy/pull/635","diff_url":"https://github.com/nipy/dipy/pull/635.diff","patch_url":"https://github.com/nipy/dipy/pull/635.patch","issue_url":"https://api.github.com/repos/nipy/dipy/issues/635","number":635,"state":"open","locked":false,"title":"Select streamlines based on logical operations on ROIs","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":"This PR starts what will be a long series of PRs towards the implementation of the AFQ system in dipy (see http://journals.plos.org/plosone/article?id=10.1371/journal.pone.0049790), work that I will undertake in close collaboration with @jyeatman, who has done much of the development of the system in Matlab, and has been the maintainer of that software for several years. \r\n\r\nFor now, this just does a couple of really simple things, as you can see: \r\n\r\n- Determines whether streamlines pass within some distance from a mask (a region of interest)\r\n- Combines the conclusions from this determination based on inclusion and exclusion criteria. For now, only a fairly limited set of logical operations are possible. \r\n\r\nQuestions include: \r\n\r\n- Does the `select_by_roi` function makes sense where it currently is? \r\n- Would we want/need to build out a more extensive set of logical operations over combinations of ROIs? What would that entail?","created_at":"2015-04-24T00:49:27Z","updated_at":"2015-08-23T00:24:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"837b9b8a984ffe323194c1e906d56d599fdfada1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/nipy/dipy/pulls/635/commits","review_comments_url":"https://api.github.com/repos/nipy/dipy/pulls/635/comments","review_comment_url":"https://api.github.com/repos/nipy/dipy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nipy/dipy/issues/635/comments","statuses_url":"https://api.github.com/repos/nipy/dipy/statuses/0065a9e87457930a413653706d7749e551f1d142","head":{"label":"arokem:intersect-with-roi","ref":"intersect-with-roi","sha":"0065a9e87457930a413653706d7749e551f1d142","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},"repo":{"id":2484790,"name":"dipy","full_name":"arokem/dipy","owner":{"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},"private":false,"html_url":"https://github.com/arokem/dipy","description":"Diffusion MR Imaging in Python","fork":true,"url":"https://api.github.com/repos/arokem/dipy","forks_url":"https://api.github.com/repos/arokem/dipy/forks","keys_url":"https://api.github.com/repos/arokem/dipy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/arokem/dipy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/arokem/dipy/teams","hooks_url":"https://api.github.com/repos/arokem/dipy/hooks","issue_events_url":"https://api.github.com/repos/arokem/dipy/issues/events{/number}","events_url":"https://api.github.com/repos/arokem/dipy/events","assignees_url":"https://api.github.com/repos/arokem/dipy/assignees{/user}","branches_url":"https://api.github.com/repos/arokem/dipy/branches{/branch}","tags_url":"https://api.github.com/repos/arokem/dipy/tags","blobs_url":"https://api.github.com/repos/arokem/dipy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/arokem/dipy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/arokem/dipy/git/refs{/sha}","trees_url":"https://api.github.com/repos/arokem/dipy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/arokem/dipy/statuses/{sha}","languages_url":"https://api.github.com/repos/arokem/dipy/languages","stargazers_url":"https://api.github.com/repos/arokem/dipy/stargazers","contributors_url":"https://api.github.com/repos/arokem/dipy/contributors","subscribers_url":"https://api.github.com/repos/arokem/dipy/subscribers","subscription_url":"https://api.github.com/repos/arokem/dipy/subscription","commits_url":"https://api.github.com/repos/arokem/dipy/commits{/sha}","git_commits_url":"https://api.github.com/repos/arokem/dipy/git/commits{/sha}","comments_url":"https://api.github.com/repos/arokem/dipy/comments{/number}","issue_comment_url":"https://api.github.com/repos/arokem/dipy/issues/comments{/number}","contents_url":"https://api.github.com/repos/arokem/dipy/contents/{+path}","compare_url":"https://api.github.com/repos/arokem/dipy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/arokem/dipy/merges","archive_url":"https://api.github.com/repos/arokem/dipy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/arokem/dipy/downloads","issues_url":"https://api.github.com/repos/arokem/dipy/issues{/number}","pulls_url":"https://api.github.com/repos/arokem/dipy/pulls{/number}","milestones_url":"https://api.github.com/repos/arokem/dipy/milestones{/number}","notifications_url":"https://api.github.com/repos/arokem/dipy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/arokem/dipy/labels{/name}","releases_url":"https://api.github.com/repos/arokem/dipy/releases{/id}","created_at":"2011-09-29T20:43:30Z","updated_at":"2015-05-02T11:33:01Z","pushed_at":"2015-08-14T23:09:50Z","git_url":"git://github.com/arokem/dipy.git","ssh_url":"git@github.com:arokem/dipy.git","clone_url":"https://github.com/arokem/dipy.git","svn_url":"https://github.com/arokem/dipy","homepage":"http://dipy.org","size":18893,"stargazers_count":3,"watchers_count":3,"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":3,"default_branch":"master"}},"base":{"label":"nipy:master","ref":"master","sha":"57f7ec926f914d72f7f2f8feb8ccb51ab827895d","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-07-31T20:40:11Z","pushed_at":"2015-08-21T22:01:45Z","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":30976,"stargazers_count":62,"watchers_count":62,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":94,"mirror_url":null,"open_issues_count":94,"forks":94,"open_issues":94,"watchers":62,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nipy/dipy/pulls/635"},"html":{"href":"https://github.com/nipy/dipy/pull/635"},"issue":{"href":"https://api.github.com/repos/nipy/dipy/issues/635"},"comments":{"href":"https://api.github.com/repos/nipy/dipy/issues/635/comments"},"review_comments":{"href":"https://api.github.com/repos/nipy/dipy/pulls/635/comments"},"review_comment":{"href":"https://api.github.com/repos/nipy/dipy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nipy/dipy/pulls/635/commits"},"statuses":{"href":"https://api.github.com/repos/nipy/dipy/statuses/0065a9e87457930a413653706d7749e551f1d142"}}}}