{"action":"created","comment":{"url":"https://api.github.com/repos/gammapy/gammapy/pulls/comments/72612293","id":72612293,"diff_hunk":"@@ -444,27 +447,124 @@ def pad(self, mode, pad_to_factor=None, pad_width=None, **kwargs):\n         >>> image2.data.shape\n         (16, 12)\n         \"\"\"\n-        if pad_to_factor is not None and pad_width is not None:\n-            raise ValueError('Indicate only one parameter: '\n-                             'either \"pad_width\" or \"pad_to_factor\"')\n-        if pad_to_factor is None and pad_width is None:\n+        # converting from unicode to ascii string as a workaround\n+        # for https://github.com/numpy/numpy/issues/7112\n+        mode = str(mode)\n+        wcs = self.wcs.deepcopy()\n+\n+        args_none = np.array([_ is None for _ in [pad_width, pad_to_factor, shape]])\n+\n+        if args_none.all():\n             raise ValueError('One parameter must be indicated: '\n-                             'either \"pad_width\" or \"pad_to_factor\"')\n+                             'either \"pad_width\", \"pad_to_factor\" or \"shape\"')\n+        if args_none.sum() < 2:\n+            raise ValueError('Indicate only one parameter: '\n+                             'either \"pad_width\", \"pad_to_factor\" or \"shape\"')\n \n         if pad_to_factor is not None:\n             pad_width = pad_to_factor - (np.array(self.data.shape) % pad_to_factor)\n             pad_width = [(0, pad_width[0]), (0, pad_width[1])]\n \n-        # converting from unicode to ascii string as a workaround\n-        # for https://github.com/numpy/numpy/issues/7112\n-        mode = str(mode)\n+        if shape is not None:\n+            xdiff = shape[1] - self.data.shape[1]\n+            ydiff = shape[0] - self.data.shape[0]\n+\n+            if (np.array([xdiff, ydiff]) % 2).any():\n+                raise ValueError('For symmetric padding, difference to new shape '\n+                                 'must be even in all axes.')\n+\n+            xpad, ypad = xdiff // 2, ydiff // 2\n+            pad_width = ((ypad, ypad), (xpad, xpad))\n+            wcs.wcs.crpix += np.array([xpad, ypad])\n \n         data = np.pad(self.data, pad_width=pad_width, mode=mode, **kwargs)\n+        return SkyImage(data=data, wcs=wcs)\n+\n+    def crop(self, shape=None):\n+        \"\"\"\n+        Crop sky image symmetrically to a given shape.\n+\n+        Paramters\n+        ---------\n+        shape : tuple\n+            Desired shape.\n+        \"\"\"\n+        xdiff = (self.data.shape[1] - shape[1])\n+        ydiff = (self.data.shape[0] - shape[0])\n+\n+        if (np.array([xdiff, ydiff]) % 2).any():\n+            raise ValueError('For symmetric cropping, difference to new shape '\n+                             'must be even in all axes.')\n+\n+        x_crop = xdiff // 2\n+        y_crop = ydiff // 2\n+        data = self.data[y_crop:-y_crop, x_crop:-x_crop]\n+\n+        wcs = self.wcs.deepcopy()\n+        wcs.wcs.crpix -= np.array([x_crop, y_crop])\n+        return SkyImage(data=data, wcs=wcs)\n+\n+    def downsample(self, factor, method=np.nansum):\n+        \"\"\"\n+        Down sample image by a given factor.\n+\n+        The image is down sampled using `skimage.measure.block_reduce`. If the\n+        shape of the data is not divisible by the down sampling factor, the image\n+        must be padded beforehand to the correct shape.\n \n-        # We don't have to adjust WCS here, because we only pad on the\n-        # right and top, and for this change, the CRPIX doesn't change.\n+        Parameters\n+        ----------\n+        factor : int\n+            Down sampling factor, must be power of two.\n+        method : np.ufunc (np.nansum), optional\n+            Method how to combine the image blocks.\n+\n+        Returns\n+        -------\n+        image : `SkyImage`\n+            Down sampled image.\n+        \"\"\"\n+        from skimage.measure import block_reduce\n+\n+        shape = self.data.shape\n+        factor = int(factor)","path":"gammapy/image/core.py","position":142,"original_position":142,"commit_id":"a8dfca542a3c1c99474d67bcc6f7d84f419ad1b7","original_commit_id":"a8dfca542a3c1c99474d67bcc6f7d84f419ad1b7","user":{"login":"cdeil","id":852409,"avatar_url":"https://avatars.githubusercontent.com/u/852409?v=3","gravatar_id":"","url":"https://api.github.com/users/cdeil","html_url":"https://github.com/cdeil","followers_url":"https://api.github.com/users/cdeil/followers","following_url":"https://api.github.com/users/cdeil/following{/other_user}","gists_url":"https://api.github.com/users/cdeil/gists{/gist_id}","starred_url":"https://api.github.com/users/cdeil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cdeil/subscriptions","organizations_url":"https://api.github.com/users/cdeil/orgs","repos_url":"https://api.github.com/users/cdeil/repos","events_url":"https://api.github.com/users/cdeil/events{/privacy}","received_events_url":"https://api.github.com/users/cdeil/received_events","type":"User","site_admin":false},"body":"The doc says `factor` has to be int.\r\nI'm -1 an auto-truncating floats by calling `factor = int(factor)` here.\r\nEither remove this line, expecting the user to follow the docs.\r\nOr if you want to ensure int, instead of silently truncating, I'd suggest throwing an error if the input isn't an int.","created_at":"2016-07-28T12:30:37Z","updated_at":"2016-07-28T12:30:37Z","html_url":"https://github.com/gammapy/gammapy/pull/653#discussion_r72612293","pull_request_url":"https://api.github.com/repos/gammapy/gammapy/pulls/653","_links":{"self":{"href":"https://api.github.com/repos/gammapy/gammapy/pulls/comments/72612293"},"html":{"href":"https://github.com/gammapy/gammapy/pull/653#discussion_r72612293"},"pull_request":{"href":"https://api.github.com/repos/gammapy/gammapy/pulls/653"}}},"pull_request":{"url":"https://api.github.com/repos/gammapy/gammapy/pulls/653","id":79183195,"html_url":"https://github.com/gammapy/gammapy/pull/653","diff_url":"https://github.com/gammapy/gammapy/pull/653.diff","patch_url":"https://github.com/gammapy/gammapy/pull/653.patch","issue_url":"https://api.github.com/repos/gammapy/gammapy/issues/653","number":653,"state":"open","locked":false,"title":"Add up- and downsampling to SkyImage","user":{"login":"adonath","id":3715928,"avatar_url":"https://avatars.githubusercontent.com/u/3715928?v=3","gravatar_id":"","url":"https://api.github.com/users/adonath","html_url":"https://github.com/adonath","followers_url":"https://api.github.com/users/adonath/followers","following_url":"https://api.github.com/users/adonath/following{/other_user}","gists_url":"https://api.github.com/users/adonath/gists{/gist_id}","starred_url":"https://api.github.com/users/adonath/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adonath/subscriptions","organizations_url":"https://api.github.com/users/adonath/orgs","repos_url":"https://api.github.com/users/adonath/repos","events_url":"https://api.github.com/users/adonath/events{/privacy}","received_events_url":"https://api.github.com/users/adonath/received_events","type":"User","site_admin":false},"body":"This PR adds the up- and downsampling to `SkyImage` and makes the following related changes:\r\n\r\n* Add `SkyImage.upsample()` and `SkyImage.downsample()` methods and tests\r\n* Modify `SkyImage.pad()` to take an additional `shape` parameter and recompute the wcs specs.\r\n* Add a `SkyImage.crop()` method to crop a skyimage and recompute the wcs specs.\r\n* Make `compute_ts_map` and `compute_ts_map_multiscale` work with `SkyImage` and `SkyImageCollection`","created_at":"2016-07-28T11:58:42Z","updated_at":"2016-07-28T12:30:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3d5ff73ec4788f4c8b10fdc3e63200c30ab963fd","assignee":{"login":"cdeil","id":852409,"avatar_url":"https://avatars.githubusercontent.com/u/852409?v=3","gravatar_id":"","url":"https://api.github.com/users/cdeil","html_url":"https://github.com/cdeil","followers_url":"https://api.github.com/users/cdeil/followers","following_url":"https://api.github.com/users/cdeil/following{/other_user}","gists_url":"https://api.github.com/users/cdeil/gists{/gist_id}","starred_url":"https://api.github.com/users/cdeil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cdeil/subscriptions","organizations_url":"https://api.github.com/users/cdeil/orgs","repos_url":"https://api.github.com/users/cdeil/repos","events_url":"https://api.github.com/users/cdeil/events{/privacy}","received_events_url":"https://api.github.com/users/cdeil/received_events","type":"User","site_admin":false},"assignees":[{"login":"cdeil","id":852409,"avatar_url":"https://avatars.githubusercontent.com/u/852409?v=3","gravatar_id":"","url":"https://api.github.com/users/cdeil","html_url":"https://github.com/cdeil","followers_url":"https://api.github.com/users/cdeil/followers","following_url":"https://api.github.com/users/cdeil/following{/other_user}","gists_url":"https://api.github.com/users/cdeil/gists{/gist_id}","starred_url":"https://api.github.com/users/cdeil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cdeil/subscriptions","organizations_url":"https://api.github.com/users/cdeil/orgs","repos_url":"https://api.github.com/users/cdeil/repos","events_url":"https://api.github.com/users/cdeil/events{/privacy}","received_events_url":"https://api.github.com/users/cdeil/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/gammapy/gammapy/milestones/7","html_url":"https://github.com/gammapy/gammapy/milestones/0.5","labels_url":"https://api.github.com/repos/gammapy/gammapy/milestones/7/labels","id":1275561,"number":7,"title":"0.5","description":"","creator":{"login":"cdeil","id":852409,"avatar_url":"https://avatars.githubusercontent.com/u/852409?v=3","gravatar_id":"","url":"https://api.github.com/users/cdeil","html_url":"https://github.com/cdeil","followers_url":"https://api.github.com/users/cdeil/followers","following_url":"https://api.github.com/users/cdeil/following{/other_user}","gists_url":"https://api.github.com/users/cdeil/gists{/gist_id}","starred_url":"https://api.github.com/users/cdeil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cdeil/subscriptions","organizations_url":"https://api.github.com/users/cdeil/orgs","repos_url":"https://api.github.com/users/cdeil/repos","events_url":"https://api.github.com/users/cdeil/events{/privacy}","received_events_url":"https://api.github.com/users/cdeil/received_events","type":"User","site_admin":false},"open_issues":14,"closed_issues":109,"state":"open","created_at":"2015-08-27T09:29:48Z","updated_at":"2016-07-28T12:22:55Z","due_on":"2016-07-21T22:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/gammapy/gammapy/pulls/653/commits","review_comments_url":"https://api.github.com/repos/gammapy/gammapy/pulls/653/comments","review_comment_url":"https://api.github.com/repos/gammapy/gammapy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/gammapy/gammapy/issues/653/comments","statuses_url":"https://api.github.com/repos/gammapy/gammapy/statuses/a8dfca542a3c1c99474d67bcc6f7d84f419ad1b7","head":{"label":"adonath:skyimage_up_and_downsampling","ref":"skyimage_up_and_downsampling","sha":"a8dfca542a3c1c99474d67bcc6f7d84f419ad1b7","user":{"login":"adonath","id":3715928,"avatar_url":"https://avatars.githubusercontent.com/u/3715928?v=3","gravatar_id":"","url":"https://api.github.com/users/adonath","html_url":"https://github.com/adonath","followers_url":"https://api.github.com/users/adonath/followers","following_url":"https://api.github.com/users/adonath/following{/other_user}","gists_url":"https://api.github.com/users/adonath/gists{/gist_id}","starred_url":"https://api.github.com/users/adonath/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adonath/subscriptions","organizations_url":"https://api.github.com/users/adonath/orgs","repos_url":"https://api.github.com/users/adonath/repos","events_url":"https://api.github.com/users/adonath/events{/privacy}","received_events_url":"https://api.github.com/users/adonath/received_events","type":"User","site_admin":false},"repo":{"id":10124106,"name":"gammapy","full_name":"adonath/gammapy","owner":{"login":"adonath","id":3715928,"avatar_url":"https://avatars.githubusercontent.com/u/3715928?v=3","gravatar_id":"","url":"https://api.github.com/users/adonath","html_url":"https://github.com/adonath","followers_url":"https://api.github.com/users/adonath/followers","following_url":"https://api.github.com/users/adonath/following{/other_user}","gists_url":"https://api.github.com/users/adonath/gists{/gist_id}","starred_url":"https://api.github.com/users/adonath/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adonath/subscriptions","organizations_url":"https://api.github.com/users/adonath/orgs","repos_url":"https://api.github.com/users/adonath/repos","events_url":"https://api.github.com/users/adonath/events{/privacy}","received_events_url":"https://api.github.com/users/adonath/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/adonath/gammapy","description":"TeV gamma-ray astronomy high-level data analysis method demo","fork":true,"url":"https://api.github.com/repos/adonath/gammapy","forks_url":"https://api.github.com/repos/adonath/gammapy/forks","keys_url":"https://api.github.com/repos/adonath/gammapy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/adonath/gammapy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/adonath/gammapy/teams","hooks_url":"https://api.github.com/repos/adonath/gammapy/hooks","issue_events_url":"https://api.github.com/repos/adonath/gammapy/issues/events{/number}","events_url":"https://api.github.com/repos/adonath/gammapy/events","assignees_url":"https://api.github.com/repos/adonath/gammapy/assignees{/user}","branches_url":"https://api.github.com/repos/adonath/gammapy/branches{/branch}","tags_url":"https://api.github.com/repos/adonath/gammapy/tags","blobs_url":"https://api.github.com/repos/adonath/gammapy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/adonath/gammapy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/adonath/gammapy/git/refs{/sha}","trees_url":"https://api.github.com/repos/adonath/gammapy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/adonath/gammapy/statuses/{sha}","languages_url":"https://api.github.com/repos/adonath/gammapy/languages","stargazers_url":"https://api.github.com/repos/adonath/gammapy/stargazers","contributors_url":"https://api.github.com/repos/adonath/gammapy/contributors","subscribers_url":"https://api.github.com/repos/adonath/gammapy/subscribers","subscription_url":"https://api.github.com/repos/adonath/gammapy/subscription","commits_url":"https://api.github.com/repos/adonath/gammapy/commits{/sha}","git_commits_url":"https://api.github.com/repos/adonath/gammapy/git/commits{/sha}","comments_url":"https://api.github.com/repos/adonath/gammapy/comments{/number}","issue_comment_url":"https://api.github.com/repos/adonath/gammapy/issues/comments{/number}","contents_url":"https://api.github.com/repos/adonath/gammapy/contents/{+path}","compare_url":"https://api.github.com/repos/adonath/gammapy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/adonath/gammapy/merges","archive_url":"https://api.github.com/repos/adonath/gammapy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/adonath/gammapy/downloads","issues_url":"https://api.github.com/repos/adonath/gammapy/issues{/number}","pulls_url":"https://api.github.com/repos/adonath/gammapy/pulls{/number}","milestones_url":"https://api.github.com/repos/adonath/gammapy/milestones{/number}","notifications_url":"https://api.github.com/repos/adonath/gammapy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/adonath/gammapy/labels{/name}","releases_url":"https://api.github.com/repos/adonath/gammapy/releases{/id}","deployments_url":"https://api.github.com/repos/adonath/gammapy/deployments","created_at":"2013-05-17T13:38:01Z","updated_at":"2015-07-30T13:58:02Z","pushed_at":"2016-07-28T11:52:28Z","git_url":"git://github.com/adonath/gammapy.git","ssh_url":"git@github.com:adonath/gammapy.git","clone_url":"https://github.com/adonath/gammapy.git","svn_url":"https://github.com/adonath/gammapy","homepage":"https://tevpy.readthedocs.org/","size":6571,"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":"gammapy:master","ref":"master","sha":"a16fb7fe7eceaedb3b6b6ede317401ae4e68620f","user":{"login":"gammapy","id":852764,"avatar_url":"https://avatars.githubusercontent.com/u/852764?v=3","gravatar_id":"","url":"https://api.github.com/users/gammapy","html_url":"https://github.com/gammapy","followers_url":"https://api.github.com/users/gammapy/followers","following_url":"https://api.github.com/users/gammapy/following{/other_user}","gists_url":"https://api.github.com/users/gammapy/gists{/gist_id}","starred_url":"https://api.github.com/users/gammapy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gammapy/subscriptions","organizations_url":"https://api.github.com/users/gammapy/orgs","repos_url":"https://api.github.com/users/gammapy/repos","events_url":"https://api.github.com/users/gammapy/events{/privacy}","received_events_url":"https://api.github.com/users/gammapy/received_events","type":"Organization","site_admin":false},"repo":{"id":10073640,"name":"gammapy","full_name":"gammapy/gammapy","owner":{"login":"gammapy","id":852764,"avatar_url":"https://avatars.githubusercontent.com/u/852764?v=3","gravatar_id":"","url":"https://api.github.com/users/gammapy","html_url":"https://github.com/gammapy","followers_url":"https://api.github.com/users/gammapy/followers","following_url":"https://api.github.com/users/gammapy/following{/other_user}","gists_url":"https://api.github.com/users/gammapy/gists{/gist_id}","starred_url":"https://api.github.com/users/gammapy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gammapy/subscriptions","organizations_url":"https://api.github.com/users/gammapy/orgs","repos_url":"https://api.github.com/users/gammapy/repos","events_url":"https://api.github.com/users/gammapy/events{/privacy}","received_events_url":"https://api.github.com/users/gammapy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/gammapy/gammapy","description":"A Python package for gamma-ray astronomy","fork":false,"url":"https://api.github.com/repos/gammapy/gammapy","forks_url":"https://api.github.com/repos/gammapy/gammapy/forks","keys_url":"https://api.github.com/repos/gammapy/gammapy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gammapy/gammapy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gammapy/gammapy/teams","hooks_url":"https://api.github.com/repos/gammapy/gammapy/hooks","issue_events_url":"https://api.github.com/repos/gammapy/gammapy/issues/events{/number}","events_url":"https://api.github.com/repos/gammapy/gammapy/events","assignees_url":"https://api.github.com/repos/gammapy/gammapy/assignees{/user}","branches_url":"https://api.github.com/repos/gammapy/gammapy/branches{/branch}","tags_url":"https://api.github.com/repos/gammapy/gammapy/tags","blobs_url":"https://api.github.com/repos/gammapy/gammapy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gammapy/gammapy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gammapy/gammapy/git/refs{/sha}","trees_url":"https://api.github.com/repos/gammapy/gammapy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gammapy/gammapy/statuses/{sha}","languages_url":"https://api.github.com/repos/gammapy/gammapy/languages","stargazers_url":"https://api.github.com/repos/gammapy/gammapy/stargazers","contributors_url":"https://api.github.com/repos/gammapy/gammapy/contributors","subscribers_url":"https://api.github.com/repos/gammapy/gammapy/subscribers","subscription_url":"https://api.github.com/repos/gammapy/gammapy/subscription","commits_url":"https://api.github.com/repos/gammapy/gammapy/commits{/sha}","git_commits_url":"https://api.github.com/repos/gammapy/gammapy/git/commits{/sha}","comments_url":"https://api.github.com/repos/gammapy/gammapy/comments{/number}","issue_comment_url":"https://api.github.com/repos/gammapy/gammapy/issues/comments{/number}","contents_url":"https://api.github.com/repos/gammapy/gammapy/contents/{+path}","compare_url":"https://api.github.com/repos/gammapy/gammapy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gammapy/gammapy/merges","archive_url":"https://api.github.com/repos/gammapy/gammapy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gammapy/gammapy/downloads","issues_url":"https://api.github.com/repos/gammapy/gammapy/issues{/number}","pulls_url":"https://api.github.com/repos/gammapy/gammapy/pulls{/number}","milestones_url":"https://api.github.com/repos/gammapy/gammapy/milestones{/number}","notifications_url":"https://api.github.com/repos/gammapy/gammapy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gammapy/gammapy/labels{/name}","releases_url":"https://api.github.com/repos/gammapy/gammapy/releases{/id}","deployments_url":"https://api.github.com/repos/gammapy/gammapy/deployments","created_at":"2013-05-15T07:50:40Z","updated_at":"2016-07-25T01:52:13Z","pushed_at":"2016-07-28T12:07:22Z","git_url":"git://github.com/gammapy/gammapy.git","ssh_url":"git@github.com:gammapy/gammapy.git","clone_url":"https://github.com/gammapy/gammapy.git","svn_url":"https://github.com/gammapy/gammapy","homepage":"http://docs.gammapy.org","size":7014,"stargazers_count":23,"watchers_count":23,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":42,"mirror_url":null,"open_issues_count":156,"forks":42,"open_issues":156,"watchers":23,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/gammapy/gammapy/pulls/653"},"html":{"href":"https://github.com/gammapy/gammapy/pull/653"},"issue":{"href":"https://api.github.com/repos/gammapy/gammapy/issues/653"},"comments":{"href":"https://api.github.com/repos/gammapy/gammapy/issues/653/comments"},"review_comments":{"href":"https://api.github.com/repos/gammapy/gammapy/pulls/653/comments"},"review_comment":{"href":"https://api.github.com/repos/gammapy/gammapy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/gammapy/gammapy/pulls/653/commits"},"statuses":{"href":"https://api.github.com/repos/gammapy/gammapy/statuses/a8dfca542a3c1c99474d67bcc6f7d84f419ad1b7"}}}}
{"actor":{"display_login":"cdeil"}}