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.

Contents:¶

  • Table 1: Overall Array Health
  • Table 2: RTP Per-Antenna Metrics Summary Table
  • Figure 1: Array Plot of Flags and A Priori Statuses
In [1]:
import os
os.environ['HDF5_USE_FILE_LOCKING'] = 'FALSE'
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 h5py
from copy import deepcopy
from IPython.display import display, HTML
from hera_notebook_templates.utils import status_colors
from hera_mc import mc
from pyuvdata import UVData

%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_'
# good_statues = "digital_ok,calibration_maintenance,calibration_triage,calibration_ok"
# 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
# os.environ["GOOD_STATUSES"] = good_statuses
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']
good_statuses = os.environ['GOOD_STATUSES']
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}"')
print(f'good_statues = "{good_statuses}"')
JD = "2459781"
data_path = "/mnt/sn1/2459781"
ant_metrics_ext = ".ant_metrics.hdf5"
redcal_ext = ".known_good.omni.calfits"
nb_outdir = "/home/obs/src/H5C_Notebooks/_rtp_summary_"
good_statues = "digital_ok,calibration_maintenance,calibration_triage,calibration_ok"
In [4]:
from astropy.time import Time
utc = Time(JD, format='jd').datetime
print(f'Date: {utc.month}-{utc.day}-{utc.year}')
Date: 7-20-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/2459781/zen.2459781.25322.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 767 ant_metrics files matching glob /mnt/sn1/2459781/zen.2459781.?????.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.')
Found 77 ant_metrics files matching glob /mnt/sn1/2459781/zen.2459781.?????.sum.known_good.omni.calfits

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 and also LST range
data_files = sorted(glob.glob(os.path.join(data_path, 'zen.*.sum.uvh5')))
hd = io.HERAData(data_files[0])
unused_ants = [ant for ant in hd.antpos if ant not in ants]    
hd_last = io.HERAData(data_files[-1])

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}

Get fem switch states¶

In [14]:
HHautos = sorted(glob.glob(f"{data_path}/zen.{JD}.*.sum.autos.uvh5"))
diffautos = sorted(glob.glob(f"{data_path}/zen.{JD}.*.diff.autos.uvh5"))

try:
    db = mc.connect_to_mc_db(None)
    session = db.sessionmaker()
    startJD = float(HHautos[0].split('zen.')[1].split('.sum')[0])
    stopJD = float(HHautos[-1].split('zen.')[1].split('.sum')[0])
    startTime = Time(startJD,format='jd')
    stopTime = Time(stopJD,format='jd')
    res = session.get_antenna_status(starttime=startTime, stoptime=stopTime)
    fem_switches = {}
    if len(res) == 0:
        femState = None
    else:
        for antpol in res:
            fem_switches[(antpol.antenna_number, antpol.antenna_feed_pol)] = antpol.fem_switch
    femState = (max(set(list(fem_switches.values())), key = list(fem_switches.values()).count)) 
except Exception as e:
    print(e)
    femState = None

Find X-engine Failures¶

