{"action":"created","comment":{"url":"https://api.github.com/repos/bokeh/datashader/pulls/comments/63458466","id":63458466,"diff_hunk":"@@ -167,6 +170,61 @@ def line(self, source, x, y, agg=None):\n             agg = any()\n         return bypixel(source, self, Line(x, y), agg)\n \n+    def raster(self,\n+               source,\n+               band=1,\n+               nodata=np.nan,\n+               replace_nodata=None):\n+        \"\"\"Sample a raster dataset by canvas size and bounds. Note: requires\n+        `rasterio` and `scikit-image`.\n+\n+        Parameters\n+        ----------\n+        source : rasterio.Dataset\n+            input datasource most likely obtain from `rasterio.open()`.\n+        band : int\n+            source band number : optional default=1\n+        nodata : number\n+            Value for nodata cells\n+        replace_nodata : number\n+            Replacement value for nodata cells\n+\n+        Returns\n+        _______\n+        data : xarray.Dataset\n+        \"\"\"\n+\n+        try:\n+            import rasterio as rio\n+            from skimage.transform import resize\n+        except ImportError:\n+            raise ImportError('install rasterio and skimage to use this feature')\n+            \n+        xmin = max(self.x_range[0], source.bounds.left)\n+        ymin = max(self.y_range[0], source.bounds.bottom)\n+        xmax = min(self.x_range[1], source.bounds.right)\n+        ymax = min(self.y_range[1], source.bounds.top)\n+        \n+        dx = self.x_range[1] - self.x_range[0]\n+        dy = self.y_range[1] - self.y_range[0]\n+\n+        width_ratio = (xmax - xmin) / dx\n+        height_ratio = (ymax - ymin) / dy\n+\n+        w = int(math.ceil(self.plot_width * width_ratio))\n+        h = int(math.ceil(self.plot_height * height_ratio))\n+\n+        rmin, cmin = source.index(self.x_range[0], self.y_range[0])\n+        rmax, cmax = source.index(self.x_range[1], self.y_range[1])\n+\n+        data = source.read(1, window=((rmax, rmin), (cmin, cmax)))\n+\n+        if replace_nodata:\n+            data[data == nodata] = replace_nodata\n+\n+        data = resize(np.flipud(data), (w, h), preserve_range=True)","path":"datashader/core.py","position":68,"original_position":68,"commit_id":"c489bb81f188b459338f8e5420e0679f45e75ea7","original_commit_id":"c489bb81f188b459338f8e5420e0679f45e75ea7","user":{"login":"jcrist","id":2783717,"avatar_url":"https://avatars.githubusercontent.com/u/2783717?v=3","gravatar_id":"","url":"https://api.github.com/users/jcrist","html_url":"https://github.com/jcrist","followers_url":"https://api.github.com/users/jcrist/followers","following_url":"https://api.github.com/users/jcrist/following{/other_user}","gists_url":"https://api.github.com/users/jcrist/gists{/gist_id}","starred_url":"https://api.github.com/users/jcrist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcrist/subscriptions","organizations_url":"https://api.github.com/users/jcrist/orgs","repos_url":"https://api.github.com/users/jcrist/repos","events_url":"https://api.github.com/users/jcrist/events{/privacy}","received_events_url":"https://api.github.com/users/jcrist/received_events","type":"User","site_admin":false},"body":"I wonder if there's a way to remove the skimage dependency here. Applying a linear scaling to a 2d numpy array (for the small case we need here) may not be that hard to write with just numpy.","created_at":"2016-05-17T02:58:51Z","updated_at":"2016-05-17T02:58:51Z","html_url":"https://github.com/bokeh/datashader/pull/157#discussion_r63458466","pull_request_url":"https://api.github.com/repos/bokeh/datashader/pulls/157","_links":{"self":{"href":"https://api.github.com/repos/bokeh/datashader/pulls/comments/63458466"},"html":{"href":"https://github.com/bokeh/datashader/pull/157#discussion_r63458466"},"pull_request":{"href":"https://api.github.com/repos/bokeh/datashader/pulls/157"}}},"pull_request":{"url":"https://api.github.com/repos/bokeh/datashader/pulls/157","id":70261834,"html_url":"https://github.com/bokeh/datashader/pull/157","diff_url":"https://github.com/bokeh/datashader/pull/157.diff","patch_url":"https://github.com/bokeh/datashader/pull/157.patch","issue_url":"https://api.github.com/repos/bokeh/datashader/issues/157","number":157,"state":"open","locked":false,"title":"added initial support for raster datasets","user":{"login":"brendancol","id":433221,"avatar_url":"https://avatars.githubusercontent.com/u/433221?v=3","gravatar_id":"","url":"https://api.github.com/users/brendancol","html_url":"https://github.com/brendancol","followers_url":"https://api.github.com/users/brendancol/followers","following_url":"https://api.github.com/users/brendancol/following{/other_user}","gists_url":"https://api.github.com/users/brendancol/gists{/gist_id}","starred_url":"https://api.github.com/users/brendancol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brendancol/subscriptions","organizations_url":"https://api.github.com/users/brendancol/orgs","repos_url":"https://api.github.com/users/brendancol/repos","events_url":"https://api.github.com/users/brendancol/events{/privacy}","received_events_url":"https://api.github.com/users/brendancol/received_events","type":"User","site_admin":false},"body":"Adds support for raster dataset through integration with `rasterio`\r\n\r\n- [x] add spelling for `Canvas.raster()`\r\n- [x] add `raster.py` example.  To run example use `bokeh serve raster.py --show`\r\n- [ ] test when example is outside data bounds\r\n- [ ] add tests\r\n\r\nBelow is of raster with `colors.Hot` transfer function:\r\n<img width=\"897\" alt=\"screen shot 2016-05-16 at 4 02 44 pm\" src=\"https://cloud.githubusercontent.com/assets/433221/15303893/d3561dfe-1b7f-11e6-8759-0ea51339e1cc.png\">\r\n","created_at":"2016-05-16T21:08:15Z","updated_at":"2016-05-17T02:58:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"774d372a96c73eaa08746271ddbe5fbc66cab226","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bokeh/datashader/pulls/157/commits","review_comments_url":"https://api.github.com/repos/bokeh/datashader/pulls/157/comments","review_comment_url":"https://api.github.com/repos/bokeh/datashader/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bokeh/datashader/issues/157/comments","statuses_url":"https://api.github.com/repos/bokeh/datashader/statuses/c489bb81f188b459338f8e5420e0679f45e75ea7","head":{"label":"brendancol:add-raster-support","ref":"add-raster-support","sha":"c489bb81f188b459338f8e5420e0679f45e75ea7","user":{"login":"brendancol","id":433221,"avatar_url":"https://avatars.githubusercontent.com/u/433221?v=3","gravatar_id":"","url":"https://api.github.com/users/brendancol","html_url":"https://github.com/brendancol","followers_url":"https://api.github.com/users/brendancol/followers","following_url":"https://api.github.com/users/brendancol/following{/other_user}","gists_url":"https://api.github.com/users/brendancol/gists{/gist_id}","starred_url":"https://api.github.com/users/brendancol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brendancol/subscriptions","organizations_url":"https://api.github.com/users/brendancol/orgs","repos_url":"https://api.github.com/users/brendancol/repos","events_url":"https://api.github.com/users/brendancol/events{/privacy}","received_events_url":"https://api.github.com/users/brendancol/received_events","type":"User","site_admin":false},"repo":{"id":49511925,"name":"datashader","full_name":"brendancol/datashader","owner":{"login":"brendancol","id":433221,"avatar_url":"https://avatars.githubusercontent.com/u/433221?v=3","gravatar_id":"","url":"https://api.github.com/users/brendancol","html_url":"https://github.com/brendancol","followers_url":"https://api.github.com/users/brendancol/followers","following_url":"https://api.github.com/users/brendancol/following{/other_user}","gists_url":"https://api.github.com/users/brendancol/gists{/gist_id}","starred_url":"https://api.github.com/users/brendancol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brendancol/subscriptions","organizations_url":"https://api.github.com/users/brendancol/orgs","repos_url":"https://api.github.com/users/brendancol/repos","events_url":"https://api.github.com/users/brendancol/events{/privacy}","received_events_url":"https://api.github.com/users/brendancol/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/brendancol/datashader","description":"Bin based rendering toolchain","fork":true,"url":"https://api.github.com/repos/brendancol/datashader","forks_url":"https://api.github.com/repos/brendancol/datashader/forks","keys_url":"https://api.github.com/repos/brendancol/datashader/keys{/key_id}","collaborators_url":"https://api.github.com/repos/brendancol/datashader/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/brendancol/datashader/teams","hooks_url":"https://api.github.com/repos/brendancol/datashader/hooks","issue_events_url":"https://api.github.com/repos/brendancol/datashader/issues/events{/number}","events_url":"https://api.github.com/repos/brendancol/datashader/events","assignees_url":"https://api.github.com/repos/brendancol/datashader/assignees{/user}","branches_url":"https://api.github.com/repos/brendancol/datashader/branches{/branch}","tags_url":"https://api.github.com/repos/brendancol/datashader/tags","blobs_url":"https://api.github.com/repos/brendancol/datashader/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/brendancol/datashader/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/brendancol/datashader/git/refs{/sha}","trees_url":"https://api.github.com/repos/brendancol/datashader/git/trees{/sha}","statuses_url":"https://api.github.com/repos/brendancol/datashader/statuses/{sha}","languages_url":"https://api.github.com/repos/brendancol/datashader/languages","stargazers_url":"https://api.github.com/repos/brendancol/datashader/stargazers","contributors_url":"https://api.github.com/repos/brendancol/datashader/contributors","subscribers_url":"https://api.github.com/repos/brendancol/datashader/subscribers","subscription_url":"https://api.github.com/repos/brendancol/datashader/subscription","commits_url":"https://api.github.com/repos/brendancol/datashader/commits{/sha}","git_commits_url":"https://api.github.com/repos/brendancol/datashader/git/commits{/sha}","comments_url":"https://api.github.com/repos/brendancol/datashader/comments{/number}","issue_comment_url":"https://api.github.com/repos/brendancol/datashader/issues/comments{/number}","contents_url":"https://api.github.com/repos/brendancol/datashader/contents/{+path}","compare_url":"https://api.github.com/repos/brendancol/datashader/compare/{base}...{head}","merges_url":"https://api.github.com/repos/brendancol/datashader/merges","archive_url":"https://api.github.com/repos/brendancol/datashader/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/brendancol/datashader/downloads","issues_url":"https://api.github.com/repos/brendancol/datashader/issues{/number}","pulls_url":"https://api.github.com/repos/brendancol/datashader/pulls{/number}","milestones_url":"https://api.github.com/repos/brendancol/datashader/milestones{/number}","notifications_url":"https://api.github.com/repos/brendancol/datashader/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/brendancol/datashader/labels{/name}","releases_url":"https://api.github.com/repos/brendancol/datashader/releases{/id}","deployments_url":"https://api.github.com/repos/brendancol/datashader/deployments","created_at":"2016-01-12T16:10:52Z","updated_at":"2016-01-12T16:10:53Z","pushed_at":"2016-05-16T21:34:34Z","git_url":"git://github.com/brendancol/datashader.git","ssh_url":"git@github.com:brendancol/datashader.git","clone_url":"https://github.com/brendancol/datashader.git","svn_url":"https://github.com/brendancol/datashader","homepage":null,"size":2166,"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":"bokeh:master","ref":"master","sha":"f97b8880195053753ae3c308bf727777417cbca4","user":{"login":"bokeh","id":8440965,"avatar_url":"https://avatars.githubusercontent.com/u/8440965?v=3","gravatar_id":"","url":"https://api.github.com/users/bokeh","html_url":"https://github.com/bokeh","followers_url":"https://api.github.com/users/bokeh/followers","following_url":"https://api.github.com/users/bokeh/following{/other_user}","gists_url":"https://api.github.com/users/bokeh/gists{/gist_id}","starred_url":"https://api.github.com/users/bokeh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bokeh/subscriptions","organizations_url":"https://api.github.com/users/bokeh/orgs","repos_url":"https://api.github.com/users/bokeh/repos","events_url":"https://api.github.com/users/bokeh/events{/privacy}","received_events_url":"https://api.github.com/users/bokeh/received_events","type":"Organization","site_admin":false},"repo":{"id":48504165,"name":"datashader","full_name":"bokeh/datashader","owner":{"login":"bokeh","id":8440965,"avatar_url":"https://avatars.githubusercontent.com/u/8440965?v=3","gravatar_id":"","url":"https://api.github.com/users/bokeh","html_url":"https://github.com/bokeh","followers_url":"https://api.github.com/users/bokeh/followers","following_url":"https://api.github.com/users/bokeh/following{/other_user}","gists_url":"https://api.github.com/users/bokeh/gists{/gist_id}","starred_url":"https://api.github.com/users/bokeh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bokeh/subscriptions","organizations_url":"https://api.github.com/users/bokeh/orgs","repos_url":"https://api.github.com/users/bokeh/repos","events_url":"https://api.github.com/users/bokeh/events{/privacy}","received_events_url":"https://api.github.com/users/bokeh/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bokeh/datashader","description":"Bin based rendering toolchain","fork":false,"url":"https://api.github.com/repos/bokeh/datashader","forks_url":"https://api.github.com/repos/bokeh/datashader/forks","keys_url":"https://api.github.com/repos/bokeh/datashader/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bokeh/datashader/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bokeh/datashader/teams","hooks_url":"https://api.github.com/repos/bokeh/datashader/hooks","issue_events_url":"https://api.github.com/repos/bokeh/datashader/issues/events{/number}","events_url":"https://api.github.com/repos/bokeh/datashader/events","assignees_url":"https://api.github.com/repos/bokeh/datashader/assignees{/user}","branches_url":"https://api.github.com/repos/bokeh/datashader/branches{/branch}","tags_url":"https://api.github.com/repos/bokeh/datashader/tags","blobs_url":"https://api.github.com/repos/bokeh/datashader/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bokeh/datashader/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bokeh/datashader/git/refs{/sha}","trees_url":"https://api.github.com/repos/bokeh/datashader/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bokeh/datashader/statuses/{sha}","languages_url":"https://api.github.com/repos/bokeh/datashader/languages","stargazers_url":"https://api.github.com/repos/bokeh/datashader/stargazers","contributors_url":"https://api.github.com/repos/bokeh/datashader/contributors","subscribers_url":"https://api.github.com/repos/bokeh/datashader/subscribers","subscription_url":"https://api.github.com/repos/bokeh/datashader/subscription","commits_url":"https://api.github.com/repos/bokeh/datashader/commits{/sha}","git_commits_url":"https://api.github.com/repos/bokeh/datashader/git/commits{/sha}","comments_url":"https://api.github.com/repos/bokeh/datashader/comments{/number}","issue_comment_url":"https://api.github.com/repos/bokeh/datashader/issues/comments{/number}","contents_url":"https://api.github.com/repos/bokeh/datashader/contents/{+path}","compare_url":"https://api.github.com/repos/bokeh/datashader/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bokeh/datashader/merges","archive_url":"https://api.github.com/repos/bokeh/datashader/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bokeh/datashader/downloads","issues_url":"https://api.github.com/repos/bokeh/datashader/issues{/number}","pulls_url":"https://api.github.com/repos/bokeh/datashader/pulls{/number}","milestones_url":"https://api.github.com/repos/bokeh/datashader/milestones{/number}","notifications_url":"https://api.github.com/repos/bokeh/datashader/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bokeh/datashader/labels{/name}","releases_url":"https://api.github.com/repos/bokeh/datashader/releases{/id}","deployments_url":"https://api.github.com/repos/bokeh/datashader/deployments","created_at":"2015-12-23T18:02:20Z","updated_at":"2016-05-13T08:57:58Z","pushed_at":"2016-05-16T21:34:35Z","git_url":"git://github.com/bokeh/datashader.git","ssh_url":"git@github.com:bokeh/datashader.git","clone_url":"https://github.com/bokeh/datashader.git","svn_url":"https://github.com/bokeh/datashader","homepage":"http://datashader.readthedocs.org/en/latest/","size":3048,"stargazers_count":116,"watchers_count":116,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":26,"mirror_url":null,"open_issues_count":35,"forks":26,"open_issues":35,"watchers":116,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bokeh/datashader/pulls/157"},"html":{"href":"https://github.com/bokeh/datashader/pull/157"},"issue":{"href":"https://api.github.com/repos/bokeh/datashader/issues/157"},"comments":{"href":"https://api.github.com/repos/bokeh/datashader/issues/157/comments"},"review_comments":{"href":"https://api.github.com/repos/bokeh/datashader/pulls/157/comments"},"review_comment":{"href":"https://api.github.com/repos/bokeh/datashader/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bokeh/datashader/pulls/157/commits"},"statuses":{"href":"https://api.github.com/repos/bokeh/datashader/statuses/c489bb81f188b459338f8e5420e0679f45e75ea7"}}}}