{"action":"created","comment":{"url":"https://api.github.com/repos/hyperion-rt/hyperion/pulls/comments/32497068","id":32497068,"diff_hunk":"@@ -0,0 +1,85 @@\n+.. _voronoi_sampling:\n+\n+=========================\n+Sampling in Voronoi grids\n+=========================\n+\n+In RT computations, the need to uniformly sample points in the cells of a grid often arises. A typical example\n+is that of the evaluation of the average value of a function (e.g., a density function) within a cell.\n+\n+Whereas this task is relatively simple in regular grids, the situation is more complicated in Voronoi grids.\n+Cells in :ref:`Voronoi grids <voronoi_grid>` are indeed convex polyhedra with an arbitrary number of faces,\n+whose shapes and volumes are determined by the intial distribution of sites.\n+\n+The Voronoi helper class in Hyperion contains support for producing a list of sampling points for each cell.\n+This is a simple example of its usage.\n+\n+We first initialise a cubic domain with unitary edge, and we fill it with 1E5 randomly-placed points:\n+\n+>>> import random, numpy as np\n+>>> sites_arr = np.array([(random.uniform(0, 1), random.uniform(0, 1), random.uniform(0, 1)) for i in range(0, 100000)])","path":"docs/advanced/voronoi_sampling.rst","position":20,"original_position":20,"commit_id":"c0e22946be0c81c8d9c9358dc146594ba2d31ad6","original_commit_id":"c0e22946be0c81c8d9c9358dc146594ba2d31ad6","user":{"login":"astrofrog","id":314716,"avatar_url":"https://avatars.githubusercontent.com/u/314716?v=3","gravatar_id":"","url":"https://api.github.com/users/astrofrog","html_url":"https://github.com/astrofrog","followers_url":"https://api.github.com/users/astrofrog/followers","following_url":"https://api.github.com/users/astrofrog/following{/other_user}","gists_url":"https://api.github.com/users/astrofrog/gists{/gist_id}","starred_url":"https://api.github.com/users/astrofrog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/astrofrog/subscriptions","organizations_url":"https://api.github.com/users/astrofrog/orgs","repos_url":"https://api.github.com/users/astrofrog/repos","events_url":"https://api.github.com/users/astrofrog/events{/privacy}","received_events_url":"https://api.github.com/users/astrofrog/received_events","type":"User","site_admin":false},"body":"A clearer way to do this would be:\r\n\r\n```\r\nN = 100000\r\nx = np.random.uniform(N)\r\ny = np.random.uniform(N)\r\nz = np.random.uniform(N)\r\nsites_arr = np.array([x, y, z]).transpose()\r\n```\r\n\r\nMore verbose, but should be *much* faster. You can also then remove the import of the 'random' module.\r\n\r\nA couple of other stylistic points (which you can ignore since they will no longer be relevant with my proposed changes):\r\n\r\n* Only import one package per line (PEP8)\r\n* You don't need the '0' in range since it will default to that, so ``range(100000)`` would give the same","created_at":"2015-06-16T07:36:04Z","updated_at":"2015-06-16T07:36:04Z","html_url":"https://github.com/hyperion-rt/hyperion/pull/134#discussion_r32497068","pull_request_url":"https://api.github.com/repos/hyperion-rt/hyperion/pulls/134","_links":{"self":{"href":"https://api.github.com/repos/hyperion-rt/hyperion/pulls/comments/32497068"},"html":{"href":"https://github.com/hyperion-rt/hyperion/pull/134#discussion_r32497068"},"pull_request":{"href":"https://api.github.com/repos/hyperion-rt/hyperion/pulls/134"}}},"pull_request":{"url":"https://api.github.com/repos/hyperion-rt/hyperion/pulls/134","id":37247969,"html_url":"https://github.com/hyperion-rt/hyperion/pull/134","diff_url":"https://github.com/hyperion-rt/hyperion/pull/134.diff","patch_url":"https://github.com/hyperion-rt/hyperion/pull/134.patch","issue_url":"https://api.github.com/repos/hyperion-rt/hyperion/issues/134","number":134,"state":"open","locked":false,"title":"Sampling","user":{"login":"bluescarni","id":623038,"avatar_url":"https://avatars.githubusercontent.com/u/623038?v=3","gravatar_id":"","url":"https://api.github.com/users/bluescarni","html_url":"https://github.com/bluescarni","followers_url":"https://api.github.com/users/bluescarni/followers","following_url":"https://api.github.com/users/bluescarni/following{/other_user}","gists_url":"https://api.github.com/users/bluescarni/gists{/gist_id}","starred_url":"https://api.github.com/users/bluescarni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bluescarni/subscriptions","organizations_url":"https://api.github.com/users/bluescarni/orgs","repos_url":"https://api.github.com/users/bluescarni/repos","events_url":"https://api.github.com/users/bluescarni/events{/privacy}","received_events_url":"https://api.github.com/users/bluescarni/received_events","type":"User","site_admin":false},"body":"This is the initial implementation of the sampling code. Example usage:\r\n\r\n```\r\ng = vh.voronoi_grid(sites_arr, np.array([[-1, 1.], [-1, 1], [-1, 1]]),verbose=True,n_samples=1000000)\r\n```\r\n\r\nThis will sample at least 1000000 points in the domain. The number of samples for each Voronoi cell is at least 10 and otherwise proportional to the cell volume.\r\n\r\nWhen constructed with a nonzero ``n_samples`` parameter the ``voronoi_grid`` object will expose two properties: ``samples`` and ``samples_idx``. The first one is the list of coordinates of the sampling points, the second one the indices (in sparse format) of the sampling points for each cell.\r\n\r\nExample:\r\n\r\n```\r\n>>> g.samples\r\narray([[ 0.95339842,  0.79318593,  0.24375318],\r\n       [ 0.95099843,  0.77655176,  0.23685462],\r\n       [ 0.95147365,  0.78657782,  0.24113526],\r\n       ..., \r\n       [ 0.50510705,  0.162278  ,  0.45528691],\r\n       [ 0.5166702 ,  0.16003916,  0.46033259],\r\n       [ 0.52101828,  0.14597512,  0.45877929]])\r\n\r\n>>> g.samples_idx\r\narray([      0,      10,      20, ..., 1852917, 1852927, 1852937], dtype=int32)\r\n```\r\n\r\nThis means  that, for the first cell, the sampling points are from index 0 to 10 in the first array, for the second cell from index 10 to 20, etc.","created_at":"2015-06-09T12:33:05Z","updated_at":"2015-06-16T07:36:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ecd82cb835485e3a70b55eed7bd465184e393bf9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/hyperion-rt/hyperion/pulls/134/commits","review_comments_url":"https://api.github.com/repos/hyperion-rt/hyperion/pulls/134/comments","review_comment_url":"https://api.github.com/repos/hyperion-rt/hyperion/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hyperion-rt/hyperion/issues/134/comments","statuses_url":"https://api.github.com/repos/hyperion-rt/hyperion/statuses/c0e22946be0c81c8d9c9358dc146594ba2d31ad6","head":{"label":"bluescarni:sampling","ref":"sampling","sha":"c0e22946be0c81c8d9c9358dc146594ba2d31ad6","user":{"login":"bluescarni","id":623038,"avatar_url":"https://avatars.githubusercontent.com/u/623038?v=3","gravatar_id":"","url":"https://api.github.com/users/bluescarni","html_url":"https://github.com/bluescarni","followers_url":"https://api.github.com/users/bluescarni/followers","following_url":"https://api.github.com/users/bluescarni/following{/other_user}","gists_url":"https://api.github.com/users/bluescarni/gists{/gist_id}","starred_url":"https://api.github.com/users/bluescarni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bluescarni/subscriptions","organizations_url":"https://api.github.com/users/bluescarni/orgs","repos_url":"https://api.github.com/users/bluescarni/repos","events_url":"https://api.github.com/users/bluescarni/events{/privacy}","received_events_url":"https://api.github.com/users/bluescarni/received_events","type":"User","site_admin":false},"repo":{"id":19731801,"name":"hyperion","full_name":"bluescarni/hyperion","owner":{"login":"bluescarni","id":623038,"avatar_url":"https://avatars.githubusercontent.com/u/623038?v=3","gravatar_id":"","url":"https://api.github.com/users/bluescarni","html_url":"https://github.com/bluescarni","followers_url":"https://api.github.com/users/bluescarni/followers","following_url":"https://api.github.com/users/bluescarni/following{/other_user}","gists_url":"https://api.github.com/users/bluescarni/gists{/gist_id}","starred_url":"https://api.github.com/users/bluescarni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bluescarni/subscriptions","organizations_url":"https://api.github.com/users/bluescarni/orgs","repos_url":"https://api.github.com/users/bluescarni/repos","events_url":"https://api.github.com/users/bluescarni/events{/privacy}","received_events_url":"https://api.github.com/users/bluescarni/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bluescarni/hyperion","description":"Hyperion Radiation Transfer Code","fork":true,"url":"https://api.github.com/repos/bluescarni/hyperion","forks_url":"https://api.github.com/repos/bluescarni/hyperion/forks","keys_url":"https://api.github.com/repos/bluescarni/hyperion/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bluescarni/hyperion/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bluescarni/hyperion/teams","hooks_url":"https://api.github.com/repos/bluescarni/hyperion/hooks","issue_events_url":"https://api.github.com/repos/bluescarni/hyperion/issues/events{/number}","events_url":"https://api.github.com/repos/bluescarni/hyperion/events","assignees_url":"https://api.github.com/repos/bluescarni/hyperion/assignees{/user}","branches_url":"https://api.github.com/repos/bluescarni/hyperion/branches{/branch}","tags_url":"https://api.github.com/repos/bluescarni/hyperion/tags","blobs_url":"https://api.github.com/repos/bluescarni/hyperion/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bluescarni/hyperion/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bluescarni/hyperion/git/refs{/sha}","trees_url":"https://api.github.com/repos/bluescarni/hyperion/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bluescarni/hyperion/statuses/{sha}","languages_url":"https://api.github.com/repos/bluescarni/hyperion/languages","stargazers_url":"https://api.github.com/repos/bluescarni/hyperion/stargazers","contributors_url":"https://api.github.com/repos/bluescarni/hyperion/contributors","subscribers_url":"https://api.github.com/repos/bluescarni/hyperion/subscribers","subscription_url":"https://api.github.com/repos/bluescarni/hyperion/subscription","commits_url":"https://api.github.com/repos/bluescarni/hyperion/commits{/sha}","git_commits_url":"https://api.github.com/repos/bluescarni/hyperion/git/commits{/sha}","comments_url":"https://api.github.com/repos/bluescarni/hyperion/comments{/number}","issue_comment_url":"https://api.github.com/repos/bluescarni/hyperion/issues/comments{/number}","contents_url":"https://api.github.com/repos/bluescarni/hyperion/contents/{+path}","compare_url":"https://api.github.com/repos/bluescarni/hyperion/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bluescarni/hyperion/merges","archive_url":"https://api.github.com/repos/bluescarni/hyperion/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bluescarni/hyperion/downloads","issues_url":"https://api.github.com/repos/bluescarni/hyperion/issues{/number}","pulls_url":"https://api.github.com/repos/bluescarni/hyperion/pulls{/number}","milestones_url":"https://api.github.com/repos/bluescarni/hyperion/milestones{/number}","notifications_url":"https://api.github.com/repos/bluescarni/hyperion/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bluescarni/hyperion/labels{/name}","releases_url":"https://api.github.com/repos/bluescarni/hyperion/releases{/id}","created_at":"2014-05-13T08:40:44Z","updated_at":"2014-08-11T10:00:08Z","pushed_at":"2015-06-15T15:07:26Z","git_url":"git://github.com/bluescarni/hyperion.git","ssh_url":"git@github.com:bluescarni/hyperion.git","clone_url":"https://github.com/bluescarni/hyperion.git","svn_url":"https://github.com/bluescarni/hyperion","homepage":"http://www.hyperion-rt.org","size":13906,"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":"hyperion-rt:master","ref":"master","sha":"87e64909eacea51568296c7c1e36513d2c568761","user":{"login":"hyperion-rt","id":2011813,"avatar_url":"https://avatars.githubusercontent.com/u/2011813?v=3","gravatar_id":"","url":"https://api.github.com/users/hyperion-rt","html_url":"https://github.com/hyperion-rt","followers_url":"https://api.github.com/users/hyperion-rt/followers","following_url":"https://api.github.com/users/hyperion-rt/following{/other_user}","gists_url":"https://api.github.com/users/hyperion-rt/gists{/gist_id}","starred_url":"https://api.github.com/users/hyperion-rt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hyperion-rt/subscriptions","organizations_url":"https://api.github.com/users/hyperion-rt/orgs","repos_url":"https://api.github.com/users/hyperion-rt/repos","events_url":"https://api.github.com/users/hyperion-rt/events{/privacy}","received_events_url":"https://api.github.com/users/hyperion-rt/received_events","type":"Organization","site_admin":false},"repo":{"id":1442240,"name":"hyperion","full_name":"hyperion-rt/hyperion","owner":{"login":"hyperion-rt","id":2011813,"avatar_url":"https://avatars.githubusercontent.com/u/2011813?v=3","gravatar_id":"","url":"https://api.github.com/users/hyperion-rt","html_url":"https://github.com/hyperion-rt","followers_url":"https://api.github.com/users/hyperion-rt/followers","following_url":"https://api.github.com/users/hyperion-rt/following{/other_user}","gists_url":"https://api.github.com/users/hyperion-rt/gists{/gist_id}","starred_url":"https://api.github.com/users/hyperion-rt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hyperion-rt/subscriptions","organizations_url":"https://api.github.com/users/hyperion-rt/orgs","repos_url":"https://api.github.com/users/hyperion-rt/repos","events_url":"https://api.github.com/users/hyperion-rt/events{/privacy}","received_events_url":"https://api.github.com/users/hyperion-rt/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hyperion-rt/hyperion","description":"Hyperion Radiation Transfer Code","fork":false,"url":"https://api.github.com/repos/hyperion-rt/hyperion","forks_url":"https://api.github.com/repos/hyperion-rt/hyperion/forks","keys_url":"https://api.github.com/repos/hyperion-rt/hyperion/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hyperion-rt/hyperion/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hyperion-rt/hyperion/teams","hooks_url":"https://api.github.com/repos/hyperion-rt/hyperion/hooks","issue_events_url":"https://api.github.com/repos/hyperion-rt/hyperion/issues/events{/number}","events_url":"https://api.github.com/repos/hyperion-rt/hyperion/events","assignees_url":"https://api.github.com/repos/hyperion-rt/hyperion/assignees{/user}","branches_url":"https://api.github.com/repos/hyperion-rt/hyperion/branches{/branch}","tags_url":"https://api.github.com/repos/hyperion-rt/hyperion/tags","blobs_url":"https://api.github.com/repos/hyperion-rt/hyperion/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hyperion-rt/hyperion/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hyperion-rt/hyperion/git/refs{/sha}","trees_url":"https://api.github.com/repos/hyperion-rt/hyperion/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hyperion-rt/hyperion/statuses/{sha}","languages_url":"https://api.github.com/repos/hyperion-rt/hyperion/languages","stargazers_url":"https://api.github.com/repos/hyperion-rt/hyperion/stargazers","contributors_url":"https://api.github.com/repos/hyperion-rt/hyperion/contributors","subscribers_url":"https://api.github.com/repos/hyperion-rt/hyperion/subscribers","subscription_url":"https://api.github.com/repos/hyperion-rt/hyperion/subscription","commits_url":"https://api.github.com/repos/hyperion-rt/hyperion/commits{/sha}","git_commits_url":"https://api.github.com/repos/hyperion-rt/hyperion/git/commits{/sha}","comments_url":"https://api.github.com/repos/hyperion-rt/hyperion/comments{/number}","issue_comment_url":"https://api.github.com/repos/hyperion-rt/hyperion/issues/comments{/number}","contents_url":"https://api.github.com/repos/hyperion-rt/hyperion/contents/{+path}","compare_url":"https://api.github.com/repos/hyperion-rt/hyperion/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hyperion-rt/hyperion/merges","archive_url":"https://api.github.com/repos/hyperion-rt/hyperion/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hyperion-rt/hyperion/downloads","issues_url":"https://api.github.com/repos/hyperion-rt/hyperion/issues{/number}","pulls_url":"https://api.github.com/repos/hyperion-rt/hyperion/pulls{/number}","milestones_url":"https://api.github.com/repos/hyperion-rt/hyperion/milestones{/number}","notifications_url":"https://api.github.com/repos/hyperion-rt/hyperion/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hyperion-rt/hyperion/labels{/name}","releases_url":"https://api.github.com/repos/hyperion-rt/hyperion/releases{/id}","created_at":"2011-03-05T04:43:44Z","updated_at":"2015-05-06T20:18:29Z","pushed_at":"2015-06-15T15:51:47Z","git_url":"git://github.com/hyperion-rt/hyperion.git","ssh_url":"git@github.com:hyperion-rt/hyperion.git","clone_url":"https://github.com/hyperion-rt/hyperion.git","svn_url":"https://github.com/hyperion-rt/hyperion","homepage":"http://www.hyperion-rt.org","size":14689,"stargazers_count":15,"watchers_count":15,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":13,"mirror_url":null,"open_issues_count":47,"forks":13,"open_issues":47,"watchers":15,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/hyperion-rt/hyperion/pulls/134"},"html":{"href":"https://github.com/hyperion-rt/hyperion/pull/134"},"issue":{"href":"https://api.github.com/repos/hyperion-rt/hyperion/issues/134"},"comments":{"href":"https://api.github.com/repos/hyperion-rt/hyperion/issues/134/comments"},"review_comments":{"href":"https://api.github.com/repos/hyperion-rt/hyperion/pulls/134/comments"},"review_comment":{"href":"https://api.github.com/repos/hyperion-rt/hyperion/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hyperion-rt/hyperion/pulls/134/commits"},"statuses":{"href":"https://api.github.com/repos/hyperion-rt/hyperion/statuses/c0e22946be0c81c8d9c9358dc146594ba2d31ad6"}}}}