Nightly Per-Antenna Quality Summary Notebook¶

Josh Dillon, Last Revised February 2021

This notebooks brings together as much information as possible from ant_metrics, auto_metrics and redcal to help figure out which antennas are working properly and summarizes it in a single giant table. It is meant to be lightweight and re-run as often as necessary over the night, so it can be run when any of those is done and then be updated when another one completes.

In [1]:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import pandas as pd
pd.set_option('display.max_rows', 1000)
from hera_qm.metrics_io import load_metric_file
from hera_cal import utils, io, redcal
import glob
import os
import h5py
from copy import deepcopy
from IPython.display import display, HTML
from hera_notebook_templates.utils import status_colors

%matplotlib inline
%config InlineBackend.figure_format = 'retina'
display(HTML("<style>.container { width:100% !important; }</style>"))
In [2]:
# If you want to run this notebook locally, copy the output of the next cell into the first few lines of this cell.

# JD = "2459122"
# data_path = '/lustre/aoc/projects/hera/H4C/2459122'
# ant_metrics_ext = ".ant_metrics.hdf5"
# redcal_ext = ".maybe_good.omni.calfits"
# nb_outdir = '/lustre/aoc/projects/hera/H4C/h4c_software/H4C_Notebooks/_rtp_summary_'
# os.environ["JULIANDATE"] = JD
# os.environ["DATA_PATH"] = data_path
# os.environ["ANT_METRICS_EXT"] = ant_metrics_ext
# os.environ["REDCAL_EXT"] = redcal_ext
# os.environ["NB_OUTDIR"] = nb_outdir
In [3]:
# Use environment variables to figure out path to data
JD = os.environ['JULIANDATE']
data_path = os.environ['DATA_PATH']
ant_metrics_ext = os.environ['ANT_METRICS_EXT']
redcal_ext = os.environ['REDCAL_EXT']
nb_outdir = os.environ['NB_OUTDIR']
print(f'JD = "{JD}"')
print(f'data_path = "{data_path}"')
print(f'ant_metrics_ext = "{ant_metrics_ext}"')
print(f'redcal_ext = "{redcal_ext}"')
print(f'nb_outdir = "{nb_outdir}"')
JD = "2459744"
data_path = "/mnt/sn1/2459744"
ant_metrics_ext = ".ant_metrics.hdf5"
redcal_ext = ".known_good.omni.calfits"
nb_outdir = "/home/obs/src/H5C_Notebooks/_rtp_summary_"
In [4]:
from astropy.time import Time
utc = Time(JD, format='jd').datetime
print(f'Date: {utc.month}-{utc.day}-{utc.year}')
Date: 6-13-2022
In [5]:
# Per-season options
def ant_to_report_url(ant):
    return f'https://htmlpreview.github.io/?https://github.com/HERA-Team/H5C_Notebooks/blob/main/antenna_report/antenna_{ant}_report.html'

Load Auto Metrics¶

In [6]:
use_auto_metrics = False

# find the auto_metrics file
glob_str = os.path.join(data_path, f'zen.{JD}*.auto_metrics.h5')
auto_metrics_file = sorted(glob.glob(glob_str))

# if it exists, load and extract relevant information
if len(auto_metrics_file) > 0:
    auto_metrics_file = auto_metrics_file[0]
    print(f'Found auto_metrics results file at {auto_metrics_file}.')
    
    auto_metrics = load_metric_file(auto_metrics_file)
    mean_round_modz_cut = auto_metrics['parameters']['mean_round_modz_cut']
    auto_ex_ants = auto_metrics['ex_ants']['r2_ex_ants']
    
    use_auto_metrics = True
else:
    print(f'No files found matching glob {glob_str}. Skipping auto_metrics.')
Found auto_metrics results file at /mnt/sn1/2459744/zen.2459744.25298.sum.auto_metrics.h5.

Load Ant Metrics¶

In [7]:
use_ant_metrics = False

# get a list of all ant_metrics files
glob_str = os.path.join(data_path, f'zen.{JD}.?????.sum{ant_metrics_ext}')
ant_metrics_files = sorted(glob.glob(glob_str))

# if they exist, load as many of them as possible
if len(ant_metrics_files) > 0:
    print(f'Found {len(ant_metrics_files)} ant_metrics files matching glob {glob_str}')
    ant_metrics_apriori_exants = {}
    ant_metrics_xants_dict = {}
    ant_metrics_dead_ants_dict = {}
    ant_metrics_crossed_ants_dict = {}
    ant_metrics_dead_metrics = {}
    ant_metrics_crossed_metrics = {}
    dead_cuts = {}
    crossed_cuts = {}
    for amf in ant_metrics_files:
        with h5py.File(amf, "r") as infile: # use h5py directly since it's much faster than load_metric_file
            # get out results for this file
            dead_cuts[amf] = infile['Metrics']['dead_ant_cut'][()]
            crossed_cuts[amf] = infile['Metrics']['cross_pol_cut'][()]
            xants = infile['Metrics']['xants'][:]
            dead_ants = infile['Metrics']['dead_ants'][:]
            crossed_ants = infile['Metrics']['crossed_ants'][:]        
            try:
                # look for ex_ants in history
                ex_ants_string = infile['Header']['history'][()].decode()
                ex_ants_string = ex_ants_string.split('--apriori_xants')[1]
                ex_ants_string = ex_ants_string.split('--')[0].strip()
            except:
                ex_ants_string = ''
                    
            # This only works for the new correlation-matrix-based ant_metrics
            if 'corr' in infile['Metrics']['final_metrics'] and 'corrXPol' in infile['Metrics']['final_metrics']:
                ant_metrics_dead_metrics[amf] = {eval(ant): infile['Metrics']['final_metrics']['corr'][ant][()]
                                                 for ant in infile['Metrics']['final_metrics']['corr']}
                ant_metrics_crossed_metrics[amf] = {eval(ant): infile['Metrics']['final_metrics']['corrXPol'][ant][()]
                                                    for ant in infile['Metrics']['final_metrics']['corrXPol']}                       
            else:
                raise(KeywordError)
        
        # organize results by file
        ant_metrics_xants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in xants]
        ant_metrics_dead_ants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in dead_ants]
        ant_metrics_crossed_ants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in crossed_ants]
        ant_metrics_apriori_exants[amf] = [int(ant) for ant in ex_ants_string.split()]
    
    dead_cut = np.median(list(dead_cuts.values()))
    crossed_cut = np.median(list(crossed_cuts.values()))
        
    use_ant_metrics = True
