{"action":"created","comment":{"url":"https://api.github.com/repos/gammapy/gammapy/pulls/comments/35293138","id":35293138,"diff_hunk":"@@ -0,0 +1,204 @@\n+# Licensed under a 3-clause BSD style license - see LICENSE.rst\n+from __future__ import print_function, division\n+from astropy.units import Quantity\n+from ..utils.array import array_stats_str\n+\n+import astropy.units as u\n+\n+\n+__all__ = ['Energy',\n+           'EnergyBounds']\n+\n+\n+class Energy(Quantity):\n+\n+    \"\"\"Energy bin centers.\n+\n+    Stored as \"ENERGIES\" FITS table extensions.\n+\n+    Parameters\n+    ----------\n+\n+    energy : `~numpy.ndarray`\n+        Energy\n+    unit : `~astropy.units.UnitBase`, str\n+        The unit of the values specified for the energy.  This may be any\n+        string that `~astropy.units.Unit` understands, but it is better to\n+        give an actual unit object.\n+\n+    \"\"\"\n+\n+    def __init__(self, energy, unit=None):\n+\n+        if isinstance(energy, Quantity):\n+            energy = energy.value\n+            unit = energy.unit\n+\n+        if isinstance(unit, u.UnitBase):\n+            pass\n+        elif isinstance(unit, basestring):\n+            unit = u.Unit(unit)\n+        elif unit is None:\n+            raise UnitsError(\"No unit was specified in Energy initializer\")\n+\n+        self._unit = unit\n+        self._value = energy\n+\n+    @staticmethod\n+    def equal_log_spacing(emin, emax, nbins):\n+        \"\"\"Create Energy with equal log-spacing.\n+\n+        The unit will be taken from emax\n+\n+        Parameters\n+        ----------\n+        emin : `~astropy.units.Quantity`\n+            Lowest energy bin\n+        emax : `~astropy.units.Quantity`\n+            Highest energy bin\n+        bins : int\n+            Number of bins\n+\n+        Returns\n+        -------\n+        Energy\n+        \"\"\"\n+\n+        if not isinstance(emin, Quantity) or not isinstance(emax, Quantity):\n+            raise ValueError(\"Energies must be Quantities\")\n+\n+        x_min, x_max = np.log10([emin.value, emax.value])\n+        energy = np.logspace(x_min, x_max, nbins)\n+        energy = Quantity(energy, emax.unit)\n+\n+        return Energy(energy)\n+\n+    @staticmethod\n+    def from_fits(hdulist):\n+        \"\"\"Read ENERGIES fits extension.\n+\n+        Parameters\n+        ---------\n+        hdu_list : `~astropy.io.fits.HDUList` \n+            HDU list with ``ENERGIES`` extensions.\n+\n+        Returns\n+        ------\n+        Energy\n+        \"\"\"\n+\n+        energy = Quantity(hdulist['ENERGIES'].data['Energy'], 'MeV')\n+        return Energy(energy)\n+\n+    def to_fits(self, **kwargs):\n+        \"\"\"Write ENERGIES fits extension\n+\n+        Returns\n+        -------\n+        hdu_list : `~astropy.io.fits.BinTableHDU`\n+            ENERGIES fits extension\n+\n+\n+        \"\"\"\n+\n+        col1 = fits.Column(name='Energy', format='D', array=self.value)\n+        cols = fits.ColDefs([col1])\n+        return fits.BinTableHDU.from_columns(cols)\n+\n+    def info(self):\n+        # is this really necessary? what's the benefit towards just typing the\n+        # name of the instance?\n+        pass\n+\n+class EnergyBounds(Quantity):\n+\n+    \"\"\"Energy bin edges\n+\n+    Stored as \"EBOUNDS\" FITS table extensions.\n+\n+    Parameters\n+    ----------\n+\n+    energy : `~numpy.ndarray`\n+        Energy\n+    unit : `~astropy.units.UnitBase`, str\n+        The unit of the values specified for the energy.  This may be any\n+        string that `~astropy.units.Unit` understands, but it is better to\n+        give an actual unit object.\n+\n+    \"\"\"\n+\n+    def __init__(self, energy, unit=None):\n+\n+        if isinstance(energy, Quantity):\n+            energy = energy.value\n+            unit = energy.unit\n+\n+        if isinstance(unit, u.UnitBase):\n+            pass\n+        elif isinstance(unit, basestring):\n+            unit = u.Unit(unit)\n+        elif unit is None:\n+            raise UnitsError(\"No unit was specified in EnergyBounds initializer\")\n+\n+        self._unit = unit\n+        self._value = energy\n+\n+    @staticmethod\n+    def equal_log_spacing(emin, emax, nbins):","path":"gammapy/spectrum/energy.py","position":148,"original_position":148,"commit_id":"646036bb1a48555b6582e5fd2ebd963317d9cc65","original_commit_id":"646036bb1a48555b6582e5fd2ebd963317d9cc65","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":"Hmm ... looking at it again, no strong opinion from my side whether to keep as is or add the extra option.","created_at":"2015-07-23T06:29:39Z","updated_at":"2015-07-23T06:29:39Z","html_url":"https://github.com/gammapy/gammapy/pull/290#discussion_r35293138","pull_request_url":"https://api.github.com/repos/gammapy/gammapy/pulls/290","_links":{"self":{"href":"https://api.github.com/repos/gammapy/gammapy/pulls/comments/35293138"},"html":{"href":"https://github.com/gammapy/gammapy/pull/290#discussion_r35293138"},"pull_request":{"href":"https://api.github.com/repos/gammapy/gammapy/pulls/290"}}},"pull_request":{"url":"https://api.github.com/repos/gammapy/gammapy/pulls/290","id":38426424,"html_url":"https://github.com/gammapy/gammapy/pull/290","diff_url":"https://github.com/gammapy/gammapy/pull/290.diff","patch_url":"https://github.com/gammapy/gammapy/pull/290.patch","issue_url":"https://api.github.com/repos/gammapy/gammapy/issues/290","number":290,"state":"open","locked":false,"title":"WIP: Improve energy handling","user":{"login":"kingj90","id":11678435,"avatar_url":"https://avatars.githubusercontent.com/u/11678435?v=3","gravatar_id":"","url":"https://api.github.com/users/kingj90","html_url":"https://github.com/kingj90","followers_url":"https://api.github.com/users/kingj90/followers","following_url":"https://api.github.com/users/kingj90/following{/other_user}","gists_url":"https://api.github.com/users/kingj90/gists{/gist_id}","starred_url":"https://api.github.com/users/kingj90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kingj90/subscriptions","organizations_url":"https://api.github.com/users/kingj90/orgs","repos_url":"https://api.github.com/users/kingj90/repos","events_url":"https://api.github.com/users/kingj90/events{/privacy}","received_events_url":"https://api.github.com/users/kingj90/received_events","type":"User","site_admin":false},"body":"Improve and document energy handling in Gammapy.\r\n\r\nTODO\r\n* [ ] fits output with header and everything (should be \"just\" typing)\r\n* [ ] Think about LogEnergyAxis\r\n* [ ] Remove old stuff and replace with the new classes (I will wait with this until I have the green light for the current API\r\n* [ ] Make Documentation properly","created_at":"2015-06-24T10:10:14Z","updated_at":"2015-07-23T06:29:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e009c5029585f8ff502fe95e1bc9b2e53654f938","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},"milestone":{"url":"https://api.github.com/repos/gammapy/gammapy/milestones/2","html_url":"https://github.com/gammapy/gammapy/milestones/0.3","labels_url":"https://api.github.com/repos/gammapy/gammapy/milestones/2/labels","id":377787,"number":2,"title":"0.3","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":29,"closed_issues":29,"state":"open","created_at":"2013-07-14T16:38:18Z","updated_at":"2015-07-22T20:24:51Z","due_on":"2015-07-27T22:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/gammapy/gammapy/pulls/290/commits","review_comments_url":"https://api.github.com/repos/gammapy/gammapy/pulls/290/comments","review_comment_url":"https://api.github.com/repos/gammapy/gammapy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/gammapy/gammapy/issues/290/comments","statuses_url":"https://api.github.com/repos/gammapy/gammapy/statuses/646036bb1a48555b6582e5fd2ebd963317d9cc65","head":{"label":"kingj90:energyhandling","ref":"energyhandling","sha":"646036bb1a48555b6582e5fd2ebd963317d9cc65","user":{"login":"kingj90","id":11678435,"avatar_url":"https://avatars.githubusercontent.com/u/11678435?v=3","gravatar_id":"","url":"https://api.github.com/users/kingj90","html_url":"https://github.com/kingj90","followers_url":"https://api.github.com/users/kingj90/followers","following_url":"https://api.github.com/users/kingj90/following{/other_user}","gists_url":"https://api.github.com/users/kingj90/gists{/gist_id}","starred_url":"https://api.github.com/users/kingj90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kingj90/subscriptions","organizations_url":"https://api.github.com/users/kingj90/orgs","repos_url":"https://api.github.com/users/kingj90/repos","events_url":"https://api.github.com/users/kingj90/events{/privacy}","received_events_url":"https://api.github.com/users/kingj90/received_events","type":"User","site_admin":false},"repo":{"id":34865384,"name":"gammapy","full_name":"kingj90/gammapy","owner":{"login":"kingj90","id":11678435,"avatar_url":"https://avatars.githubusercontent.com/u/11678435?v=3","gravatar_id":"","url":"https://api.github.com/users/kingj90","html_url":"https://github.com/kingj90","followers_url":"https://api.github.com/users/kingj90/followers","following_url":"https://api.github.com/users/kingj90/following{/other_user}","gists_url":"https://api.github.com/users/kingj90/gists{/gist_id}","starred_url":"https://api.github.com/users/kingj90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kingj90/subscriptions","organizations_url":"https://api.github.com/users/kingj90/orgs","repos_url":"https://api.github.com/users/kingj90/repos","events_url":"https://api.github.com/users/kingj90/events{/privacy}","received_events_url":"https://api.github.com/users/kingj90/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kingj90/gammapy","description":"A Python package for gamma-ray astronomy","fork":true,"url":"https://api.github.com/repos/kingj90/gammapy","forks_url":"https://api.github.com/repos/kingj90/gammapy/forks","keys_url":"https://api.github.com/repos/kingj90/gammapy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kingj90/gammapy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kingj90/gammapy/teams","hooks_url":"https://api.github.com/repos/kingj90/gammapy/hooks","issue_events_url":"https://api.github.com/repos/kingj90/gammapy/issues/events{/number}","events_url":"https://api.github.com/repos/kingj90/gammapy/events","assignees_url":"https://api.github.com/repos/kingj90/gammapy/assignees{/user}","branches_url":"https://api.github.com/repos/kingj90/gammapy/branches{/branch}","tags_url":"https://api.github.com/repos/kingj90/gammapy/tags","blobs_url":"https://api.github.com/repos/kingj90/gammapy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kingj90/gammapy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kingj90/gammapy/git/refs{/sha}","trees_url":"https://api.github.com/repos/kingj90/gammapy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kingj90/gammapy/statuses/{sha}","languages_url":"https://api.github.com/repos/kingj90/gammapy/languages","stargazers_url":"https://api.github.com/repos/kingj90/gammapy/stargazers","contributors_url":"https://api.github.com/repos/kingj90/gammapy/contributors","subscribers_url":"https://api.github.com/repos/kingj90/gammapy/subscribers","subscription_url":"https://api.github.com/repos/kingj90/gammapy/subscription","commits_url":"https://api.github.com/repos/kingj90/gammapy/commits{/sha}","git_commits_url":"https://api.github.com/repos/kingj90/gammapy/git/commits{/sha}","comments_url":"https://api.github.com/repos/kingj90/gammapy/comments{/number}","issue_comment_url":"https://api.github.com/repos/kingj90/gammapy/issues/comments{/number}","contents_url":"https://api.github.com/repos/kingj90/gammapy/contents/{+path}","compare_url":"https://api.github.com/repos/kingj90/gammapy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kingj90/gammapy/merges","archive_url":"https://api.github.com/repos/kingj90/gammapy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kingj90/gammapy/downloads","issues_url":"https://api.github.com/repos/kingj90/gammapy/issues{/number}","pulls_url":"https://api.github.com/repos/kingj90/gammapy/pulls{/number}","milestones_url":"https://api.github.com/repos/kingj90/gammapy/milestones{/number}","notifications_url":"https://api.github.com/repos/kingj90/gammapy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kingj90/gammapy/labels{/name}","releases_url":"https://api.github.com/repos/kingj90/gammapy/releases{/id}","created_at":"2015-04-30T16:42:10Z","updated_at":"2015-04-30T16:42:10Z","pushed_at":"2015-07-20T02:05:55Z","git_url":"git://github.com/kingj90/gammapy.git","ssh_url":"git@github.com:kingj90/gammapy.git","clone_url":"https://github.com/kingj90/gammapy.git","svn_url":"https://github.com/kingj90/gammapy","homepage":"https://gammapy.readthedocs.org/","size":2982,"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":"8117644e466456a572ca09cd5650ba0167f77982","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}","created_at":"2013-05-15T07:50:40Z","updated_at":"2015-06-06T13:39:51Z","pushed_at":"2015-07-22T04:45:33Z","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":"https://gammapy.readthedocs.org/","size":5553,"stargazers_count":12,"watchers_count":12,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":20,"mirror_url":null,"open_issues_count":103,"forks":20,"open_issues":103,"watchers":12,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/gammapy/gammapy/pulls/290"},"html":{"href":"https://github.com/gammapy/gammapy/pull/290"},"issue":{"href":"https://api.github.com/repos/gammapy/gammapy/issues/290"},"comments":{"href":"https://api.github.com/repos/gammapy/gammapy/issues/290/comments"},"review_comments":{"href":"https://api.github.com/repos/gammapy/gammapy/pulls/290/comments"},"review_comment":{"href":"https://api.github.com/repos/gammapy/gammapy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/gammapy/gammapy/pulls/290/commits"},"statuses":{"href":"https://api.github.com/repos/gammapy/gammapy/statuses/646036bb1a48555b6582e5fd2ebd963317d9cc65"}}}}