{"action":"created","comment":{"url":"https://api.github.com/repos/rmjarvis/Piff/pulls/comments/79651698","id":79651698,"diff_hunk":"@@ -0,0 +1,311 @@\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:: model_kolmogorov\n+\"\"\"\n+\n+from __future__ import print_function\n+import numpy as np\n+\n+from .model import Model\n+from .star import Star, StarFit, StarData\n+\n+class Kolmogorov(Model):\n+    \"\"\"An extremely simple PSF model that just considers the PSF as a sheared Kolmogorov with\n+    parameters for full-width-half-maximum `fwhm`, the applied shear `g1` and `g2`, and optionally,\n+    centroid parameters `cenu` and `cenv`.\n+    \"\"\"\n+    def __init__(self, fastfit=False, force_model_center=True, logger=None):\n+        \"\"\"A PSF modeled as a Kolmogorov profile.\n+\n+        :param fastfit:  Use HSM moments for fitting.  Approximate, but fast.  [default: True]\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 logger:  A logger object for logging debug info. [default: None]\n+        \"\"\"\n+        self._fastfit = fastfit\n+        self._force_model_center = force_model_center\n+        # Params are [u, v], fwhm, g1, g2\n+        self._nparams = 3 if force_model_center else 5\n+\n+        self.kwargs = {\n+            'fastfit' : fastfit,\n+            'force_model_center' : force_model_center\n+        }\n+\n+    @staticmethod\n+    def hsmfit(star):\n+        \"\"\"Compute the hsm moments for a given star.\n+\n+        :param star:    A Star instance\n+\n+        :returns: (flux, cenu, cenv, sigma, g1, g2, flag)\n+        \"\"\"\n+        import galsim\n+        image, weight, image_pos = star.data.getImage()\n+        mom = image.FindAdaptiveMom(weight=weight, strict=False)\n+\n+        fwhm = mom.moments_sigma / 0.4519  # Magic number to convert sigma -> FWHM for a Kolmogorov\n+        shape = mom.observed_shape\n+        # These are in pixel coordinates.  Need to convert to world coords.\n+        jac = image.wcs.jacobian(image_pos=image_pos)\n+        scale, shear, theta, flip = jac.getDecomposition()\n+        # Fix sigma\n+        fwhm *= scale\n+        # Fix shear.  First the flip, if any.\n+        if flip:\n+            shape = galsim.Shear(g1 = -shape.g1, g2 = shape.g2)\n+        # Next the rotation\n+        shape = galsim.Shear(g = shape.g, beta = shape.beta + theta)\n+        # Finally the shear\n+        shape = shear + shape\n+\n+        # Another magic number below to convert flux -> actual flux for Kolmogorov.\n+        flux = mom.moments_amp / 0.9053\n+\n+        center = image.wcs.toWorld(mom.moments_centroid) - image.wcs.toWorld(image_pos)","path":"piff/kolmogorov_model.py","position":80,"original_position":80,"commit_id":"8662e3438d56fb1a6810d82ab6960851630ba98d","original_commit_id":"8662e3438d56fb1a6810d82ab6960851630ba98d","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":"This being Python, I'd probably recommend having utility functions that exist outside of each of the classes, but which they can all use via duck typing as required.  I don't think there's likely to be much advantage to having a class hierarchy for this.","created_at":"2016-09-20T16:20:04Z","updated_at":"2016-09-20T16:20:04Z","html_url":"https://github.com/rmjarvis/Piff/pull/39#discussion_r79651698","pull_request_url":"https://api.github.com/repos/rmjarvis/Piff/pulls/39","_links":{"self":{"href":"https://api.github.com/repos/rmjarvis/Piff/pulls/comments/79651698"},"html":{"href":"https://github.com/rmjarvis/Piff/pull/39#discussion_r79651698"},"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.\r\n\r\nI copied a number of unit tests from `test_pixel.py` to ensure that the above params are interpolatable across the field.\r\n\r\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.","created_at":"2016-09-19T15:58:54Z","updated_at":"2016-09-20T16:20:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"44012947ecfdd287a9aab1b3d101645790f9d03b","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/8662e3438d56fb1a6810d82ab6960851630ba98d","head":{"label":"rmjarvis:#38","ref":"#38","sha":"8662e3438d56fb1a6810d82ab6960851630ba98d","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-09-20T00:28:40Z","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":28377,"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":18,"forks":2,"open_issues":18,"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-09-20T00:28:40Z","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":28377,"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":18,"forks":2,"open_issues":18,"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/8662e3438d56fb1a6810d82ab6960851630ba98d"}}}}
{"actor":{"display_login":"rmjarvis"}}