else:
    print(f'No files found matching glob {glob_str}. Skipping ant_metrics.')
Found 372 ant_metrics files matching glob /mnt/sn1/2459744/zen.2459744.?????.sum.ant_metrics.hdf5

Load chi^2 info from redcal¶

In [8]:
use_redcal = False
glob_str = os.path.join(data_path, f'zen.{JD}.?????.sum{redcal_ext}')

redcal_files = sorted(glob.glob(glob_str))
if len(redcal_files) > 0:
    print(f'Found {len(redcal_files)} ant_metrics files matching glob {glob_str}')
    post_redcal_ant_flags_dict = {}
    flagged_by_redcal_dict = {}
    cspa_med_dict = {}
    for cal in redcal_files:
        hc = io.HERACal(cal)
        _, flags, cspa, chisq = hc.read()
        cspa_med_dict[cal] = {ant: np.nanmedian(cspa[ant], axis=1) for ant in cspa}

        post_redcal_ant_flags_dict[cal] = {ant: np.all(flags[ant]) for ant in flags}
        # check history to distinguish antennas flagged going into redcal from ones flagged during redcal
        tossed_antenna_lines =  hc.history.replace('\n','').split('Throwing out antenna ')[1:]
        flagged_by_redcal_dict[cal] = sorted([int(line.split(' ')[0]) for line in tossed_antenna_lines])
        
    use_redcal = True
else:
    print(f'No files found matching glob {glob_str}. Skipping redcal chisq.')
No files found matching glob /mnt/sn1/2459744/zen.2459744.?????.sum.known_good.omni.calfits. Skipping redcal chisq.

Figure out some general properties¶

In [9]:
# Parse some general array properties, taking into account the fact that we might be missing some of the metrics
ants = []
pols = []
antpol_pairs = []

if use_auto_metrics:
    ants = sorted(set(bl[0] for bl in auto_metrics['modzs']['r2_shape_modzs']))
    pols = sorted(set(bl[2] for bl in auto_metrics['modzs']['r2_shape_modzs']))
if use_ant_metrics:
    antpol_pairs = sorted(set([antpol for dms in ant_metrics_dead_metrics.values() for antpol in dms.keys()]))
    antpols = sorted(set(antpol[1] for antpol in antpol_pairs))
    ants = sorted(set(antpol[0] for antpol in antpol_pairs) | set(ants))
    pols = sorted(set(utils.join_pol(ap, ap) for ap in antpols) | set(pols))
if use_redcal:
    antpol_pairs = sorted(set([ant for cspa in cspa_med_dict.values() for ant in cspa.keys()]) | set(antpol_pairs))
    antpols = sorted(set(antpol[1] for antpol in antpol_pairs))
    ants = sorted(set(antpol[0] for antpol in antpol_pairs) | set(ants))
    pols = sorted(set(utils.join_pol(ap, ap) for ap in antpols) | set(pols))

# Figure out remaining antennas not in data
hd = io.HERAData(sorted(glob.glob(os.path.join(data_path, 'zen.*.sum.uvh5')))[0])
unused_ants = [ant for ant in hd.antpos if ant not in ants]    

Load a priori antenna statuses and node numbers¶

In [10]:
# try to load a priori antenna statusesm but fail gracefully if this doesn't work.
a_priori_statuses = {ant: 'Not Found' for ant in ants}
nodes = {ant: np.nan for ant in ants + unused_ants}
try:
    from hera_mc import cm_hookup

    # get node numbers
    hookup = cm_hookup.get_hookup('default')
    for ant_name in hookup:
        ant = int("".join(filter(str.isdigit, ant_name)))
        if ant in nodes:
            if hookup[ant_name].get_part_from_type('node')['E<ground'] is not None:
                nodes[ant] = int(hookup[ant_name].get_part_from_type('node')['E<ground'][1:])
    
    # get apriori antenna status
    for ant_name, data in hookup.items():
        ant = int("".join(filter(str.isdigit, ant_name)))
        if ant in a_priori_statuses:
            a_priori_statuses[ant] = data.apriori

except Exception as err:
    print(f'Could not load node numbers and a priori antenna statuses.\nEncountered {type(err)} with message: {err}')

Summarize auto metrics¶

In [11]:
if use_auto_metrics:
    # Parse modzs
    modzs_to_check = {'Shape': 'r2_shape_modzs', 'Power': 'r2_power_modzs', 
                      'Temporal Variability': 'r2_temp_var_modzs', 'Temporal Discontinuties': 'r2_temp_diff_modzs'}
    worst_metrics = []
    worst_zs = []
    all_modzs = {}
    binary_flags = {rationale: [] for rationale in modzs_to_check}

    for ant in ants:
        # parse modzs and figure out flag counts
        modzs = {f'{pol} {rationale}': auto_metrics['modzs'][dict_name][(ant, ant, pol)] 
                 for rationale, dict_name in modzs_to_check.items() for pol in pols}
        for pol in pols:
            for rationale, dict_name in modzs_to_check.items():
                binary_flags[rationale].append(auto_metrics['modzs'][dict_name][(ant, ant, pol)] > mean_round_modz_cut)

        # parse out all metrics for dataframe
        for k in modzs:
            col_label = k + ' Modified Z-Score'
            if col_label in all_modzs:
                all_modzs[col_label].append(modzs[k])
            else:
                all_modzs[col_label] = [modzs[k]]
                
    mean_round_modz_cut = auto_metrics['parameters']['mean_round_modz_cut']
else:
    mean_round_modz_cut = 0

Summarize ant metrics¶

In [12]:
if use_ant_metrics:
    a_priori_flag_frac = {ant: np.mean([ant in apxa for apxa in ant_metrics_apriori_exants.values()]) for ant in ants}
    dead_ant_frac = {ap: {ant: np.mean([(ant, ap) in das for das in ant_metrics_dead_ants_dict.values()])
                                 for ant in ants} for ap in antpols}
    crossed_ant_frac = {ant: np.mean([np.any([(ant, ap) in cas for ap in antpols])
                                      for cas in ant_metrics_crossed_ants_dict.values()]) for ant in ants}
    ant_metrics_xants_frac_by_antpol = {antpol: np.mean([antpol in amx for amx in ant_metrics_xants_dict.values()]) for antpol in antpol_pairs}
    ant_metrics_xants_frac_by_ant = {ant: np.mean([np.any([(ant, ap) in amx for ap in antpols])
                                     for amx in ant_metrics_xants_dict.values()]) for ant in ants}
    average_dead_metrics = {ap: {ant: np.nanmean([dm.get((ant, ap), np.nan) for dm in ant_metrics_dead_metrics.values()]) 
                                 for ant in ants} for ap in antpols}
    average_crossed_metrics = {ant: np.nanmean([cm.get((ant, ap), np.nan) for ap in antpols 
                                                for cm in ant_metrics_crossed_metrics.values()]) for ant in ants}
else:
    dead_cut = 0.4
    crossed_cut = 0.0

Summarize redcal chi^2 metrics¶

In [13]:
if use_redcal:
    cspa = {ant: np.nanmedian(np.hstack([cspa_med_dict[cal][ant] for cal in redcal_files])) for ant in antpol_pairs}
    redcal_prior_flag_frac = {ant: np.mean([np.any([afd[ant, ap] and not ant in flagged_by_redcal_dict[cal] for ap in antpols])
                                            for cal, afd in post_redcal_ant_flags_dict.items()]) for ant in ants}
    redcal_flagged_frac = {ant: np.mean([ant in fbr for fbr in flagged_by_redcal_dict.values()]) for ant in ants}

Build DataFrame¶

In [14]:
# build dataframe
to_show = {'Ant': [f'<a href="{ant_to_report_url(ant)}" target="_blank">{ant}</a>' for ant in ants],
           'Node': [nodes[ant] for ant in ants], 
           'A Priori Status': [a_priori_statuses[ant] for ant in ants]}
           #'Worst Metric': worst_metrics, 'Worst Modified Z-Score': worst_zs}
df = pd.DataFrame(to_show)

# create bar chart columns for flagging percentages:
bar_cols = {}
if use_auto_metrics:
    bar_cols['Auto Metrics Flags'] = [float(ant in auto_ex_ants) for ant in ants]
if use_ant_metrics:
    if np.sum(list(a_priori_flag_frac.values())) > 0:  # only include this col if there are any a priori flags
        bar_cols['A Priori Flag Fraction in Ant Metrics'] = [a_priori_flag_frac[ant] for ant in ants]
    for ap in antpols:
        bar_cols[f'Dead Fraction in Ant Metrics ({ap})'] = [dead_ant_frac[ap][ant] for ant in ants]
    bar_cols['Crossed Fraction in Ant Metrics'] = [crossed_ant_frac[ant] for ant in ants]
if use_redcal:
    bar_cols['Flag Fraction Before Redcal'] = [redcal_prior_flag_frac[ant] for ant in ants]
    bar_cols['Flagged By Redcal chi^2 Fraction'] = [redcal_flagged_frac[ant] for ant in ants]  
for col in bar_cols:
    df[col] = bar_cols[col]

# add auto_metrics
if use_auto_metrics:
    for label, modz in all_modzs.items():
        df[label] = modz
z_score_cols = [col for col in df.columns if 'Modified Z-Score' in col]        
        
# add ant_metrics
ant_metrics_cols = {}
if use_ant_metrics:
    for ap in antpols:
        ant_metrics_cols[f'Average Dead Ant Metric ({ap})'] = [average_dead_metrics[ap][ant] for ant in ants]
    ant_metrics_cols['Average Crossed Ant Metric'] = [average_crossed_metrics[ant] for ant in ants]
    for col in ant_metrics_cols:
        df[col] = ant_metrics_cols[col]   

# add redcal chisq
redcal_cols = []
if use_redcal:
    for ap in antpols:
        col_title = f'Median chi^2 Per Antenna ({ap})'
        df[col_title] = [cspa[ant, ap] for ant in ants]
        redcal_cols.append(col_title)

# sort by node number and then by antenna number within nodes
df.sort_values(['Node', 'Ant'], ascending=True)

# style dataframe
table = df.style.hide_index()\
          .applymap(lambda val: f'background-color: {status_colors[val]}' if val in status_colors else '', subset=['A Priori Status']) \
          .background_gradient(cmap='viridis', vmax=mean_round_modz_cut * 3, vmin=0, axis=None, subset=z_score_cols) \
          .background_gradient(cmap='bwr_r', vmin=dead_cut-.25, vmax=dead_cut+.25, axis=0, subset=list([col for col in ant_metrics_cols if 'dead' in col.lower()])) \
          .background_gradient(cmap='bwr_r', vmin=crossed_cut-.25, vmax=crossed_cut+.25, axis=0, subset=list([col for col in ant_metrics_cols if 'crossed' in col.lower()])) \
          .background_gradient(cmap='plasma', vmax=4, vmin=1, axis=None, subset=redcal_cols) \
          .applymap(lambda val: 'font-weight: bold' if val < dead_cut else '', subset=list([col for col in ant_metrics_cols if 'dead' in col.lower()])) \
          .applymap(lambda val: 'font-weight: bold' if val < crossed_cut else '', subset=list([col for col in ant_metrics_cols if 'crossed' in col.lower()])) \
          .applymap(lambda val: 'font-weight: bold' if val > mean_round_modz_cut else '', subset=z_score_cols) \
          .applymap(lambda val: 'color: red' if val > mean_round_modz_cut else '', subset=z_score_cols) \
          .bar(subset=list(bar_cols.keys()), vmin=0, vmax=1) \
          .format({col: '{:,.4f}'.format for col in z_score_cols}) \
          .format({col: '{:,.4f}'.format for col in ant_metrics_cols}) \
          .format({col: '{:,.2%}'.format for col in bar_cols}) \
          .applymap(lambda val: 'font-weight: bold', subset=['Ant']) \
          .set_table_styles([dict(selector="th",props=[('max-width', f'70pt')])]) \

Table 1: RTP Per-Antenna Metrics Summary Table¶

This admittedly very busy table incorporates summary information about all antennas in the array. Its columns depend on what information is available when the notebook is run (i.e. whether auto_metrics, ant_metrics, and/or redcal is done). These can be divided into 5 sections:

Basic Antenna Info: antenna number, node, and its a priori status.

Flag Fractions: Fraction of the night that an antenna was flagged for various reasons. Note that auto_metrics flags antennas for the whole night, so it'll be 0% or 100%.

