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 = "2459790"
data_path = "/mnt/sn1/2459790"
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: 7-29-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/2459790/zen.2459790.25319.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/2459790/zen.2459790.?????.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/2459790/zen.2459790.?????.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 2459790
Date 7-29-2022
LST Range 15.995 -- 17.995 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 108 / 147 (73.5%)
Cross-Polarized Antennas
Total Number of Nodes 15
Nodes Registering 0s N18
Nodes Not Correlating N10
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 68 / 147 (46.3%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 114 / 147 (77.6%)
Redcal Done? ✅
Redcal Flagged Antennas 15 / 147 (10.2%)
Never Flagged Antennas 10 / 147 (6.8%)
A Priori Good Antennas Flagged 80 / 87 total a priori good antennas:
5, 7, 9, 10, 15, 16, 17, 19, 20, 21, 29, 30,
31, 37, 40, 41, 42, 45, 46, 50, 51, 53, 54,
55, 56, 57, 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, 165, 167, 169, 170, 176,
177, 178, 179, 181, 186, 187, 189, 190, 191
A Priori Bad Antennas Not Flagged 3 / 60 total a priori bad antennas:
3, 67, 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_2459790.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% 1.521002 -0.415874 -0.397819 -0.637493 -1.003110 -0.481391 -0.494977 -0.089300 0.646221 0.642047 0.415760 3.571465 3.775135
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.449901 6.171632 -0.342304 1.581410 -0.159998 0.636469 8.498932 2.453500 0.659029 0.648597 0.412256 5.674331 5.970091
5 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.238507 2.958880 1.375139 6.326471 1.355962 5.325416 3.858274 -1.335545 0.666664 0.659358 0.412287 7.110702 7.108611
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.884360 -1.480125 0.494291 0.987161 -0.421800 0.124028 -0.516814 16.879183 0.661227 0.654208 0.401917 4.746852 4.962232
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 22.625530 24.233279 22.428598 23.652003 33.377455 34.423809 1.073756 0.137819 0.637694 0.625895 0.397935 3.338468 3.240026
9 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.297379 -1.307755 0.018535 1.359296 1.449393 11.621406 -0.074049 14.647376 0.642364 0.636599 0.400180 3.114049 3.056996
10 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.817808 5.900215 13.267887 10.057039 17.327297 11.519051 13.475919 13.465459 0.616931 0.609220 0.402250 2.703770 2.737008
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 26.32% 0.684619 2.333641 1.805994 -0.152185 0.391524 0.755406 0.166633 1.783574 0.678038 0.670163 0.412306 2.342446 2.559868
16 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 13.16% -0.798114 -0.252875 -0.700884 1.152372 -1.211257 0.270441 1.109652 -0.869004 0.685170 0.681261 0.407983 2.368784 2.301993
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 13.16% 0.981314 2.100930 0.177691 -0.023039 -0.270226 0.186530 0.734771 0.539853 0.685896 0.683049 0.397619 2.318964 2.750007
18 N01 RF_maintenance 100.00% 0.00% 48.39% 0.00% 100.00% 0.00% 9.016704 8.818083 1.052157 3.160028 3.683416 8.796172 90.544696 83.389980 0.617191 0.486893 0.409279 4.430803 3.190969
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.312050 9.613432 9.371180 11.541786 9.677225 5.354811 3.188264 1.506773 0.672347 0.666245 0.399428 4.019016 4.638637
20 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.835110 10.861989 1.685716 11.987232 1.794882 16.814390 -0.646132 -1.311130 0.656975 0.641689 0.395342 3.096751 3.460853
21 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.209222 0.975152 0.877425 0.940526 -0.852800 0.046592 0.570930 6.779951 0.636693 0.627216 0.399856 3.501438 3.385305
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 33.115640 35.780920 63.071017 63.541161 46.774927 46.620650 10.362973 8.895502 0.042116 0.048670 0.004716 1.230622 1.244993
28 N01 RF_maintenance 100.00% 40.32% 100.00% 0.00% 100.00% 0.00% 17.999876 25.151951 7.458779 12.484619 43.109654 49.287513 10.085097 52.347595 0.472482 0.251088 0.285037 24.866662 7.825443
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 5.26% 10.53% -1.520434 -0.961049 1.091667 -0.652337 0.084337 -0.461341 -0.722417 -0.493009 0.706674 0.703850 0.404679 1.960184 2.394433
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.581024 -0.107635 1.382941 -0.780116 1.397135 -0.313760 8.809668 0.022548 0.696087 0.694539 0.399432 4.473591 5.457960
31 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 15.79% 5.26% 0.177807 -0.558127 -0.768527 -0.462450 -1.155509 -0.382316 -0.504971 -0.746398 0.694373 0.686931 0.400936 1.459454 1.696615
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 46.747724 8.124520 3.576367 1.347410 15.215174 22.081389 42.608415 119.182392 0.607218 0.641983 0.327233 4.094904 3.597104
33 N02 RF_maintenance 100.00% 0.00% 48.39% 0.00% 100.00% 0.00% 1.095259 5.085199 1.808690 0.747986 -0.059067 3.483360 3.376527 16.809631 0.648373 0.487753 0.467565 2.938506 1.997294
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.704960 10.116021 0.327300 0.619525 0.823050 0.133149 0.199128 1.062015 0.643530 0.630088 0.395359 3.619539 3.450579
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.050798 1.256450 -0.036951 -0.435774 -0.230690 0.312474 0.075294 10.800952 0.671652 0.660955 0.402477 4.277091 4.697005
38 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.267515 0.438543 -0.617868 -0.240610 1.085891 0.410498 6.035896 1.762048 0.689897 0.683087 0.407677 5.205930 4.948485
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 42.11% 1.457951 0.106773 -0.037648 -0.743321 -0.974090 -0.670376 -0.290847 -0.901919 0.710092 0.708230 0.403652 2.119643 2.327384
41 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 5.26% 28.95% 2.201074 -0.975850 3.468809 1.283226 3.138535 0.662854 -1.207984 3.716362 0.715041 0.711720 0.393765 2.147671 2.442175
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 52.63% -0.090952 0.746400 3.130201 -0.008807 1.085819 -0.483778 -0.611446 -0.567861 0.721613 0.719781 0.410267 3.585332 3.564391
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.272790 1.316311 -0.444495 1.416001 -1.168352 0.204436 0.163275 25.464303 0.682824 0.671043 0.409848 3.387149 3.493563
46 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.255382 -0.647945 0.419183 -0.472936 -0.229747 -1.065610 -0.338325 4.852941 0.661490 0.653094 0.417278 2.762149 2.886119
50 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.691958 38.759384 -0.650421 2.501175 -0.216945 10.496608 1.262542 4.266574 0.650859 0.589431 0.359615 5.613371 7.414400
51 N03 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 1.231024 47.497338 -0.104133 78.978960 -0.430224 47.425983 1.629286 22.023689 0.678289 0.040669 0.428399 4.874480 1.238137
52 N03 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 16.372552 55.980260 0.981707 79.765238 3.492161 47.919470 11.799091 21.741822 0.659665 0.037667 0.411582 11.106672 1.205723
53 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 5.26% 13.16% 1.388696 1.691642 -0.158140 -0.569970 -1.248053 -0.203483 1.735660 1.537441 0.713143 0.708414 0.397925 1.864203 2.033933
54 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.529705 1.055777 0.540893 0.467078 8.259194 12.554069 2.636152 16.122909 0.717896 0.713324 0.370961 21.088963 20.727157
55 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.504644 0.852192 0.079333 1.537243 1.484434 1.940851 8.703946 0.465484 0.722170 0.722841 0.397750 5.590464 6.582316
56 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.580366 1.444461 2.263383 2.606050 2.047872 3.500737 -0.055898 10.352251 0.729138 0.728046 0.407061 4.917789 4.953184
57 N04 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 32.722029 1.784847 62.648796 1.622141 46.653858 6.935595 7.605177 3.434984 0.049490 0.721476 0.463917 1.512759 4.444995
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.568003 0.162009 0.869442 0.328597 1.727290 1.367587 0.207324 1.030630 0.657270 0.647118 0.400932 1.385752 1.410226
66 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.624806 -0.016345 -0.704413 1.113404 0.308938 1.199409 -0.392073 3.124422 0.681265 0.671820 0.392982 1.529239 1.592531
67 N03 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.756547 -0.852337 0.141678 0.617324 0.550483 1.118390 0.999202 2.482634 0.701872 0.695038 0.388710 7.095329 9.388582
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 5.26% 0.542154 0.190804 -0.171746 0.633423 0.875716 2.195458 -0.131758 0.443062 0.711054 0.706192 0.383496 1.904907 2.023213
69 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 47.37% -1.219308 -0.742504 0.008807 -0.347959 0.793091 0.578427 0.104652 -0.622644 0.720756 0.725447 0.385695 4.629634 5.246323
70 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.727594 -1.685143 0.214140 -0.671580 -0.469335 -0.318317 -0.015595 1.000834 0.731066 0.728309 0.410852 19.759453 14.395418
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% 0.021318 -1.171040 -0.677951 0.513706 0.197434 1.428146 -0.537709 -0.865489 0.728708 0.734966 0.406279 28.254659 40.442315
72 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.434747 -0.529161 -0.245733 2.880807 0.981366 2.825753 2.851920 -0.493792 0.717778 0.723628 0.412257 4.166777 4.193996
73 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.139821 1.276817 -0.132756 0.314171 -0.196619 -0.408068 6.038104 0.495494 0.707342 0.702161 0.429556 3.870312 3.878121
81 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.336113 6.395126 -0.424891 5.605101 0.382786 6.229377 10.051652 1.433882 0.642153 0.635825 0.390173 5.153980 5.922205
82 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.237629 -0.174513 -0.045997 0.713138 1.768566 -0.937490 0.054286 -0.152115 0.668912 0.663829 0.388594 7.183098 5.634430
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 16.476033 5.492073 17.037380 6.467092 23.618660 6.018879 -1.127536 -0.993124 0.693585 0.694955 0.381646 5.842233 6.668505
84 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 12.022500 11.824979 0.467348 1.313116 0.662379 3.623796 2.741784 6.386698 0.715827 0.713714 0.379357 6.213818 6.186056
85 N08 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
86 N08 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
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.133015 17.467764 7.978908 14.016753 26.190187 17.591398 199.064052 -1.458161 0.719966 0.731050 0.414832 2.941144 3.027425
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 29.978773 30.690534 55.240352 56.186738 46.939566 46.699850 14.866837 9.400276 0.045072 0.049674 0.001626 1.007305 1.006398
90 N09 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.567167 5.294811 1.491071 5.283809 -0.229229 5.872657 3.034547 -0.338455 0.679388 0.679375 0.428774 1.864863 1.833712
91 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 29.267564 31.588068 55.078388 57.024721 46.929817 46.602531 10.445736 9.602217 0.037813 0.041492 0.000304 1.141183 1.146197
92 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 48.456506 74.710902 9.957742 12.310009 50.977011 54.789464 10.601602 26.232621 0.095884 0.092257 0.012750 7.996896 9.797230
93 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.373787 0.695485 4.175789 -0.642237 4.750920 1.274292 -0.652630 0.289277 0.094554 0.094661 -0.014977 0.000000 0.000000
94 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.098668 -2.047438 -0.746163 -0.423713 -1.109927 1.514837 4.473951 19.597535 0.057288 0.068337 0.007092 0.000000 0.000000
98 N07 digital_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
99 N07 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
100 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.468897 0.530554 1.090099 -0.146008 0.678605 -0.855517 0.601359 0.165275 0.690816 0.685252 0.385927 4.192842 3.832074
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.591652 15.344648 12.677782 12.050613 15.080009 13.990731 0.767481 -0.591208 0.711970 0.707234 0.395036 4.347245 3.647847
102 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 24.373806 22.570403 97.027864 93.025494 2960.379662 2677.471808 18114.718507 15328.771731 nan nan nan 0.000000 0.000000
103 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.462543 12.407669 -0.310747 0.840436 -0.511519 -0.272091 0.028406 -0.473176 0.727055 0.724103 0.401852 3.034016 2.707351
104 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.172525 105.766458 1.558118 14.385794 1.025235 5.151840 1.847188 0.399960 0.722715 0.720831 0.413931 0.000000 0.000000
105 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 33.567568 39.897205 55.029433 56.873595 46.933151 46.947237 8.365327 8.146149 0.038267 0.040719 0.004228 0.877670 0.864233
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% 29.608553 30.693119 53.018209 53.840112 46.814304 46.364787 8.900733 9.582869 0.044876 0.049218 0.003704 1.156652 1.174236
108 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.399363 10.937748 10.682091 12.484501 12.635478 15.212015 -1.204227 -1.736195 0.665763 0.662998 0.429574 2.869952 2.940853
109 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.372426 0.321956 0.499029 0.232361 -0.961863 -0.214595 2.753593 0.962209 0.082327 0.081405 0.017620 0.000000 0.000000
110 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 52.225406 6.805543 4.561854 5.069005 13.716792 16.321071 14.063971 125.680284 0.076752 0.070925 0.008161 1.015971 1.018683
111 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.883118 1.567355 0.034051 2.536210 0.244111 2.317653 -0.389568 -0.035935 0.054040 0.061825 0.004276 0.979634 0.979546
112 N10 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.463066 -0.532177 -0.031931 2.087322 -0.026905 1.266404 -0.057072 -1.342956 0.058071 0.064865 0.005705 0.905479 0.922792
116 N07 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
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.391695 6.369007 7.150999 7.585480 7.230270 6.835374 -1.296104 -1.687817 0.663033 0.654571 0.406871 3.937552 4.090767
118 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.539363 2.367631 3.226453 -0.248138 2.910259 0.560459 2.062531 1.960701 0.673023 0.668665 0.397414 2.415923 2.343932
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.382431 2.049845 10.255347 -0.337926 12.763538 -0.307941 -1.456602 -0.307192 0.695963 0.690754 0.408264 2.681277 2.511707
120 N08 RF_maintenance 100.00% 40.32% 100.00% 0.00% 100.00% 0.00% 26.174238 44.029724 9.157076 70.073934 43.826474 47.546170 5.732629 14.153574 0.477609 0.056016 0.376169 2.129066 0.939106
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.043563 7.243922 -0.307183 0.567895 -0.832618 0.181617 25.019310 18.588259 0.714110 0.713223 0.401180 3.321417 3.569296
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.106318 13.986559 10.811051 11.514149 26.606364 26.678601 20.797187 19.772800 0.711919 0.710859 0.409402 3.793008 4.328433
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.625923 11.611871 2.233201 0.409573 0.975144 -0.268182 -0.273211 1.108409 0.710705 0.709785 0.416022 5.396513 4.758870
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.628492 -1.033466 0.372668 -0.755486 0.144669 -0.195585 -0.324242 0.035935 0.082883 0.078027 0.018750 63.450681 55.872674
128 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.429020 2.572935 0.172433 3.117099 -0.796872 3.612961 0.426283 -0.720386 0.068753 0.067640 0.010826 103.064693 103.221100
129 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.467476 -1.936499 0.362865 -0.869592 -0.456404 -0.930465 -0.524995 -0.130874 0.058226 0.059764 0.005123 41.927628 39.872150
130 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.027820 0.107864 1.353633 0.665597 -0.528540 0.552767 0.299732 7.526018 0.064400 0.060289 0.006381 31.092876 32.909113
135 N12 digital_ok 0.00% 32.26% 34.95% 0.00% 34.21% 0.00% -0.411519 -0.475517 -0.818986 -0.219073 -1.005636 -0.393252 2.600877 1.429385 0.546230 0.535375 0.355007 1.707253 1.623423
136 N12 RF_maintenance 100.00% 29.57% 34.95% 0.00% 100.00% 0.00% 4.519259 13.101290 -0.176630 0.727833 2.893123 2.562472 3.659086 10.304009 0.548203 0.531906 0.333999 7.373435 8.605739
137 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 31.767440 31.987415 54.392933 55.342264 46.853030 46.637741 8.620470 10.845228 0.038199 0.046229 0.003348 1.283704 1.282251
138 N07 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 38.240403 3.812654 54.009986 2.022215 47.067205 0.837559 9.687070 0.559549 0.048222 0.667804 0.454205 1.165153 3.807482
140 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.513973 5.804169 0.844731 1.473059 2.589736 3.486017 4.279509 4.262587 0.682919 0.678422 0.403670 4.313440 4.226118
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.267632 6.583836 1.033585 12.727839 1.435969 5.066403 1.104217 18.640390 0.681565 0.666435 0.405134 3.778542 4.197297
142 N13 digital_ok 100.00% 51.08% 100.00% 0.00% 100.00% 0.00% 31.309827 37.978388 8.069366 64.110075 41.011320 46.815368 8.476108 8.764875 0.437480 0.045681 0.255969 8.832036 1.361816
143 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 5.26% 5.26% 0.217008 0.255586 1.814519 1.951467 2.178414 1.199588 2.652783 -1.222837 0.685636 0.681519 0.407222 1.907915 1.722581
144 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 5.26% 2.63% -0.057210 0.016345 1.420015 -0.703914 3.181915 -1.112040 3.428507 1.485672 0.684023 0.678438 0.417009 1.935046 1.815968
145 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 31.531275 31.367852 63.452347 64.619665 46.772555 46.817851 9.077385 10.669026 0.036251 0.037506 -0.000465 1.732537 1.923084
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 33.346001 35.592098 63.183305 65.662730 46.667880 46.485341 10.468514 11.332435 0.053262 0.056704 0.002222 0.000000 0.000000
155 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 31.385309 32.911445 62.038689 63.411817 46.802537 46.630629 10.193798 9.713919 0.043054 0.042676 -0.000513 1.340450 1.416795
156 N12 RF_maintenance 100.00% 29.57% 34.95% 0.00% 100.00% 0.00% 11.288275 11.074671 12.924789 12.301859 18.132934 16.737613 17.630558 20.250524 0.554693 0.539719 0.354400 6.713992 7.027486
157 N12 RF_maintenance 100.00% 29.57% 34.95% 0.00% 100.00% 0.00% 9.054577 25.811857 11.519631 24.522123 15.077424 36.126355 12.114271 0.030803 0.556264 0.527820 0.362368 2.170611 2.133414
158 N12 RF_maintenance 100.00% 29.57% 29.57% 0.00% 100.00% 0.00% 4.115096 6.857774 6.211775 10.222958 11.732932 16.136568 24.969987 21.529725 0.574469 0.567452 0.368690 2.046054 2.233566
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 29.327514 29.026795 62.805136 63.968108 46.720386 46.590015 9.848154 10.832424 0.042492 0.043087 0.003793 1.191973 1.190399
161 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
162 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
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 10.53% 0.00% 1.128610 -0.489846 0.496489 -0.671030 0.026905 -0.760500 1.845269 0.081999 0.677622 0.673052 0.404469 2.080230 1.971424
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 10.53% 0.00% -1.044045 -0.672047 -0.806482 -0.756481 -0.819853 -0.592463 2.625457 1.704848 0.672438 0.666536 0.400948 2.087760 2.445616
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.233570 1.749940 7.547199 1.768592 7.962714 0.109890 1.082145 1.862221 0.668160 0.662293 0.400327 6.399207 8.720965
166 N14 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 22.999057 22.718127 3.655918 2.849431 10.233650 11.537541 27.008810 36.700080 0.606997 0.597460 0.291506 0.832106 0.823995
167 N15 digital_ok 100.00% 37.63% 24.19% 0.00% 100.00% 0.00% 29.266979 31.475138 18.305126 22.272781 41.849911 35.458534 28.970432 18.041848 0.527343 0.544084 0.203116 0.000000 0.000000
168 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 24.158550 28.241402 22.745088 25.825643 33.889870 38.132924 0.085161 0.359832 0.605457 0.590725 0.385995 0.000000 0.000000
169 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 26.948260 26.155980 24.890308 24.478286 37.480139 36.111871 0.617082 -0.047453 0.579551 0.572111 0.380769 38.026265 36.341137
170 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 27.071664 24.322679 25.113006 23.516792 38.027915 34.212746 0.878889 -0.184218 0.560393 0.561801 0.376016 53.621043 34.358759
176 N12 digital_ok 0.00% 32.26% 34.95% 0.00% 34.21% 5.26% -0.024172 0.474408 -0.453755 1.679598 -0.438622 1.324173 -0.673617 -0.380983 0.536298 0.528195 0.346692 1.928179 1.933388
177 N12 digital_ok 100.00% 29.57% 34.95% 0.00% 100.00% 0.00% 2.019617 1.874894 1.670203 2.651604 0.166394 3.029905 2.322401 4.999487 0.548023 0.536440 0.354983 4.633764 6.605217
178 N12 digital_ok 0.00% 29.57% 34.95% 0.00% 39.47% 0.00% -0.376969 -1.756645 1.678083 -0.748220 -0.233138 -0.926556 -0.149233 0.675365 0.553944 0.544781 0.358069 1.150282 1.122988
179 N12 digital_ok 0.00% 29.57% 34.95% 0.00% 39.47% 0.00% 0.039632 0.645627 -0.725579 -0.491859 0.778920 -0.125440 0.456110 -0.989763 0.560344 0.546851 0.368297 1.433443 1.461511
180 N13 RF_maintenance 100.00% 0.00% 56.45% 0.00% 100.00% 0.00% 1.342896 21.303195 1.782802 57.819826 1.133039 30.980744 -0.618664 7.602017 0.656857 0.431242 0.477611 16.492157 4.574938
181 N13 digital_ok 100.00% 100.00% 80.65% 0.00% 100.00% 0.00% 31.794138 72.036315 63.630336 6.435849 46.753056 50.130643 9.134681 13.535439 0.044583 0.288197 0.160126 1.234410 2.740933
182 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
183 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.550787 0.619810 -0.097531 -0.712713 -0.433663 -0.709447 0.084576 2.885416 0.665463 0.653357 0.417236 1.931544 2.120513
184 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.028665 -0.818500 0.145778 1.168113 -0.117133 0.123597 -0.179643 -0.361377 0.667249 0.657220 0.400502 1.956281 2.081029
185 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.497798 0.676935 2.924705 1.259924 0.252164 -0.212107 -1.259923 -0.809781 0.664805 0.660613 0.392902 1.934540 1.872456
186 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.102441 0.825402 4.113183 1.954967 1.608893 0.740726 5.377829 -0.047210 0.652564 0.651397 0.385413 5.044009 5.422550
187 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.301644 11.384998 6.893244 12.911999 6.997750 15.675013 3.584812 1.902555 0.651244 0.649412 0.390060 0.940427 0.923577
189 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.849756 6.635938 1.025394 -0.149762 0.163844 0.444494 0.282625 0.531917 0.608935 0.605557 0.388350 0.000000 0.000000
190 N15 digital_ok 100.00% 45.70% 100.00% 0.00% 100.00% 0.00% 63.274389 36.059131 6.422338 64.547397 25.778351 46.707514 87.391553 10.085135 0.481425 0.050798 0.329065 0.000000 0.000000
191 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.083564 1.384680 -0.767504 -0.526806 -0.909011 -0.215582 2.680969 4.585037 0.578537 0.567913 0.390878 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% 17.678323 8.299468 16.623564 0.766760 24.821731 8.727108 24.353057 41.851912 0.625127 0.611459 0.384467 4.262536 4.294999
206 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.166058 12.890685 2.730255 11.693203 8.566604 17.919689 29.912745 25.605432 0.594908 0.609501 0.372434 2.591773 3.071012
207 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 20.692002 17.516300 19.018280 16.724378 28.573640 24.404526 7.981260 6.728917 0.599558 0.604916 0.372818 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% 15.670918 12.728626 100.849362 103.513390 3210.224279 3779.154252 12034.025529 16896.763033 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.290733 18.932280 9.534865 18.386628 14.436727 26.067295 -0.965936 -1.324599 0.614372 0.606359 0.392648 2.443827 2.109423
224 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 30.730964 30.546976 28.020417 28.074435 42.559670 41.595107 1.241187 0.507024 0.567662 0.567869 0.372046 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% 9.641685 17.467494 inf inf 4473.497856 4473.472752 20427.790071 20422.173257 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 37.027346 36.460655 46.864826 46.712247 47.097756 46.494700 13.943589 10.444804 0.064725 0.055749 -0.003143 0.000000 0.000000
321 N02 not_connected 100.00% 24.19% 67.20% 0.00% 100.00% 0.00% 15.448864 13.236282 15.448538 14.530726 24.312479 21.956440 34.612286 34.253538 0.476485 0.416315 0.308233 0.000000 0.000000
323 N02 not_connected 100.00% 45.70% 69.89% 0.00% 100.00% 0.00% 29.562644 18.207855 3.421136 18.296262 17.850331 26.006387 10.081508 1.065901 0.395723 0.389915 0.259863 0.000000 0.000000
324 N04 not_connected 100.00% 43.01% 67.20% 0.00% 100.00% 0.00% 21.117681 22.952703 20.807212 21.643162 31.225262 31.650519 10.770738 12.255990 0.456625 0.397960 0.307333 0.000000 0.000000
329 N12 dish_maintenance 100.00% 64.52% 72.58% 0.00% 100.00% 0.00% 3.559708 11.984021 2.101407 14.495535 9.087567 18.795945 13.914743 0.024299 0.379053 0.335344 0.246260 0.000000 0.000000
333 N12 dish_maintenance 100.00% 75.27% 100.00% 0.00% 100.00% 0.00% 6.754193 11.828295 10.455971 13.161853 7.285821 16.740085 3.250987 -0.222776 0.322062 0.306950 0.206678 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, 5, 7, 8, 9, 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, 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, 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: [65, 66, 183, 184, 185]

golden_ants: [65, 66, 183, 184, 185]
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_2459790.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 [ ]: