{"action":"created","comment":{"url":"https://api.github.com/repos/desihub/desitarget/pulls/comments/89258640","pull_request_review_id":9804526,"id":89258640,"diff_hunk":"@@ -213,25 +273,60 @@ def ndens_select(data, source_name, **kwargs):\n     else:\n         in_z = z>0.0\n \n-    try:\n-        bounds = kwargs['min_ra'], kwargs['max_ra'], kwargs['min_dec'], kwargs['max_dec']\n-        mock_dens = estimate_density(ra[in_z], dec[in_z], bounds=bounds)\n-    except KeyError:\n-        mock_dens = estimate_density(ra[in_z], dec[in_z])\n-\n-    frac_keep = min(kwargs['number_density']/mock_dens , 1.0)\n-    if mock_dens < kwargs['number_density']:\n-        print(\"WARNING: mock cannot achieve the goal density for source {} Goal {}. Mock {}\".format(source_name, kwargs['number_density'], mock_dens))\n-\n-\n     n = len(ra)\n-    keepornot = np.random.uniform(0.,1.,n)\n-    limit = np.zeros(n) + frac_keep\n-    kept = keepornot < limit\n-    select_sample = (in_z) & (kept)\n \n+    limit = np.zeros(n) \n     target_class = np.zeros(n,dtype=np.int64) - 1\n-    target_class[select_sample] = desi_mask.mask(source_name)\n+    keepornot = np.random.uniform(0.,1.,n)\n+\n+    if density_fluctuations:\n+        bricks = desispec.brick.brickname(ra, dec)\n+        unique_bricks = list(set(bricks))\n+    \n+        for brickname in unique_bricks:\n+            in_brick = (brickname == bricks)\n+            n_in_brick = np.count_nonzero(in_brick)\n+   #         print('brickname {} len {}'.format(brickname, n_in_brick))\n+        \n+            #locate the brick info we need\n+            id_binfo  = np.where(brick_info['BRICKNAME'] == brickname)\n+            id_binfo = id_binfo[0]\n+\n+            if len(id_binfo) != 1:\n+                num_density = 0.0\n+                brick_area = 0.25\n+                warnings.warn(\"Tile is on the border. NumDensity= 0.0\", RuntimeWarning)\n+            else:\n+                brick_area = brick_info['BRICKAREA'][id_binfo]\n+                num_density = brick_info['FLUC_EBV'][sourcename][id_binfo]  * brick_info['NTARGET_'+sourcename] \n+                \n+                \n+            mock_dens = n_in_brick/brick_area\n+                \n+            frac_keep = num_density/mock_dens\n+  #          print('num density desired {}, num density in mock {}, frac_keep {}'.format(num_density, mock_dens, frac_keep))\n+            \n+            kept = keepornot < (limit + frac_keep)","path":"py/desitarget/mock/selection.py","position":211,"original_position":211,"commit_id":"ad951f3b083fd66680fa59711d0fee1fdcfcdbe3","original_commit_id":"ad951f3b083fd66680fa59711d0fee1fdcfcdbe3","user":{"login":"sbailey","id":218471,"avatar_url":"https://avatars.githubusercontent.com/u/218471?v=3","gravatar_id":"","url":"https://api.github.com/users/sbailey","html_url":"https://github.com/sbailey","followers_url":"https://api.github.com/users/sbailey/followers","following_url":"https://api.github.com/users/sbailey/following{/other_user}","gists_url":"https://api.github.com/users/sbailey/gists{/gist_id}","starred_url":"https://api.github.com/users/sbailey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sbailey/subscriptions","organizations_url":"https://api.github.com/users/sbailey/orgs","repos_url":"https://api.github.com/users/sbailey/repos","events_url":"https://api.github.com/users/sbailey/events{/privacy}","received_events_url":"https://api.github.com/users/sbailey/received_events","type":"User","site_admin":false},"body":"Since `limit` is just an array of zeros, I don't think it is needed here, and you could just use `kept = keepornot < frac_keep`.  It should be ok to do the boolean comparison between an array (`keepornot`) and a scalar (`frac_keep`).","created_at":"2016-11-23T05:36:28Z","updated_at":"2016-11-23T05:50:34Z","html_url":"https://github.com/desihub/desitarget/pull/122#discussion_r89258640","pull_request_url":"https://api.github.com/repos/desihub/desitarget/pulls/122","_links":{"self":{"href":"https://api.github.com/repos/desihub/desitarget/pulls/comments/89258640"},"html":{"href":"https://github.com/desihub/desitarget/pull/122#discussion_r89258640"},"pull_request":{"href":"https://api.github.com/repos/desihub/desitarget/pulls/122"}}},"pull_request":{"url":"https://api.github.com/repos/desihub/desitarget/pulls/122","id":94933171,"html_url":"https://github.com/desihub/desitarget/pull/122","diff_url":"https://github.com/desihub/desitarget/pull/122.diff","patch_url":"https://github.com/desihub/desitarget/pull/122.patch","issue_url":"https://api.github.com/repos/desihub/desitarget/issues/122","number":122,"state":"open","locked":false,"title":"Mock density fluctuations","user":{"login":"forero","id":1848618,"avatar_url":"https://avatars.githubusercontent.com/u/1848618?v=3","gravatar_id":"","url":"https://api.github.com/users/forero","html_url":"https://github.com/forero","followers_url":"https://api.github.com/users/forero/followers","following_url":"https://api.github.com/users/forero/following{/other_user}","gists_url":"https://api.github.com/users/forero/gists{/gist_id}","starred_url":"https://api.github.com/users/forero/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/forero/subscriptions","organizations_url":"https://api.github.com/users/forero/orgs","repos_url":"https://api.github.com/users/forero/repos","events_url":"https://api.github.com/users/forero/events{/privacy}","received_events_url":"https://api.github.com/users/forero/received_events","type":"User","site_admin":false},"body":"Introduces density fluctuations in mock files. The fluctuations are based on DECaLS DR3.\r\nSolves #104 and #101.","created_at":"2016-11-23T01:56:31Z","updated_at":"2016-11-23T05:50:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ae065d3728975e8b376d83c65b4c47e3300ddc4c","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/desihub/desitarget/pulls/122/commits","review_comments_url":"https://api.github.com/repos/desihub/desitarget/pulls/122/comments","review_comment_url":"https://api.github.com/repos/desihub/desitarget/pulls/comments{/number}","comments_url":"https://api.github.com/repos/desihub/desitarget/issues/122/comments","statuses_url":"https://api.github.com/repos/desihub/desitarget/statuses/ad951f3b083fd66680fa59711d0fee1fdcfcdbe3","head":{"label":"desihub:mock_density_fluctuations","ref":"mock_density_fluctuations","sha":"ad951f3b083fd66680fa59711d0fee1fdcfcdbe3","user":{"login":"desihub","id":9540621,"avatar_url":"https://avatars.githubusercontent.com/u/9540621?v=3","gravatar_id":"","url":"https://api.github.com/users/desihub","html_url":"https://github.com/desihub","followers_url":"https://api.github.com/users/desihub/followers","following_url":"https://api.github.com/users/desihub/following{/other_user}","gists_url":"https://api.github.com/users/desihub/gists{/gist_id}","starred_url":"https://api.github.com/users/desihub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/desihub/subscriptions","organizations_url":"https://api.github.com/users/desihub/orgs","repos_url":"https://api.github.com/users/desihub/repos","events_url":"https://api.github.com/users/desihub/events{/privacy}","received_events_url":"https://api.github.com/users/desihub/received_events","type":"Organization","site_admin":false},"repo":{"id":31446151,"name":"desitarget","full_name":"desihub/desitarget","owner":{"login":"desihub","id":9540621,"avatar_url":"https://avatars.githubusercontent.com/u/9540621?v=3","gravatar_id":"","url":"https://api.github.com/users/desihub","html_url":"https://github.com/desihub","followers_url":"https://api.github.com/users/desihub/followers","following_url":"https://api.github.com/users/desihub/following{/other_user}","gists_url":"https://api.github.com/users/desihub/gists{/gist_id}","starred_url":"https://api.github.com/users/desihub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/desihub/subscriptions","organizations_url":"https://api.github.com/users/desihub/orgs","repos_url":"https://api.github.com/users/desihub/repos","events_url":"https://api.github.com/users/desihub/events{/privacy}","received_events_url":"https://api.github.com/users/desihub/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/desihub/desitarget","description":"DESI Targeting","fork":false,"url":"https://api.github.com/repos/desihub/desitarget","forks_url":"https://api.github.com/repos/desihub/desitarget/forks","keys_url":"https://api.github.com/repos/desihub/desitarget/keys{/key_id}","collaborators_url":"https://api.github.com/repos/desihub/desitarget/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/desihub/desitarget/teams","hooks_url":"https://api.github.com/repos/desihub/desitarget/hooks","issue_events_url":"https://api.github.com/repos/desihub/desitarget/issues/events{/number}","events_url":"https://api.github.com/repos/desihub/desitarget/events","assignees_url":"https://api.github.com/repos/desihub/desitarget/assignees{/user}","branches_url":"https://api.github.com/repos/desihub/desitarget/branches{/branch}","tags_url":"https://api.github.com/repos/desihub/desitarget/tags","blobs_url":"https://api.github.com/repos/desihub/desitarget/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/desihub/desitarget/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/desihub/desitarget/git/refs{/sha}","trees_url":"https://api.github.com/repos/desihub/desitarget/git/trees{/sha}","statuses_url":"https://api.github.com/repos/desihub/desitarget/statuses/{sha}","languages_url":"https://api.github.com/repos/desihub/desitarget/languages","stargazers_url":"https://api.github.com/repos/desihub/desitarget/stargazers","contributors_url":"https://api.github.com/repos/desihub/desitarget/contributors","subscribers_url":"https://api.github.com/repos/desihub/desitarget/subscribers","subscription_url":"https://api.github.com/repos/desihub/desitarget/subscription","commits_url":"https://api.github.com/repos/desihub/desitarget/commits{/sha}","git_commits_url":"https://api.github.com/repos/desihub/desitarget/git/commits{/sha}","comments_url":"https://api.github.com/repos/desihub/desitarget/comments{/number}","issue_comment_url":"https://api.github.com/repos/desihub/desitarget/issues/comments{/number}","contents_url":"https://api.github.com/repos/desihub/desitarget/contents/{+path}","compare_url":"https://api.github.com/repos/desihub/desitarget/compare/{base}...{head}","merges_url":"https://api.github.com/repos/desihub/desitarget/merges","archive_url":"https://api.github.com/repos/desihub/desitarget/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/desihub/desitarget/downloads","issues_url":"https://api.github.com/repos/desihub/desitarget/issues{/number}","pulls_url":"https://api.github.com/repos/desihub/desitarget/pulls{/number}","milestones_url":"https://api.github.com/repos/desihub/desitarget/milestones{/number}","notifications_url":"https://api.github.com/repos/desihub/desitarget/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/desihub/desitarget/labels{/name}","releases_url":"https://api.github.com/repos/desihub/desitarget/releases{/id}","deployments_url":"https://api.github.com/repos/desihub/desitarget/deployments","created_at":"2015-02-28T01:05:54Z","updated_at":"2016-10-24T17:09:51Z","pushed_at":"2016-11-23T02:03:06Z","git_url":"git://github.com/desihub/desitarget.git","ssh_url":"git@github.com:desihub/desitarget.git","clone_url":"https://github.com/desihub/desitarget.git","svn_url":"https://github.com/desihub/desitarget","homepage":"","size":41462,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":22,"forks":6,"open_issues":22,"watchers":1,"default_branch":"master"}},"base":{"label":"desihub:master","ref":"master","sha":"30e6438792a45fd25851d39afea2189d75dc3ee1","user":{"login":"desihub","id":9540621,"avatar_url":"https://avatars.githubusercontent.com/u/9540621?v=3","gravatar_id":"","url":"https://api.github.com/users/desihub","html_url":"https://github.com/desihub","followers_url":"https://api.github.com/users/desihub/followers","following_url":"https://api.github.com/users/desihub/following{/other_user}","gists_url":"https://api.github.com/users/desihub/gists{/gist_id}","starred_url":"https://api.github.com/users/desihub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/desihub/subscriptions","organizations_url":"https://api.github.com/users/desihub/orgs","repos_url":"https://api.github.com/users/desihub/repos","events_url":"https://api.github.com/users/desihub/events{/privacy}","received_events_url":"https://api.github.com/users/desihub/received_events","type":"Organization","site_admin":false},"repo":{"id":31446151,"name":"desitarget","full_name":"desihub/desitarget","owner":{"login":"desihub","id":9540621,"avatar_url":"https://avatars.githubusercontent.com/u/9540621?v=3","gravatar_id":"","url":"https://api.github.com/users/desihub","html_url":"https://github.com/desihub","followers_url":"https://api.github.com/users/desihub/followers","following_url":"https://api.github.com/users/desihub/following{/other_user}","gists_url":"https://api.github.com/users/desihub/gists{/gist_id}","starred_url":"https://api.github.com/users/desihub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/desihub/subscriptions","organizations_url":"https://api.github.com/users/desihub/orgs","repos_url":"https://api.github.com/users/desihub/repos","events_url":"https://api.github.com/users/desihub/events{/privacy}","received_events_url":"https://api.github.com/users/desihub/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/desihub/desitarget","description":"DESI Targeting","fork":false,"url":"https://api.github.com/repos/desihub/desitarget","forks_url":"https://api.github.com/repos/desihub/desitarget/forks","keys_url":"https://api.github.com/repos/desihub/desitarget/keys{/key_id}","collaborators_url":"https://api.github.com/repos/desihub/desitarget/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/desihub/desitarget/teams","hooks_url":"https://api.github.com/repos/desihub/desitarget/hooks","issue_events_url":"https://api.github.com/repos/desihub/desitarget/issues/events{/number}","events_url":"https://api.github.com/repos/desihub/desitarget/events","assignees_url":"https://api.github.com/repos/desihub/desitarget/assignees{/user}","branches_url":"https://api.github.com/repos/desihub/desitarget/branches{/branch}","tags_url":"https://api.github.com/repos/desihub/desitarget/tags","blobs_url":"https://api.github.com/repos/desihub/desitarget/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/desihub/desitarget/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/desihub/desitarget/git/refs{/sha}","trees_url":"https://api.github.com/repos/desihub/desitarget/git/trees{/sha}","statuses_url":"https://api.github.com/repos/desihub/desitarget/statuses/{sha}","languages_url":"https://api.github.com/repos/desihub/desitarget/languages","stargazers_url":"https://api.github.com/repos/desihub/desitarget/stargazers","contributors_url":"https://api.github.com/repos/desihub/desitarget/contributors","subscribers_url":"https://api.github.com/repos/desihub/desitarget/subscribers","subscription_url":"https://api.github.com/repos/desihub/desitarget/subscription","commits_url":"https://api.github.com/repos/desihub/desitarget/commits{/sha}","git_commits_url":"https://api.github.com/repos/desihub/desitarget/git/commits{/sha}","comments_url":"https://api.github.com/repos/desihub/desitarget/comments{/number}","issue_comment_url":"https://api.github.com/repos/desihub/desitarget/issues/comments{/number}","contents_url":"https://api.github.com/repos/desihub/desitarget/contents/{+path}","compare_url":"https://api.github.com/repos/desihub/desitarget/compare/{base}...{head}","merges_url":"https://api.github.com/repos/desihub/desitarget/merges","archive_url":"https://api.github.com/repos/desihub/desitarget/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/desihub/desitarget/downloads","issues_url":"https://api.github.com/repos/desihub/desitarget/issues{/number}","pulls_url":"https://api.github.com/repos/desihub/desitarget/pulls{/number}","milestones_url":"https://api.github.com/repos/desihub/desitarget/milestones{/number}","notifications_url":"https://api.github.com/repos/desihub/desitarget/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/desihub/desitarget/labels{/name}","releases_url":"https://api.github.com/repos/desihub/desitarget/releases{/id}","deployments_url":"https://api.github.com/repos/desihub/desitarget/deployments","created_at":"2015-02-28T01:05:54Z","updated_at":"2016-10-24T17:09:51Z","pushed_at":"2016-11-23T02:03:06Z","git_url":"git://github.com/desihub/desitarget.git","ssh_url":"git@github.com:desihub/desitarget.git","clone_url":"https://github.com/desihub/desitarget.git","svn_url":"https://github.com/desihub/desitarget","homepage":"","size":41462,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":22,"forks":6,"open_issues":22,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/desihub/desitarget/pulls/122"},"html":{"href":"https://github.com/desihub/desitarget/pull/122"},"issue":{"href":"https://api.github.com/repos/desihub/desitarget/issues/122"},"comments":{"href":"https://api.github.com/repos/desihub/desitarget/issues/122/comments"},"review_comments":{"href":"https://api.github.com/repos/desihub/desitarget/pulls/122/comments"},"review_comment":{"href":"https://api.github.com/repos/desihub/desitarget/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/desihub/desitarget/pulls/122/commits"},"statuses":{"href":"https://api.github.com/repos/desihub/desitarget/statuses/ad951f3b083fd66680fa59711d0fee1fdcfcdbe3"}}}}
{"actor":{"display_login":"sbailey"}}