In [15]:
read_inds = [1, len(HHautos)//2, -2]
x_status = [1,1,1,1,1,1,1,1]
s = UVData()
s.read(HHautos[1])

nants = len(s.get_ants())
freqs = s.freq_array[0]*1e-6
nfreqs = len(freqs)

antCon = {a: None for a in ants}
rightAnts = []
for i in read_inds:
    s = UVData()
    d = UVData()
    s.read(HHautos[i])
    d.read(diffautos[i])
    for pol in [0,1]:
        sm = np.abs(s.data_array[:,0,:,pol])
        df = np.abs(d.data_array[:,0,:,pol])
        sm = np.r_[sm, np.nan + np.zeros((-len(sm) % nants,len(freqs)))]
        sm = np.nanmean(sm.reshape(-1,nants,nfreqs),axis=1)
        df = np.r_[df, np.nan + np.zeros((-len(df) % nants,len(freqs)))]
        df = np.nanmean(df.reshape(-1,nants,nfreqs),axis=1)

        evens = (sm + df)/2
        odds = (sm - df)/2
        rat = np.divide(evens,odds)
        rat = np.nan_to_num(rat)
        for xbox in range(0,8):
            xavg = np.nanmean(rat[:,xbox*192:(xbox+1)*192],axis=1)
            if np.nanmax(xavg)>1.5 or np.nanmin(xavg)<0.5:
                x_status[xbox] = 0
    for ant in ants:
        for pol in ["xx", "yy"]:
            if antCon[ant] is False:
                continue
            spectrum = s.get_data(ant, ant, pol)
            stdev = np.std(spectrum)
            med = np.median(np.abs(spectrum))
            if (femState == "load" or femState == 'noise') and 80000 < stdev <= 4000000 and antCon[ant] is not False:
                antCon[ant] = True
            elif femState == "antenna" and stdev > 500000 and med > 950000 and antCon[ant] is not False:
                antCon[ant] = True
            else:
                antCon[ant] = False
            if np.min(np.abs(spectrum)) < 100000:
                antCon[ant] = False
for ant in ants:
    if antCon[ant] is True:
        rightAnts.append(ant)
            
x_status_str = ''
for i,x in enumerate(x_status):
    if x==0:
        x_status_str += '\u274C '
    else:
        x_status_str += '\u2705 '

Build Overall Health DataFrame¶

In [16]:
def comma_sep_paragraph(vals, chars_per_line=40):
    outstrs = []
    for val in vals:
        if (len(outstrs) == 0) or (len(outstrs[-1]) > chars_per_line):
            outstrs.append(str(val))
        else:
            outstrs[-1] += ', ' + str(val)
    return ',<br>'.join(outstrs)
In [17]:
# Time data
to_show = {'JD': [JD]}
to_show['Date'] = f'{utc.month}-{utc.day}-{utc.year}'
to_show['LST Range'] = f'{hd.lsts[0] * 12 / np.pi:.3f} -- {hd_last.lsts[-1] * 12 / np.pi:.3f} hours'

# X-engine status
to_show['X-Engine Status'] = x_status_str

# Files
to_show['Number of Files'] = len(data_files)

# Antenna Calculations
to_show['Total Number of Antennas'] = len(ants)

to_show[' '] = ''
to_show['OPERATIONAL STATUS SUMMARY'] = ''

status_count = {status: 0 for status in status_colors}
for ant, status in a_priori_statuses.items():
    if status in status_count:
        status_count[status] = status_count[status] + 1
    else:
        status_count[status] = 1
to_show['Antenna A Priori Status Count'] = '<br>'.join([f'{status}: {status_count[status]}' for status in status_colors if status in status_count and status_count[status] > 0])

to_show['Commanded Signal Source'] = femState
to_show['Antennas in Commanded State'] = f'{len(rightAnts)} / {len(ants)} ({len(rightAnts) / len(ants):.1%})'

if use_ant_metrics:
    to_show['Cross-Polarized Antennas'] = ', '.join([str(ant) for ant in ants if crossed_ant_frac[ant] == 1])

# Node calculations
nodes_used = set([nodes[ant] for ant in ants if np.isfinite(nodes[ant])])
to_show['Total Number of Nodes'] = len(nodes_used)
if use_ant_metrics:
    node_off = {node: True for node in nodes_used}
    not_correlating = {node: True for node in nodes_used}
    for ant in ants:
        for ap in antpols:
            if np.isfinite(nodes[ant]):
                if np.isfinite(average_dead_metrics[ap][ant]):
                    node_off[nodes[ant]] = False
                if dead_ant_frac[ap][ant] < 1:
                    not_correlating[nodes[ant]] = False
    to_show['Nodes Registering 0s'] = ', '.join([f'N{n:02}' for n in sorted([node for node in node_off if node_off[node]])])
    to_show['Nodes Not Correlating'] = ', '.join([f'N{n:02}' for n in sorted([node for node in not_correlating if not_correlating[node] and not node_off[node]])])

# Pipeline calculations    
to_show['  '] = ''
to_show['NIGHTLY ANALYSIS SUMMARY'] = ''
    
all_flagged_ants = []
if use_ant_metrics:
    to_show['Ant Metrics Done?'] = '\u2705'
    ant_metrics_flagged_ants = [ant for ant in ants if ant_metrics_xants_frac_by_ant[ant] > 0]
    all_flagged_ants.extend(ant_metrics_flagged_ants)
    to_show['Ant Metrics Flagged Antennas'] = f'{len(ant_metrics_flagged_ants)} / {len(ants)} ({len(ant_metrics_flagged_ants) / len(ants):.1%})' 
else:
    to_show['Ant Metrics Done?'] = '\u274C'
if use_auto_metrics:
    to_show['Auto Metrics Done?'] = '\u2705'
    auto_metrics_flagged_ants = [ant for ant in ants if ant in auto_ex_ants]
    all_flagged_ants.extend(auto_metrics_flagged_ants)    
    to_show['Auto Metrics Flagged Antennas'] = f'{len(auto_metrics_flagged_ants)} / {len(ants)} ({len(auto_metrics_flagged_ants) / len(ants):.1%})' 
else:
    to_show['Auto Metrics Done?'] = '\u274C'
if use_redcal:
    to_show['Redcal Done?'] = '\u2705'    
    redcal_flagged_ants = [ant for ant in ants if redcal_flagged_frac[ant] > 0]
    all_flagged_ants.extend(redcal_flagged_ants)    
    to_show['Redcal Flagged Antennas'] = f'{len(redcal_flagged_ants)} / {len(ants)} ({len(redcal_flagged_ants) / len(ants):.1%})' 
else:
    to_show['Redcal Done?'] = '\u274C' 
to_show['Never Flagged Antennas'] = f'{len(ants) - len(set(all_flagged_ants))} / {len(ants)} ({(len(ants) - len(set(all_flagged_ants))) / len(ants):.1%})'

# Count bad antennas with good statuses and vice versa
apriori_good_flagged = []
aprior_bad_unflagged = []
for ant in ants:
    if ant in set(all_flagged_ants) and a_priori_statuses[ant] in good_statuses.split(','):
        apriori_good_flagged.append(ant)
    elif ant not in set(all_flagged_ants) and a_priori_statuses[ant] not in good_statuses.split(','):
        aprior_bad_unflagged.append(ant)
to_show['A Priori Good Antennas Flagged'] = comma_sep_paragraph(apriori_good_flagged)
to_show['A Priori Bad Antennas Not Flagged'] = comma_sep_paragraph(aprior_bad_unflagged)


# Apply Styling
df = pd.DataFrame(to_show)
divider_cols = [df.columns.get_loc(col) for col in ['NIGHTLY ANALYSIS SUMMARY', 'OPERATIONAL STATUS SUMMARY']]
try:
    to_red_columns = [df.columns.get_loc(col) for col in ['Cross-Polarized Antennas', 'Nodes Registering 0s', 
                                                          'Nodes Not Correlating', 'A Priori Good Antennas Flagged']]
except:
    to_red_columns = []
def red_specific_cells(x):
    df1 = pd.DataFrame('', index=x.index, columns=x.columns)
    for col in to_red_columns:
        df1.iloc[col] = 'color: red'
    return df1

df = df.T
table = df.style.hide_columns().apply(red_specific_cells, axis=None)
for col in divider_cols:
    table = table.set_table_styles([{"selector":f"tr:nth-child({col+1})", "props": [("background-color", "black"), ("color", "white")]}], overwrite=False)

Table 1: Overall Array Health¶

In [18]:
HTML(table.render())
Out[18]:
JD 2459781
Date 7-20-2022
LST Range 15.404 -- 23.804 hours
X-Engine Status ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
Number of Files 813
Total Number of Antennas 147
OPERATIONAL STATUS SUMMARY
Antenna A Priori Status Count dish_maintenance: 3
RF_maintenance: 46
RF_ok: 11
digital_maintenance: 2
digital_ok: 82
not_connected: 3
Commanded Signal Source antenna
Antennas in Commanded State 86 / 147 (58.5%)
Cross-Polarized Antennas
Total Number of Nodes 15
Nodes Registering 0s N18
Nodes Not Correlating N12
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 90 / 147 (61.2%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 79 / 147 (53.7%)
Redcal Done? ✅
Redcal Flagged Antennas 15 / 147 (10.2%)
Never Flagged Antennas 34 / 147 (23.1%)
A Priori Good Antennas Flagged 7, 10, 21, 29, 31, 37, 40, 41, 42, 50, 51,
53, 54, 55, 56, 57, 68, 69, 71, 72, 81, 83,
84, 88, 91, 92, 101, 103, 105, 106, 107, 108,
111, 117, 118, 128, 129, 135, 138, 141, 142,
145, 160, 161, 167, 169, 170, 176, 177, 178,
179, 181, 185, 186, 187, 189, 190, 191
A Priori Bad Antennas Not Flagged 3, 4, 8, 36, 38, 70, 73, 82, 100, 119
In [19]:
# write to csv
outpath = os.path.join(nb_outdir, f'array_health_table_{JD}.csv')
print(f'Now saving Table 2 to a csv at {outpath}')
df.replace({'\u2705': 'Y'}, regex=True).replace({'\u274C': 'N'}, regex=True).replace({'<br>': ' '}, regex=True).to_csv(outpath)
Now saving Table 2 to a csv at /home/obs/src/H5C_Notebooks/_rtp_summary_/array_health_table_2459781.csv

Build DataFrame¶

In [20]:
# build dataframe
to_show = {'Ant': [f'<a href="{ant_to_report_url(ant)}" target="_blank">{ant}</a>' for ant in ants],
           'Node': [f'N{nodes[ant]:02}' 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 2: 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 [21]:
HTML(table.render())
Out[21]:
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 Flag Fraction Before Redcal Flagged By Redcal chi^2 Fraction 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 Median chi^2 Per Antenna (Jee) Median chi^2 Per Antenna (Jnn)
3 N01 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.061252 -0.840749 0.132118 -0.709711 0.186246 -0.097647 -0.009702 0.019053 0.715195 0.667605 0.360532 3.957168 3.652405
4 N01 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.338803 0.345204 0.402007 -0.347592 0.870878 0.554578 2.626680 0.351972 0.730494 0.668130 0.361168 5.227682 4.201041
5 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.213971 -0.909254 -0.064076 -1.199698 0.458325 -1.970952 0.190367 -1.226525 0.738511 0.679718 0.358318 2.204118 2.261917
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.385246 -0.236091 -0.135059 -0.143344 0.513781 0.740723 -0.197948 7.694379 0.727850 0.673319 0.356127 3.360384 3.751826
8 N02 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.401105 1.443518 0.574770 0.701023 -1.082572 -0.977026 -1.097633 -1.916165 0.717517 0.650937 0.359280 3.791084 3.897396
9 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.142531 -1.007255 0.665038 -0.878442 1.333777 -0.039592 0.132952 -0.379105 0.710909 0.662472 0.359400 1.902558 1.704570
10 N02 digital_ok 0.00% 6.52% 1.30% 0.00% 6.49% 1.30% -0.068829 0.341809 -0.011990 0.987572 0.681600 0.980095 0.443622 0.773769 0.700387 0.633851 0.368527 1.912135 1.931601
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.044184 -0.085052 0.867489 0.272438 0.916721 0.830202 0.172798 0.688658 0.736875 0.678297 0.354862 2.306370 2.462291
16 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.375612 -1.204917 -0.343269 -0.895131 -0.057022 -0.939667 0.996685 1.194903 0.753082 0.697218 0.352779 2.256963 2.332889
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.447418 -0.427785 -0.134444 -0.512471 0.353848 0.014261 -0.099862 -0.248836 0.745364 0.694632 0.350049 2.275537 2.312511
18 N01 RF_maintenance 100.00% 49.15% 64.80% 0.00% 100.00% 0.00% 0.381959 2.467448 -0.033140 4.175485 15.272660 15.383676 46.221043 25.320550 0.694929 0.516125 0.480072 2.240609 1.612923
19 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.133890 -0.570969 -1.007275 -0.148791 -0.638423 0.239009 -0.511939 0.330041 0.738928 0.685205 0.351515 1.844071 1.964551
20 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.282631 -0.471051 3.142204 0.009219 -0.079656 0.780624 0.252694 0.077227 0.696864 0.662397 0.351586 2.059069 1.977580
21 N02 digital_ok 100.00% 58.28% 49.15% 0.00% 100.00% 0.00% 1.414380 1.909725 3.490655 2.335019 15.448195 15.683628 0.313642 3.818779 0.653358 0.650585 0.426775 2.143881 2.378520
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.399862 3.781633 7.386381 7.522124 16.121629 16.166929 1.480404 1.412973 0.039461 0.041269 0.001673 1.159977 1.177097
28 N01 RF_maintenance 100.00% 60.89% 100.00% 0.00% 100.00% 0.00% 0.841489 2.776487 1.413753 6.463127 15.746812 16.220575 2.230026 9.791441 0.505678 0.201298 0.338240 8.423132 2.406612
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 1.30% -1.132956 -0.377296 -0.911700 -0.248803 -0.605554 0.405543 -0.696411 0.021273 0.760625 0.706348 0.345859 2.318371 2.493608
30 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.056260 0.371540 1.100408 1.741147 0.382848 0.474645 2.490789 0.417518 0.737883 0.684358 0.345762 2.167838 2.242908
31 N02 digital_ok 100.00% 49.15% 49.15% 0.00% 100.00% 0.00% 1.353464 1.768270 3.702223 3.052975 15.677030 15.662079 0.679960 0.583859 0.715086 0.701685 0.424248 2.133491 2.179171
32 N02 RF_maintenance 100.00% 59.58% 59.58% 0.00% 100.00% 0.00% 9.144815 9.379213 2.081702 1.859568 15.760966 15.959597 46.331245 47.482253 0.645806 0.638752 0.228237 3.491413 2.724901
33 N02 RF_maintenance 100.00% 0.00% 16.95% 0.00% 100.00% 0.00% -0.002606 2.063470 0.169376 1.418841 0.788280 -0.483757 0.627608 10.287418 0.720966 0.487345 0.475381 3.618823 1.970056
36 N03 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.977580 0.528676 -0.741383 0.277467 0.113591 0.695055 -0.295498 0.499280 0.733644 0.668803 0.351324 3.988189 3.418992
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.427408 -0.577099 0.724589 -0.580902 0.853006 0.137688 0.591226 4.232800 0.742192 0.693021 0.345973 3.900797 3.746001
38 N03 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.661358 -0.944769 0.998703 -0.810767 1.718914 0.241055 2.504962 0.264792 0.753849 0.709262 0.350006 3.643737 3.502485
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 24.68% 0.208030 0.570076 0.603021 1.765664 0.962718 0.381404 0.176446 0.148214 0.761425 0.701406 0.351968 2.070480 2.044129
41 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 5.19% -0.950951 -0.522653 -1.224387 -0.412266 -1.571511 0.111939 -0.918736 -0.249220 0.772141 0.722254 0.340159 2.541020 2.046398
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 16.88% -1.081552 0.324786 -1.129218 0.277803 -1.035298 0.868240 -0.695728 -0.045798 0.770154 0.720335 0.350128 2.220832 2.099640
45 N05 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.043373 0.263291 0.556360 1.985333 1.117969 -0.444234 0.102951 6.776197 0.738036 0.658759 0.367134 3.372093 2.979351
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.976665 -0.159675 -0.820438 0.046181 -0.007648 0.625017 -0.517887 0.361509 0.730595 0.677128 0.363293 1.826147 1.729769
50 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.763746 0.860558 -0.335939 -0.674885 0.682150 -1.228811 1.053745 32.523428 0.736243 0.630886 0.335204 4.895875 4.163206
51 N03 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 0.048841 7.372118 -0.290377 7.860824 -3.333447 1.067691 -1.234789 4.067093 0.749430 0.050243 0.463581 3.590190 1.216142
52 N03 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 1.533954 8.138126 0.957829 7.954982 0.828318 1.119136 5.439577 3.149015 0.733462 0.040409 0.451799 7.166528 1.159983
53 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 14.29% 0.772393 0.765536 0.043443 -0.022358 -2.643848 -2.907701 -1.265452 -0.693476 0.772790 0.725975 0.340188 2.211753 2.075968
54 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 94.81% 0.251124 0.133954 0.033034 0.342000 0.007648 0.919281 1.040739 0.327071 0.767192 0.721174 0.311208 4.068035 4.567711
55 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.605872 -0.889427 2.549550 -1.003594 0.966922 -0.843292 4.535369 -0.450427 0.743045 0.734896 0.345639 2.752058 3.400862
56 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 36.36% -1.098192 -0.908530 -1.039078 -1.027173 -0.539222 -0.281890 -0.630118 1.755331 0.779098 0.738641 0.341375 2.686603 2.228268
57 N04 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 3.263594 0.668652 5.663463 0.400753 1.663354 5.743242 0.178178 1.296898 0.049775 0.715672 0.454521 1.325760 3.462819
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.035786 -0.327632 -0.058014 0.286915 1.363436 1.143975 0.067662 0.576299 0.733468 0.679220 0.347521 1.995996 1.875643
66 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.694515 -0.197429 -0.710389 0.775107 -0.371030 1.290251 -0.400469 1.419025 0.753929 0.701362 0.337551 1.957498 1.878375
67 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.471704 0.050877 -0.177374 4.695227 1.099736 -1.564913 0.287766 0.441212 0.766805 0.654651 0.361349 4.049105 3.115260
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 12.99% 0.074492 0.168763 -0.096224 1.072880 0.880309 1.451496 -0.056190 0.283508 0.772814 0.726461 0.329462 2.427876 2.328513
69 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 98.70% -0.854057 -0.720557 -0.776308 -0.580607 0.309145 -0.248027 -0.298402 0.134569 0.779704 0.740603 0.326013 4.629319 4.251655
70 N04 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.101899 -0.900651 1.376149 -0.698778 3.270536 0.184448 1.331917 0.073838 0.774928 0.740932 0.347409 18.089443 11.735558
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% -0.751275 -0.938043 -0.674986 -0.806986 -0.704743 0.206447 -0.507686 -0.268809 0.778665 0.744967 0.338824 16.001745 13.844806
72 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 88.31% 0.767713 -0.939972 0.047678 -1.082244 0.446075 -0.405173 1.828852 -0.811709 0.772484 0.739471 0.348994 4.150568 3.416127
73 N05 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.194056 -0.030222 0.515192 2.323132 0.821712 -0.218591 1.424049 0.792465 0.756397 0.685975 0.374732 3.513512 2.795858
81 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.693035 -0.592093 0.852770 -1.275840 -0.180978 -1.920628 4.876562 0.009527 0.708409 0.673452 0.345467 3.430387 3.818491
82 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.103083 -0.460004 0.494929 0.795420 0.530188 0.303915 0.200693 0.083639 0.725239 0.685543 0.344822 3.695644 3.572510
83 N07 digital_ok 100.00% 64.80% 0.00% 0.00% 100.00% 0.00% 2.646367 -0.846898 4.988843 -1.289093 0.462680 -1.575129 0.049474 -0.968223 0.318944 0.721336 0.526019 1.308100 4.396810
84 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.60% 1.432247 1.356698 -0.373540 -0.427795 -3.415355 -3.036931 -1.723602 -1.695237 0.698540 0.652366 0.314057 2.703125 2.587525
85 N08 RF_maintenance 100.00% 49.15% 50.46% 0.00% 100.00% 0.00% -0.404792 5.374477 -1.256422 -0.084229 15.161522 15.278786 -1.881330 2.641406 0.694034 0.637396 0.391902 2.543823 3.279252
86 N08 RF_maintenance 100.00% 49.15% 49.15% 0.00% 100.00% 0.00% -0.675579 1.203384 -0.976425 -0.584279 15.168059 15.525540 -1.370183 -1.391713 0.692330 0.661824 0.396665 2.749552 2.546218
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.953326 1.595227 0.104371 0.682230 -2.190312 -1.134416 8.449881 -2.084053 0.698056 0.646714 0.336454 3.366856 3.093990
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.435439 3.839686 5.140996 5.317083 1.717429 1.323164 0.509618 0.191667 0.038360 0.038697 0.000268 1.154739 1.150823
90 N09 RF_maintenance 100.00% 10.43% 0.00% 0.00% 100.00% 0.00% -0.051746 -0.400183 3.156583 -1.260654 -2.687992 -1.822032 0.640739 3.634241 0.678299 0.709494 0.385619 2.588678 3.054978
91 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.206910 3.487085 6.517159 6.804947 16.114893 16.159068 1.252455 1.210389 0.033984 0.038660 0.001465 1.155728 1.151928
92 N10 digital_ok 100.00% 79.14% 100.00% 0.00% 100.00% 0.00% 6.461609 9.805749 2.448681 4.744797 16.211044 16.385882 1.741192 4.767011 0.355782 0.258881 0.161719 2.662643 2.295693
93 N10 RF_maintenance 100.00% 59.58% 59.58% 40.42% 100.00% 0.00% -0.519411 1.797682 -0.521392 3.672548 15.253525 15.572084 -1.151289 0.406218 0.234255 0.234627 -0.330550 2.334306 2.085418
94 N10 RF_maintenance 100.00% 55.67% 49.15% 0.00% 100.00% 0.00% 1.172523 1.334828 0.765205 0.740356 15.611195 15.622480 1.030340 0.600110 0.656091 0.635722 0.436922 2.475377 2.546575
98 N07 digital_maintenance 0.00% 0.00% 10.43% 0.00% 100.00% 0.00% -0.687222 0.193657 -0.126988 2.526469 0.087740 -1.796223 -0.169404 0.460535 0.711250 0.599164 0.372622 3.567481 3.464532
99 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.400108 -0.169763 -1.226324 0.657023 -1.305477 1.061627 0.247582 0.190861 0.731123 0.670788 0.345721 1.866005 2.028297
100 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.020849 -0.509904 -0.894702 -0.197479 -1.084952 0.155181 -0.280045 -0.214733 0.754103 0.707159 0.341869 4.058245 4.532968
101 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 16.88% 1.314658 1.284191 -0.291071 -0.624568 -3.213746 -3.056882 -0.030017 -1.563155 0.690616 0.642855 0.324623 2.477853 2.334917
102 N08 RF_maintenance 100.00% 49.15% 49.15% 0.00% 100.00% 0.00% 1.211969 0.574604 -0.605342 0.491539 15.356693 15.814396 16.611723 73.419182 0.665361 0.668976 0.394456 2.416957 2.691735
103 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 1.30% 0.495105 1.293478 -0.574309 -0.623044 -2.582061 -2.512957 -1.540221 -1.616718 0.700958 0.649721 0.326063 2.635222 2.342142
104 N08 RF_maintenance 100.00% 10.43% 10.43% 89.57% 100.00% 0.00% 1.282981 2.053392 -0.850090 1.378885 -2.731725 32.037002 -0.947344 23.768956 0.362559 0.329425 -0.225477 5.904000 5.208054
105 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.555724 4.317346 6.212145 6.505624 16.112306 16.160876 1.109700 1.083226 0.034256 0.039046 0.007200 1.147587 1.146686
106 N09 digital_ok 100.00% 49.15% 49.15% 0.00% 100.00% 0.00% -0.050082 0.055443 0.420521 0.223734 15.445684 15.463439 1.180200 -0.189579 0.737763 0.730190 0.445730 2.487907 2.295680
107 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.070433 3.176365 5.198819 5.379920 1.730201 1.304947 0.198113 0.305745 0.038321 0.042649 0.005113 1.186526 1.186827
108 N09 digital_ok 100.00% 49.15% 49.15% 0.00% 100.00% 0.00% -0.253436 0.015806 -0.064166 -0.537906 15.379960 15.326530 -0.596639 -1.263922 0.712015 0.705344 0.453278 2.111058 2.219477
109 N10 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.093615 -0.325875 -0.842797 -0.108971 -0.229248 0.211656 1.373545 0.833944 0.736573 0.683391 0.360149 1.571194 1.505462
110 N10 RF_maintenance 100.00% 7.82% 0.00% 0.00% 100.00% 0.00% 8.151316 -0.765822 -0.243648 -1.115572 -0.770377 -0.821024 3.743385 -0.930664 0.646289 0.680719 0.294122 5.905529 5.194617
111 N10 digital_ok 0.00% 6.52% 0.00% 0.00% 6.49% 0.00% -0.329436 -0.887135 -0.173554 -1.046976 0.635370 -0.888111 0.067806 1.002771 0.709098 0.656443 0.356010 1.708517 1.496187
112 N10 RF_maintenance 100.00% 50.85% 52.15% 0.00% 100.00% 0.00% 0.806875 1.428128 2.041535 1.419550 16.302356 16.378765 -0.496083 -0.699018 0.739655 0.648413 0.272397 0.000000 0.000000
116 N07 RF_maintenance 0.00% 6.52% 0.00% 0.00% 100.00% 0.00% -0.159123 -0.666500 1.308929 -0.738604 -0.074431 -0.869981 0.009702 -0.615013 0.689037 0.657572 0.356799 3.350407 3.946159
117 N07 digital_ok 100.00% 49.15% 49.15% 0.00% 100.00% 0.00% -0.993625 -0.871464 -0.796719 -0.798767 15.216788 15.279742 -1.379195 -1.576006 0.696664 0.677937 0.435554 2.308937 2.374587
118 N07 digital_ok 100.00% 49.15% 49.15% 0.00% 100.00% 0.00% -0.575675 0.446567 -0.461975 0.181251 15.292783 15.536031 0.068251 0.228706 0.711107 0.696479 0.428069 2.202730 2.294811
119 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.012712 -0.846158 -0.568407 -0.521720 -3.362717 -0.477903 -1.568997 -0.511571 0.754225 0.703926 0.349948 3.853307 3.632402
120 N08 RF_maintenance 100.00% 64.80% 100.00% 0.00% 100.00% 0.00% 2.427220 6.451404 -1.181919 6.890328 -0.399019 1.316835 -0.258492 2.320694 0.387456 0.050008 0.288712 4.602723 1.356964
121 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.114664 0.295986 -0.476678 -1.171412 -3.159380 -0.768169 6.326338 5.784658 0.695035 0.641010 0.328693 5.480649 4.980413
122 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.242442 1.047641 -0.766473 -0.418322 -2.280711 -3.328589 -1.219327 -1.529208 0.693806 0.636648 0.331675 2.522378 2.252901
123 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.370970 1.251432 -0.009219 0.190181 -2.727524 -2.372497 -1.763980 -1.993208 0.691548 0.637242 0.332212 2.757290 2.552648
125 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.377364 3.492181 6.604281 6.837188 16.113346 16.156805 1.091367 1.328093 0.028337 0.031189 0.002080 1.166821 1.163408
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.959998 3.513787 6.535442 6.889002 16.115922 16.160914 1.131660 1.251018 0.030807 0.032992 -0.000298 1.216003 1.217194
127 N10 RF_maintenance 100.00% 50.85% 52.15% 0.00% 100.00% 0.00% 0.605143 1.224199 3.778423 2.778751 16.304419 16.382511 -0.047385 0.788952 0.742314 0.670404 0.248047 0.000000 0.000000
128 N10 digital_ok 100.00% 50.85% 52.15% 0.00% 100.00% 0.00% 0.407713 1.695136 2.246340 1.225630 16.305409 16.376713 0.082161 -0.225521 0.760337 0.662100 0.256452 0.000000 0.000000
129 N10 digital_ok 100.00% 55.67% 49.15% 0.00% 100.00% 0.00% 0.926493 0.538588 0.552070 0.119928 15.548762 15.496059 -0.129689 -0.127748 0.665458 0.653292 0.421631 2.583579 2.665317
130 N10 digital_maintenance 100.00% 56.98% 55.67% 0.00% 100.00% 0.00% 1.051708 1.074965 1.071546 0.277166 15.510889 15.501480 0.702296 1.683418 0.644808 0.628584 0.411967 2.440169 2.449535
135 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.863640 1.467177 2.862639 1.805226 16.303935 16.381011 -0.218687 -0.326015 0.084352 0.089060 0.008546 0.000000 0.000000
136 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.830751 2.100590 2.019011 1.742182 16.307763 16.379668 0.581137 1.549909 0.085072 0.095525 0.010323 0.000000 0.000000
137 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.262453 3.547004 6.437916 6.625634 16.118140 16.162880 1.185535 1.264598 0.032694 0.042576 0.004639 1.153447 1.155018
138 N07 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 3.899081 -0.090285 4.723770 0.062726 1.732546 0.308314 0.238409 -0.143527 0.045357 0.669092 0.464821 1.216081 3.756839
140 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.202553 -0.237492 -0.502017 -0.419347 0.326654 0.501340 0.799587 1.499521 0.741973 0.689656 0.347987 2.495985 2.365116
141 N13 digital_ok 100.00% 0.00% 54.76% 0.00% 100.00% 0.00% 0.133793 1.751771 0.719992 5.471881 0.154425 -1.419908 2.210269 0.701955 0.736997 0.469543 0.431072 4.846405 2.706289
142 N13 digital_ok 100.00% 71.32% 100.00% 0.00% 100.00% 0.00% 3.416737 3.972349 4.461273 6.223919 0.009795 1.207993 0.499849 0.461272 0.366077 0.041026 0.208548 5.227498 1.266632
143 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.070922 -1.167469 0.407239 -1.042683 0.352338 -0.927940 -0.053981 -0.834788 0.743946 0.709114 0.342797 2.654296 2.914605
144 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.108093 -0.178528 3.418458 3.180119 -1.239716 -1.605278 0.203265 0.317884 0.688819 0.651843 0.351996 2.333862 2.883515
145 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.051410 3.279435 6.054028 6.263641 1.610455 1.186162 0.455302 0.675623 0.030064 0.031732 0.001502 1.351188 1.402942
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.422586 4.058317 6.074504 6.416113 1.605095 1.226632 1.611298 1.967346 0.048805 0.053894 0.002600 1.327556 1.335626
155 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.218464 3.336022 7.410835 7.634297 16.304297 16.382037 -0.167958 -0.173644 0.031715 0.034230 0.001578 0.000000 0.000000
156 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.252320 -0.704833 0.093408 -0.559492 0.750071 -0.448773 1.211928 5.540868 0.054132 0.055730 0.004061 1.187263 1.188657
157 N12 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.036266 -1.065859 0.264319 -1.270888 0.873030 -1.265814 0.114238 -0.190282 0.069467 0.063091 0.004676 1.250567 1.248627
158 N12 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.093793 0.047999 1.683681 0.685425 -0.152167 0.403263 2.042196 0.920148 0.079212 0.064400 0.008749 1.275622 1.280207
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.014799 3.364759 5.987684 6.186439 1.597020 1.145504 0.457357 0.601398 0.045471 0.044460 0.000090 1.221155 1.232356
161 N13 digital_ok 100.00% 0.00% 10.43% 0.00% 100.00% 0.00% -0.139700 10.237917 -0.014098 2.043711 0.682151 -1.102156 0.272922 -0.068853 0.743247 0.554015 0.339416 5.479247 7.030397
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.413249 -0.775264 -0.488854 -0.825513 -0.341156 -0.667382 0.660323 -0.433030 0.740886 0.689997 0.342132 3.146964 2.558074
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.207850 0.116777 0.675569 1.275097 0.843359 0.350710 0.441614 0.530555 0.743425 0.681877 0.345634 2.473211 2.368035
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.133761 0.181120 0.032696 0.894336 0.660731 0.583783 -0.082522 1.023060 0.742150 0.682713 0.349415 2.368422 2.143705
165 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.848291 0.221607 -1.093330 0.824475 -1.486931 0.455153 -0.107307 0.735023 0.742296 0.677020 0.352421 2.184485 2.452791
166 N14 RF_maintenance 100.00% 10.43% 2.61% 0.00% 100.00% 0.00% 4.841873 2.434224 -0.260838 -0.621442 -2.445358 -0.878468 6.801395 37.499243 0.661440 0.608427 0.260517 3.375191 3.117673
167 N15 digital_ok 100.00% 10.43% 10.43% 0.00% 100.00% 0.00% 4.327875 2.474508 0.248791 0.715140 0.198658 -0.589533 29.062020 9.160660 0.573322 0.579078 0.246914 2.417700 3.187172
168 N15 RF_maintenance 0.00% 7.82% 9.13% 0.00% 100.00% 0.00% 1.750877 2.054095 0.642821 1.015873 -0.843917 -0.167012 -1.869875 -2.070388 0.700709 0.634832 0.352564 4.276536 4.716191
169 N15 digital_ok 0.00% 9.13% 9.13% 0.00% 9.09% 0.00% 2.134744 1.779943 0.937542 0.819256 -0.145457 -0.646234 -2.101618 -1.776040 0.686027 0.622058 0.349032 1.509315 1.499173
170 N15 digital_ok 0.00% 10.43% 10.43% 0.00% 10.39% 0.00% 2.125253 1.479477 0.978507 0.691952 0.018025 -0.974979 -2.061312 -2.094310 0.671366 0.623124 0.346761 1.506505 1.388808
176 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.789670 -1.132236 -0.774894 -0.971114 -0.279159 -0.442764 -0.531227 -0.824988 0.052816 0.066755 0.005541 1.211791 1.210702
177 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.832397 0.255735 -0.943635 1.546540 -0.369753 1.427137 1.694951 2.345347 0.064000 0.063155 0.004807 1.231050 1.232021
178 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.682481 -0.963370 -0.400668 -0.655157 0.373032 0.200034 -0.085681 -0.385980 0.066294 0.062887 0.005478 1.239995 1.240591
179 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.340948 1.367375 1.132793 0.846644 15.505970 15.690443 0.713670 0.517809 0.053136 0.065065 0.008594 1.213963 1.217845
180 N13 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% -0.703647 3.582659 -0.930574 6.244044 -0.499964 1.094788 -0.602190 0.484115 0.732202 0.132424 0.485603 13.890577 1.388490
181 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.060282 8.526733 6.075857 4.395933 1.593637 0.789727 0.444013 1.019234 0.048273 0.204186 0.100483 1.205524 1.688978
182 N13 RF_maintenance 100.00% 0.00% 6.52% 0.00% 100.00% 0.00% 1.463688 -0.615913 0.594022 -1.175374 -1.167986 7.799806 -1.923505 24.226684 0.724504 0.628471 0.377259 4.516739 3.824908
183 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.609673 0.000864 -0.186952 0.508489 0.279713 0.763060 0.083291 3.291930 0.737843 0.661905 0.359372 2.413725 2.235549
184 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.601291 0.362789 1.006246 1.175220 0.358280 0.610392 0.497146 0.209710 0.735248 0.666290 0.348399 2.963192 2.472719
185 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
186 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
187 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
189 N15 digital_ok 100.00% 58.28% 58.28% 0.00% 100.00% 0.00% 1.323178 1.076472 0.928557 0.418899 15.615326 15.563443 0.254823 0.182449 0.641014 0.623832 0.412253 1.849260 1.868387
190 N15 digital_ok 100.00% 60.89% 100.00% 0.00% 100.00% 0.00% 7.749193 3.967148 1.688194 7.640890 15.582637 16.165603 39.114978 1.575664 0.570406 0.045168 0.419091 1.481292 1.067483
191 N15 digital_ok 100.00% 59.58% 59.58% 0.00% 100.00% 0.00% 0.912533 0.973188 0.747871 0.317214 15.614795 15.567810 2.142807 2.897043 0.611266 0.587730 0.413743 1.895304 2.014033
203 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
205 N19 RF_ok 0.00% 7.82% 7.82% 0.00% 100.00% 0.00% 2.021094 0.113797 0.832856 -0.673995 -0.476099 -3.144575 -2.061123 2.627723 0.693755 0.641766 0.348024 3.988064 3.567108
206 N19 RF_ok 0.00% 10.43% 9.13% 0.00% 100.00% 0.00% -0.000864 1.571030 0.175106 0.531244 -0.698860 -1.578728 -0.071505 -1.621939 0.651753 0.631447 0.352305 2.824054 3.025223
207 N19 RF_ok 0.00% 10.43% 9.13% 0.00% 100.00% 0.00% 2.255449 1.642361 0.998111 0.719582 0.112547 0.035707 -2.068591 -1.952926 0.665115 0.620086 0.341370 7.334525 7.585301
220 N18 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
221 N18 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
222 N18 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
223 N19 RF_ok 0.00% 7.82% 9.13% 0.00% 100.00% 0.00% 1.395588 1.158582 0.381350 0.426777 -1.803530 2.334512 -1.846811 -1.539845 0.691527 0.620122 0.356080 3.757014 2.901746
224 N19 RF_ok 0.00% 10.43% 10.43% 0.00% 100.00% 0.00% 2.626864 2.299944 1.407315 1.327550 1.169909 0.518147 -2.305114 -2.312605 0.657005 0.591932 0.346843 3.992818 3.233101
241 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
242 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
243 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.486881 1.368820 12.011190 11.884024 535.545115 559.216531 6700.225726 6699.748213 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 4.459066 4.232907 4.276850 4.328773 1.539814 1.143545 1.796487 1.014999 0.076384 0.066658 -0.009126 0.000000 0.000000
321 N02 not_connected 0.00% 11.73% 29.99% 0.00% 100.00% 0.00% 0.657125 0.222996 -0.107524 -0.257490 -2.595293 -3.052330 1.159765 1.041105 0.603871 0.494663 0.310302 0.000000 0.000000
323 N02 not_connected 0.00% 17.86% 32.59% 0.00% 100.00% 0.00% 3.672483 0.885452 0.229405 0.210761 -2.403385 -2.113717 0.926653 -1.163884 0.460981 0.471042 0.236950 0.000000 0.000000
324 N04 not_connected 0.00% 11.73% 32.59% 0.00% 100.00% 0.00% 1.456946 1.492041 0.493525 0.559527 -1.220847 -1.269867 -1.911722 -2.096701 0.592766 0.480203 0.304067 0.000000 0.000000
329 N12 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.162790 -0.624897 1.356893 -1.277434 15.322708 15.255860 3.317044 -1.679973 0.066600 0.063782 0.022110 0.000000 0.000000
333 N12 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.862412 -0.623927 3.332578 -1.299558 15.331463 15.241477 0.155648 -1.422098 0.059366 0.063826 0.018840 0.000000 0.000000
In [22]:
# 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] > 0 for col in bar_cols.values()])]
print('ex_ants: [' + ", ".join(str(ant) for ant in proposed_ex_ants) + ']')
print(f'\nunflagged_ants: [{", ".join([str(ant) for ant in ants if ant not in proposed_ex_ants])}]')
# "golden" means no flags and good a priori status
golden_ants = ", ".join([str(ant) for ant in ants if ((ant not in proposed_ex_ants) and (a_priori_statuses[ant] in good_statuses.split(',')))])
print(f'\ngolden_ants: [{golden_ants}]')
ex_ants: [3, 4, 7, 8, 10, 18, 21, 27, 28, 29, 31, 32, 33, 36, 37, 38, 40, 41, 42, 45, 50, 51, 52, 53, 54, 55, 56, 57, 67, 68, 69, 70, 71, 72, 73, 81, 82, 83, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 98, 100, 101, 102, 103, 104, 105, 106, 107, 108, 110, 111, 112, 116, 117, 118, 119, 120, 121, 125, 126, 127, 128, 129, 130, 135, 136, 137, 138, 141, 142, 145, 150, 155, 156, 157, 158, 160, 161, 166, 167, 168, 169, 170, 176, 177, 178, 179, 180, 181, 182, 185, 186, 187, 189, 190, 191, 203, 205, 206, 207, 220, 221, 222, 223, 224, 241, 242, 243, 320, 321, 323, 324, 329, 333]

unflagged_ants: [5, 9, 15, 16, 17, 19, 20, 30, 46, 65, 66, 99, 109, 122, 123, 140, 143, 144, 162, 163, 164, 165, 183, 184]

golden_ants: [5, 9, 15, 16, 17, 19, 20, 30, 46, 65, 66, 99, 109, 122, 123, 140, 143, 144, 162, 163, 164, 165, 183, 184]
In [23]:
# write to csv
outpath = os.path.join(nb_outdir, f'rtp_summary_table_{JD}.csv')
print(f'Now saving Table 2 to a csv at {outpath}')
df.to_csv(outpath)
Now saving Table 2 to a csv at /home/obs/src/H5C_Notebooks/_rtp_summary_/rtp_summary_table_2459781.csv
In [24]:
# 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 [25]:
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 [26]:
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 [27]:
from hera_qm import __version__
print(__version__)
from hera_cal import __version__
print(__version__)
2.0.2
3.1.1.dev2+g1b5039f
In [ ]: