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 = "2459742"
data_path = "/mnt/sn1/2459742"
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-11-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/2459742/zen.2459742.25308.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/2459742/zen.2459742.?????.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/2459742/zen.2459742.?????.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% 25.819586 23.926297 47.755294 45.231005 28395.505416 26999.628315 19214.915229 18083.016473 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.591554 2.848133 1.848651 1.754700 3.973845 8.914584 3.474933 24.345753 0.071117 0.069276 0.011832
8 2 RF_maintenance 100.00% 0.00% 0.00% 0.00% 26.093114 26.770121 44.240962 46.511273 51.854364 47.472527 36.413385 27.530582 0.625827 0.582645 0.466160
9 2 digital_ok 0.00% 100.00% 100.00% 0.00% 0.087895 -0.470691 -0.616013 -0.686918 1.990178 1.414981 -0.427845 -0.358441 0.063873 0.065028 0.008837
10 2 digital_ok 100.00% 100.00% 100.00% 0.00% -0.593734 2.721941 0.509140 1.313307 5.882070 17.625529 28.305219 33.945834 0.032535 0.033341 0.001836
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% 1.419240 3.609632 1.464353 3.160311 2.316475 18.780642 15.062061 5.742156 0.035732 0.038932 0.001671
20 2 digital_ok 0.00% 100.00% 100.00% 0.00% 1.759390 0.779783 2.737416 0.638084 0.865305 -0.769136 1.313001 -1.342970 0.034287 0.036697 0.001920
21 2 digital_ok 100.00% 100.00% 100.00% 0.00% 0.461855 -0.012407 -0.367210 -0.212083 3.412380 2.408700 2.208651 20.995340 0.031764 0.031337 0.001029
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.507399 -0.033520 3.334116 -0.092797 7.675066 6.229887 3.938103 1.744475 0.029711 0.030161 0.000043
32 2 RF_maintenance 100.00% 100.00% 100.00% 0.00% 1.726235 1.136210 0.230409 -0.341413 2.765666 1.488663 5.000010 4.888965 0.029642 0.029658 0.000809
33 2 RF_maintenance 100.00% 100.00% 100.00% 0.00% -0.197998 6.775136 -0.560979 18.725739 1.144411 12.046952 0.631030 11.459870 0.060152 0.042318 0.005360
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% 26.958931 27.480515 35.982787 37.587087 48.001979 36.319154 5.983541 6.209131 0.666201 0.626335 0.461555
41 4 digital_ok 0.00% 100.00% 100.00% 0.00% -0.902832 -0.349066 -0.662063 -0.583371 -0.386664 0.469629 -0.230580 -0.702328 0.032455 0.033271 0.001147
42 4 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
45 5 RF_maintenance 100.00% 100.00% 100.00% 0.00% -1.054587 16.628333 -0.881697 9.667628 -0.917601 1.697729 0.133339 4.127325 0.028695 0.032381 0.002309
46 5 digital_ok 100.00% 100.00% 100.00% 0.00% 2.234078 2.459086 5.341571 4.707498 16.078208 15.547657 40.275526 40.253817 0.028735 0.027759 0.002907
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% nan nan inf inf nan nan nan nan nan nan nan
55 4 digital_ok 0.00% 100.00% 100.00% 0.00% -0.988760 1.083426 0.203331 -0.712631 0.481735 2.123081 -0.395336 2.962824 0.034728 0.040688 0.004063
56 4 digital_ok 0.00% 100.00% 100.00% 0.00% -0.519617 0.320404 0.385078 1.925609 2.252633 1.392220 2.276239 1.623201 0.035697 0.034997 0.000454
57 4 digital_ok 100.00% 100.00% 100.00% 0.00% 2.644101 3.000306 0.995458 3.727161 4.577786 4.520408 -0.142826 0.030294 0.037737 0.036686 0.004589
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.236051 1.270812 0.148885 -0.373416 2.603920 13.176514 0.782498 2.624057 0.035774 0.036738 0.004318
70 4 RF_maintenance 100.00% 0.00% 2.69% 0.00% 31.687496 28.298032 27.741390 25.271073 69.159230 48.255551 14.080454 26.400611 0.688026 0.628965 0.468654
71 4 digital_ok 100.00% 100.00% 100.00% 0.00% 3.133924 4.466216 4.418230 6.973439 1.150294 0.951696 4.308505 0.990923 0.033159 0.036752 0.004028
72 4 digital_ok 100.00% 100.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan
73 5 RF_maintenance 100.00% 100.00% 100.00% 0.00% 0.685819 5.370248 2.493961 1.035166 8.875992 4.697665 16.561663 10.194439 0.028712 0.034024 0.003084
81 7 digital_ok 0.00% 100.00% 100.00% 0.00% 2.300610 0.372538 0.857101 1.762878 -1.419082 -0.861108 -0.954291 -0.172451 0.064400 0.060290 0.007255
82 7 RF_maintenance 0.00% 100.00% 100.00% 0.00% 3.016234 3.633241 1.113732 0.076778 0.064257 0.138846 3.717659 2.522287 0.077878 0.072268 0.004951
83 7 digital_ok 100.00% 100.00% 100.00% 0.00% 16.676011 16.527253 5.427887 5.520789 0.549269 0.751980 4.649598 3.661232 0.077845 0.087810 0.006929
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% 34.967324 38.795621 69.059513 57.549910 236.668503 311.047545 1215.319361 997.645761 0.017866 0.016690 0.000716
93 10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 30.116731 41.654208 46.534227 91.482428 145.292960 665.652114 559.785982 2413.717289 0.017280 0.016366 0.000898
94 10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 31.076446 40.562666 54.885611 68.432184 277.156561 280.139542 945.039873 1316.948276 0.016746 0.016265 0.000451
98 7 digital_maintenance 100.00% 100.00% 100.00% 0.00% 16.956694 16.685161 4.385428 4.460525 0.691870 1.362948 4.960787 4.016487 0.078293 0.093165 0.027757
99 7 digital_ok 100.00% 0.00% 0.00% 0.00% 28.923023 29.125363 33.859959 34.792366 59.851255 41.692609 10.904656 8.958168 0.629560 0.601839 0.452769
100 7 RF_maintenance 100.00% 100.00% 100.00% 0.00% 17.028663 16.487899 4.740327 6.324679 0.827333 1.939115 6.102842 6.801402 0.050243 0.076852 0.023137
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% 35.680507 43.023022 69.948516 61.772944 243.633978 217.872166 1021.878212 1161.706908 0.017928 0.016629 0.000901
110 10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 29.357177 37.632574 50.012797 75.910715 185.428292 354.164666 890.425662 1489.004008 0.017579 0.016324 0.001086
111 10 digital_ok 100.00% 100.00% 100.00% 0.00% 32.933384 36.152741 61.173099 51.823849 222.928036 222.706888 901.335298 856.917237 0.016804 0.016569 0.000413
112 10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 32.158780 48.822567 58.670339 63.815067 250.867832 288.065400 1183.827608 1175.285122 0.018073 0.016560 0.001254
116 7 RF_maintenance 100.00% 100.00% 100.00% 0.00% 15.779283 15.460792 5.338854 5.579886 0.250008 0.522308 3.443604 3.927530 0.089521 0.096405 0.005021
119 7 RF_maintenance 100.00% 100.00% 100.00% 0.00% 16.458810 0.221451 3.554495 2.532459 0.612065 -1.222379 3.190678 0.081568 0.089627 0.075215 0.016981
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% 33.087299 42.291100 66.052124 84.745197 310.177741 449.727158 1535.678795 1747.515332 0.016633 0.016342 0.000451
128 10 digital_ok 100.00% 100.00% 100.00% 0.00% 30.459169 38.425632 46.234106 64.524326 160.349675 208.850068 649.218790 951.724928 0.016908 0.016346 0.000514
129 10 digital_ok 100.00% 100.00% 100.00% 0.00% 36.409353 36.955908 67.021635 69.997117 227.714465 577.540099 1115.031224 1701.117474 0.018125 0.016512 0.001542
130 10 digital_maintenance 100.00% 100.00% 100.00% 0.00% 32.403215 33.348734 60.989094 59.765997 233.356913 161.727846 996.715500 863.235223 0.016679 0.016375 0.000401
135 12 digital_ok 0.00% 100.00% 100.00% 0.00% -0.698336 -0.575412 -0.116406 -0.409989 -0.492038 1.177611 0.846159 0.609708 0.034365 0.033077 0.001634
136 12 RF_maintenance 0.00% 100.00% 100.00% 0.00% -0.076396 -0.563184 -0.332238 -0.517116 2.427300 -0.596562 0.640114 0.600476 0.035886 0.035565 0.000771
138 7 digital_ok 0.00% 100.00% 100.00% 0.00% 2.919733 2.119847 2.027263 1.532151 -1.131070 -0.968645 -0.357446 -0.621210 0.090811 0.062586 0.002916
140 13 digital_ok 100.00% 100.00% 100.00% 0.00% 3.330892 3.945374 9.656759 9.669843 12.470410 11.575917 37.218584 34.684874 0.040825 0.055324 0.003036
141 13 digital_ok 100.00% 100.00% 100.00% 0.00% -0.065058 10.327151 1.110431 8.009772 2.530275 1.196954 1.358809 3.206512 0.042572 0.054005 0.002718
142 13 digital_ok 100.00% 100.00% 100.00% 0.00% 1.586655 15.259795 2.603271 10.351193 -0.590734 0.357021 1.682881 1.803112 0.048375 0.045124 0.002468
143 14 digital_ok 100.00% 0.00% 0.00% 0.00% 25.609147 27.922570 38.387516 39.182870 44.852723 40.929757 3.708171 4.681382 0.665275 0.646472 0.433789
144 14 digital_ok 100.00% 100.00% 100.00% 0.00% 5.033868 7.656741 3.626369 5.446664 0.424207 0.484926 2.525521 2.454250 0.037557 0.041231 0.002192
145 14 digital_ok 0.00% 100.00% 100.00% 0.00% 2.809606 -0.824228 2.866218 -0.730389 -0.064257 -0.567351 1.238920 0.646653 0.034349 0.036572 0.002916
150 15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 16.175949 15.130398 10.303318 11.578329 1.746312 3.082478 5.211769 7.819962 0.131228 0.128181 0.013643
155 12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 17.848547 18.266949 9.440117 9.973681 1.582773 1.954105 5.687686 7.216173 0.033494 0.036142 0.000797
156 12 RF_maintenance 0.00% 100.00% 100.00% 0.00% -0.017526 -0.845661 -0.841541 -0.998630 0.312170 0.532725 -0.709294 1.581361 0.033219 0.035589 0.001878
157 12 RF_maintenance 0.00% 100.00% 100.00% 0.00% 1.947869 0.248158 2.514460 -0.526248 -0.809641 1.454559 0.821256 -0.949829 0.035274 0.035854 0.001759
158 12 RF_maintenance 0.00% 100.00% 100.00% 0.00% 0.704096 -0.008508 1.241433 1.828100 -0.678287 -0.215578 -0.571940 2.585100 0.036694 0.033378 0.002122
160 13 digital_ok 100.00% 100.00% 100.00% 0.00% 2.431036 1.148688 1.616753 -0.244991 1.190449 1.594617 0.148089 7.261616 0.043238 0.054357 0.005559
161 13 digital_ok 0.00% 100.00% 100.00% 0.00% -0.925371 -0.220203 -0.010274 0.010274 -0.612080 -0.424110 0.230580 -0.077988 0.049818 0.035323 0.000736
162 13 digital_ok 0.00% 100.00% 100.00% 0.00% -0.694120 -0.323694 0.048865 -0.443931 -0.064651 -0.489220 -0.070755 0.009088 0.080012 0.035677 0.013191
163 14 digital_ok 100.00% 100.00% 100.00% 0.00% -0.138979 -0.951539 0.677953 -0.390891 1.633210 4.947509 4.599601 5.938838 0.040501 0.055656 0.008752
164 14 digital_ok 0.00% 100.00% 100.00% 0.00% 0.816496 1.057801 -0.567175 -0.701076 0.189216 3.438443 0.059932 -0.022262 0.044326 0.063796 0.012885
165 14 digital_ok 0.00% 100.00% 100.00% 0.00% -0.464615 -0.353802 -0.443797 0.012533 1.138096 1.573473 -0.633171 -0.728973 0.031752 0.034379 0.000807
166 14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 2.404722 5.420397 1.832434 3.279436 0.502835 -0.454904 0.154013 -0.033481 0.031783 0.035971 0.002471
167 15 digital_ok 100.00% 0.00% 0.00% 0.00% 13.570250 19.399382 43.155933 45.951475 75.435075 19.523048 18.450577 17.699910 0.585585 0.588443 0.240436
168 15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 25.956113 26.531820 44.924786 48.887028 25.180004 9.029577 -1.595257 -4.339889 0.721260 0.702331 0.378703
169 15 digital_ok 100.00% 0.00% 0.00% 0.00% 26.042681 26.210276 47.433391 47.519318 13.116706 11.145613 -3.655614 -2.677599 0.696930 0.692895 0.377263
170 15 digital_ok 100.00% 0.00% 0.00% 0.00% 25.673673 26.057194 47.678131 46.351135 14.835565 15.845342 -3.539678 1.063477 0.677421 0.687298 0.389763
176 12 digital_ok 0.00% 100.00% 100.00% 0.00% 1.855719 0.027506 1.201671 -0.887848 -0.769976 -0.995606 -1.024843 -1.411361 0.037622 0.035098 0.003318
177 12 digital_ok 100.00% 100.00% 100.00% 0.00% -0.341874 2.854113 0.299261 2.864940 0.447519 7.510124 0.666376 4.529841 0.042123 0.036021 0.002162
178 12 digital_ok 100.00% 100.00% 100.00% 0.00% 2.155568 3.491287 4.376493 8.488832 28.082001 31.068228 56.059387 63.024067 0.042603 0.037982 0.001249
179 12 digital_ok 100.00% 100.00% 100.00% 0.00% 2.041777 0.665753 0.298135 -0.481143 23.615423 -1.296129 8.828640 -0.610797 0.040433 0.037099 0.003777
180 13 RF_maintenance 100.00% 100.00% 100.00% 0.00% 0.741019 16.116748 -0.750883 10.726054 2.938630 1.145793 18.045600 3.151041 0.040279 0.046663 0.006267
181 13 digital_ok 100.00% 100.00% 100.00% 0.00% 6.970098 1.625408 5.408537 2.282874 0.242603 -0.014556 0.466645 1.919951 0.044475 0.030402 0.004557
182 13 RF_maintenance 100.00% 0.00% 13.98% 0.00% 25.140916 24.260003 44.546223 4.957699 30.550719 48.572751 2.364157 69.044364 0.638810 0.489978 0.465183
183 13 digital_ok 100.00% 100.00% 100.00% 0.00% -0.468389 0.094293 0.404436 0.875036 -1.444220 -0.086919 -0.128001 5.502453 0.033430 0.032916 0.001703
184 14 digital_ok 100.00% 100.00% 100.00% 0.00% 1.283178 1.103237 1.863059 2.098878 19.545868 19.229948 71.938628 71.972674 0.031331 0.034586 0.001119
185 14 digital_ok 100.00% 100.00% 100.00% 0.00% 3.469508 3.731873 12.071791 14.405799 5.530758 4.273825 12.261058 11.002072 0.040852 0.043343 0.005344
186 14 digital_ok 0.00% 100.00% 100.00% 0.00% 0.008508 0.623326 -0.405041 0.165736 3.936945 -0.381991 3.111672 0.566030 0.037121 0.040700 0.002454
187 14 digital_ok 0.00% 100.00% 100.00% 0.00% -0.281909 1.122500 -1.003209 0.711775 -0.586282 -0.203520 1.876600 3.045890 0.036293 0.035908 0.002942
189 15 digital_ok 100.00% 100.00% 100.00% 0.00% -0.213403 0.413223 -0.742444 0.520353 4.341129 1.206025 12.064594 4.275317 0.032176 0.036416 0.001326
190 15 digital_ok 0.00% 100.00% 100.00% 0.00% -0.219252 -0.654862 -0.029991 1.398815 0.670695 0.071761 -0.400912 -0.009088 0.031599 0.035675 0.002134
191 15 digital_ok 100.00% 100.00% 100.00% 0.00% 1.609403 2.958114 -0.338977 3.646594 0.911234 0.953891 0.497882 10.150620 0.033455 0.031270 0.002223
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% 3.23% 8.60% 0.00% 26.215308 27.544859 43.459515 44.919450 26.664017 17.288621 1.020454 0.931085 0.521018 0.501507 0.409048
323 2 not_connected 100.00% 100.00% 100.00% 0.00% 6.355521 1.800763 11.123488 20.809460 2.207825 6.919513 3.681131 3.598975 0.065668 0.050715 0.013658
324 4 not_connected 100.00% 100.00% 100.00% 0.00% 5.032218 4.639493 26.399814 27.868244 -0.128570 -0.252259 -0.938462 -0.842989 0.040136 0.034442 0.001322
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% 9.404170 2.203089 10.244686 18.532403 -0.550616 0.713076 2.101102 5.342858 0.032899 0.036309 0.001530
333 12 dish_maintenance 100.00% 100.00% 100.00% 0.00% 15.197474 0.026344 7.887951 14.695007 0.369145 1.853835 1.875197 6.373244 0.039333 0.041285 0.002370
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_2459742.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 [ ]: