{"action":"created","comment":{"url":"https://api.github.com/repos/lsst/ip_diffim/pulls/comments/126255408","pull_request_review_id":48729306,"id":126255408,"diff_hunk":"@@ -898,3 +949,133 @@ class ZogyMapReduceConfig(ImageMapReduceConfig):\n         doc='Zogy subtask to run on each sub-image',\n         target=ZogyMapperSubtask\n     )\n+\n+\n+class ZogyImagePsfMatchConfig(ImagePsfMatchConfig):\n+    zogyConfig = pexConfig.ConfigField(\n+        dtype=ZogyConfig,\n+        doc='ZogyTask config to use when running on complete exposure (non spatially-varying)',\n+    )\n+\n+    zogyMapReduceConfig = pexConfig.ConfigField(\n+        dtype=ZogyMapReduceConfig,\n+        doc='ZogyMapReduce config to use when running Zogy on each sub-image (spatially-varying)',\n+    )\n+\n+    def setDefaults(self):\n+        self.zogyMapReduceConfig.gridStepX = self.zogyMapReduceConfig.gridStepY = 19\n+        self.zogyMapReduceConfig.cellSizeX = self.zogyMapReduceConfig.cellSizeY = 20\n+        self.zogyMapReduceConfig.borderSizeX = self.zogyMapReduceConfig.borderSizeY = 6\n+        self.zogyMapReduceConfig.reducerSubtask.reduceOperation = 'average'\n+\n+\n+class ZogyImagePsfMatchTask(ImagePsfMatchTask):\n+    ConfigClass = ZogyImagePsfMatchConfig\n+\n+    def __init__(self, *args, **kwargs):\n+        ImagePsfMatchTask.__init__(self, *args, **kwargs)\n+\n+    def setDefaults(self):\n+        config = self.config.zogyMapReduceConfig\n+        config.gridStepX = config.gridStepY = 19\n+        config.cellSizeX = config.cellSizeY = 20\n+        config.borderSizeX = config.borderSizeY = 6\n+        config.reducerSubtask.reduceOperation = 'average'\n+\n+    def _computeImageMean(self, exposure):\n+        \"\"\"Compute the sigma-clipped mean of the pixels image of `exposure`.\n+        \"\"\"\n+        statsControl = afwMath.StatisticsControl()\n+        statsControl.setNumSigmaClip(3.)\n+        statsControl.setNumIter(3)\n+        ignoreMaskPlanes = (\"INTRP\", \"EDGE\", \"DETECTED\", \"SAT\", \"CR\", \"BAD\", \"NO_DATA\", \"DETECTED_NEGATIVE\")\n+        statsControl.setAndMask(afwImage.MaskU.getPlaneBitMask(ignoreMaskPlanes))\n+        statObj = afwMath.makeStatistics(exposure.getMaskedImage().getImage(),\n+                                         exposure.getMaskedImage().getMask(),\n+                                         afwMath.MEANCLIP|afwMath.MEDIAN, statsControl)\n+        mn = statObj.getValue(afwMath.MEANCLIP)\n+        med = statObj.getValue(afwMath.MEDIAN)\n+        return mn, med\n+\n+    def subtractExposures(self, templateExposure, scienceExposure,\n+                          doWarping=True, spatiallyVarying=True, inImageSpace=False,\n+                          doPreConvolve=False):\n+\n+        mn1 = self._computeImageMean(templateExposure)\n+        mn2 = self._computeImageMean(scienceExposure)\n+        self.log.info(\"Exposure means=%f, %f; median=%f, %f:\" % (mn1[0], mn2[0], mn1[1], mn2[1]))\n+        if not np.isnan(mn1[0]) and np.abs(mn1[0]) > 1:\n+            mi = templateExposure.getMaskedImage()\n+            mi -= mn1[0]\n+        if not np.isnan(mn2[0]) and np.abs(mn2[0]) > 1:\n+            mi = scienceExposure.getMaskedImage()\n+            mi -= mn2[0]\n+\n+        self.log.info('Running Zogy algorithm: spatiallyVarying=%r' % spatiallyVarying)\n+\n+        if not self._validateWcs(templateExposure, scienceExposure):\n+            if doWarping:\n+                self.log.info(\"Astrometrically registering template to science image\")\n+                # Also warp the PSF\n+                xyTransform = afwImage.XYTransformFromWcsPair(scienceExposure.getWcs(),\n+                                                              templateExposure.getWcs())\n+                psfWarped = measAlg.WarpedPsf(templateExposure.getPsf(), xyTransform)\n+                templateExposure = self._warper.warpExposure(scienceExposure.getWcs(),\n+                                                             templateExposure,\n+                                                             destBBox=scienceExposure.getBBox())\n+\n+                templateExposure.setPsf(psfWarped)\n+                templateExposure.writeFits('WARPEDTEMPLATE_ZOGY.fits')\n+            else:\n+                self.log.error(\"ERROR: Input images not registered\")\n+                raise RuntimeError(\"Input images not registered\")\n+\n+        def gm(exp):\n+            return exp.getMaskedImage().getMask()\n+        def ga(exp):\n+            return exp.getMaskedImage().getImage().getArray()\n+        def gv(exp):\n+            return exp.getMaskedImage().getImage().getArray()\n+\n+        if spatiallyVarying:\n+            config = self.config.zogyMapReduceConfig\n+            task = ImageMapReduceTask(config=config)\n+            results = task.run(scienceExposure, template=templateExposure, inImageSpace=inImageSpace,\n+                               doScorr=doPreConvolve, forceEvenSized=True)\n+            results.D = results.exposure\n+            # The CoaddPsf apparently cannot be used for detection as it doesn't have a","path":"python/lsst/ip/diffim/zogy.py","position":419,"original_position":419,"commit_id":"fe07bf8436556bebd8cc79b19e3d610e63dde06b","original_commit_id":"fe07bf8436556bebd8cc79b19e3d610e63dde06b","user":{"login":"djreiss","id":512257,"avatar_url":"https://avatars0.githubusercontent.com/u/512257?v=3","gravatar_id":"","url":"https://api.github.com/users/djreiss","html_url":"https://github.com/djreiss","followers_url":"https://api.github.com/users/djreiss/followers","following_url":"https://api.github.com/users/djreiss/following{/other_user}","gists_url":"https://api.github.com/users/djreiss/gists{/gist_id}","starred_url":"https://api.github.com/users/djreiss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/djreiss/subscriptions","organizations_url":"https://api.github.com/users/djreiss/orgs","repos_url":"https://api.github.com/users/djreiss/repos","events_url":"https://api.github.com/users/djreiss/events{/privacy}","received_events_url":"https://api.github.com/users/djreiss/received_events","type":"User","site_admin":false},"body":"My understanding from looking at the code was that it computes a single psf from the `averagePosition` and uses that for detection. But it is still a good point that the comment is untrue.","created_at":"2017-07-07T22:08:13Z","updated_at":"2017-07-07T22:08:13Z","html_url":"https://github.com/lsst/ip_diffim/pull/66#discussion_r126255408","pull_request_url":"https://api.github.com/repos/lsst/ip_diffim/pulls/66","_links":{"self":{"href":"https://api.github.com/repos/lsst/ip_diffim/pulls/comments/126255408"},"html":{"href":"https://github.com/lsst/ip_diffim/pull/66#discussion_r126255408"},"pull_request":{"href":"https://api.github.com/repos/lsst/ip_diffim/pulls/66"}}},"pull_request":{"url":"https://api.github.com/repos/lsst/ip_diffim/pulls/66","id":124294185,"html_url":"https://github.com/lsst/ip_diffim/pull/66","diff_url":"https://github.com/lsst/ip_diffim/pull/66.diff","patch_url":"https://github.com/lsst/ip_diffim/pull/66.patch","issue_url":"https://api.github.com/repos/lsst/ip_diffim/issues/66","number":66,"state":"open","locked":false,"title":"DM-10805: Spatially-varying ZOGY option","user":{"login":"djreiss","id":512257,"avatar_url":"https://avatars0.githubusercontent.com/u/512257?v=3","gravatar_id":"","url":"https://api.github.com/users/djreiss","html_url":"https://github.com/djreiss","followers_url":"https://api.github.com/users/djreiss/followers","following_url":"https://api.github.com/users/djreiss/following{/other_user}","gists_url":"https://api.github.com/users/djreiss/gists{/gist_id}","starred_url":"https://api.github.com/users/djreiss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/djreiss/subscriptions","organizations_url":"https://api.github.com/users/djreiss/orgs","repos_url":"https://api.github.com/users/djreiss/repos","events_url":"https://api.github.com/users/djreiss/events{/privacy}","received_events_url":"https://api.github.com/users/djreiss/received_events","type":"User","site_admin":false},"body":"- Include unit tests for new task","created_at":"2017-06-06T21:39:13Z","updated_at":"2017-07-07T22:08:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3704582cff6f1ebeec2276102f48f0685bc10e82","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/lsst/ip_diffim/pulls/66/commits","review_comments_url":"https://api.github.com/repos/lsst/ip_diffim/pulls/66/comments","review_comment_url":"https://api.github.com/repos/lsst/ip_diffim/pulls/comments{/number}","comments_url":"https://api.github.com/repos/lsst/ip_diffim/issues/66/comments","statuses_url":"https://api.github.com/repos/lsst/ip_diffim/statuses/fe07bf8436556bebd8cc79b19e3d610e63dde06b","head":{"label":"lsst:tickets/DM-10805","ref":"tickets/DM-10805","sha":"fe07bf8436556bebd8cc79b19e3d610e63dde06b","user":{"login":"lsst","id":1134504,"avatar_url":"https://avatars2.githubusercontent.com/u/1134504?v=3","gravatar_id":"","url":"https://api.github.com/users/lsst","html_url":"https://github.com/lsst","followers_url":"https://api.github.com/users/lsst/followers","following_url":"https://api.github.com/users/lsst/following{/other_user}","gists_url":"https://api.github.com/users/lsst/gists{/gist_id}","starred_url":"https://api.github.com/users/lsst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lsst/subscriptions","organizations_url":"https://api.github.com/users/lsst/orgs","repos_url":"https://api.github.com/users/lsst/repos","events_url":"https://api.github.com/users/lsst/events{/privacy}","received_events_url":"https://api.github.com/users/lsst/received_events","type":"Organization","site_admin":false},"repo":{"id":23013321,"name":"ip_diffim","full_name":"lsst/ip_diffim","owner":{"login":"lsst","id":1134504,"avatar_url":"https://avatars2.githubusercontent.com/u/1134504?v=3","gravatar_id":"","url":"https://api.github.com/users/lsst","html_url":"https://github.com/lsst","followers_url":"https://api.github.com/users/lsst/followers","following_url":"https://api.github.com/users/lsst/following{/other_user}","gists_url":"https://api.github.com/users/lsst/gists{/gist_id}","starred_url":"https://api.github.com/users/lsst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lsst/subscriptions","organizations_url":"https://api.github.com/users/lsst/orgs","repos_url":"https://api.github.com/users/lsst/repos","events_url":"https://api.github.com/users/lsst/events{/privacy}","received_events_url":"https://api.github.com/users/lsst/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/lsst/ip_diffim","description":"LSST data management: astronomical image differencing","fork":false,"url":"https://api.github.com/repos/lsst/ip_diffim","forks_url":"https://api.github.com/repos/lsst/ip_diffim/forks","keys_url":"https://api.github.com/repos/lsst/ip_diffim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lsst/ip_diffim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lsst/ip_diffim/teams","hooks_url":"https://api.github.com/repos/lsst/ip_diffim/hooks","issue_events_url":"https://api.github.com/repos/lsst/ip_diffim/issues/events{/number}","events_url":"https://api.github.com/repos/lsst/ip_diffim/events","assignees_url":"https://api.github.com/repos/lsst/ip_diffim/assignees{/user}","branches_url":"https://api.github.com/repos/lsst/ip_diffim/branches{/branch}","tags_url":"https://api.github.com/repos/lsst/ip_diffim/tags","blobs_url":"https://api.github.com/repos/lsst/ip_diffim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lsst/ip_diffim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lsst/ip_diffim/git/refs{/sha}","trees_url":"https://api.github.com/repos/lsst/ip_diffim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lsst/ip_diffim/statuses/{sha}","languages_url":"https://api.github.com/repos/lsst/ip_diffim/languages","stargazers_url":"https://api.github.com/repos/lsst/ip_diffim/stargazers","contributors_url":"https://api.github.com/repos/lsst/ip_diffim/contributors","subscribers_url":"https://api.github.com/repos/lsst/ip_diffim/subscribers","subscription_url":"https://api.github.com/repos/lsst/ip_diffim/subscription","commits_url":"https://api.github.com/repos/lsst/ip_diffim/commits{/sha}","git_commits_url":"https://api.github.com/repos/lsst/ip_diffim/git/commits{/sha}","comments_url":"https://api.github.com/repos/lsst/ip_diffim/comments{/number}","issue_comment_url":"https://api.github.com/repos/lsst/ip_diffim/issues/comments{/number}","contents_url":"https://api.github.com/repos/lsst/ip_diffim/contents/{+path}","compare_url":"https://api.github.com/repos/lsst/ip_diffim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lsst/ip_diffim/merges","archive_url":"https://api.github.com/repos/lsst/ip_diffim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lsst/ip_diffim/downloads","issues_url":"https://api.github.com/repos/lsst/ip_diffim/issues{/number}","pulls_url":"https://api.github.com/repos/lsst/ip_diffim/pulls{/number}","milestones_url":"https://api.github.com/repos/lsst/ip_diffim/milestones{/number}","notifications_url":"https://api.github.com/repos/lsst/ip_diffim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lsst/ip_diffim/labels{/name}","releases_url":"https://api.github.com/repos/lsst/ip_diffim/releases{/id}","deployments_url":"https://api.github.com/repos/lsst/ip_diffim/deployments","created_at":"2014-08-16T07:44:12Z","updated_at":"2016-10-30T20:52:29Z","pushed_at":"2017-07-06T15:52:39Z","git_url":"git://github.com/lsst/ip_diffim.git","ssh_url":"git@github.com:lsst/ip_diffim.git","clone_url":"https://github.com/lsst/ip_diffim.git","svn_url":"https://github.com/lsst/ip_diffim","homepage":"http://dm.lsst.org/","size":79522,"stargazers_count":3,"watchers_count":3,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":3,"forks":2,"open_issues":3,"watchers":3,"default_branch":"master"}},"base":{"label":"lsst:master","ref":"master","sha":"373a35160ac4efb80cb1876d51ca3a6b6b4f2304","user":{"login":"lsst","id":1134504,"avatar_url":"https://avatars2.githubusercontent.com/u/1134504?v=3","gravatar_id":"","url":"https://api.github.com/users/lsst","html_url":"https://github.com/lsst","followers_url":"https://api.github.com/users/lsst/followers","following_url":"https://api.github.com/users/lsst/following{/other_user}","gists_url":"https://api.github.com/users/lsst/gists{/gist_id}","starred_url":"https://api.github.com/users/lsst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lsst/subscriptions","organizations_url":"https://api.github.com/users/lsst/orgs","repos_url":"https://api.github.com/users/lsst/repos","events_url":"https://api.github.com/users/lsst/events{/privacy}","received_events_url":"https://api.github.com/users/lsst/received_events","type":"Organization","site_admin":false},"repo":{"id":23013321,"name":"ip_diffim","full_name":"lsst/ip_diffim","owner":{"login":"lsst","id":1134504,"avatar_url":"https://avatars2.githubusercontent.com/u/1134504?v=3","gravatar_id":"","url":"https://api.github.com/users/lsst","html_url":"https://github.com/lsst","followers_url":"https://api.github.com/users/lsst/followers","following_url":"https://api.github.com/users/lsst/following{/other_user}","gists_url":"https://api.github.com/users/lsst/gists{/gist_id}","starred_url":"https://api.github.com/users/lsst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lsst/subscriptions","organizations_url":"https://api.github.com/users/lsst/orgs","repos_url":"https://api.github.com/users/lsst/repos","events_url":"https://api.github.com/users/lsst/events{/privacy}","received_events_url":"https://api.github.com/users/lsst/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/lsst/ip_diffim","description":"LSST data management: astronomical image differencing","fork":false,"url":"https://api.github.com/repos/lsst/ip_diffim","forks_url":"https://api.github.com/repos/lsst/ip_diffim/forks","keys_url":"https://api.github.com/repos/lsst/ip_diffim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lsst/ip_diffim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lsst/ip_diffim/teams","hooks_url":"https://api.github.com/repos/lsst/ip_diffim/hooks","issue_events_url":"https://api.github.com/repos/lsst/ip_diffim/issues/events{/number}","events_url":"https://api.github.com/repos/lsst/ip_diffim/events","assignees_url":"https://api.github.com/repos/lsst/ip_diffim/assignees{/user}","branches_url":"https://api.github.com/repos/lsst/ip_diffim/branches{/branch}","tags_url":"https://api.github.com/repos/lsst/ip_diffim/tags","blobs_url":"https://api.github.com/repos/lsst/ip_diffim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lsst/ip_diffim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lsst/ip_diffim/git/refs{/sha}","trees_url":"https://api.github.com/repos/lsst/ip_diffim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lsst/ip_diffim/statuses/{sha}","languages_url":"https://api.github.com/repos/lsst/ip_diffim/languages","stargazers_url":"https://api.github.com/repos/lsst/ip_diffim/stargazers","contributors_url":"https://api.github.com/repos/lsst/ip_diffim/contributors","subscribers_url":"https://api.github.com/repos/lsst/ip_diffim/subscribers","subscription_url":"https://api.github.com/repos/lsst/ip_diffim/subscription","commits_url":"https://api.github.com/repos/lsst/ip_diffim/commits{/sha}","git_commits_url":"https://api.github.com/repos/lsst/ip_diffim/git/commits{/sha}","comments_url":"https://api.github.com/repos/lsst/ip_diffim/comments{/number}","issue_comment_url":"https://api.github.com/repos/lsst/ip_diffim/issues/comments{/number}","contents_url":"https://api.github.com/repos/lsst/ip_diffim/contents/{+path}","compare_url":"https://api.github.com/repos/lsst/ip_diffim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lsst/ip_diffim/merges","archive_url":"https://api.github.com/repos/lsst/ip_diffim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lsst/ip_diffim/downloads","issues_url":"https://api.github.com/repos/lsst/ip_diffim/issues{/number}","pulls_url":"https://api.github.com/repos/lsst/ip_diffim/pulls{/number}","milestones_url":"https://api.github.com/repos/lsst/ip_diffim/milestones{/number}","notifications_url":"https://api.github.com/repos/lsst/ip_diffim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lsst/ip_diffim/labels{/name}","releases_url":"https://api.github.com/repos/lsst/ip_diffim/releases{/id}","deployments_url":"https://api.github.com/repos/lsst/ip_diffim/deployments","created_at":"2014-08-16T07:44:12Z","updated_at":"2016-10-30T20:52:29Z","pushed_at":"2017-07-06T15:52:39Z","git_url":"git://github.com/lsst/ip_diffim.git","ssh_url":"git@github.com:lsst/ip_diffim.git","clone_url":"https://github.com/lsst/ip_diffim.git","svn_url":"https://github.com/lsst/ip_diffim","homepage":"http://dm.lsst.org/","size":79522,"stargazers_count":3,"watchers_count":3,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":3,"forks":2,"open_issues":3,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/lsst/ip_diffim/pulls/66"},"html":{"href":"https://github.com/lsst/ip_diffim/pull/66"},"issue":{"href":"https://api.github.com/repos/lsst/ip_diffim/issues/66"},"comments":{"href":"https://api.github.com/repos/lsst/ip_diffim/issues/66/comments"},"review_comments":{"href":"https://api.github.com/repos/lsst/ip_diffim/pulls/66/comments"},"review_comment":{"href":"https://api.github.com/repos/lsst/ip_diffim/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/lsst/ip_diffim/pulls/66/commits"},"statuses":{"href":"https://api.github.com/repos/lsst/ip_diffim/statuses/fe07bf8436556bebd8cc79b19e3d610e63dde06b"}}}}
{"actor":{"display_login":"djreiss"}}