{"action":"created","comment":{"url":"https://api.github.com/repos/astroplanners/astroplan/pulls/comments/34757117","id":34757117,"diff_hunk":"@@ -73,6 +75,80 @@ def _generate_24hr_grid(t0, start, end, N, for_deriv=False):\n \n     return t0 + time_grid\n \n+# Observatory database and list of names:\n+_site_db = None\n+_site_names = []\n+\n+def _load_sites():\n+    '''\n+    Load observatory database from astroplan/data/observatories.json\n+    '''\n+    global _site_db, _site_names\n+    _site_db = dict()\n+    db = json.loads(get_pkg_data_contents('data/observatories.json'))\n+    _site_names = [db[site]['name'] for site in db]\n+    for site in db:\n+        location = EarthLocation.from_geodetic(db[site]['longitude'],\n+                                   db[site]['latitude'],\n+                                   db[site]['elevation'])\n+        _site_db[db[site]['name']] = location\n+        for alias in db[site]['aliases']:\n+            _site_db[alias.lower()] = location\n+\n+def get_site(site_name):\n+    '''\n+    Construct an `~astropy.coordinates.EarthLocation` object for a known\n+    observatory.","path":"astroplan/core.py","position":51,"original_position":51,"commit_id":"866811a55558332f5cb164b2c187ba12c2dfd272","original_commit_id":"866811a55558332f5cb164b2c187ba12c2dfd272","user":{"login":"eteq","id":346587,"avatar_url":"https://avatars.githubusercontent.com/u/346587?v=3","gravatar_id":"","url":"https://api.github.com/users/eteq","html_url":"https://github.com/eteq","followers_url":"https://api.github.com/users/eteq/followers","following_url":"https://api.github.com/users/eteq/following{/other_user}","gists_url":"https://api.github.com/users/eteq/gists{/gist_id}","starred_url":"https://api.github.com/users/eteq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eteq/subscriptions","organizations_url":"https://api.github.com/users/eteq/orgs","repos_url":"https://api.github.com/users/eteq/repos","events_url":"https://api.github.com/users/eteq/events{/privacy}","received_events_url":"https://api.github.com/users/eteq/received_events","type":"User","site_admin":false},"body":"\"a known observatory\" -> \"an observatory in the builtin list.\"?   \r\n\r\nAlso, perhaps \"construct\"->\"return\"?  \"construct\" implies to me it's a new object every time, but in this case it's actually the *same* object if you ask for the same name twice.  A subtle distinction, but important if someone wants to do ``is`` comparison or the like.","created_at":"2015-07-16T05:40:15Z","updated_at":"2015-07-16T05:40:15Z","html_url":"https://github.com/astroplanners/astroplan/pull/26#discussion_r34757117","pull_request_url":"https://api.github.com/repos/astroplanners/astroplan/pulls/26","_links":{"self":{"href":"https://api.github.com/repos/astroplanners/astroplan/pulls/comments/34757117"},"html":{"href":"https://github.com/astroplanners/astroplan/pull/26#discussion_r34757117"},"pull_request":{"href":"https://api.github.com/repos/astroplanners/astroplan/pulls/26"}}},"pull_request":{"url":"https://api.github.com/repos/astroplanners/astroplan/pulls/26","id":40053352,"html_url":"https://github.com/astroplanners/astroplan/pull/26","diff_url":"https://github.com/astroplanners/astroplan/pull/26.diff","patch_url":"https://github.com/astroplanners/astroplan/pull/26.patch","issue_url":"https://api.github.com/repos/astroplanners/astroplan/issues/26","number":26,"state":"open","locked":false,"title":"Sites","user":{"login":"bmorris3","id":3497584,"avatar_url":"https://avatars.githubusercontent.com/u/3497584?v=3","gravatar_id":"","url":"https://api.github.com/users/bmorris3","html_url":"https://github.com/bmorris3","followers_url":"https://api.github.com/users/bmorris3/followers","following_url":"https://api.github.com/users/bmorris3/following{/other_user}","gists_url":"https://api.github.com/users/bmorris3/gists{/gist_id}","starred_url":"https://api.github.com/users/bmorris3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bmorris3/subscriptions","organizations_url":"https://api.github.com/users/bmorris3/orgs","repos_url":"https://api.github.com/users/bmorris3/repos","events_url":"https://api.github.com/users/bmorris3/events{/privacy}","received_events_url":"https://api.github.com/users/bmorris3/received_events","type":"User","site_admin":false},"body":"I've implemented here a simple site importing tool, as the basis for discussion amongst @astroplanners/astroplanners-contributors on what we want our site tool to look like. A user can get an `EarthLocation` object for known observatories with the following syntax: \r\n```python\r\n>>> from astroplan import get_site, Observer\r\n>>> keck = get_site('Keck')\r\n>>> obs = Observer(location=keck)\r\n>>> print(keck.to_geodetic())\r\n(<Longitude -155.47833333333332 deg>, <Latitude 19.828333333333326 deg>, \r\n <Quantity 4160.000000000752 m>)\r\n```\r\nThere are several aliases for each observatory, and if the queried name is not recognized, a `KeyError` is raised with an informative error message that suggests fuzzy matches (using `difflib`, thanks @adrn!). For example, searching for `'keck obs'` raises the following error:\r\n\r\n```python\r\nIn [1]: import astroplan; astroplan.get_site(str('keck obs'))\r\n---------------------------------------------------------------------------\r\nKeyError                                  Traceback (most recent call last)\r\n<ipython-input-1-7986be699dec> in <module>()\r\n----> 1 import astroplan; astroplan.get_site(str('keck obs'))\r\n\r\nastroplan/astroplan/core.py in get_site(site_name)\r\n    126             errmsg = ('Site not in database. `use get_site_names()` to see '\r\n    127                       'available sites.')\r\n--> 128         raise KeyError(errmsg)\r\n    129 \r\n    130     return _site_db[site_name.lower()]\r\n\r\nKeyError: u\"Site not in database. `use get_site_names()` to see available sites. \r\nDid you mean: 'keck observatory', 'keck'?\"\r\n```","created_at":"2015-07-15T18:24:24Z","updated_at":"2015-07-16T05:40:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e6a40179318ae1c808f58047b888d0df0b152f80","assignee":null,"milestone":{"url":"https://api.github.com/repos/astroplanners/astroplan/milestones/1","html_url":"https://github.com/astroplanners/astroplan/milestones/0.1%20release","labels_url":"https://api.github.com/repos/astroplanners/astroplan/milestones/1/labels","id":1087263,"number":1,"title":"0.1 release","description":"First release","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":4,"closed_issues":5,"state":"open","created_at":"2015-04-28T11:35:13Z","updated_at":"2015-07-15T23:25:40Z","due_on":"2015-08-09T22:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/astroplanners/astroplan/pulls/26/commits","review_comments_url":"https://api.github.com/repos/astroplanners/astroplan/pulls/26/comments","review_comment_url":"https://api.github.com/repos/astroplanners/astroplan/pulls/comments{/number}","comments_url":"https://api.github.com/repos/astroplanners/astroplan/issues/26/comments","statuses_url":"https://api.github.com/repos/astroplanners/astroplan/statuses/866811a55558332f5cb164b2c187ba12c2dfd272","head":{"label":"bmorris3:sites","ref":"sites","sha":"866811a55558332f5cb164b2c187ba12c2dfd272","user":{"login":"bmorris3","id":3497584,"avatar_url":"https://avatars.githubusercontent.com/u/3497584?v=3","gravatar_id":"","url":"https://api.github.com/users/bmorris3","html_url":"https://github.com/bmorris3","followers_url":"https://api.github.com/users/bmorris3/followers","following_url":"https://api.github.com/users/bmorris3/following{/other_user}","gists_url":"https://api.github.com/users/bmorris3/gists{/gist_id}","starred_url":"https://api.github.com/users/bmorris3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bmorris3/subscriptions","organizations_url":"https://api.github.com/users/bmorris3/orgs","repos_url":"https://api.github.com/users/bmorris3/repos","events_url":"https://api.github.com/users/bmorris3/events{/privacy}","received_events_url":"https://api.github.com/users/bmorris3/received_events","type":"User","site_admin":false},"repo":{"id":34740000,"name":"astroplan","full_name":"bmorris3/astroplan","owner":{"login":"bmorris3","id":3497584,"avatar_url":"https://avatars.githubusercontent.com/u/3497584?v=3","gravatar_id":"","url":"https://api.github.com/users/bmorris3","html_url":"https://github.com/bmorris3","followers_url":"https://api.github.com/users/bmorris3/followers","following_url":"https://api.github.com/users/bmorris3/following{/other_user}","gists_url":"https://api.github.com/users/bmorris3/gists{/gist_id}","starred_url":"https://api.github.com/users/bmorris3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bmorris3/subscriptions","organizations_url":"https://api.github.com/users/bmorris3/orgs","repos_url":"https://api.github.com/users/bmorris3/repos","events_url":"https://api.github.com/users/bmorris3/events{/privacy}","received_events_url":"https://api.github.com/users/bmorris3/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bmorris3/astroplan","description":"Observation planning package for astronomers","fork":true,"url":"https://api.github.com/repos/bmorris3/astroplan","forks_url":"https://api.github.com/repos/bmorris3/astroplan/forks","keys_url":"https://api.github.com/repos/bmorris3/astroplan/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bmorris3/astroplan/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bmorris3/astroplan/teams","hooks_url":"https://api.github.com/repos/bmorris3/astroplan/hooks","issue_events_url":"https://api.github.com/repos/bmorris3/astroplan/issues/events{/number}","events_url":"https://api.github.com/repos/bmorris3/astroplan/events","assignees_url":"https://api.github.com/repos/bmorris3/astroplan/assignees{/user}","branches_url":"https://api.github.com/repos/bmorris3/astroplan/branches{/branch}","tags_url":"https://api.github.com/repos/bmorris3/astroplan/tags","blobs_url":"https://api.github.com/repos/bmorris3/astroplan/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bmorris3/astroplan/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bmorris3/astroplan/git/refs{/sha}","trees_url":"https://api.github.com/repos/bmorris3/astroplan/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bmorris3/astroplan/statuses/{sha}","languages_url":"https://api.github.com/repos/bmorris3/astroplan/languages","stargazers_url":"https://api.github.com/repos/bmorris3/astroplan/stargazers","contributors_url":"https://api.github.com/repos/bmorris3/astroplan/contributors","subscribers_url":"https://api.github.com/repos/bmorris3/astroplan/subscribers","subscription_url":"https://api.github.com/repos/bmorris3/astroplan/subscription","commits_url":"https://api.github.com/repos/bmorris3/astroplan/commits{/sha}","git_commits_url":"https://api.github.com/repos/bmorris3/astroplan/git/commits{/sha}","comments_url":"https://api.github.com/repos/bmorris3/astroplan/comments{/number}","issue_comment_url":"https://api.github.com/repos/bmorris3/astroplan/issues/comments{/number}","contents_url":"https://api.github.com/repos/bmorris3/astroplan/contents/{+path}","compare_url":"https://api.github.com/repos/bmorris3/astroplan/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bmorris3/astroplan/merges","archive_url":"https://api.github.com/repos/bmorris3/astroplan/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bmorris3/astroplan/downloads","issues_url":"https://api.github.com/repos/bmorris3/astroplan/issues{/number}","pulls_url":"https://api.github.com/repos/bmorris3/astroplan/pulls{/number}","milestones_url":"https://api.github.com/repos/bmorris3/astroplan/milestones{/number}","notifications_url":"https://api.github.com/repos/bmorris3/astroplan/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bmorris3/astroplan/labels{/name}","releases_url":"https://api.github.com/repos/bmorris3/astroplan/releases{/id}","created_at":"2015-04-28T15:47:16Z","updated_at":"2015-04-28T15:47:16Z","pushed_at":"2015-07-15T20:56:35Z","git_url":"git://github.com/bmorris3/astroplan.git","ssh_url":"git@github.com:bmorris3/astroplan.git","clone_url":"https://github.com/bmorris3/astroplan.git","svn_url":"https://github.com/bmorris3/astroplan","homepage":"https://astroplan.readthedocs.org/","size":504,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"astroplanners:master","ref":"master","sha":"79c5fee382b13b0a9759d4ee232131c52a044943","user":{"login":"astroplanners","id":12143843,"avatar_url":"https://avatars.githubusercontent.com/u/12143843?v=3","gravatar_id":"","url":"https://api.github.com/users/astroplanners","html_url":"https://github.com/astroplanners","followers_url":"https://api.github.com/users/astroplanners/followers","following_url":"https://api.github.com/users/astroplanners/following{/other_user}","gists_url":"https://api.github.com/users/astroplanners/gists{/gist_id}","starred_url":"https://api.github.com/users/astroplanners/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/astroplanners/subscriptions","organizations_url":"https://api.github.com/users/astroplanners/orgs","repos_url":"https://api.github.com/users/astroplanners/repos","events_url":"https://api.github.com/users/astroplanners/events{/privacy}","received_events_url":"https://api.github.com/users/astroplanners/received_events","type":"Organization","site_admin":false},"repo":{"id":34693515,"name":"astroplan","full_name":"astroplanners/astroplan","owner":{"login":"astroplanners","id":12143843,"avatar_url":"https://avatars.githubusercontent.com/u/12143843?v=3","gravatar_id":"","url":"https://api.github.com/users/astroplanners","html_url":"https://github.com/astroplanners","followers_url":"https://api.github.com/users/astroplanners/followers","following_url":"https://api.github.com/users/astroplanners/following{/other_user}","gists_url":"https://api.github.com/users/astroplanners/gists{/gist_id}","starred_url":"https://api.github.com/users/astroplanners/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/astroplanners/subscriptions","organizations_url":"https://api.github.com/users/astroplanners/orgs","repos_url":"https://api.github.com/users/astroplanners/repos","events_url":"https://api.github.com/users/astroplanners/events{/privacy}","received_events_url":"https://api.github.com/users/astroplanners/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/astroplanners/astroplan","description":"Observation planning package for astronomers","fork":false,"url":"https://api.github.com/repos/astroplanners/astroplan","forks_url":"https://api.github.com/repos/astroplanners/astroplan/forks","keys_url":"https://api.github.com/repos/astroplanners/astroplan/keys{/key_id}","collaborators_url":"https://api.github.com/repos/astroplanners/astroplan/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/astroplanners/astroplan/teams","hooks_url":"https://api.github.com/repos/astroplanners/astroplan/hooks","issue_events_url":"https://api.github.com/repos/astroplanners/astroplan/issues/events{/number}","events_url":"https://api.github.com/repos/astroplanners/astroplan/events","assignees_url":"https://api.github.com/repos/astroplanners/astroplan/assignees{/user}","branches_url":"https://api.github.com/repos/astroplanners/astroplan/branches{/branch}","tags_url":"https://api.github.com/repos/astroplanners/astroplan/tags","blobs_url":"https://api.github.com/repos/astroplanners/astroplan/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/astroplanners/astroplan/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/astroplanners/astroplan/git/refs{/sha}","trees_url":"https://api.github.com/repos/astroplanners/astroplan/git/trees{/sha}","statuses_url":"https://api.github.com/repos/astroplanners/astroplan/statuses/{sha}","languages_url":"https://api.github.com/repos/astroplanners/astroplan/languages","stargazers_url":"https://api.github.com/repos/astroplanners/astroplan/stargazers","contributors_url":"https://api.github.com/repos/astroplanners/astroplan/contributors","subscribers_url":"https://api.github.com/repos/astroplanners/astroplan/subscribers","subscription_url":"https://api.github.com/repos/astroplanners/astroplan/subscription","commits_url":"https://api.github.com/repos/astroplanners/astroplan/commits{/sha}","git_commits_url":"https://api.github.com/repos/astroplanners/astroplan/git/commits{/sha}","comments_url":"https://api.github.com/repos/astroplanners/astroplan/comments{/number}","issue_comment_url":"https://api.github.com/repos/astroplanners/astroplan/issues/comments{/number}","contents_url":"https://api.github.com/repos/astroplanners/astroplan/contents/{+path}","compare_url":"https://api.github.com/repos/astroplanners/astroplan/compare/{base}...{head}","merges_url":"https://api.github.com/repos/astroplanners/astroplan/merges","archive_url":"https://api.github.com/repos/astroplanners/astroplan/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/astroplanners/astroplan/downloads","issues_url":"https://api.github.com/repos/astroplanners/astroplan/issues{/number}","pulls_url":"https://api.github.com/repos/astroplanners/astroplan/pulls{/number}","milestones_url":"https://api.github.com/repos/astroplanners/astroplan/milestones{/number}","notifications_url":"https://api.github.com/repos/astroplanners/astroplan/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/astroplanners/astroplan/labels{/name}","releases_url":"https://api.github.com/repos/astroplanners/astroplan/releases{/id}","created_at":"2015-04-27T22:00:00Z","updated_at":"2015-07-09T05:17:38Z","pushed_at":"2015-07-15T23:10:34Z","git_url":"git://github.com/astroplanners/astroplan.git","ssh_url":"git@github.com:astroplanners/astroplan.git","clone_url":"https://github.com/astroplanners/astroplan.git","svn_url":"https://github.com/astroplanners/astroplan","homepage":"https://astroplan.readthedocs.org/","size":875,"stargazers_count":7,"watchers_count":7,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":14,"forks":6,"open_issues":14,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/astroplanners/astroplan/pulls/26"},"html":{"href":"https://github.com/astroplanners/astroplan/pull/26"},"issue":{"href":"https://api.github.com/repos/astroplanners/astroplan/issues/26"},"comments":{"href":"https://api.github.com/repos/astroplanners/astroplan/issues/26/comments"},"review_comments":{"href":"https://api.github.com/repos/astroplanners/astroplan/pulls/26/comments"},"review_comment":{"href":"https://api.github.com/repos/astroplanners/astroplan/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/astroplanners/astroplan/pulls/26/commits"},"statuses":{"href":"https://api.github.com/repos/astroplanners/astroplan/statuses/866811a55558332f5cb164b2c187ba12c2dfd272"}}}}