auto_metrics Details: If auto_metrics is included, this section shows the modified Z-score signifying how much of an outlier each antenna and polarization is in each of four categories: bandpass shape, overall power, temporal variability, and temporal discontinuities. Bold red text indicates that this is a reason for flagging the antenna. It is reproduced from the auto_metrics_inspect.ipynb nightly notebook, so check that out for more details on the precise metrics.

ant_metrics Details: If ant_metrics is included, this section shows the average correlation-based metrics for antennas over the whole night. Low "dead ant" metrics (nominally below 0.4) indicate antennas not correlating with the rest of the array. Negative "crossed ant" metrics indicate antennas that show stronger correlations in their cross-pols than their same-pols, indicating that the two polarizations are probably swapped. Bold text indicates that the average is below the threshold for flagging.

redcal chi^2 Details: If redcal is included, this shows the median chi^2 per antenna. This would be 1 in an ideal array. Antennas are thrown out when they they are outliers in their median chi^2, usually greater than 4-sigma outliers in modified Z-score.

In [15]:
HTML(table.render())
Out[15]:
Ant Node A Priori Status Auto Metrics Flags Dead Fraction in Ant Metrics (Jee) Dead Fraction in Ant Metrics (Jnn) Crossed Fraction in Ant Metrics ee Shape Modified Z-Score nn Shape Modified Z-Score ee Power Modified Z-Score nn Power Modified Z-Score ee Temporal Variability Modified Z-Score nn Temporal Variability Modified Z-Score ee Temporal Discontinuties Modified Z-Score nn Temporal Discontinuties Modified Z-Score Average Dead Ant Metric (Jee) Average Dead Ant Metric (Jnn) Average Crossed Ant Metric
0 0 RF_maintenance 100.00% 100.00% 100.00% 0.00% 23.745067 22.279687 inf inf 11034.614658 10490.836226 31709.055561 29830.375285 nan nan nan
1 0 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
2 0 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
3 1 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
4 1 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
5 1 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
7 2 digital_ok 100.00% 100.00% 100.00% 0.00% 3.419805 2.366344 1.596031 1.482148 2.961123 15.035363 10.355678 36.678817 0.081989 0.057449 0.011311
8 2 RF_maintenance 100.00% 0.00% 5.91% 0.00% 23.928382 25.197011 32.103049 33.435641 18.032347 17.788948 62.697260 72.299516 0.616599 0.592307 0.444073
9 2 digital_ok 0.00% 100.00% 100.00% 0.00% -0.003457 -0.968534 -0.696041 -0.574193 -0.250770 -0.748589 -1.533151 -1.079096 0.072826 0.054467 0.007730
10 2 digital_ok 100.00% 100.00% 100.00% 0.00% -1.258387 2.228991 0.540298 1.122417 25.441259 6.259615 51.916742 68.690328 0.031167 0.037904 0.001725
11 0 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
12 0 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
13 0 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
14 0 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
15 1 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
16 1 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
17 1 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
18 1 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
19 2 digital_ok 100.00% 100.00% 100.00% 0.00% -0.983553 3.566603 -0.838969 3.127114 32.754894 32.860955 33.357027 35.833803 0.034825 0.037766 0.002597
20 2 digital_ok 100.00% 100.00% 100.00% 0.00% 1.651366 0.368433 1.692891 0.491546 1.300379 0.129726 27.264012 4.157153 0.033510 0.037118 0.001280
21 2 digital_ok 100.00% 100.00% 100.00% 0.00% 0.641144 -0.093461 -0.571189 1.373062 16.271952 75.756035 74.465364 131.780130 0.031176 0.031013 0.000692
23 0 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
24 0 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
25 0 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
26 0 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
27 1 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
28 1 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
29 1 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
30 1 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
31 2 digital_ok 100.00% 100.00% 100.00% 0.00% 5.251356 -0.313627 1.990900 -0.042923 0.699009 1.463618 7.008240 5.747207 0.029302 0.030071 -0.000083
32 2 RF_maintenance 100.00% 100.00% 100.00% 0.00% 1.816479 0.607684 0.449462 -0.349402 1.886981 2.049674 16.218110 9.349620 0.029513 0.029866 0.000790
33 2 RF_maintenance 100.00% 100.00% 100.00% 0.00% 0.502850 6.623041 -0.559278 13.515255 2.439756 5.724773 1.484499 22.650785 0.059625 0.041787 0.004890
36 3 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
37 3 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
38 3 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
39 0 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
40 4 digital_ok 100.00% 0.00% 0.00% 0.00% 25.002373 26.176726 26.186508 27.013183 14.623472 7.971717 35.118966 28.223244 0.663814 0.652972 0.431555
41 4 digital_ok 100.00% 100.00% 100.00% 0.00% -0.777669 -0.092357 -0.845753 -0.467406 3.044780 -0.431616 7.172071 19.228560 0.038686 0.034850 0.001042
42 4 digital_ok 0.00% 100.00% 100.00% 0.00% 1.726606 0.763278 -0.315539 -0.652941 0.851803 0.080438 0.633673 0.732446 0.056117 0.070162 0.007882
45 5 RF_maintenance 100.00% 100.00% 100.00% 0.00% -1.216099 15.730775 -0.840531 6.844846 -0.364753 0.599583 0.934051 7.472484 0.030392 0.033399 0.002086
46 5 digital_ok 100.00% 100.00% 100.00% 0.00% 2.035113 2.070552 3.724428 3.214138 9.009725 7.022037 97.974763 74.036010 0.029909 0.027936 0.002832
50 3 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
51 3 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
52 3 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
53 3 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
54 4 digital_ok 100.00% 100.00% 100.00% 0.00% -1.015471 -0.271845 -0.643402 0.507661 1.121304 0.117858 16.631079 10.316789 0.057961 0.074096 0.002524
55 4 digital_ok 100.00% 100.00% 100.00% 0.00% -0.891308 -0.044909 -0.241986 -0.385557 -0.225983 10.084356 22.593567 10.735717 0.034742 0.059656 0.002199
56 4 digital_ok 100.00% 100.00% 100.00% 0.00% -0.882399 0.003819 -0.039359 1.250945 -0.439667 0.878358 5.932587 12.032302 0.053351 0.063668 0.002980
57 4 digital_ok 0.00% 100.00% 100.00% 0.00% 2.661131 1.938150 1.907505 1.231726 3.606325 0.860026 0.186661 -0.135638 0.039477 0.034834 0.002708
65 3 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
66 3 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
67 3 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
68 3 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
69 4 digital_ok 100.00% 100.00% 100.00% 0.00% 1.255763 0.608853 0.357273 -0.385680 0.962601 3.987464 2.708774 10.346170 0.046487 0.057012 0.011650
70 4 RF_maintenance 100.00% 0.00% 0.00% 0.00% 29.303087 26.697288 19.738553 18.162045 25.344107 16.595767 53.960669 75.719429 0.697259 0.678575 0.416264
71 4 digital_ok 100.00% 100.00% 100.00% 0.00% 3.078258 3.672954 3.501543 5.038295 2.951610 2.941850 6.111998 3.069403 0.037171 0.048442 0.005837
72 4 digital_ok 100.00% 0.00% 0.00% 0.00% 22.700944 26.270140 26.435924 28.814775 13.660083 8.705283 64.979801 35.239239 0.674342 0.678521 0.402431
73 5 RF_maintenance 100.00% 100.00% 100.00% 0.00% 0.573324 4.985209 2.068540 0.545827 4.129380 3.224431 34.364586 25.443658 0.030668 0.033619 0.001018
81 7 digital_ok 0.00% 100.00% 100.00% 0.00% 1.584450 0.404793 0.851324 1.223337 -1.234918 -0.531490 2.447992 -0.715308 0.055419 0.065795 0.003710
82 7 RF_maintenance 100.00% 100.00% 100.00% 0.00% 0.972556 3.314428 1.799364 0.033579 6.008412 6.077935 218.404674 227.844396 0.042846 0.042808 0.001139
83 7 digital_ok 100.00% 100.00% 100.00% 0.00% 14.870898 15.342133 3.617834 3.955554 0.695625 0.892166 8.346778 6.879404 0.056937 0.066706 0.006503
84 8 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
85 8 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
86 8 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
87 8 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
88 9 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
89 9 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
90 9 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
91 9 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
92 10 digital_ok 100.00% 100.00% 100.00% 0.00% 36.575875 36.493622 57.744264 39.889568 139.371075 68.260425 2541.989306 1402.171871 0.017458 0.016774 0.000410
93 10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 37.857066 38.950572 62.462410 64.676264 119.181144 188.309187 2157.302102 4012.074732 0.016413 0.016246 0.000298
94 10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 31.013901 38.598006 50.448537 51.071054 119.058456 139.685975 2230.741034 2341.600781 0.016332 0.016365 0.000381
98 7 digital_maintenance 100.00% 100.00% 100.00% 0.00% 15.294242 15.622271 2.952519 3.233491 8.314767 0.534690 24.246283 6.415632 0.067414 0.074679 0.025184
99 7 digital_ok 100.00% 0.00% 0.00% 0.00% 25.009318 27.585430 24.706898 25.131198 17.633319 16.627719 48.597018 63.462620 0.623681 0.618673 0.439409
100 7 RF_maintenance 100.00% 100.00% 100.00% 0.00% 15.192506 15.241840 3.142292 4.531574 0.766188 0.833804 10.826863 11.934054 0.046376 0.063807 0.024022
101 8 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
102 8 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
103 8 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
104 8 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
105 9 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
106 9 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
107 9 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
108 9 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
109 10 digital_ok 100.00% 100.00% 100.00% 0.00% 30.901529 47.683671 46.667275 47.634872 117.417503 128.164420 2272.361231 2470.522253 0.017831 0.016474 0.001127
110 10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 27.317161 34.827196 35.160748 50.583533 79.595575 152.010893 1469.089817 2141.267359 0.017391 0.016281 0.000949
111 10 digital_ok 100.00% 100.00% 100.00% 0.00% 31.130105 38.646106 43.934780 46.242951 83.374101 121.752105 1231.184365 2179.254120 0.016778 0.016350 0.000429
112 10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 30.931788 39.381856 45.601385 41.667622 95.633475 105.970920 2000.131685 1502.761006 0.017793 0.016640 0.000966
116 7 RF_maintenance 100.00% 100.00% 100.00% 0.00% 14.331441 14.606785 3.586850 4.044016 0.474917 0.543289 5.720956 7.366068 0.077359 0.083288 0.004155
119 7 RF_maintenance 100.00% 100.00% 100.00% 0.00% 14.827662 -0.107704 2.356394 1.919213 0.465602 4.571504 5.443387 8.514241 0.078059 0.060362 0.010831
120 8 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
121 8 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
122 8 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
123 8 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
124 9 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
125 9 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
126 9 RF_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
127 10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 29.070760 47.815617 40.551316 44.480917 93.051834 78.175401 1661.219368 1475.584126 0.016802 0.016462 0.000396
128 10 digital_ok 100.00% 100.00% 100.00% 0.00% 30.146155 36.099387 37.606271 50.178428 39.518267 116.333648 851.921887 2208.538028 0.016565 0.016379 0.000445
129 10 digital_ok 100.00% 100.00% 100.00% 0.00% 32.850761 33.380987 48.641412 41.796373 147.922879 90.546967 2204.920277 1638.673212 0.017880 0.016886 0.000848
130 10 digital_maintenance 100.00% 100.00% 100.00% 0.00% 30.003928 34.521743 44.386398 43.898132 79.820242 72.707994 1828.859768 1531.333185 0.016595 0.016494 0.000368
135 12 digital_ok 100.00% 100.00% 100.00% 0.00% -0.649928 -0.798423 -0.458341 -0.354180 -0.484981 1.111765 12.620618 18.196813 0.035678 0.031894 0.003299
136 12 RF_maintenance 0.00% 100.00% 100.00% 0.00% 0.003457 -0.918393 0.005615 -0.327171 -0.231694 0.825822 0.959543 0.505407 0.033327 0.035791 0.000346
138 7 digital_ok 100.00% 100.00% 100.00% 0.00% 2.099424 2.134298 1.732998 1.020620 2.149675 0.007893 37.452376 14.033766 0.078391 0.050099 0.001886
140 13 digital_ok 100.00% 100.00% 100.00% 0.00% 3.077619 3.443050 6.458962 6.382852 22.348908 21.297541 196.965341 201.785653 0.034110 0.048684 0.002240
141 13 digital_ok 100.00% 100.00% 100.00% 0.00% -0.481224 9.800979 0.434133 5.662747 1.391295 -0.108461 12.505270 12.744651 0.041071 0.048775 0.000811
142 13 digital_ok 100.00% 100.00% 100.00% 0.00% 1.159033 14.386002 1.596854 7.356347 0.555747 0.400107 6.383466 3.147391 0.043502 0.044766 0.002016
143 14 digital_ok 100.00% 0.00% 0.00% 0.00% 23.487974 26.202657 27.953953 28.192213 8.952099 8.300592 18.032700 19.649346 0.656815 0.661220 0.418312
144 14 digital_ok 100.00% 100.00% 100.00% 0.00% 3.205040 3.909956 1.811860 2.248926 6.308281 5.043182 30.226134 38.641843 0.038071 0.037535 0.001180
145 14 digital_ok 100.00% 100.00% 100.00% 0.00% 1.589351 -0.773766 1.439334 -0.225067 6.675861 6.036487 75.585099 11.369609 0.035132 0.037410 0.003133
150 15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 14.674306 14.318933 7.067094 8.261405 0.633621 1.205947 8.927182 12.647589 0.141916 0.148038 0.015116
155 12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 15.745128 16.054934 6.384211 7.042491 0.480050 1.194817 8.905899 12.263308 0.033572 0.037514 0.000500
156 12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 0.186804 -0.634285 -0.339834 -0.779586 -0.724739 60.230047 4.751265 62.086315 0.032575 0.035299 0.001552
157 12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 1.876313 0.366689 2.033461 -0.410065 -0.005934 0.061935 13.702403 3.739165 0.035527 0.037271 0.001688
158 12 RF_maintenance 0.00% 100.00% 100.00% 0.00% 0.120428 -0.040823 0.518956 1.224449 0.678840 0.841984 0.135638 1.756480 0.035929 0.036440 0.003268
160 13 digital_ok 100.00% 100.00% 100.00% 0.00% 2.227995 0.669220 1.307225 -0.139938 -0.141815 0.643914 0.858216 18.212887 0.041832 0.049126 0.006183
161 13 digital_ok 0.00% 100.00% 100.00% 0.00% -1.211649 -0.585703 -0.332974 -0.078733 -0.787649 -0.670141 0.423245 -0.324813 0.050755 0.055717 0.006318
162 13 digital_ok 100.00% 100.00% 100.00% 0.00% -0.389022 -0.649379 -0.360107 -0.370343 0.181966 0.555823 4.276409 7.509008 0.104441 0.097440 0.009213
163 14 digital_ok 100.00% 100.00% 100.00% 0.00% -0.585037 -0.790667 0.038891 -0.341223 0.459321 2.654467 11.731132 29.152961 0.040016 0.047670 0.007188
164 14 digital_ok 100.00% 100.00% 100.00% 0.00% 0.906997 -0.062452 -0.212506 -0.492693 1.397746 35.492888 0.987413 58.039915 0.042982 0.051283 0.011187
165 14 digital_ok 0.00% 100.00% 100.00% 0.00% -0.234909 -0.521357 -0.043504 -0.005615 1.111606 -0.080438 -1.860842 -0.271939 0.031948 0.033489 0.000701
166 14 RF_maintenance 0.00% 100.00% 100.00% 0.00% 1.806104 2.656985 0.935660 0.968962 -0.481772 2.474123 -0.252439 -0.229742 0.030187 0.034409 0.002954
167 15 digital_ok 100.00% 3.23% 0.00% 0.00% 8.479923 19.677550 29.382406 33.248453 38.148056 27.708476 934.298093 378.789579 0.523658 0.596076 0.215186
168 15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 23.926537 25.021259 32.538197 35.110405 4.882123 4.565522 10.229889 22.860173 0.712380 0.704543 0.375536
169 15 digital_ok 100.00% 0.00% 0.00% 0.00% 23.883997 24.710242 34.356730 34.140069 4.516195 4.476216 11.692367 38.237882 0.684481 0.689848 0.372405
170 15 digital_ok 100.00% 0.00% 0.00% 0.00% 23.549461 24.573417 34.534966 33.370091 4.821457 5.818933 16.769556 31.641247 0.665308 0.685111 0.381553
176 12 digital_ok 0.00% 100.00% 100.00% 0.00% 1.845846 -0.424309 1.132304 -0.785756 0.492227 -0.424700 -1.571004 -1.340138 0.037306 0.034765 0.003120
177 12 digital_ok 100.00% 100.00% 100.00% 0.00% -0.619228 3.607294 -0.187373 3.576827 -0.650298 93.158545 8.148668 73.548311 0.040373 0.036709 0.002552
178 12 digital_ok 100.00% 100.00% 100.00% 0.00% 2.158875 3.058822 3.172280 6.034161 13.890093 10.274837 98.404284 114.120407 0.041224 0.038668 0.001838
179 12 digital_ok 100.00% 100.00% 100.00% 0.00% 2.130495 0.088240 0.518621 -0.378100 8.192605 -0.192360 19.381009 -0.156089 0.038249 0.035634 0.001955
180 13 RF_maintenance 100.00% 100.00% 100.00% 0.00% 0.394872 15.106965 -0.653968 7.647266 1.368306 1.016777 33.293776 5.683978 0.038482 0.049238 0.005281
181 13 digital_ok 100.00% 100.00% 100.00% 0.00% 5.970154 1.765336 3.555661 1.605543 -1.062244 -0.634798 6.993912 7.930953 0.037519 0.038444 0.003991
182 13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 24.217755 25.237857 32.535755 33.067243 6.521675 74.726374 26.419944 89.853220 0.638135 0.643022 0.438384
183 13 digital_ok 100.00% 100.00% 100.00% 0.00% -0.964235 1.375214 -0.070498 1.365418 0.064841 68.069942 1.998662 69.138518 0.032809 0.032708 0.001060
184 14 digital_ok 100.00% 100.00% 100.00% 0.00% 0.323014 0.571952 0.693722 1.996783 124.210514 9.692804 151.909437 120.305018 0.031091 0.033123 0.000826
185 14 digital_ok 100.00% 100.00% 100.00% 0.00% 3.335550 2.826347 10.208678 10.305030 8.480326 7.216798 34.537176 73.530644 0.039807 0.036819 0.002579
186 14 digital_ok 100.00% 100.00% 100.00% 0.00% -0.539427 0.647157 -0.684250 -0.030457 1.882674 1.615394 11.098974 12.469827 0.037337 0.037432 0.003230
187 14 digital_ok 100.00% 100.00% 100.00% 0.00% 0.308452 0.557101 -0.436127 0.552562 1.517434 2.220845 11.827497 8.096028 0.036126 0.034505 0.001226
189 15 digital_ok 100.00% 100.00% 100.00% 0.00% -0.415262 -0.569565 -0.703209 -0.783789 0.411501 8.402843 24.696403 12.033735 0.033714 0.036731 0.001424
190 15 digital_ok 0.00% 100.00% 100.00% 0.00% -0.211631 -0.401449 -0.370326 1.019030 -0.533838 0.593126 0.178269 0.849925 0.032363 0.036276 0.001857
191 15 digital_ok 100.00% 100.00% 100.00% 0.00% 1.676921 -0.513434 -0.009532 0.593872 0.264757 31.476305 11.260239 9.905165 0.034544 0.034197 0.001990
220 18 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
221 18 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
222 18 RF_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
320 3 dish_maintenance 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
321 2 not_connected 100.00% 11.29% 13.98% 0.00% 24.165718 25.761421 31.375174 32.191623 6.586443 3.989295 7.233050 2.824874 0.507075 0.506024 0.397241
323 2 not_connected 100.00% 100.00% 100.00% 0.00% 5.182535 1.262152 8.349404 15.083991 -0.364907 2.622091 5.913607 4.821594 0.069456 0.046030 0.010238
324 4 not_connected 100.00% 100.00% 100.00% 0.00% 4.743231 3.761912 19.185075 20.057687 -0.350934 0.641348 0.571377 -0.855124 0.035882 0.032824 0.000932
325 9 dish_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
329 12 dish_maintenance 100.00% 100.00% 100.00% 0.00% 2.866333 1.682420 9.576291 13.384177 44.908716 1.060194 24.379600 15.552496 0.031006 0.031602 0.001250
333 12 dish_maintenance 100.00% 100.00% 100.00% 0.00% 13.561128 -0.000118 5.914553 10.469673 0.273200 -0.385406 2.252942 7.307718 0.038674 0.039263 0.001230
In [16]:
# print ex_ants for easy copy-pasting to YAML file
proposed_ex_ants = [ant for i, ant in enumerate(ants) if np.any([col[i] > .1 for col in bar_cols.values()])]
print('ex_ants: [' + ", ".join(str(ant) for ant in proposed_ex_ants) + ']')
ex_ants: [0, 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 36, 37, 38, 39, 40, 41, 42, 45, 46, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70, 71, 72, 73, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 116, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 135, 136, 138, 140, 141, 142, 143, 144, 145, 150, 155, 156, 157, 158, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 189, 190, 191, 220, 221, 222, 320, 321, 323, 324, 325, 329, 333]
In [17]:
# write to csv
outpath = os.path.join(nb_outdir, f'rtp_summary_table_{JD}.csv')
print(f'Now saving Table 1 to a csv at {outpath}')
df.to_csv(outpath)
Now saving Table 1 to a csv at /home/obs/src/H5C_Notebooks/_rtp_summary_/rtp_summary_table_2459744.csv
In [18]:
# Load antenna positions
data_list = sorted(glob.glob(os.path.join(data_path, f'zen.{JD}.?????.sum.uvh5')))
hd = io.HERAData(data_list[len(data_list) // 2])

# Figure out where to draw the nodes
node_centers = {}
for node in sorted(set(list(nodes.values()))):
    if np.isfinite(node):
        this_node_ants = [ant for ant in ants + unused_ants if nodes[ant] == node]
        if len(this_node_ants) == 1:
            # put the node label just to the west of the lone antenna 
            node_centers[node] = hd.antpos[ant][node] + np.array([-14.6 / 2, 0, 0])
        else:
            # put the node label between the two antennas closest to the node center
            node_centers[node] = np.mean([hd.antpos[ant] for ant in this_node_ants], axis=0)
            closest_two_pos = sorted([hd.antpos[ant] for ant in this_node_ants], 
                                     key=lambda pos: np.linalg.norm(pos - node_centers[node]))[0:2]
            node_centers[node] = np.mean(closest_two_pos, axis=0)
In [19]:
def Plot_Array(ants, unused_ants, outriggers):
    plt.figure(figsize=(16,16))
    
    plt.scatter(np.array([hd.antpos[ant][0] for ant in hd.data_ants if ant in ants]), 
                np.array([hd.antpos[ant][1] for ant in hd.data_ants if ant in ants]), c='w', s=0)

    # connect every antenna to their node
    for ant in ants:
        if nodes[ant] in node_centers:
            plt.plot([hd.antpos[ant][0], node_centers[nodes[ant]][0]], 
                     [hd.antpos[ant][1], node_centers[nodes[ant]][1]], 'k', zorder=0)

    rc_color = '#0000ff'
    antm_color = '#ffa500'
    autom_color = '#ff1493'

    # Plot 
    unflagged_ants = []
    for i, ant in enumerate(ants):
        ant_has_flag = False
        # plot large blue annuli for redcal flags
        if use_redcal:
            if redcal_flagged_frac[ant] > 0:
                ant_has_flag = True
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=7 * (2 - 1 * float(not outriggers)), fill=True, lw=0,
                                                color=rc_color, alpha=redcal_flagged_frac[ant]))
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=6 * (2 - 1 * float(not outriggers)), fill=True, color='w'))
        
        # plot medium green annuli for ant_metrics flags
        if use_ant_metrics: 
            if ant_metrics_xants_frac_by_ant[ant] > 0:
                ant_has_flag = True
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=6 * (2 - 1 * float(not outriggers)), fill=True, lw=0,
                                                color=antm_color, alpha=ant_metrics_xants_frac_by_ant[ant]))
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=5 * (2 - 1 * float(not outriggers)), fill=True, color='w'))
        
        # plot small red annuli for auto_metrics
        if use_auto_metrics:
            if ant in auto_ex_ants:
                ant_has_flag = True                
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=5 * (2 - 1 * float(not outriggers)), fill=True, lw=0, color=autom_color)) 
        
        # plot black/white circles with black outlines for antennas
        plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=4 * (2 - 1 * float(not outriggers)), fill=True, color=['w', 'k'][ant_has_flag], ec='k'))
        if not ant_has_flag:
            unflagged_ants.append(ant)

        # label antennas, using apriori statuses if available
        try:
            bgc = matplotlib.colors.to_rgb(status_colors[a_priori_statuses[ant]])
            c = 'black' if (bgc[0]*0.299 + bgc[1]*0.587 + bgc[2]*0.114) > 186 / 256 else 'white'
        except:
            c = 'k'
            bgc='white'
        plt.text(hd.antpos[ant][0], hd.antpos[ant][1], str(ant), va='center', ha='center', color=c, backgroundcolor=bgc)

    # label nodes
    for node in sorted(set(list(nodes.values()))):
        if not np.isnan(node) and not np.all(np.isnan(node_centers[node])):
            plt.text(node_centers[node][0], node_centers[node][1], str(node), va='center', ha='center', bbox={'color': 'w', 'ec': 'k'})
    
    # build legend 
    legend_objs = []
    legend_labels = []
    
    # use circles for annuli 
    legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markeredgecolor='k', markerfacecolor='w', markersize=13))
    legend_labels.append(f'{len(unflagged_ants)} / {len(ants)} Total {["Core", "Outrigger"][outriggers]} Antennas Never Flagged')
    legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markerfacecolor='k', markersize=15))
    legend_labels.append(f'{len(ants) - len(unflagged_ants)} Antennas {["Core", "Outrigger"][outriggers]} Flagged for Any Reason')

    if use_auto_metrics:
        legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markeredgewidth=2, markeredgecolor=autom_color, markersize=15))
        legend_labels.append(f'{len([ant for ant in auto_ex_ants if ant in ants])} {["Core", "Outrigger"][outriggers]} Antennas Flagged by Auto Metrics')
    if use_ant_metrics: 
        legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markeredgewidth=2, markeredgecolor=antm_color, markersize=15))
        legend_labels.append(f'{np.round(np.sum([frac for ant, frac in ant_metrics_xants_frac_by_ant.items() if ant in ants]), 2)} Antenna-Nights on' 
                             f'\n{np.sum([frac > 0 for ant, frac in ant_metrics_xants_frac_by_ant.items() if ant in ants])} {["Core", "Outrigger"][outriggers]} Antennas '
                             'Flagged by Ant Metrics\n(alpha indicates fraction of time)')        
    if use_redcal:
        legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markeredgewidth=2, markeredgecolor=rc_color, markersize=15))
        legend_labels.append(f'{np.round(np.sum(list(redcal_flagged_frac.values())), 2)} Antenna-Nights on' 
                             f'\n{np.sum([frac > 0 for ant, frac in redcal_flagged_frac.items() if ant in ants])} {["Core", "Outrigger"][outriggers]} Antennas '
                             'Flagged by Redcal\n(alpha indicates fraction of time)')

    # use rectangular patches for a priori statuses that appear in the array
    for aps in sorted(list(set(list(a_priori_statuses.values())))):
        if aps != 'Not Found':
            legend_objs.append(plt.Circle((0, 0), radius=7, fill=True, color=status_colors[aps]))
            legend_labels.append(f'A Priori Status:\n{aps} ({[status for ant, status in a_priori_statuses.items() if ant in ants].count(aps)} {["Core", "Outrigger"][outriggers]} Antennas)')

    # label nodes as a white box with black outline
    if len(node_centers) > 0:
        legend_objs.append(matplotlib.patches.Patch(facecolor='w', edgecolor='k'))
        legend_labels.append('Node Number')

    if len(unused_ants) > 0:
        legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markerfacecolor='grey', markersize=15, alpha=.2))
        legend_labels.append(f'Anntenna Not In Data')
        
    
    plt.legend(legend_objs, legend_labels, ncol=2, fontsize='large', framealpha=1)
    
    if outriggers:
        pass
    else:
        plt.xlim([-200, 150])
        plt.ylim([-150, 150])        
       
    # set axis equal and label everything
    plt.axis('equal')
    plt.tight_layout()
    plt.title(f'Summary of {["Core", "Outrigger"][outriggers]} Antenna Statuses and Metrics on {JD}', size=20)    
    plt.xlabel("Antenna East-West Position (meters)", size=12)
    plt.ylabel("Antenna North-South Position (meters)", size=12)
    plt.xticks(fontsize=12)
    plt.yticks(fontsize=12)
    xlim = plt.gca().get_xlim()
    ylim = plt.gca().get_ylim()    
        
    # plot unused antennas
    plt.autoscale(False)    
    for ant in unused_ants:
        if nodes[ant] in node_centers:
            plt.plot([hd.antpos[ant][0], node_centers[nodes[ant]][0]], 
                     [hd.antpos[ant][1], node_centers[nodes[ant]][1]], 'k', alpha=.2, zorder=0)
        
        plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=4, fill=True, color='w', ec=None, alpha=1, zorder=0))
        plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=4, fill=True, color='grey', ec=None, alpha=.2, zorder=0))
        if hd.antpos[ant][0] < xlim[1] and hd.antpos[ant][0] > xlim[0]:
            if hd.antpos[ant][1] < ylim[1] and hd.antpos[ant][1] > ylim[0]:
                plt.text(hd.antpos[ant][0], hd.antpos[ant][1], str(ant), va='center', ha='center', color='k', alpha=.2) 

