{"action":"created","comment":{"url":"https://api.github.com/repos/rmjarvis/Piff/pulls/comments/86640755","pull_request_review_id":7292485,"id":86640755,"diff_hunk":"@@ -0,0 +1,389 @@\n+# Copyright (c) 2016 by Mike Jarvis and the other collaborators on GitHub at\n+# https://github.com/rmjarvis/Piff  All rights reserved.\n+#\n+# Piff is free software: Redistribution and use in source and binary forms\n+# with or without modification, are permitted provided that the following\n+# conditions are met:\n+#\n+# 1. Redistributions of source code must retain the above copyright notice, this\n+#    list of conditions and the disclaimer given in the accompanying LICENSE\n+#    file.\n+# 2. Redistributions in binary form must reproduce the above copyright notice,\n+#    this list of conditions and the disclaimer given in the documentation\n+#    and/or other materials provided with the distribution.\n+\n+\"\"\"\n+.. module:: gsobject_model\n+\"\"\"\n+\n+import numpy as np\n+\n+from .model import Model\n+from .star import Star, StarFit, StarData\n+from .util import hsm\n+\n+\n+class GSObjectModel(Model):\n+    \"\"\" Model that takes a fiducial GalSim.GSObject and dilates, shifts, and shears it to get a\n+    good match to stars.\n+\n+    :param gsobj:    GSObject to use as fiducial profile.\n+    :param fastfit:  Use HSM moments for fitting.  Approximate, but fast.  [default: False]\n+    :param force_model_center: If True, PSF model centroid is fixed at origin and\n+                        PSF fitting will marginalize over stellar position.  If False, stellar\n+                        position is fixed at input value and the fitted PSF may be off-center.\n+                        [default: True]\n+    :param include_pixel:   Include integration over pixel?  [default: True]\n+    :param logger:   A logger object for logging debug info. [default: None]\n+    \"\"\"\n+    def __init__(self, gsobj, fastfit=False, force_model_center=True, include_pixel=True,\n+                 logger=None):\n+        import galsim\n+        if isinstance(gsobj, basestring):\n+            gsobj = eval(gsobj)\n+\n+        self.kwargs = {'gsobj':repr(gsobj),\n+                       'fastfit':fastfit,\n+                       'force_model_center':force_model_center,\n+                       'include_pixel':include_pixel}\n+\n+        self.gsobj = gsobj\n+        self._fastfit = fastfit\n+        self._force_model_center = force_model_center\n+        self._method = 'auto' if include_pixel else 'no_pixel'\n+        # Params are [u, v], size, g1, g2\n+        if self._force_model_center:\n+            self._nparams = 3\n+            params = [1.0, 0.0, 0.0]\n+        else:\n+            self._nparams = 5\n+            params = [0.0, 0.0, 1.0, 0.0, 0.0]\n+\n+        # Calibrate gsobj by measuring it with HSM.  This way we can use differences in HSM moments\n+        # to get a reasonable starting guess for stars.\n+        prof = self.getProfile(params)\n+        img = prof.drawImage(method=self._method)\n+        sd = StarData(img, img.trueCenter())\n+        fiducial_star = Star(sd, None)\n+        flux, cenu, cenv, size, g1, g2, flag = hsm(fiducial_star)\n+        if flag != 0:\n+            raise RuntimeError(\"Error calculating fiducial moments for this gsobject.\")\n+        self._fiducial_size = size\n+        self._fiducial_shape = galsim.Shear(g1=g1, g2=g2)\n+        self._fiducial_flux = flux\n+        self._fiducial_centroid = galsim.PositionD(cenu, cenv)\n+\n+    def moment_fit(self, star, logger=None):\n+        \"\"\"Estimate transformations needed to bring self.gsobj towards given star.\"\"\"\n+        import galsim\n+        flux, cenu, cenv, size, g1, g2, flag = hsm(star)\n+        centroid = galsim.PositionD(cenu, cenv)\n+        shape = galsim.Shear(g1=g1, g2=g2)\n+\n+        if flag:\n+            raise RuntimeError(\"Failed measuring HSM moments of star.\")\n+\n+        dflux = flux/self._fiducial_flux\n+        dcentroid = centroid - self._fiducial_centroid\n+        dsize = size/self._fiducial_size\n+        dshape = shape - self._fiducial_shape","path":"piff/gsobject_model.py","position":89,"original_position":89,"commit_id":"b17318a7a2c202b583e26e143f7940a35ca43a20","original_commit_id":"b17318a7a2c202b583e26e143f7940a35ca43a20","user":{"login":"rmjarvis","id":623887,"avatar_url":"https://avatars.githubusercontent.com/u/623887?v=3","gravatar_id":"","url":"https://api.github.com/users/rmjarvis","html_url":"https://github.com/rmjarvis","followers_url":"https://api.github.com/users/rmjarvis/followers","following_url":"https://api.github.com/users/rmjarvis/following{/other_user}","gists_url":"https://api.github.com/users/rmjarvis/gists{/gist_id}","starred_url":"https://api.github.com/users/rmjarvis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rmjarvis/subscriptions","organizations_url":"https://api.github.com/users/rmjarvis/orgs","repos_url":"https://api.github.com/users/rmjarvis/repos","events_url":"https://api.github.com/users/rmjarvis/events{/privacy}","received_events_url":"https://api.github.com/users/rmjarvis/received_events","type":"User","site_admin":false},"body":"I see.  I think maybe I have a little better understanding of how this fiducial stuff works now.  (I was confused earlier about what it was intended for -- mostly because I only looked at the parameters for the Gaussian case, where things are all supposed to be either 1 or 0.  And for Gaussian, it's only close but not perfect because of the GalSim automatic pixel scale bit.\r\n\r\nSo, I think we probably do want to bump up the GalSim accuracy slightly then.  Probably maxk_threshold=folding_threshold=1.e-4 would be appropriate.  And I don't think that would slow things down all that much for these nicely smooth profiles.  In particular, maxk_threshold is the one that mostly governs the pixel scale in real space.","created_at":"2016-11-04T22:04:57Z","updated_at":"2016-11-04T22:04:57Z","html_url":"https://github.com/rmjarvis/Piff/pull/39#discussion_r86640755","pull_request_url":"https://api.github.com/repos/rmjarvis/Piff/pulls/39","_links":{"self":{"href":"https://api.github.com/repos/rmjarvis/Piff/pulls/comments/86640755"},"html":{"href":"https://github.com/rmjarvis/Piff/pull/39#discussion_r86640755"},"pull_request":{"href":"https://api.github.com/repos/rmjarvis/Piff/pulls/39"}}},"pull_request":{"url":"https://api.github.com/repos/rmjarvis/Piff/pulls/39","id":85820958,"html_url":"https://github.com/rmjarvis/Piff/pull/39","diff_url":"https://github.com/rmjarvis/Piff/pull/39.diff","patch_url":"https://github.com/rmjarvis/Piff/pull/39.patch","issue_url":"https://api.github.com/repos/rmjarvis/Piff/issues/39","number":39,"state":"open","locked":false,"title":"#38  Kolmogorov Model","user":{"login":"jmeyers314","id":3650485,"avatar_url":"https://avatars.githubusercontent.com/u/3650485?v=3","gravatar_id":"","url":"https://api.github.com/users/jmeyers314","html_url":"https://github.com/jmeyers314","followers_url":"https://api.github.com/users/jmeyers314/followers","following_url":"https://api.github.com/users/jmeyers314/following{/other_user}","gists_url":"https://api.github.com/users/jmeyers314/gists{/gist_id}","starred_url":"https://api.github.com/users/jmeyers314/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmeyers314/subscriptions","organizations_url":"https://api.github.com/users/jmeyers314/orgs","repos_url":"https://api.github.com/users/jmeyers314/repos","events_url":"https://api.github.com/users/jmeyers314/events{/privacy}","received_events_url":"https://api.github.com/users/jmeyers314/received_events","type":"User","site_admin":false},"body":"This PR adds a sheared Kolmogorov PSF model.  The parameters are just a PSF size (fwhm), and shear components g1 and g2.  The center of the PSF is also optionally allowed to be a parameter.\n\nI copied a number of unit tests from `test_pixel.py` to ensure that the above params are interpolatable across the field.\n\nOne aspect I know isn't implemented currently is marginalization over the flux and center (when center isn't part of the PSF).  The flux marginalization when the center is fixed might be analytic with a Gaussian prior --  I can think some more about that.  However, I don't think we can marginalize the flux or the center when the center is free without performing a numerical integral, which sounds expensive.  Probably for now we can get away without this, though, I'm hoping.\n","created_at":"2016-09-19T15:58:54Z","updated_at":"2016-11-04T22:04:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"21af9fada8fddb142f019f58bed66beabd2f8743","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/rmjarvis/Piff/pulls/39/commits","review_comments_url":"https://api.github.com/repos/rmjarvis/Piff/pulls/39/comments","review_comment_url":"https://api.github.com/repos/rmjarvis/Piff/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rmjarvis/Piff/issues/39/comments","statuses_url":"https://api.github.com/repos/rmjarvis/Piff/statuses/b17318a7a2c202b583e26e143f7940a35ca43a20","head":{"label":"rmjarvis:#38","ref":"#38","sha":"b17318a7a2c202b583e26e143f7940a35ca43a20","user":{"login":"rmjarvis","id":623887,"avatar_url":"https://avatars.githubusercontent.com/u/623887?v=3","gravatar_id":"","url":"https://api.github.com/users/rmjarvis","html_url":"https://github.com/rmjarvis","followers_url":"https://api.github.com/users/rmjarvis/followers","following_url":"https://api.github.com/users/rmjarvis/following{/other_user}","gists_url":"https://api.github.com/users/rmjarvis/gists{/gist_id}","starred_url":"https://api.github.com/users/rmjarvis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rmjarvis/subscriptions","organizations_url":"https://api.github.com/users/rmjarvis/orgs","repos_url":"https://api.github.com/users/rmjarvis/repos","events_url":"https://api.github.com/users/rmjarvis/events{/privacy}","received_events_url":"https://api.github.com/users/rmjarvis/received_events","type":"User","site_admin":false},"repo":{"id":52539402,"name":"Piff","full_name":"rmjarvis/Piff","owner":{"login":"rmjarvis","id":623887,"avatar_url":"https://avatars.githubusercontent.com/u/623887?v=3","gravatar_id":"","url":"https://api.github.com/users/rmjarvis","html_url":"https://github.com/rmjarvis","followers_url":"https://api.github.com/users/rmjarvis/followers","following_url":"https://api.github.com/users/rmjarvis/following{/other_user}","gists_url":"https://api.github.com/users/rmjarvis/gists{/gist_id}","starred_url":"https://api.github.com/users/rmjarvis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rmjarvis/subscriptions","organizations_url":"https://api.github.com/users/rmjarvis/orgs","repos_url":"https://api.github.com/users/rmjarvis/repos","events_url":"https://api.github.com/users/rmjarvis/events{/privacy}","received_events_url":"https://api.github.com/users/rmjarvis/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rmjarvis/Piff","description":"PSFs In the Full FOV.  A software package for modeling the point-spread function (PSF) across the full field of view (FOV).  Documentation:","fork":false,"url":"https://api.github.com/repos/rmjarvis/Piff","forks_url":"https://api.github.com/repos/rmjarvis/Piff/forks","keys_url":"https://api.github.com/repos/rmjarvis/Piff/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rmjarvis/Piff/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rmjarvis/Piff/teams","hooks_url":"https://api.github.com/repos/rmjarvis/Piff/hooks","issue_events_url":"https://api.github.com/repos/rmjarvis/Piff/issues/events{/number}","events_url":"https://api.github.com/repos/rmjarvis/Piff/events","assignees_url":"https://api.github.com/repos/rmjarvis/Piff/assignees{/user}","branches_url":"https://api.github.com/repos/rmjarvis/Piff/branches{/branch}","tags_url":"https://api.github.com/repos/rmjarvis/Piff/tags","blobs_url":"https://api.github.com/repos/rmjarvis/Piff/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rmjarvis/Piff/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rmjarvis/Piff/git/refs{/sha}","trees_url":"https://api.github.com/repos/rmjarvis/Piff/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rmjarvis/Piff/statuses/{sha}","languages_url":"https://api.github.com/repos/rmjarvis/Piff/languages","stargazers_url":"https://api.github.com/repos/rmjarvis/Piff/stargazers","contributors_url":"https://api.github.com/repos/rmjarvis/Piff/contributors","subscribers_url":"https://api.github.com/repos/rmjarvis/Piff/subscribers","subscription_url":"https://api.github.com/repos/rmjarvis/Piff/subscription","commits_url":"https://api.github.com/repos/rmjarvis/Piff/commits{/sha}","git_commits_url":"https://api.github.com/repos/rmjarvis/Piff/git/commits{/sha}","comments_url":"https://api.github.com/repos/rmjarvis/Piff/comments{/number}","issue_comment_url":"https://api.github.com/repos/rmjarvis/Piff/issues/comments{/number}","contents_url":"https://api.github.com/repos/rmjarvis/Piff/contents/{+path}","compare_url":"https://api.github.com/repos/rmjarvis/Piff/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rmjarvis/Piff/merges","archive_url":"https://api.github.com/repos/rmjarvis/Piff/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rmjarvis/Piff/downloads","issues_url":"https://api.github.com/repos/rmjarvis/Piff/issues{/number}","pulls_url":"https://api.github.com/repos/rmjarvis/Piff/pulls{/number}","milestones_url":"https://api.github.com/repos/rmjarvis/Piff/milestones{/number}","notifications_url":"https://api.github.com/repos/rmjarvis/Piff/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rmjarvis/Piff/labels{/name}","releases_url":"https://api.github.com/repos/rmjarvis/Piff/releases{/id}","deployments_url":"https://api.github.com/repos/rmjarvis/Piff/deployments","created_at":"2016-02-25T16:24:08Z","updated_at":"2016-08-30T20:31:08Z","pushed_at":"2016-10-28T21:46:19Z","git_url":"git://github.com/rmjarvis/Piff.git","ssh_url":"git@github.com:rmjarvis/Piff.git","clone_url":"https://github.com/rmjarvis/Piff.git","svn_url":"https://github.com/rmjarvis/Piff","homepage":"http://rmjarvis.github.io/Piff/html/index.html","size":28611,"stargazers_count":3,"watchers_count":3,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":2,"mirror_url":null,"open_issues_count":16,"forks":2,"open_issues":16,"watchers":3,"default_branch":"master"}},"base":{"label":"rmjarvis:master","ref":"master","sha":"33b107c961e2ec7ca9ac310e128f778e0e1b0ae7","user":{"login":"rmjarvis","id":623887,"avatar_url":"https://avatars.githubusercontent.com/u/623887?v=3","gravatar_id":"","url":"https://api.github.com/users/rmjarvis","html_url":"https://github.com/rmjarvis","followers_url":"https://api.github.com/users/rmjarvis/followers","following_url":"https://api.github.com/users/rmjarvis/following{/other_user}","gists_url":"https://api.github.com/users/rmjarvis/gists{/gist_id}","starred_url":"https://api.github.com/users/rmjarvis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rmjarvis/subscriptions","organizations_url":"https://api.github.com/users/rmjarvis/orgs","repos_url":"https://api.github.com/users/rmjarvis/repos","events_url":"https://api.github.com/users/rmjarvis/events{/privacy}","received_events_url":"https://api.github.com/users/rmjarvis/received_events","type":"User","site_admin":false},"repo":{"id":52539402,"name":"Piff","full_name":"rmjarvis/Piff","owner":{"login":"rmjarvis","id":623887,"avatar_url":"https://avatars.githubusercontent.com/u/623887?v=3","gravatar_id":"","url":"https://api.github.com/users/rmjarvis","html_url":"https://github.com/rmjarvis","followers_url":"https://api.github.com/users/rmjarvis/followers","following_url":"https://api.github.com/users/rmjarvis/following{/other_user}","gists_url":"https://api.github.com/users/rmjarvis/gists{/gist_id}","starred_url":"https://api.github.com/users/rmjarvis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rmjarvis/subscriptions","organizations_url":"https://api.github.com/users/rmjarvis/orgs","repos_url":"https://api.github.com/users/rmjarvis/repos","events_url":"https://api.github.com/users/rmjarvis/events{/privacy}","received_events_url":"https://api.github.com/users/rmjarvis/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rmjarvis/Piff","description":"PSFs In the Full FOV.  A software package for modeling the point-spread function (PSF) across the full field of view (FOV).  Documentation:","fork":false,"url":"https://api.github.com/repos/rmjarvis/Piff","forks_url":"https://api.github.com/repos/rmjarvis/Piff/forks","keys_url":"https://api.github.com/repos/rmjarvis/Piff/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rmjarvis/Piff/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rmjarvis/Piff/teams","hooks_url":"https://api.github.com/repos/rmjarvis/Piff/hooks","issue_events_url":"https://api.github.com/repos/rmjarvis/Piff/issues/events{/number}","events_url":"https://api.github.com/repos/rmjarvis/Piff/events","assignees_url":"https://api.github.com/repos/rmjarvis/Piff/assignees{/user}","branches_url":"https://api.github.com/repos/rmjarvis/Piff/branches{/branch}","tags_url":"https://api.github.com/repos/rmjarvis/Piff/tags","blobs_url":"https://api.github.com/repos/rmjarvis/Piff/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rmjarvis/Piff/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rmjarvis/Piff/git/refs{/sha}","trees_url":"https://api.github.com/repos/rmjarvis/Piff/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rmjarvis/Piff/statuses/{sha}","languages_url":"https://api.github.com/repos/rmjarvis/Piff/languages","stargazers_url":"https://api.github.com/repos/rmjarvis/Piff/stargazers","contributors_url":"https://api.github.com/repos/rmjarvis/Piff/contributors","subscribers_url":"https://api.github.com/repos/rmjarvis/Piff/subscribers","subscription_url":"https://api.github.com/repos/rmjarvis/Piff/subscription","commits_url":"https://api.github.com/repos/rmjarvis/Piff/commits{/sha}","git_commits_url":"https://api.github.com/repos/rmjarvis/Piff/git/commits{/sha}","comments_url":"https://api.github.com/repos/rmjarvis/Piff/comments{/number}","issue_comment_url":"https://api.github.com/repos/rmjarvis/Piff/issues/comments{/number}","contents_url":"https://api.github.com/repos/rmjarvis/Piff/contents/{+path}","compare_url":"https://api.github.com/repos/rmjarvis/Piff/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rmjarvis/Piff/merges","archive_url":"https://api.github.com/repos/rmjarvis/Piff/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rmjarvis/Piff/downloads","issues_url":"https://api.github.com/repos/rmjarvis/Piff/issues{/number}","pulls_url":"https://api.github.com/repos/rmjarvis/Piff/pulls{/number}","milestones_url":"https://api.github.com/repos/rmjarvis/Piff/milestones{/number}","notifications_url":"https://api.github.com/repos/rmjarvis/Piff/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rmjarvis/Piff/labels{/name}","releases_url":"https://api.github.com/repos/rmjarvis/Piff/releases{/id}","deployments_url":"https://api.github.com/repos/rmjarvis/Piff/deployments","created_at":"2016-02-25T16:24:08Z","updated_at":"2016-08-30T20:31:08Z","pushed_at":"2016-10-28T21:46:19Z","git_url":"git://github.com/rmjarvis/Piff.git","ssh_url":"git@github.com:rmjarvis/Piff.git","clone_url":"https://github.com/rmjarvis/Piff.git","svn_url":"https://github.com/rmjarvis/Piff","homepage":"http://rmjarvis.github.io/Piff/html/index.html","size":28611,"stargazers_count":3,"watchers_count":3,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":2,"mirror_url":null,"open_issues_count":16,"forks":2,"open_issues":16,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rmjarvis/Piff/pulls/39"},"html":{"href":"https://github.com/rmjarvis/Piff/pull/39"},"issue":{"href":"https://api.github.com/repos/rmjarvis/Piff/issues/39"},"comments":{"href":"https://api.github.com/repos/rmjarvis/Piff/issues/39/comments"},"review_comments":{"href":"https://api.github.com/repos/rmjarvis/Piff/pulls/39/comments"},"review_comment":{"href":"https://api.github.com/repos/rmjarvis/Piff/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rmjarvis/Piff/pulls/39/commits"},"statuses":{"href":"https://api.github.com/repos/rmjarvis/Piff/statuses/b17318a7a2c202b583e26e143f7940a35ca43a20"}}}}
{"actor":{"display_login":"rmjarvis"}}