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_statuses = "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_statuses = "{good_statuses}"')
JD = "2459793"
data_path = "/mnt/sn1/2459793"
ant_metrics_ext = ".ant_metrics.hdf5"
redcal_ext = ".known_good.omni.calfits"
nb_outdir = "/home/obs/src/H5C_Notebooks/_rtp_summary_"
good_statuses = "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: 8-1-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/2459793/zen.2459793.25302.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/2459793/zen.2459793.?????.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 38 ant_metrics files matching glob /mnt/sn1/2459793/zen.2459793.?????.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 (np.max([dead_ant_frac[ap][ant] for ap in antpols]) + crossed_ant_frac[ant] == 1) 
                                                                                 and (crossed_ant_frac[ant] > .5)])

# 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
n_apriori_good = len([ant for ant in ants if a_priori_statuses[ant] in good_statuses.split(',')])
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'] = f'{len(apriori_good_flagged)} / {n_apriori_good} total a priori good antennas:<br>' + \
                                            comma_sep_paragraph(apriori_good_flagged)
to_show['A Priori Bad Antennas Not Flagged'] = f'{len(aprior_bad_unflagged)} / {len(ants) - n_apriori_good} total a priori bad antennas:<br>' + \
                                            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 2459793
Date 8-1-2022
LST Range 16.188 -- 18.188 hours
X-Engine Status ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
Number of Files 372
Total Number of Antennas 147
OPERATIONAL STATUS SUMMARY
Antenna A Priori Status Count dish_maintenance: 3
RF_maintenance: 42
RF_ok: 11
digital_maintenance: 1
digital_ok: 87
not_connected: 3
Commanded Signal Source antenna
Antennas in Commanded State 115 / 147 (78.2%)
Cross-Polarized Antennas
Total Number of Nodes 15
Nodes Registering 0s N18
Nodes Not Correlating N08, N10
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 75 / 147 (51.0%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 102 / 147 (69.4%)
Redcal Done? ✅
Redcal Flagged Antennas 25 / 147 (17.0%)
Never Flagged Antennas 8 / 147 (5.4%)
A Priori Good Antennas Flagged 82 / 87 total a priori good antennas:
10, 15, 16, 17, 19, 20, 21, 29, 30, 31, 37,
40, 41, 42, 45, 46, 50, 51, 53, 54, 55, 56,
57, 65, 66, 68, 69, 71, 72, 73, 81, 83, 84,
88, 91, 92, 93, 99, 101, 103, 105, 106, 107,
108, 109, 111, 117, 118, 121, 122, 123, 128,
129, 130, 135, 138, 140, 141, 142, 143, 144,
145, 160, 161, 162, 163, 164, 165, 167, 169,
170, 176, 177, 178, 179, 181, 183, 184, 185,
186, 190, 191
A Priori Bad Antennas Not Flagged 3 / 60 total a priori bad antennas:
3, 4, 100
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_2459793.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.468386 -0.479098 -0.240915 -0.610412 -1.269880 -1.082439 -0.614583 0.081929 0.666470 0.657255 0.440444 5.753162 6.383508
4 N01 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.098292 3.000083 -1.060157 1.797536 -0.907144 0.091653 1.602102 0.435515 0.678044 0.662553 0.440394 15.947908 15.895030
5 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.828015 1.278104 0.944165 3.531357 0.380687 1.409452 -0.104169 -1.913624 0.686872 0.674187 0.439433 1.283291 1.210201
7 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.922405 -1.145921 -0.623628 0.401566 -0.344595 -0.562686 0.149497 1.079322 0.681484 0.673008 0.418529 1.043851 1.091168
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 12.194743 12.922351 17.824016 18.122081 23.402655 23.769945 2.447515 1.696543 0.656478 0.641659 0.408760 37.164302 44.962564
9 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.205110 -1.079759 -0.079892 -0.557752 0.897591 0.785258 0.351881 2.841861 0.659984 0.651786 0.407351 1.067650 1.045568
10 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.912649 2.793613 -1.063412 7.027519 -0.023687 7.664951 17.887434 16.095393 0.640780 0.625555 0.414268 10.343378 14.223343
15 N01 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
16 N01 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
17 N01 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
18 N01 RF_maintenance 100.00% 0.00% 40.32% 0.00% 100.00% 0.00% 3.650329 4.157677 -0.900392 1.440534 6.563599 4.511805 276.092475 87.586033 0.655440 0.511706 0.443326 18.180399 6.630844
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.583905 -0.546033 9.364530 0.934567 9.745491 1.683272 -1.097482 1.837243 0.686101 0.680833 0.402371 11.802440 14.905283
20 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 21.05% 2.63% -1.037493 -0.016215 -0.307013 -1.175389 -0.007151 0.819474 0.121164 0.254571 0.673690 0.658504 0.399570 1.347133 1.272092
21 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.180623 0.802515 1.060040 2.613668 -0.692090 0.483274 1.511042 20.745358 0.656309 0.641571 0.410522 7.126754 7.178620
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.928336 19.020995 54.067005 55.149981 33.859173 33.435615 13.246705 11.175454 0.045082 0.049410 0.001860 1.299375 1.320600
28 N01 RF_maintenance 100.00% 37.63% 100.00% 0.00% 100.00% 0.00% 9.642360 12.292920 7.621267 11.402828 30.296904 35.338738 13.638468 88.884796 0.481219 0.254668 0.306729 12.454266 3.329029
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 21.05% -0.824286 -0.227899 -0.108323 -0.012157 -1.396906 -0.225412 -0.935321 0.490755 0.721876 0.716387 0.423807 1.422454 1.459317
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.416020 -0.214261 -0.641202 -0.492010 -0.045370 -0.083545 17.247106 0.120606 0.711809 0.707126 0.413985 13.517376 17.194836
31 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.549728 -0.655533 -0.936316 -0.631315 -0.271134 -1.201553 4.062426 5.098840 0.707860 0.697275 0.411333 13.026849 13.697021
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 23.054980 25.447482 2.034601 7.499256 8.583121 9.973193 32.822656 63.688163 0.628491 0.632315 0.226871 12.540766 10.607693
33 N02 RF_maintenance 100.00% 0.00% 40.32% 0.00% 100.00% 0.00% -0.123526 3.331454 -0.205030 0.964198 7.234742 9.413723 89.380613 119.633577 0.671169 0.508868 0.486818 7.669551 3.283925
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.556620 5.039247 -0.314001 1.056473 1.133319 1.017585 -0.092166 2.589713 0.672013 0.655650 0.417222 4.943251 4.551569
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.547868 0.426141 -0.687478 0.220622 -0.957210 -0.690261 0.394095 15.791001 0.696397 0.682929 0.417550 14.660391 12.564380
38 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.818033 -0.222902 -0.967379 -0.832491 1.061380 -0.827341 11.243264 3.857394 0.711757 0.701457 0.421710 9.364808 8.325140
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 86.84% 0.016215 -0.332096 -0.559496 -0.344338 1.398941 0.434668 -0.325404 -0.511980 0.729788 0.724755 0.423918 16.896009 17.492036
41 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 71.05% 0.742644 -0.294970 2.016434 1.516106 0.234053 -0.134569 -1.039261 1.316181 0.735237 0.729238 0.425370 21.757132 26.771574
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 68.42% -0.362541 0.753337 1.498931 0.504420 -0.551115 -0.332000 -1.087265 -0.543010 0.733478 0.730548 0.428496 18.756726 14.834800
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.377344 0.400468 -0.778385 1.281497 -1.220266 0.028346 0.265119 32.692838 0.701913 0.688817 0.424852 4.707556 4.807511
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 13.16% 13.16% -1.067336 -0.535329 0.012157 -0.694324 -1.185607 -0.595106 -0.702846 2.008471 0.685412 0.672789 0.434231 1.441763 1.485316
50 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 21.05% 1.109229 1.628371 -0.988220 2.017067 0.277469 2.280772 1.611847 -0.265565 0.680413 0.666528 0.397704 1.276712 1.271289
51 N03 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 0.579739 24.798644 -0.260477 68.267069 -0.503932 34.136398 0.822520 27.875445 0.703609 0.040410 0.406406 10.345452 1.214386
52 N03 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 8.403382 29.664453 0.685662 68.899058 4.541918 34.149111 8.168242 28.316049 0.682836 0.043966 0.390020 7.992193 1.207748
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.514993 0.608589 -1.052241 0.134322 -1.170457 0.009347 4.247337 12.265534 0.730103 0.723538 0.416641 45.462969 44.809636
54 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 39.47% 2.655580 1.050519 1.706488 1.313972 0.007151 0.242173 2.490282 0.113130 0.733752 0.733698 0.410107 1.824474 2.113091
55 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 84.21% 1.197948 -0.333924 0.338954 -0.204456 0.078492 0.075955 2.337730 0.021199 0.737261 0.735933 0.420858 15.890937 12.566680
56 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 89.47% -0.757186 -0.234297 0.884056 0.646888 -0.327697 -0.053105 -1.079603 2.409728 0.740733 0.740488 0.426477 10.851259 9.433466
57 N04 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 17.814249 -0.454513 51.318211 -1.168441 33.752936 2.808766 9.509048 2.634964 0.050236 0.733254 0.443794 1.333193 14.666851
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 13.16% 0.683974 -0.108468 0.136405 0.728162 0.836042 0.182597 0.170053 1.864777 0.688996 0.673109 0.412564 1.207761 1.238980
66 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.036098 -0.345609 -0.631803 1.801706 1.233221 2.008831 -0.258233 4.278071 0.707142 0.695017 0.405171 11.380209 11.190342
67 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.714873 -0.408147 -0.195919 1.056073 1.399894 1.978993 1.833786 6.221155 0.722503 0.714276 0.404877 17.374030 15.485541
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 21.05% 0.188220 0.070777 -0.797471 0.979740 1.583718 2.733524 -0.288199 -0.029160 0.727755 0.722821 0.407449 1.067743 1.065957
69 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 84.21% -1.169382 -0.280395 -0.753711 0.622165 -1.166084 1.598162 -0.062194 0.772040 0.738859 0.737661 0.426835 32.543232 44.851631
70 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.626440 -1.048714 0.062137 -0.759633 -0.246143 -0.750235 11.822411 2.745294 0.742044 0.738881 0.435793 32.139980 32.776153
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% -0.739482 -0.327693 -0.967183 -1.177453 -1.168766 -1.485756 -0.381079 0.776058 0.745174 0.746627 0.436682 30.885766 29.204062
72 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 60.53% 2.869502 -0.156621 -0.447199 0.981631 0.695396 0.393133 3.470736 -1.318707 0.733814 0.738782 0.434572 7.462608 7.674183
73 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 55.26% 0.949451 1.136357 -0.068606 1.245936 -0.386279 0.713136 0.865985 -0.016309 0.725652 0.716907 0.453638 5.314599 5.213642
81 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.663844 6.543388 -0.506769 9.196561 -0.739026 10.276931 0.540663 -1.364181 0.676569 0.660363 0.393849 14.666991 15.914324
82 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.205137 -0.745440 0.561638 2.093586 0.893583 0.818218 0.250364 -0.070093 0.698785 0.687473 0.396634 12.886938 14.790926
83 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 21.05% 1.338024 2.647470 1.605106 3.970655 0.960997 2.693715 -0.814435 -1.854250 0.720300 0.715083 0.394109 1.176361 1.243203
84 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.132101 6.001750 -0.241325 1.921434 -0.923329 0.044121 -0.443319 0.013350 0.088915 0.097188 0.017771 1.204411 1.206964
85 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.393545 3.213710 -0.680677 5.306435 -1.705743 4.236568 -0.744562 -1.704187 0.079341 0.094495 0.014210 1.250025 1.253244
86 N08 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.757227 1.685133 -0.093095 -0.961496 0.939104 0.067084 -0.646135 -0.555539 0.072160 0.066853 0.005262 1.206622 1.200014
87 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.594594 6.938071 1.465010 -0.112228 29.460821 -0.940967 80.311515 -0.744158 0.071771 0.064862 0.008718 1.193743 1.189567
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 16.235096 16.360363 47.458004 48.941877 34.087688 33.578470 17.985895 11.726607 0.037551 0.037944 -0.000123 1.128310 1.133240
90 N09 RF_maintenance 100.00% 48.39% 51.08% 0.00% 100.00% 0.00% 14.522731 14.676248 8.155381 2.426356 29.970284 30.710138 9.963823 7.000296 0.406341 0.413315 0.230726 2.477441 2.582877
91 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 15.770151 16.849359 47.336344 49.641535 33.904805 33.466100 13.145354 12.331943 0.036046 0.036706 -0.000067 1.092665 1.114030
92 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 24.842994 39.414763 9.653148 13.007637 36.042587 37.300654 11.205292 19.238826 0.097397 0.094961 0.012732 0.000000 0.000000
93 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.426124 -0.020680 2.496118 -1.063937 1.481617 -0.546678 -0.879491 1.080350 0.096883 0.096559 -0.014075 0.000000 0.000000
94 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.042297 -0.469319 -0.657466 -1.040420 -1.055796 0.573895 5.829516 6.704567 0.061019 0.066481 0.006847 0.000000 0.000000
98 N07 digital_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.491609 14.844927 8.872833 3.070607 9.760448 4.187683 -0.032898 4.134260 0.672493 0.649665 0.381154 3.442880 3.506642
99 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.666472 4.196873 8.990270 6.755814 11.022321 6.225922 0.837212 -1.490788 0.687629 0.685995 0.382151 9.138214 9.817110
100 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.291669 -0.149459 -0.435627 0.688694 -1.099328 -0.721815 -0.621757 1.725353 0.713400 0.706212 0.403156 51.255858 33.542339
101 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.159319 5.737911 3.154624 1.156898 1.508491 0.193307 2.000570 -0.010341 0.101378 0.091320 0.018431 1.203716 1.211301
102 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 4.522040 1.302690 30.273088 20.548638 65.974961 36.382296 630.653756 339.726038 0.061161 0.068304 0.010434 1.169170 1.176454
103 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.386864 5.759846 -0.674333 -0.322287 -0.598758 -0.941489 -0.067640 -0.478984 0.061097 0.066404 0.004198 1.194691 1.195641
104 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 4.275904 57.220476 0.664905 14.819635 -0.048443 4.624010 0.940575 1.286236 0.071323 0.077436 0.009498 1.229347 1.231758
105 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.998928 21.108626 47.313739 49.552085 33.990700 33.726076 10.710298 11.293842 0.035149 0.036124 0.001503 1.159606 1.151389
106 N09 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
107 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 15.718964 16.164728 47.912118 49.254146 33.883445 33.254164 11.594504 12.553741 0.039189 0.039676 0.001507 1.026796 0.983879
108 N09 digital_ok 100.00% 53.76% 51.08% 0.00% 100.00% 0.00% 13.803667 13.127793 6.816674 2.811302 30.146872 30.460471 7.630314 6.801077 0.385287 0.401670 0.232140 1.910749 1.870680
109 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.675597 0.107890 -0.369063 1.270458 -1.511354 1.001946 -0.557164 0.366803 0.078990 0.085486 0.017049 0.000000 0.000000
110 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 29.385998 1.122958 3.131058 1.139080 6.457232 -1.228500 1.012530 -1.294270 0.070629 0.075662 0.007666 0.000000 0.000000
111 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.379635 0.557866 -0.144213 0.350432 0.016213 -0.120436 -0.245312 1.725619 0.064090 0.059669 0.003750 0.000000 0.000000
112 N10 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.678233 -0.684933 0.095020 -0.142142 -0.302407 -1.415126 -0.496944 -1.279703 0.059357 0.071190 0.007308 0.000000 0.000000
116 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.131603 4.875987 -0.720041 6.994108 -0.971448 7.419025 -0.122492 -1.517812 0.665148 0.654273 0.391413 14.238775 12.969911
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.956887 2.949345 9.077473 4.701317 9.075933 2.439373 -1.837544 -1.927894 0.694781 0.687321 0.407316 25.630688 22.193038
118 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 31.58% 10.53% 1.918851 0.696610 1.819400 0.592188 0.663015 1.518365 2.105413 3.192520 0.700113 0.696825 0.405565 1.055615 0.963417
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.050526 0.632041 7.427527 0.549046 7.753362 -1.284401 -1.669247 -0.458723 0.716178 0.712760 0.425825 11.034551 11.149385
120 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 14.916418 22.933992 9.107240 60.810631 30.939629 34.215812 7.555081 17.175489 0.111731 0.040297 0.057128 1.225463 1.184947
121 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.395401 3.558162 0.272117 1.342617 0.005847 1.415861 9.612807 25.906112 0.071088 0.071042 0.006847 1.213669 1.224184
122 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.812282 5.543148 1.181444 0.758721 0.764417 -0.301792 -0.405071 1.126406 0.089884 0.082072 0.011143 1.238943 1.235970
123 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 5.847165 5.660064 0.820967 -0.194438 0.182071 -0.299309 -0.921091 -0.511263 0.117736 0.114414 0.027943 1.183035 1.192019
125 N09 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
126 N09 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
127 N10 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.225417 -0.565116 0.577286 0.039906 1.169081 0.362453 0.016309 0.864709 0.084300 0.077705 0.015694 0.000000 0.000000
128 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.890177 0.673384 -0.093580 0.639952 -0.729950 -0.448827 -0.284565 -1.034731 0.072190 0.068002 0.009031 0.000000 0.000000
129 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.773077 -1.353146 -0.507972 -0.821870 -0.413312 -0.693986 -0.594304 0.035872 0.063436 0.065368 0.005544 0.000000 0.000000
130 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.607919 0.403009 1.152639 1.249503 -0.573201 -0.053533 0.128587 9.084627 0.067102 0.066770 0.006289 0.000000 0.000000
135 N12 digital_ok 0.00% 18.82% 21.51% 0.00% 28.95% 15.79% -0.605163 -0.742602 -1.198229 -0.653356 -1.427827 -0.788136 1.360954 0.864076 0.582969 0.570510 0.367916 1.437237 1.455191
136 N12 RF_maintenance 100.00% 18.82% 21.51% 0.00% 100.00% 0.00% 1.723451 7.276569 -0.359599 0.137398 3.646250 2.224845 2.147639 6.092371 0.585533 0.573448 0.353897 4.937557 5.928549
137 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.103580 16.786061 46.734437 48.207089 33.948423 33.457118 11.176688 14.307824 0.039062 0.049031 0.004430 1.483619 1.530227
138 N07 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 20.328127 1.595117 46.450147 2.315781 34.060812 0.817249 11.930665 0.324119 0.047719 0.697983 0.452852 1.210146 4.530166
140 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.728252 3.318537 0.729215 1.679796 2.441337 3.034528 1.045672 0.988379 0.703074 0.699248 0.432728 4.148929 3.546036
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.762007 3.638125 -0.920808 12.392127 1.440446 4.290085 0.815872 15.963276 0.701538 0.686192 0.443146 2.979503 3.134175
142 N13 digital_ok 100.00% 45.70% 100.00% 0.00% 100.00% 0.00% 16.176371 19.949278 9.654893 55.638977 29.953753 33.639647 9.506969 11.041825 0.436593 0.044748 0.242897 2.432989 1.237210
143 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 73.68% -0.077812 -0.840367 1.802100 -0.013311 1.284230 -0.503815 0.603660 -1.138968 0.706544 0.701272 0.433542 2.280156 2.263374
144 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 7.89% 63.16% 0.462064 0.708073 1.017180 -0.427932 0.547217 -0.596501 1.103746 -0.425283 0.703467 0.696523 0.436613 0.000000 0.000000
145 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.189311 17.129466 54.397615 56.038941 33.862715 33.349418 11.777234 14.094572 0.034666 0.037725 -0.000171 0.894869 0.905850
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.504689 18.206301 54.219145 56.994355 33.945164 33.510344 12.272881 13.490895 0.052970 0.058187 0.002975 0.000000 0.000000
155 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.214666 18.066150 53.150972 54.991767 33.786046 33.281386 13.018031 13.955139 0.043249 0.044091 -0.000093 1.283770 1.359919
156 N12 RF_maintenance 100.00% 18.82% 21.51% 0.00% 100.00% 0.00% 0.376462 0.858788 0.833518 0.489302 0.204894 0.744426 2.795311 20.368869 0.588364 0.575969 0.376424 2.250602 2.207373
157 N12 RF_maintenance 0.00% 18.82% 21.51% 0.00% 100.00% 0.00% -0.223810 1.494603 0.662990 1.854624 1.438884 0.174885 0.340197 -0.833681 0.591323 0.584553 0.379918 4.951222 5.341576
158 N12 RF_maintenance 0.00% 18.82% 21.51% 0.00% 100.00% 0.00% -0.127323 -1.168597 -1.026112 -0.897501 -0.872145 -0.663804 0.530034 0.738168 0.603185 0.597417 0.387125 3.362438 3.368284
160 N13 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
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.615003 30.713256 -0.999237 3.359247 -0.607237 6.759915 -0.234124 0.960728 0.698499 0.617159 0.396648 6.638837 5.788762
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 57.89% 1.448534 0.636385 -0.595331 -0.969232 1.831982 0.290034 -0.271817 -0.294492 0.695845 0.692733 0.419602 3.306078 3.134896
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 13.16% 36.84% 0.436113 -0.361002 0.281624 -0.685991 0.169785 -0.685177 0.020794 0.948856 0.702667 0.697653 0.417007 1.414890 1.499332
164 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.099271 -0.493534 -1.292652 2.177667 -1.162252 15.225426 -0.259443 13.091630 0.697736 0.688911 0.416202 5.893168 6.134051
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.942341 0.663096 5.694568 -0.750175 4.956027 -1.395027 0.587795 -0.147694 0.695020 0.688709 0.414486 4.974702 5.051279
166 N14 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.471642 1.268791 0.279388 -0.181427 11.349929 5.184913 143.292437 35.259322 0.658891 0.675931 0.385358 0.000000 0.000000
167 N15 digital_ok 100.00% 18.82% 21.51% 0.00% 100.00% 0.00% 14.183683 16.104309 13.824746 17.061831 32.751998 26.132218 61.759073 13.076758 0.572232 0.570989 0.172346 0.000000 0.000000
168 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.007304 15.190664 18.021042 20.020023 23.470077 26.637942 0.668716 1.935566 0.635763 0.616625 0.405399 0.000000 0.000000
169 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.720004 14.058251 19.958687 18.876305 26.691768 25.101412 1.706237 1.265418 0.610012 0.596820 0.401375 0.000000 0.000000
170 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.634603 13.058055 20.017779 18.121011 26.765795 23.577939 1.769174 1.102524 0.591996 0.587248 0.396504 0.000000 0.000000
176 N12 digital_ok 0.00% 21.51% 21.51% 0.00% 31.58% 0.00% -0.134853 -0.199996 -1.185959 -0.204134 0.104354 -0.691465 -0.632567 -0.877087 0.566952 0.559871 0.373613 1.085697 1.127521
177 N12 digital_ok 100.00% 18.82% 21.51% 0.00% 100.00% 0.00% 0.791244 5.639517 0.453141 8.834044 -0.880919 9.434306 -0.149281 0.365283 0.576814 0.561962 0.380872 32.393046 63.492905
178 N12 digital_ok 0.00% 18.82% 21.51% 0.00% 31.58% 0.00% -0.665765 -0.984695 1.076340 -0.955359 -0.501802 -1.971427 -0.375624 -1.023403 0.586301 0.577481 0.381441 1.174942 1.176169
179 N12 digital_ok 0.00% 18.82% 21.51% 0.00% 36.84% 2.63% 0.230208 -0.120997 -0.807375 0.369019 1.334660 0.431049 3.364108 -0.596932 0.592190 0.580134 0.390408 0.797769 0.845974
180 N13 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
181 N13 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
182 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 12.548191 13.405052 18.022331 18.494139 23.397098 24.251190 0.359731 0.830946 0.668927 0.657062 0.433076 5.452691 5.660005
183 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.335102 0.325823 0.082405 2.987440 -0.710999 54.246399 -0.141560 48.343968 0.694034 0.682890 0.424783 5.919094 5.653067
184 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.418334 -0.115566 10.215569 1.688678 76.272367 0.728279 52.680462 -0.101232 0.678282 0.683756 0.409389 0.000000 0.000000
185 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 42.11% 21.05% 0.684147 0.353777 1.783410 1.666480 -0.185536 0.295842 -1.442065 -0.424662 0.690606 0.684853 0.403942 0.000000 0.000000
186 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.886099 0.463979 4.036659 2.486264 1.596434 0.152847 5.435664 0.169204 0.679649 0.676067 0.398444 5.735711 6.216639
187 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 63.16% 0.00% 0.489291 0.468806 0.290787 0.100096 -0.598202 -1.883697 1.318934 -1.168520 0.677644 0.674683 0.404104 0.000000 0.000000
189 N15 digital_ok 0.00% 0.00% 0.00% 0.00% 63.16% 0.00% 2.756006 3.103624 0.552265 -0.231681 -0.542480 -0.958251 0.143002 -0.305932 0.638692 0.630438 0.404493 0.000000 0.000000
190 N15 digital_ok 100.00% 24.19% 100.00% 0.00% 100.00% 0.00% 26.806551 19.109275 3.331524 56.022457 18.734906 33.536493 128.621991 13.407516 0.542041 0.051581 0.325557 0.000000 0.000000
191 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.364012 -0.003817 -0.634670 -0.784665 -0.912101 -1.142251 1.648681 5.476770 0.607584 0.590053 0.412637 0.000000 0.000000
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 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.348930 4.265434 13.012402 1.967175 17.308914 3.767654 27.813243 45.253364 0.651828 0.636765 0.395349 2.966110 2.849190
206 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.880907 8.069921 2.215057 10.905390 4.995863 13.889634 31.925802 27.679666 0.625947 0.635876 0.385597 2.982764 2.983251
207 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.073093 9.099018 15.055782 12.362343 19.683932 15.675409 9.109954 8.129122 0.628490 0.629465 0.387217 0.000000 0.000000
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% 7.634694 5.808577 85.494363 87.309389 2489.924396 2952.679694 14213.195309 20060.362669 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.376617 9.923256 6.971679 13.813600 8.906011 17.197273 -0.785137 -0.918298 0.641549 0.630984 0.407056 0.000000 0.000000
224 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 16.854471 16.550686 22.647886 21.914612 30.747117 29.423725 2.501270 1.866266 0.593583 0.591481 0.384432 0.000000 0.000000
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% 5.001662 9.157050 104.707899 98.933975 3465.714731 3465.276571 23974.377379 23969.621078 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.646720 19.179750 40.277589 40.828648 34.086708 33.333197 18.326922 12.857845 0.064347 0.053853 -0.003347 0.000000 0.000000
321 N02 not_connected 100.00% 18.82% 59.14% 0.00% 100.00% 0.00% 8.104187 6.620588 11.917155 10.497741 16.455100 13.658422 39.869150 39.897307 0.496132 0.424220 0.321670 0.000000 0.000000
323 N02 not_connected 100.00% 32.26% 65.05% 0.00% 100.00% 0.00% 15.652996 9.601624 2.572184 13.950908 12.141991 16.993351 13.004275 2.848297 0.419800 0.394339 0.268240 0.000000 0.000000
324 N04 not_connected 100.00% 24.19% 59.14% 0.00% 100.00% 0.00% 11.429708 12.141843 16.443480 16.482882 21.832412 21.786856 0.710167 0.215855 0.481266 0.410086 0.325309 0.000000 0.000000
329 N12 dish_maintenance 100.00% 56.45% 73.12% 0.00% 100.00% 0.00% 2.413692 5.821992 4.153006 10.480147 3.920176 12.820706 3.680616 -1.256216 0.400576 0.338301 0.261710 0.000000 0.000000
333 N12 dish_maintenance 100.00% 67.74% 100.00% 0.00% 100.00% 0.00% 1.601055 5.207023 3.953051 -0.257352 2.402052 103.679544 4.791123 34.900903 0.352851 0.203884 0.219552 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, 8, 10, 15, 16, 17, 18, 19, 20, 21, 27, 28, 29, 30, 31, 32, 33, 36, 37, 38, 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, 90, 91, 92, 93, 94, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 116, 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130, 135, 136, 137, 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, 203, 205, 206, 207, 220, 221, 222, 223, 224, 241, 242, 243, 320, 321, 323, 324, 329, 333]

unflagged_ants: [5, 7, 9]

golden_ants: [5, 7, 9]
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_2459793.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 [ ]: