{"action":"created","comment":{"url":"https://api.github.com/repos/HERA-Team/hera_qm/pulls/comments/128923238","pull_request_review_id":51647233,"id":128923238,"diff_hunk":"@@ -431,3 +436,155 @@ def save_antenna_metrics(self, metricsJSONFilename):\n \n         with open(metricsJSONFilename, 'w') as outfile:\n             json.dump(allMetricsData, outfile, indent=4)\n+\n+# code for running ant_metrics on a file\n+def get_metrics_OptionParser(method_name):\n+    \"\"\"\n+    Function to get an OptionParser instance for working with metrics wrappers.\n+\n+    Args:\n+        method_name -- target wrapper, must be \"ant_metrics\" or \"xrfi\"\n+    Returns:\n+        o -- an optparse.OptionParser instance with the relevant options for the selected method\n+    \"\"\"\n+    methods = [\"ant_metrics\", \"xrfi\"]\n+    if method_name not in methods:\n+        raise AssertionError('method_name must be one of {}'.format(','.join(methods)))\n+\n+    o = optparse.OptionParser()\n+\n+    if method_name == 'ant_metrics':\n+        o.set_usage(\"ant_metrics_run.py -C [calfile] [options] *.uv\")\n+        aipy.scripting.add_standard_options(o, cal=True)\n+        o.add_option('--crossCut', dest='crossCut', default=5, type='float',\n+                     help='Modified z-score cut for most cross-polarized antenna. Default 5 \"sigmas\"')\n+        o.add_option('--deadCut', dest='deadCut', default=5, type='float',\n+                     help='Modified z-score cut for most likely dead antenna. Default 5 \"sigmas\"')\n+        o.add_option('--extension', dest='extension', default='.ant_metrics.json', type='string',\n+                     help='Extension to be appended to the file name. Default is \".ant_metrics.json\"')\n+        o.add_option('--metrics_path', dest='metrics_path', default='', type='string',\n+                     help='Path to save metrics file to. Default is same directory as file')\n+    elif method_name == 'xrfi':\n+        o.set_usage(\"xrfi_run.py\")\n+\n+    return o\n+\n+# helper functions\n+def get_pol(fname):\n+    \"\"\"Strips the filename of a HERA visibility to its polarization\n+    Args:\n+        fname -- name of file (string)\n+    Returns:\n+        polarization -- polarization label e.g. \"xx\" (string)\n+    \"\"\"\n+    # XXX assumes file naming format\n+    # extract just the filename if we're passed a path with periods in it\n+    fn = re.findall('zen\\.\\d{7}\\.\\d{5}\\..*', fname)[0]\n+    return fn.split('.')[3]\n+\n+def generate_fullpol_file_list(files, pol_list):\n+    \"\"\"Generate a list of unique JDs that have all four polarizations available\n+    Args:\n+       files -- list of files to look for\n+       pol_list -- list of polarizations to look for\n+    Returns:\n+       jd_list -- list of JDs where all supplied polarizations could be found\n+\n+    This function, when given a list of files, will look for the specified polarizations,\n+    and add the JD to the returned list if all polarizations were found.\n+    \"\"\"\n+    # initialize\n+    file_list = []\n+\n+    for filename in files:\n+        abspath = os.path.abspath(filename)\n+        if abspath not in file_list:\n+            # try to find the other polarizations\n+            pols_exist = True\n+            file_pol = get_pol(filename)\n+            dirname = os.path.dirname(abspath)\n+            for pol in pol_list:\n+                # guard against strange directory names that might contain something that\n+                # looks like a pol string\n+                fn = re.sub(file_pol, pol, filename)\n+                full_filename = os.path.join(dirname, fn)\n+                if not os.path.exists(full_filename):\n+                    warnings.warn(\"Could not find \" + full_filename + \"; skipping that JD\")\n+                    pols_exist = False\n+                    break\n+            if pols_exist:\n+                # add all pols to file_list\n+                for pol in pol_list:\n+                    fn = re.sub(file_pol, pol, filename)\n+                    full_filename = os.path.join(dirname, fn)\n+                    file_list.append(full_filename)\n+\n+    return file_list\n+\n+def ant_metrics_run(files, opts):\n+    \"\"\"\n+    Run a series of ant_metrics tests on a given set of input files.\n+\n+    Args:\n+       files -- a list of files to run ant metrics on. Can be any of the 4 polarizations\n+       opts -- an optparse OptionParser instance\n+    Return:\n+       None\n+\n+    The funciton will take in a list of files and options. It will run the\n+    sereis of ant metrics tests, and produce a JSON file containing the relevant\n+    information. The file list passed in need only contain one of the polarization\n+    files for a given JD, and the function will look for the other polarizations\n+    in the same folder. If not all four polarizations are found, a warning is\n+    generated, since the code assumes all four polarizations are present.\n+    \"\"\"\n+    # XXX: does this create a circular dependency if we only do this inside the function?","path":"hera_qm/ant_metrics.py","position":138,"original_position":138,"commit_id":"7f9e9f12e69fb6453f73518404d0292d851df242","original_commit_id":"7f9e9f12e69fb6453f73518404d0292d851df242","user":{"login":"adampbeardsley","id":4752917,"avatar_url":"https://avatars0.githubusercontent.com/u/4752917?v=4","gravatar_id":"","url":"https://api.github.com/users/adampbeardsley","html_url":"https://github.com/adampbeardsley","followers_url":"https://api.github.com/users/adampbeardsley/followers","following_url":"https://api.github.com/users/adampbeardsley/following{/other_user}","gists_url":"https://api.github.com/users/adampbeardsley/gists{/gist_id}","starred_url":"https://api.github.com/users/adampbeardsley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adampbeardsley/subscriptions","organizations_url":"https://api.github.com/users/adampbeardsley/orgs","repos_url":"https://api.github.com/users/adampbeardsley/repos","events_url":"https://api.github.com/users/adampbeardsley/events{/privacy}","received_events_url":"https://api.github.com/users/adampbeardsley/received_events","type":"User","site_admin":false},"body":"Technically I think it does. We could sidestep it by importing omni.aa_to_info directly, which doesn't use hera_qm. Also, Danny is working on an alternative function for getting info. Once that's integrated into hera_cal, we could import that instead.","created_at":"2017-07-23T16:04:11Z","updated_at":"2017-07-23T16:04:12Z","html_url":"https://github.com/HERA-Team/hera_qm/pull/32#discussion_r128923238","pull_request_url":"https://api.github.com/repos/HERA-Team/hera_qm/pulls/32","_links":{"self":{"href":"https://api.github.com/repos/HERA-Team/hera_qm/pulls/comments/128923238"},"html":{"href":"https://github.com/HERA-Team/hera_qm/pull/32#discussion_r128923238"},"pull_request":{"href":"https://api.github.com/repos/HERA-Team/hera_qm/pulls/32"}}},"pull_request":{"url":"https://api.github.com/repos/HERA-Team/hera_qm/pulls/32","id":131915380,"html_url":"https://github.com/HERA-Team/hera_qm/pull/32","diff_url":"https://github.com/HERA-Team/hera_qm/pull/32.diff","patch_url":"https://github.com/HERA-Team/hera_qm/pull/32.patch","issue_url":"https://api.github.com/repos/HERA-Team/hera_qm/issues/32","number":32,"state":"open","locked":false,"title":"Ant metrics wrapper","user":{"login":"plaplant","id":9141156,"avatar_url":"https://avatars1.githubusercontent.com/u/9141156?v=4","gravatar_id":"","url":"https://api.github.com/users/plaplant","html_url":"https://github.com/plaplant","followers_url":"https://api.github.com/users/plaplant/followers","following_url":"https://api.github.com/users/plaplant/following{/other_user}","gists_url":"https://api.github.com/users/plaplant/gists{/gist_id}","starred_url":"https://api.github.com/users/plaplant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plaplant/subscriptions","organizations_url":"https://api.github.com/users/plaplant/orgs","repos_url":"https://api.github.com/users/plaplant/repos","events_url":"https://api.github.com/users/plaplant/events{/privacy}","received_events_url":"https://api.github.com/users/plaplant/received_events","type":"User","site_admin":false},"body":"This PR adds a wrapper function for running several ant metrics tests on files passed in. The function is suitable for calling from a script to be part of RTP. Several helper functions were also added to support the wrapper (mostly file system interaction things).","created_at":"2017-07-22T22:51:05Z","updated_at":"2017-07-23T16:04:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"30e0fb67e72d337558f9b51f43975d6ac58f577a","assignee":null,"assignees":[],"requested_reviewers":[{"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}],"milestone":null,"commits_url":"https://api.github.com/repos/HERA-Team/hera_qm/pulls/32/commits","review_comments_url":"https://api.github.com/repos/HERA-Team/hera_qm/pulls/32/comments","review_comment_url":"https://api.github.com/repos/HERA-Team/hera_qm/pulls/comments{/number}","comments_url":"https://api.github.com/repos/HERA-Team/hera_qm/issues/32/comments","statuses_url":"https://api.github.com/repos/HERA-Team/hera_qm/statuses/7f9e9f12e69fb6453f73518404d0292d851df242","head":{"label":"HERA-Team:ant_metrics_wrapper","ref":"ant_metrics_wrapper","sha":"7f9e9f12e69fb6453f73518404d0292d851df242","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":93206037,"name":"hera_qm","full_name":"HERA-Team/hera_qm","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_qm","description":"HERA Data Quality Metrics","fork":false,"url":"https://api.github.com/repos/HERA-Team/hera_qm","forks_url":"https://api.github.com/repos/HERA-Team/hera_qm/forks","keys_url":"https://api.github.com/repos/HERA-Team/hera_qm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/HERA-Team/hera_qm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/HERA-Team/hera_qm/teams","hooks_url":"https://api.github.com/repos/HERA-Team/hera_qm/hooks","issue_events_url":"https://api.github.com/repos/HERA-Team/hera_qm/issues/events{/number}","events_url":"https://api.github.com/repos/HERA-Team/hera_qm/events","assignees_url":"https://api.github.com/repos/HERA-Team/hera_qm/assignees{/user}","branches_url":"https://api.github.com/repos/HERA-Team/hera_qm/branches{/branch}","tags_url":"https://api.github.com/repos/HERA-Team/hera_qm/tags","blobs_url":"https://api.github.com/repos/HERA-Team/hera_qm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/HERA-Team/hera_qm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/HERA-Team/hera_qm/git/refs{/sha}","trees_url":"https://api.github.com/repos/HERA-Team/hera_qm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/HERA-Team/hera_qm/statuses/{sha}","languages_url":"https://api.github.com/repos/HERA-Team/hera_qm/languages","stargazers_url":"https://api.github.com/repos/HERA-Team/hera_qm/stargazers","contributors_url":"https://api.github.com/repos/HERA-Team/hera_qm/contributors","subscribers_url":"https://api.github.com/repos/HERA-Team/hera_qm/subscribers","subscription_url":"https://api.github.com/repos/HERA-Team/hera_qm/subscription","commits_url":"https://api.github.com/repos/HERA-Team/hera_qm/commits{/sha}","git_commits_url":"https://api.github.com/repos/HERA-Team/hera_qm/git/commits{/sha}","comments_url":"https://api.github.com/repos/HERA-Team/hera_qm/comments{/number}","issue_comment_url":"https://api.github.com/repos/HERA-Team/hera_qm/issues/comments{/number}","contents_url":"https://api.github.com/repos/HERA-Team/hera_qm/contents/{+path}","compare_url":"https://api.github.com/repos/HERA-Team/hera_qm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/HERA-Team/hera_qm/merges","archive_url":"https://api.github.com/repos/HERA-Team/hera_qm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/HERA-Team/hera_qm/downloads","issues_url":"https://api.github.com/repos/HERA-Team/hera_qm/issues{/number}","pulls_url":"https://api.github.com/repos/HERA-Team/hera_qm/pulls{/number}","milestones_url":"https://api.github.com/repos/HERA-Team/hera_qm/milestones{/number}","notifications_url":"https://api.github.com/repos/HERA-Team/hera_qm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/HERA-Team/hera_qm/labels{/name}","releases_url":"https://api.github.com/repos/HERA-Team/hera_qm/releases{/id}","deployments_url":"https://api.github.com/repos/HERA-Team/hera_qm/deployments","created_at":"2017-06-02T21:42:55Z","updated_at":"2017-06-02T22:41:23Z","pushed_at":"2017-07-23T14:43:18Z","git_url":"git://github.com/HERA-Team/hera_qm.git","ssh_url":"git@github.com:HERA-Team/hera_qm.git","clone_url":"https://github.com/HERA-Team/hera_qm.git","svn_url":"https://github.com/HERA-Team/hera_qm","homepage":null,"size":6384,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":21,"forks":0,"open_issues":21,"watchers":0,"default_branch":"master"}},"base":{"label":"HERA-Team:master","ref":"master","sha":"dbc2de3224b7dddce58e01d1028649a6070540e0","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":93206037,"name":"hera_qm","full_name":"HERA-Team/hera_qm","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_qm","description":"HERA Data Quality Metrics","fork":false,"url":"https://api.github.com/repos/HERA-Team/hera_qm","forks_url":"https://api.github.com/repos/HERA-Team/hera_qm/forks","keys_url":"https://api.github.com/repos/HERA-Team/hera_qm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/HERA-Team/hera_qm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/HERA-Team/hera_qm/teams","hooks_url":"https://api.github.com/repos/HERA-Team/hera_qm/hooks","issue_events_url":"https://api.github.com/repos/HERA-Team/hera_qm/issues/events{/number}","events_url":"https://api.github.com/repos/HERA-Team/hera_qm/events","assignees_url":"https://api.github.com/repos/HERA-Team/hera_qm/assignees{/user}","branches_url":"https://api.github.com/repos/HERA-Team/hera_qm/branches{/branch}","tags_url":"https://api.github.com/repos/HERA-Team/hera_qm/tags","blobs_url":"https://api.github.com/repos/HERA-Team/hera_qm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/HERA-Team/hera_qm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/HERA-Team/hera_qm/git/refs{/sha}","trees_url":"https://api.github.com/repos/HERA-Team/hera_qm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/HERA-Team/hera_qm/statuses/{sha}","languages_url":"https://api.github.com/repos/HERA-Team/hera_qm/languages","stargazers_url":"https://api.github.com/repos/HERA-Team/hera_qm/stargazers","contributors_url":"https://api.github.com/repos/HERA-Team/hera_qm/contributors","subscribers_url":"https://api.github.com/repos/HERA-Team/hera_qm/subscribers","subscription_url":"https://api.github.com/repos/HERA-Team/hera_qm/subscription","commits_url":"https://api.github.com/repos/HERA-Team/hera_qm/commits{/sha}","git_commits_url":"https://api.github.com/repos/HERA-Team/hera_qm/git/commits{/sha}","comments_url":"https://api.github.com/repos/HERA-Team/hera_qm/comments{/number}","issue_comment_url":"https://api.github.com/repos/HERA-Team/hera_qm/issues/comments{/number}","contents_url":"https://api.github.com/repos/HERA-Team/hera_qm/contents/{+path}","compare_url":"https://api.github.com/repos/HERA-Team/hera_qm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/HERA-Team/hera_qm/merges","archive_url":"https://api.github.com/repos/HERA-Team/hera_qm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/HERA-Team/hera_qm/downloads","issues_url":"https://api.github.com/repos/HERA-Team/hera_qm/issues{/number}","pulls_url":"https://api.github.com/repos/HERA-Team/hera_qm/pulls{/number}","milestones_url":"https://api.github.com/repos/HERA-Team/hera_qm/milestones{/number}","notifications_url":"https://api.github.com/repos/HERA-Team/hera_qm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/HERA-Team/hera_qm/labels{/name}","releases_url":"https://api.github.com/repos/HERA-Team/hera_qm/releases{/id}","deployments_url":"https://api.github.com/repos/HERA-Team/hera_qm/deployments","created_at":"2017-06-02T21:42:55Z","updated_at":"2017-06-02T22:41:23Z","pushed_at":"2017-07-23T14:43:18Z","git_url":"git://github.com/HERA-Team/hera_qm.git","ssh_url":"git@github.com:HERA-Team/hera_qm.git","clone_url":"https://github.com/HERA-Team/hera_qm.git","svn_url":"https://github.com/HERA-Team/hera_qm","homepage":null,"size":6384,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":21,"forks":0,"open_issues":21,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/HERA-Team/hera_qm/pulls/32"},"html":{"href":"https://github.com/HERA-Team/hera_qm/pull/32"},"issue":{"href":"https://api.github.com/repos/HERA-Team/hera_qm/issues/32"},"comments":{"href":"https://api.github.com/repos/HERA-Team/hera_qm/issues/32/comments"},"review_comments":{"href":"https://api.github.com/repos/HERA-Team/hera_qm/pulls/32/comments"},"review_comment":{"href":"https://api.github.com/repos/HERA-Team/hera_qm/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/HERA-Team/hera_qm/pulls/32/commits"},"statuses":{"href":"https://api.github.com/repos/HERA-Team/hera_qm/statuses/7f9e9f12e69fb6453f73518404d0292d851df242"}}}}
{"actor":{"display_login":"adampbeardsley"}}