{"action":"created","comment":{"url":"https://api.github.com/repos/HERA-Team/hera_cal/pulls/comments/167671538","pull_request_review_id":95924068,"id":167671538,"diff_hunk":"@@ -0,0 +1,286 @@\n+import numpy as np\n+from pyuvdata import UVCal, UVData\n+from collections import OrderedDict as odict\n+from pyuvdata.utils import polstr2num, polnum2str\n+from copy import deepcopy\n+from hera_cal.datacontainer import DataContainer\n+import operator\n+\n+str2antpol = {'x': -5, 'y': -6}\n+antpol2str = {antpol: string for string,antpol in str2antpol.items()}\n+#TODO: update to use jones strings (e.g. 'jxx' and 'jyy'). Currently uses pyuvdata for visibility polarizations.\n+\n+def load_vis(input_data, return_meta=False, format='miriad', pol_select=None, pop_autos=False, pick_data_ants=True, nested_dict=False):\n+    '''Load miriad or uvfits files or UVData objects into DataContainers, optionally returning \n+    the most useful metadata. More than one spectral window is not supported.\n+\n+    Arguments:\n+        input_data: data file path, or UVData instance, or list of either strings of data file paths \n+            or list of UVData instances to concatenate into a single dictionary\n+        return_meta:  boolean, if True: also return antpos, ants, freqs, times, lsts, and pols\n+        format: either 'miriad' or 'uvfits', can be ignored if input_data is UVData objects\n+        pol_select: list of polarization strings to keep\n+        pop_autos: boolean, if True: remove autocorrelations\n+        pick_data_ants: boolean, if True and return_meta=True, return only antennas in data\n+        nested_dict: boolean, if True replace DataContainers with the legacy nested dictionary format\n+            where visibilities and flags are accessed as data[(0,1)]['xx']\n+\n+    Returns:\n+        if return_meta is True:\n+            (data, flags, antpos, ants, freqs, times, lsts, pols)\n+        else:\n+            (data, flags)\n+\n+        data: DataContainer containing baseline-pol complex visibility data with keys\n+            like (0,1,'xx') and with shape=(Ntimes,Nfreqs) \n+        flags: DataContainer containing data flags\n+        antpos: dictionary containing antennas numbers as keys and position vectors\n+        ants: ndarray containing unique antenna indices\n+        freqs: ndarray containing frequency channels (Hz)\n+        times: ndarray containing julian date bins of data\n+        lsts: ndarray containing LST bins of data (radians)\n+        pol: ndarray containing list of polarization strings\n+    '''\n+\n+    uvd = UVData()\n+    if isinstance(input_data, (tuple, list, np.ndarray)): #List loading\n+        if np.all([isinstance(id, str) for id in input_data]): #List of visibility data paths\n+            if format is 'miriad':\n+                uvd.read_miriad(list(input_data))\n+            elif format is 'uvfits':\n+                 #TODO: implement this\n+                raise NotImplementedError('This function has not been implemented yet.')\n+            else:\n+                raise NotImplementedError(\"Data format must be either 'miriad' or 'uvfits'.\")\n+        elif np.all([isinstance(id, UVData) for id in input_data]): #List of uvdata objects\n+            uvd = reduce(operator.add, input_data)\n+        else:\n+            raise TypeError('If input is a list, it must be only strings or only UVData objects.')\n+    elif isinstance(input_data, str): #single visibility data path\n+        if format is 'miriad':\n+            uvd.read_miriad(input_data)\n+        elif format is 'uvfits':\n+             #TODO: implement this\n+            raise NotImplementedError('This function has not been implemented yet.')\n+        else:\n+            raise NotImplementedError(\"Data format must be either 'miriad' or 'uvfits'.\")\n+    elif isinstance(input_data, UVData): #single UVData object\n+        uvd = input_data\n+    else:\n+        raise TypeError('Input must be a UVData object, a string, or a list of either.')\n+\n+    data, flags = {}, {}\n+    # create nested dictionaries of visibilities in the data[bl][pol] format\n+    for nbl, (i, j) in enumerate(map(uvd.baseline_to_antnums, np.unique(uvd.baseline_array))):\n+        if (i, j) not in data:\n+            data[i, j] = {}\n+            flags[i, j] = {}\n+        for ip, pol in enumerate(uvd.polarization_array):\n+            pol = polnum2str(pol)\n+            new_data = deepcopy(uvd.get_data((i, j, pol)))\n+            new_flags = deepcopy(uvd.get_flags((i, j, pol)))\n+            if pol not in data[(i, j)]:\n+                data[(i, j)][pol] = new_data\n+                flags[(i, j)][pol] = new_flags\n+            else:\n+                data[(i, j)][pol] = np.concatenate([data[(i, j)][pol], new_data ])\n+                flags[(i, j)][pol] = np.concatenate([flags[(i, j)][pol], new_flags ])","path":"hera_cal/io.py","position":87,"original_position":87,"commit_id":"8add4738a0204ea16cf9c10157fe420a3c43becf","original_commit_id":"8add4738a0204ea16cf9c10157fe420a3c43becf","user":{"login":"jsdillon","id":5281139,"avatar_url":"https://avatars1.githubusercontent.com/u/5281139?v=4","gravatar_id":"","url":"https://api.github.com/users/jsdillon","html_url":"https://github.com/jsdillon","followers_url":"https://api.github.com/users/jsdillon/followers","following_url":"https://api.github.com/users/jsdillon/following{/other_user}","gists_url":"https://api.github.com/users/jsdillon/gists{/gist_id}","starred_url":"https://api.github.com/users/jsdillon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jsdillon/subscriptions","organizations_url":"https://api.github.com/users/jsdillon/orgs","repos_url":"https://api.github.com/users/jsdillon/repos","events_url":"https://api.github.com/users/jsdillon/events{/privacy}","received_events_url":"https://api.github.com/users/jsdillon/received_events","type":"User","site_admin":false},"body":"Good point. Fixed.","created_at":"2018-02-12T20:07:50Z","updated_at":"2018-02-12T20:07:50Z","html_url":"https://github.com/HERA-Team/hera_cal/pull/175#discussion_r167671538","pull_request_url":"https://api.github.com/repos/HERA-Team/hera_cal/pulls/175","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/HERA-Team/hera_cal/pulls/comments/167671538"},"html":{"href":"https://github.com/HERA-Team/hera_cal/pull/175#discussion_r167671538"},"pull_request":{"href":"https://api.github.com/repos/HERA-Team/hera_cal/pulls/175"}},"in_reply_to_id":167613122},"pull_request":{"url":"https://api.github.com/repos/HERA-Team/hera_cal/pulls/175","id":168387261,"html_url":"https://github.com/HERA-Team/hera_cal/pull/175","diff_url":"https://github.com/HERA-Team/hera_cal/pull/175.diff","patch_url":"https://github.com/HERA-Team/hera_cal/pull/175.patch","issue_url":"https://api.github.com/repos/HERA-Team/hera_cal/issues/175","number":175,"state":"open","locked":false,"title":"Add io module","user":{"login":"jsdillon","id":5281139,"avatar_url":"https://avatars1.githubusercontent.com/u/5281139?v=4","gravatar_id":"","url":"https://api.github.com/users/jsdillon","html_url":"https://github.com/jsdillon","followers_url":"https://api.github.com/users/jsdillon/followers","following_url":"https://api.github.com/users/jsdillon/following{/other_user}","gists_url":"https://api.github.com/users/jsdillon/gists{/gist_id}","starred_url":"https://api.github.com/users/jsdillon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jsdillon/subscriptions","organizations_url":"https://api.github.com/users/jsdillon/orgs","repos_url":"https://api.github.com/users/jsdillon/repos","events_url":"https://api.github.com/users/jsdillon/events{/privacy}","received_events_url":"https://api.github.com/users/jsdillon/received_events","type":"User","site_admin":false},"body":"This begins to address #163, though several things remain to be done (support for non-miriad visibility files and writing visibility files and calfits files from scratch). ","created_at":"2018-02-10T05:30:07Z","updated_at":"2018-02-12T20:07:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"80435c40b24dce0fb3a63973fa4f8ceab6888cbd","assignee":null,"assignees":[],"requested_reviewers":[{"login":"nkern","id":4307358,"avatar_url":"https://avatars0.githubusercontent.com/u/4307358?v=4","gravatar_id":"","url":"https://api.github.com/users/nkern","html_url":"https://github.com/nkern","followers_url":"https://api.github.com/users/nkern/followers","following_url":"https://api.github.com/users/nkern/following{/other_user}","gists_url":"https://api.github.com/users/nkern/gists{/gist_id}","starred_url":"https://api.github.com/users/nkern/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nkern/subscriptions","organizations_url":"https://api.github.com/users/nkern/orgs","repos_url":"https://api.github.com/users/nkern/repos","events_url":"https://api.github.com/users/nkern/events{/privacy}","received_events_url":"https://api.github.com/users/nkern/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/HERA-Team/hera_cal/pulls/175/commits","review_comments_url":"https://api.github.com/repos/HERA-Team/hera_cal/pulls/175/comments","review_comment_url":"https://api.github.com/repos/HERA-Team/hera_cal/pulls/comments{/number}","comments_url":"https://api.github.com/repos/HERA-Team/hera_cal/issues/175/comments","statuses_url":"https://api.github.com/repos/HERA-Team/hera_cal/statuses/8add4738a0204ea16cf9c10157fe420a3c43becf","head":{"label":"HERA-Team:add_io","ref":"add_io","sha":"8add4738a0204ea16cf9c10157fe420a3c43becf","user":{"login":"HERA-Team","id":14352544,"avatar_url":"https://avatars1.githubusercontent.com/u/14352544?v=4","gravatar_id":"","url":"https://api.github.com/users/HERA-Team","html_url":"https://github.com/HERA-Team","followers_url":"https://api.github.com/users/HERA-Team/followers","following_url":"https://api.github.com/users/HERA-Team/following{/other_user}","gists_url":"https://api.github.com/users/HERA-Team/gists{/gist_id}","starred_url":"https://api.github.com/users/HERA-Team/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HERA-Team/subscriptions","organizations_url":"https://api.github.com/users/HERA-Team/orgs","repos_url":"https://api.github.com/users/HERA-Team/repos","events_url":"https://api.github.com/users/HERA-Team/events{/privacy}","received_events_url":"https://api.github.com/users/HERA-Team/received_events","type":"Organization","site_admin":false},"repo":{"id":75780327,"name":"hera_cal","full_name":"HERA-Team/hera_cal","owner":{"login":"HERA-Team","id":14352544,"avatar_url":"https://avatars1.githubusercontent.com/u/14352544?v=4","gravatar_id":"","url":"https://api.github.com/users/HERA-Team","html_url":"https://github.com/HERA-Team","followers_url":"https://api.github.com/users/HERA-Team/followers","following_url":"https://api.github.com/users/HERA-Team/following{/other_user}","gists_url":"https://api.github.com/users/HERA-Team/gists{/gist_id}","starred_url":"https://api.github.com/users/HERA-Team/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HERA-Team/subscriptions","organizations_url":"https://api.github.com/users/HERA-Team/orgs","repos_url":"https://api.github.com/users/HERA-Team/repos","events_url":"https://api.github.com/users/HERA-Team/events{/privacy}","received_events_url":"https://api.github.com/users/HERA-Team/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/HERA-Team/hera_cal","description":"Library for online calibration of HERA data.","fork":false,"url":"https://api.github.com/repos/HERA-Team/hera_cal","forks_url":"https://api.github.com/repos/HERA-Team/hera_cal/forks","keys_url":"https://api.github.com/repos/HERA-Team/hera_cal/keys{/key_id}","collaborators_url":"https://api.github.com/repos/HERA-Team/hera_cal/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/HERA-Team/hera_cal/teams","hooks_url":"https://api.github.com/repos/HERA-Team/hera_cal/hooks","issue_events_url":"https://api.github.com/repos/HERA-Team/hera_cal/issues/events{/number}","events_url":"https://api.github.com/repos/HERA-Team/hera_cal/events","assignees_url":"https://api.github.com/repos/HERA-Team/hera_cal/assignees{/user}","branches_url":"https://api.github.com/repos/HERA-Team/hera_cal/branches{/branch}","tags_url":"https://api.github.com/repos/HERA-Team/hera_cal/tags","blobs_url":"https://api.github.com/repos/HERA-Team/hera_cal/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/HERA-Team/hera_cal/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/HERA-Team/hera_cal/git/refs{/sha}","trees_url":"https://api.github.com/repos/HERA-Team/hera_cal/git/trees{/sha}","statuses_url":"https://api.github.com/repos/HERA-Team/hera_cal/statuses/{sha}","languages_url":"https://api.github.com/repos/HERA-Team/hera_cal/languages","stargazers_url":"https://api.github.com/repos/HERA-Team/hera_cal/stargazers","contributors_url":"https://api.github.com/repos/HERA-Team/hera_cal/contributors","subscribers_url":"https://api.github.com/repos/HERA-Team/hera_cal/subscribers","subscription_url":"https://api.github.com/repos/HERA-Team/hera_cal/subscription","commits_url":"https://api.github.com/repos/HERA-Team/hera_cal/commits{/sha}","git_commits_url":"https://api.github.com/repos/HERA-Team/hera_cal/git/commits{/sha}","comments_url":"https://api.github.com/repos/HERA-Team/hera_cal/comments{/number}","issue_comment_url":"https://api.github.com/repos/HERA-Team/hera_cal/issues/comments{/number}","contents_url":"https://api.github.com/repos/HERA-Team/hera_cal/contents/{+path}","compare_url":"https://api.github.com/repos/HERA-Team/hera_cal/compare/{base}...{head}","merges_url":"https://api.github.com/repos/HERA-Team/hera_cal/merges","archive_url":"https://api.github.com/repos/HERA-Team/hera_cal/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/HERA-Team/hera_cal/downloads","issues_url":"https://api.github.com/repos/HERA-Team/hera_cal/issues{/number}","pulls_url":"https://api.github.com/repos/HERA-Team/hera_cal/pulls{/number}","milestones_url":"https://api.github.com/repos/HERA-Team/hera_cal/milestones{/number}","notifications_url":"https://api.github.com/repos/HERA-Team/hera_cal/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/HERA-Team/hera_cal/labels{/name}","releases_url":"https://api.github.com/repos/HERA-Team/hera_cal/releases{/id}","deployments_url":"https://api.github.com/repos/HERA-Team/hera_cal/deployments","created_at":"2016-12-06T23:24:02Z","updated_at":"2018-02-04T22:11:50Z","pushed_at":"2018-02-11T01:17:55Z","git_url":"git://github.com/HERA-Team/hera_cal.git","ssh_url":"git@github.com:HERA-Team/hera_cal.git","clone_url":"https://github.com/HERA-Team/hera_cal.git","svn_url":"https://github.com/HERA-Team/hera_cal","homepage":null,"size":63600,"stargazers_count":1,"watchers_count":1,"language":"Jupyter Notebook","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"archived":false,"open_issues_count":38,"license":null,"forks":2,"open_issues":38,"watchers":1,"default_branch":"master"}},"base":{"label":"HERA-Team:master","ref":"master","sha":"df79fea28ae1d89e038896231252aebd2caa190d","user":{"login":"HERA-Team","id":14352544,"avatar_url":"https://avatars1.githubusercontent.com/u/14352544?v=4","gravatar_id":"","url":"https://api.github.com/users/HERA-Team","html_url":"https://github.com/HERA-Team","followers_url":"https://api.github.com/users/HERA-Team/followers","following_url":"https://api.github.com/users/HERA-Team/following{/other_user}","gists_url":"https://api.github.com/users/HERA-Team/gists{/gist_id}","starred_url":"https://api.github.com/users/HERA-Team/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HERA-Team/subscriptions","organizations_url":"https://api.github.com/users/HERA-Team/orgs","repos_url":"https://api.github.com/users/HERA-Team/repos","events_url":"https://api.github.com/users/HERA-Team/events{/privacy}","received_events_url":"https://api.github.com/users/HERA-Team/received_events","type":"Organization","site_admin":false},"repo":{"id":75780327,"name":"hera_cal","full_name":"HERA-Team/hera_cal","owner":{"login":"HERA-Team","id":14352544,"avatar_url":"https://avatars1.githubusercontent.com/u/14352544?v=4","gravatar_id":"","url":"https://api.github.com/users/HERA-Team","html_url":"https://github.com/HERA-Team","followers_url":"https://api.github.com/users/HERA-Team/followers","following_url":"https://api.github.com/users/HERA-Team/following{/other_user}","gists_url":"https://api.github.com/users/HERA-Team/gists{/gist_id}","starred_url":"https://api.github.com/users/HERA-Team/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HERA-Team/subscriptions","organizations_url":"https://api.github.com/users/HERA-Team/orgs","repos_url":"https://api.github.com/users/HERA-Team/repos","events_url":"https://api.github.com/users/HERA-Team/events{/privacy}","received_events_url":"https://api.github.com/users/HERA-Team/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/HERA-Team/hera_cal","description":"Library for online calibration of HERA data.","fork":false,"url":"https://api.github.com/repos/HERA-Team/hera_cal","forks_url":"https://api.github.com/repos/HERA-Team/hera_cal/forks","keys_url":"https://api.github.com/repos/HERA-Team/hera_cal/keys{/key_id}","collaborators_url":"https://api.github.com/repos/HERA-Team/hera_cal/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/HERA-Team/hera_cal/teams","hooks_url":"https://api.github.com/repos/HERA-Team/hera_cal/hooks","issue_events_url":"https://api.github.com/repos/HERA-Team/hera_cal/issues/events{/number}","events_url":"https://api.github.com/repos/HERA-Team/hera_cal/events","assignees_url":"https://api.github.com/repos/HERA-Team/hera_cal/assignees{/user}","branches_url":"https://api.github.com/repos/HERA-Team/hera_cal/branches{/branch}","tags_url":"https://api.github.com/repos/HERA-Team/hera_cal/tags","blobs_url":"https://api.github.com/repos/HERA-Team/hera_cal/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/HERA-Team/hera_cal/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/HERA-Team/hera_cal/git/refs{/sha}","trees_url":"https://api.github.com/repos/HERA-Team/hera_cal/git/trees{/sha}","statuses_url":"https://api.github.com/repos/HERA-Team/hera_cal/statuses/{sha}","languages_url":"https://api.github.com/repos/HERA-Team/hera_cal/languages","stargazers_url":"https://api.github.com/repos/HERA-Team/hera_cal/stargazers","contributors_url":"https://api.github.com/repos/HERA-Team/hera_cal/contributors","subscribers_url":"https://api.github.com/repos/HERA-Team/hera_cal/subscribers","subscription_url":"https://api.github.com/repos/HERA-Team/hera_cal/subscription","commits_url":"https://api.github.com/repos/HERA-Team/hera_cal/commits{/sha}","git_commits_url":"https://api.github.com/repos/HERA-Team/hera_cal/git/commits{/sha}","comments_url":"https://api.github.com/repos/HERA-Team/hera_cal/comments{/number}","issue_comment_url":"https://api.github.com/repos/HERA-Team/hera_cal/issues/comments{/number}","contents_url":"https://api.github.com/repos/HERA-Team/hera_cal/contents/{+path}","compare_url":"https://api.github.com/repos/HERA-Team/hera_cal/compare/{base}...{head}","merges_url":"https://api.github.com/repos/HERA-Team/hera_cal/merges","archive_url":"https://api.github.com/repos/HERA-Team/hera_cal/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/HERA-Team/hera_cal/downloads","issues_url":"https://api.github.com/repos/HERA-Team/hera_cal/issues{/number}","pulls_url":"https://api.github.com/repos/HERA-Team/hera_cal/pulls{/number}","milestones_url":"https://api.github.com/repos/HERA-Team/hera_cal/milestones{/number}","notifications_url":"https://api.github.com/repos/HERA-Team/hera_cal/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/HERA-Team/hera_cal/labels{/name}","releases_url":"https://api.github.com/repos/HERA-Team/hera_cal/releases{/id}","deployments_url":"https://api.github.com/repos/HERA-Team/hera_cal/deployments","created_at":"2016-12-06T23:24:02Z","updated_at":"2018-02-04T22:11:50Z","pushed_at":"2018-02-11T01:17:55Z","git_url":"git://github.com/HERA-Team/hera_cal.git","ssh_url":"git@github.com:HERA-Team/hera_cal.git","clone_url":"https://github.com/HERA-Team/hera_cal.git","svn_url":"https://github.com/HERA-Team/hera_cal","homepage":null,"size":63600,"stargazers_count":1,"watchers_count":1,"language":"Jupyter Notebook","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"archived":false,"open_issues_count":38,"license":null,"forks":2,"open_issues":38,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/HERA-Team/hera_cal/pulls/175"},"html":{"href":"https://github.com/HERA-Team/hera_cal/pull/175"},"issue":{"href":"https://api.github.com/repos/HERA-Team/hera_cal/issues/175"},"comments":{"href":"https://api.github.com/repos/HERA-Team/hera_cal/issues/175/comments"},"review_comments":{"href":"https://api.github.com/repos/HERA-Team/hera_cal/pulls/175/comments"},"review_comment":{"href":"https://api.github.com/repos/HERA-Team/hera_cal/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/HERA-Team/hera_cal/pulls/175/commits"},"statuses":{"href":"https://api.github.com/repos/HERA-Team/hera_cal/statuses/8add4738a0204ea16cf9c10157fe420a3c43becf"}},"author_association":"OWNER"}}
{"actor":{"display_login":"jsdillon"}}