Figure 1: Array Plot of Flags and A Priori Statuses¶

This plot shows all antennas, which nodes they are connected to, and their a priori statuses (as the highlight text of their antenna numbers). It may also show (depending on what is finished running):

  • Whether they were flagged by auto_metrics (red circle) for bandpass shape, overall power, temporal variability, or temporal discontinuities. This is done in a binary fashion for the whole night.
  • Whether they were flagged by ant_metrics (green circle) as either dead (on either polarization) or crossed, with the transparency indicating the fraction of the night (i.e. number of files) that were flagged.
  • Whether they were flagged by redcal (blue circle) for high chi^2, with the transparency indicating the fraction of the night (i.e. number of files) that were flagged.

Note that the last fraction does not include antennas that were flagged before going into redcal due to their a priori status, for example.

In [20]:
core_ants = [ant for ant in ants if ant < 320]
outrigger_ants = [ant for ant in ants if ant >= 320]
Plot_Array(ants=core_ants, unused_ants=unused_ants, outriggers=False)
if len(outrigger_ants) > 0:
    Plot_Array(ants=outrigger_ants, unused_ants=sorted(set(unused_ants + core_ants)), outriggers=True)

Metadata¶

In [21]:
from hera_qm import __version__
print(__version__)
from hera_cal import __version__
print(__version__)
2.0.2
3.1.1.dev2+g1b5039f
In [ ]: