{"action":"created","comment":{"url":"https://api.github.com/repos/pynbody/pynbody/pulls/comments/24271898","id":24271898,"diff_hunk":"@@ -100,36 +100,50 @@ class Sphere(Filter):\n     def __init__(self, radius, cen=(0, 0, 0)):\n         self._descriptor = \"sphere\"\n         self.cen = np.asarray(cen)\n-        if self.cen.shape != (3,):\n-            raise ValueError, \"Centre must be length 3 array\"\n+#        if self.cen.shape != (3,):\n+#            raise ValueError, \"Centre must be length 3 array\"\n \n-        if isinstance(radius, str):\n-            radius = units.Unit(radius)\n+        if not isinstance(radius, list) : \n+            radius = [radius]\n+\n+        if isinstance(radius[0], str):\n+            radius = map(units.Unit,radius)\n+\n+        # check if many different centers were passed in\n+            if isinstance(cen, list) or isinstance(cen, np.ndarray) : \n+                if len(cen) != len(radius) : \n+                    radius = radius * len(cen)\n \n         self.radius = radius\n \n+\n     def __call__(self, sim):\n         radius = self.radius\n \n         with sim.immediate_mode:\n             pos = sim['pos']\n \n-        if units.is_unit_like(radius):\n-            radius = float(radius.in_units(pos.units,\n-                                           **pos.conversion_context()))\n+        if units.is_unit_like(radius[0]):\n+            radius = np.asarray([r.in_units(pos.units, **pos.conversion_context()) for r in radius], dtype='float')\n+\n+        else : \n+            radius = np.asarray(radius, dtype='float')\n \n         cen = self.cen\n         if units.has_units(cen):\n             cen = cen.in_units(pos.units)\n+\n+        if len(cen.shape) == 1 : \n+            cen = np.expand_dims(cen,axis=0)\n+\n         return util._sphere_selection(np.asarray(pos),np.asarray(cen,dtype=pos.dtype),radius)\n \n \n     def __repr__(self):\n-        if units.is_unit(self.radius):\n-\n-            return \"Sphere('%s', %s)\" % (str(self.radius), repr(self.cen))\n+        if units.is_unit(self.radius[0]):\n+            return \" & \".join([\"Sphere('%s', %s)\" % (str(radius), repr(cen)) for radius, cen in zip(self.radius, self.cen)])\n         else:\n-            return \"Sphere(%.2e, %s)\" % (self.radius, repr(self.cen))\n+            return \" & \".join([\"Sphere(%.2e, %s)\" % (radius, repr(cen)) for radius, cen in zip(self.radius, self.cen)])","path":"pynbody/filt.py","position":58,"original_position":58,"commit_id":"2500e35e352891d006a98104e276b677fa1c94cd","original_commit_id":"2500e35e352891d006a98104e276b677fa1c94cd","user":{"login":"apontzen","id":4377338,"avatar_url":"https://avatars.githubusercontent.com/u/4377338?v=3","gravatar_id":"","url":"https://api.github.com/users/apontzen","html_url":"https://github.com/apontzen","followers_url":"https://api.github.com/users/apontzen/followers","following_url":"https://api.github.com/users/apontzen/following{/other_user}","gists_url":"https://api.github.com/users/apontzen/gists{/gist_id}","starred_url":"https://api.github.com/users/apontzen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apontzen/subscriptions","organizations_url":"https://api.github.com/users/apontzen/orgs","repos_url":"https://api.github.com/users/apontzen/repos","events_url":"https://api.github.com/users/apontzen/events{/privacy}","received_events_url":"https://api.github.com/users/apontzen/received_events","type":"User","site_admin":false},"body":"Actually wouldn't it just be neatest to be honest that it's a single operation and have __repr__ return `Sphere(ndarray(...),ndarray(...))` rather than pretend it's a string of operations?","created_at":"2015-02-06T21:04:03Z","updated_at":"2015-02-06T21:04:03Z","html_url":"https://github.com/pynbody/pynbody/pull/236#discussion_r24271898","pull_request_url":"https://api.github.com/repos/pynbody/pynbody/pulls/236","_links":{"self":{"href":"https://api.github.com/repos/pynbody/pynbody/pulls/comments/24271898"},"html":{"href":"https://github.com/pynbody/pynbody/pull/236#discussion_r24271898"},"pull_request":{"href":"https://api.github.com/repos/pynbody/pynbody/pulls/236"}}},"pull_request":{"url":"https://api.github.com/repos/pynbody/pynbody/pulls/236","id":28717541,"html_url":"https://github.com/pynbody/pynbody/pull/236","diff_url":"https://github.com/pynbody/pynbody/pull/236.diff","patch_url":"https://github.com/pynbody/pynbody/pull/236.patch","issue_url":"https://api.github.com/repos/pynbody/pynbody/issues/236","number":236,"state":"open","locked":false,"title":"Speedup sphere selection","user":{"login":"rokroskar","id":3353586,"avatar_url":"https://avatars.githubusercontent.com/u/3353586?v=3","gravatar_id":"","url":"https://api.github.com/users/rokroskar","html_url":"https://github.com/rokroskar","followers_url":"https://api.github.com/users/rokroskar/followers","following_url":"https://api.github.com/users/rokroskar/following{/other_user}","gists_url":"https://api.github.com/users/rokroskar/gists{/gist_id}","starred_url":"https://api.github.com/users/rokroskar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rokroskar/subscriptions","organizations_url":"https://api.github.com/users/rokroskar/orgs","repos_url":"https://api.github.com/users/rokroskar/repos","events_url":"https://api.github.com/users/rokroskar/events{/privacy}","received_events_url":"https://api.github.com/users/rokroskar/received_events","type":"User","site_admin":false},"body":"Stringing together a large number of filters is slow because the loop is over the full output for each filter. This PR modifies the `_sphere_selection` function to take an array of centers and radii and only loops over the full particle array once. \r\n\r\nIt works something like this: \r\n\r\n```\r\ns = pynbody.load(simulation)\r\nfilt = filt = pynbody.filt.Sphere('0.1 kpc', s.s['pos'][:2000])\r\n```\r\n\r\nthis creates a filter that includes all particles within a radius 0.1 kpc around the first 2000 stars. ","created_at":"2015-02-05T11:35:47Z","updated_at":"2015-02-06T21:04:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"afb4268e4ac1cd669e1283fa40413259ccbb5755","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/pynbody/pynbody/pulls/236/commits","review_comments_url":"https://api.github.com/repos/pynbody/pynbody/pulls/236/comments","review_comment_url":"https://api.github.com/repos/pynbody/pynbody/pulls/comments/{number}","comments_url":"https://api.github.com/repos/pynbody/pynbody/issues/236/comments","statuses_url":"https://api.github.com/repos/pynbody/pynbody/statuses/2500e35e352891d006a98104e276b677fa1c94cd","head":{"label":"pynbody:speedup_sphere_selection","ref":"speedup_sphere_selection","sha":"2500e35e352891d006a98104e276b677fa1c94cd","user":{"login":"pynbody","id":4417908,"avatar_url":"https://avatars.githubusercontent.com/u/4417908?v=3","gravatar_id":"","url":"https://api.github.com/users/pynbody","html_url":"https://github.com/pynbody","followers_url":"https://api.github.com/users/pynbody/followers","following_url":"https://api.github.com/users/pynbody/following{/other_user}","gists_url":"https://api.github.com/users/pynbody/gists{/gist_id}","starred_url":"https://api.github.com/users/pynbody/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pynbody/subscriptions","organizations_url":"https://api.github.com/users/pynbody/orgs","repos_url":"https://api.github.com/users/pynbody/repos","events_url":"https://api.github.com/users/pynbody/events{/privacy}","received_events_url":"https://api.github.com/users/pynbody/received_events","type":"Organization","site_admin":false},"repo":{"id":10058773,"name":"pynbody","full_name":"pynbody/pynbody","owner":{"login":"pynbody","id":4417908,"avatar_url":"https://avatars.githubusercontent.com/u/4417908?v=3","gravatar_id":"","url":"https://api.github.com/users/pynbody","html_url":"https://github.com/pynbody","followers_url":"https://api.github.com/users/pynbody/followers","following_url":"https://api.github.com/users/pynbody/following{/other_user}","gists_url":"https://api.github.com/users/pynbody/gists{/gist_id}","starred_url":"https://api.github.com/users/pynbody/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pynbody/subscriptions","organizations_url":"https://api.github.com/users/pynbody/orgs","repos_url":"https://api.github.com/users/pynbody/repos","events_url":"https://api.github.com/users/pynbody/events{/privacy}","received_events_url":"https://api.github.com/users/pynbody/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pynbody/pynbody","description":"N-body and hydro analysis tools for python 2 and 3","fork":false,"url":"https://api.github.com/repos/pynbody/pynbody","forks_url":"https://api.github.com/repos/pynbody/pynbody/forks","keys_url":"https://api.github.com/repos/pynbody/pynbody/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pynbody/pynbody/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pynbody/pynbody/teams","hooks_url":"https://api.github.com/repos/pynbody/pynbody/hooks","issue_events_url":"https://api.github.com/repos/pynbody/pynbody/issues/events{/number}","events_url":"https://api.github.com/repos/pynbody/pynbody/events","assignees_url":"https://api.github.com/repos/pynbody/pynbody/assignees{/user}","branches_url":"https://api.github.com/repos/pynbody/pynbody/branches{/branch}","tags_url":"https://api.github.com/repos/pynbody/pynbody/tags","blobs_url":"https://api.github.com/repos/pynbody/pynbody/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pynbody/pynbody/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pynbody/pynbody/git/refs{/sha}","trees_url":"https://api.github.com/repos/pynbody/pynbody/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pynbody/pynbody/statuses/{sha}","languages_url":"https://api.github.com/repos/pynbody/pynbody/languages","stargazers_url":"https://api.github.com/repos/pynbody/pynbody/stargazers","contributors_url":"https://api.github.com/repos/pynbody/pynbody/contributors","subscribers_url":"https://api.github.com/repos/pynbody/pynbody/subscribers","subscription_url":"https://api.github.com/repos/pynbody/pynbody/subscription","commits_url":"https://api.github.com/repos/pynbody/pynbody/commits{/sha}","git_commits_url":"https://api.github.com/repos/pynbody/pynbody/git/commits{/sha}","comments_url":"https://api.github.com/repos/pynbody/pynbody/comments{/number}","issue_comment_url":"https://api.github.com/repos/pynbody/pynbody/issues/comments/{number}","contents_url":"https://api.github.com/repos/pynbody/pynbody/contents/{+path}","compare_url":"https://api.github.com/repos/pynbody/pynbody/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pynbody/pynbody/merges","archive_url":"https://api.github.com/repos/pynbody/pynbody/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pynbody/pynbody/downloads","issues_url":"https://api.github.com/repos/pynbody/pynbody/issues{/number}","pulls_url":"https://api.github.com/repos/pynbody/pynbody/pulls{/number}","milestones_url":"https://api.github.com/repos/pynbody/pynbody/milestones{/number}","notifications_url":"https://api.github.com/repos/pynbody/pynbody/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pynbody/pynbody/labels{/name}","releases_url":"https://api.github.com/repos/pynbody/pynbody/releases{/id}","created_at":"2013-05-14T15:46:59Z","updated_at":"2015-02-06T11:50:59Z","pushed_at":"2015-02-05T12:57:46Z","git_url":"git://github.com/pynbody/pynbody.git","ssh_url":"git@github.com:pynbody/pynbody.git","clone_url":"https://github.com/pynbody/pynbody.git","svn_url":"https://github.com/pynbody/pynbody","homepage":"http://pynbody.github.io/pynbody/index.html","size":208182,"stargazers_count":31,"watchers_count":31,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":15,"mirror_url":null,"open_issues_count":26,"forks":15,"open_issues":26,"watchers":31,"default_branch":"master"}},"base":{"label":"pynbody:master","ref":"master","sha":"bf2e358a183bf05173e0c1e99a7d05bb38486ca1","user":{"login":"pynbody","id":4417908,"avatar_url":"https://avatars.githubusercontent.com/u/4417908?v=3","gravatar_id":"","url":"https://api.github.com/users/pynbody","html_url":"https://github.com/pynbody","followers_url":"https://api.github.com/users/pynbody/followers","following_url":"https://api.github.com/users/pynbody/following{/other_user}","gists_url":"https://api.github.com/users/pynbody/gists{/gist_id}","starred_url":"https://api.github.com/users/pynbody/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pynbody/subscriptions","organizations_url":"https://api.github.com/users/pynbody/orgs","repos_url":"https://api.github.com/users/pynbody/repos","events_url":"https://api.github.com/users/pynbody/events{/privacy}","received_events_url":"https://api.github.com/users/pynbody/received_events","type":"Organization","site_admin":false},"repo":{"id":10058773,"name":"pynbody","full_name":"pynbody/pynbody","owner":{"login":"pynbody","id":4417908,"avatar_url":"https://avatars.githubusercontent.com/u/4417908?v=3","gravatar_id":"","url":"https://api.github.com/users/pynbody","html_url":"https://github.com/pynbody","followers_url":"https://api.github.com/users/pynbody/followers","following_url":"https://api.github.com/users/pynbody/following{/other_user}","gists_url":"https://api.github.com/users/pynbody/gists{/gist_id}","starred_url":"https://api.github.com/users/pynbody/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pynbody/subscriptions","organizations_url":"https://api.github.com/users/pynbody/orgs","repos_url":"https://api.github.com/users/pynbody/repos","events_url":"https://api.github.com/users/pynbody/events{/privacy}","received_events_url":"https://api.github.com/users/pynbody/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pynbody/pynbody","description":"N-body and hydro analysis tools for python 2 and 3","fork":false,"url":"https://api.github.com/repos/pynbody/pynbody","forks_url":"https://api.github.com/repos/pynbody/pynbody/forks","keys_url":"https://api.github.com/repos/pynbody/pynbody/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pynbody/pynbody/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pynbody/pynbody/teams","hooks_url":"https://api.github.com/repos/pynbody/pynbody/hooks","issue_events_url":"https://api.github.com/repos/pynbody/pynbody/issues/events{/number}","events_url":"https://api.github.com/repos/pynbody/pynbody/events","assignees_url":"https://api.github.com/repos/pynbody/pynbody/assignees{/user}","branches_url":"https://api.github.com/repos/pynbody/pynbody/branches{/branch}","tags_url":"https://api.github.com/repos/pynbody/pynbody/tags","blobs_url":"https://api.github.com/repos/pynbody/pynbody/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pynbody/pynbody/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pynbody/pynbody/git/refs{/sha}","trees_url":"https://api.github.com/repos/pynbody/pynbody/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pynbody/pynbody/statuses/{sha}","languages_url":"https://api.github.com/repos/pynbody/pynbody/languages","stargazers_url":"https://api.github.com/repos/pynbody/pynbody/stargazers","contributors_url":"https://api.github.com/repos/pynbody/pynbody/contributors","subscribers_url":"https://api.github.com/repos/pynbody/pynbody/subscribers","subscription_url":"https://api.github.com/repos/pynbody/pynbody/subscription","commits_url":"https://api.github.com/repos/pynbody/pynbody/commits{/sha}","git_commits_url":"https://api.github.com/repos/pynbody/pynbody/git/commits{/sha}","comments_url":"https://api.github.com/repos/pynbody/pynbody/comments{/number}","issue_comment_url":"https://api.github.com/repos/pynbody/pynbody/issues/comments/{number}","contents_url":"https://api.github.com/repos/pynbody/pynbody/contents/{+path}","compare_url":"https://api.github.com/repos/pynbody/pynbody/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pynbody/pynbody/merges","archive_url":"https://api.github.com/repos/pynbody/pynbody/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pynbody/pynbody/downloads","issues_url":"https://api.github.com/repos/pynbody/pynbody/issues{/number}","pulls_url":"https://api.github.com/repos/pynbody/pynbody/pulls{/number}","milestones_url":"https://api.github.com/repos/pynbody/pynbody/milestones{/number}","notifications_url":"https://api.github.com/repos/pynbody/pynbody/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pynbody/pynbody/labels{/name}","releases_url":"https://api.github.com/repos/pynbody/pynbody/releases{/id}","created_at":"2013-05-14T15:46:59Z","updated_at":"2015-02-06T11:50:59Z","pushed_at":"2015-02-05T12:57:46Z","git_url":"git://github.com/pynbody/pynbody.git","ssh_url":"git@github.com:pynbody/pynbody.git","clone_url":"https://github.com/pynbody/pynbody.git","svn_url":"https://github.com/pynbody/pynbody","homepage":"http://pynbody.github.io/pynbody/index.html","size":208182,"stargazers_count":31,"watchers_count":31,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":15,"mirror_url":null,"open_issues_count":26,"forks":15,"open_issues":26,"watchers":31,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pynbody/pynbody/pulls/236"},"html":{"href":"https://github.com/pynbody/pynbody/pull/236"},"issue":{"href":"https://api.github.com/repos/pynbody/pynbody/issues/236"},"comments":{"href":"https://api.github.com/repos/pynbody/pynbody/issues/236/comments"},"review_comments":{"href":"https://api.github.com/repos/pynbody/pynbody/pulls/236/comments"},"review_comment":{"href":"https://api.github.com/repos/pynbody/pynbody/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/pynbody/pynbody/pulls/236/commits"},"statuses":{"href":"https://api.github.com/repos/pynbody/pynbody/statuses/2500e35e352891d006a98104e276b677fa1c94cd"}}}}