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 = "2459794"
data_path = "/mnt/sn1/2459794"
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-2-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/2459794/zen.2459794.25320.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/2459794/zen.2459794.?????.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/2459794/zen.2459794.?????.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 2459794
Date 8-2-2022
LST Range 16.258 -- 18.258 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 107 / 147 (72.8%)
Cross-Polarized Antennas
Total Number of Nodes 15
Nodes Registering 0s N09, N18
Nodes Not Correlating N04, N08, N10
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 81 / 147 (55.1%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 116 / 147 (78.9%)
Redcal Done? ✅
Redcal Flagged Antennas 11 / 147 (7.5%)
Never Flagged Antennas 8 / 147 (5.4%)
A Priori Good Antennas Flagged 81 / 87 total a priori good antennas:
5, 7, 9, 10, 15, 16, 17, 19, 20, 21, 29, 30,
31, 37, 40, 41, 42, 45, 50, 51, 53, 54, 55,
56, 57, 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, 163, 165, 167, 169, 170, 176,
177, 178, 179, 181, 183, 185, 186, 187, 190,
191
A Priori Bad Antennas Not Flagged 2 / 60 total a priori bad antennas:
3, 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_2459794.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.542359 -0.820805 -0.726882 -1.042336 -0.716104 -0.229038 -0.655759 -0.905684 0.675360 0.663781 0.437358 0.000000 0.000000
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.151300 5.396737 -0.593702 1.940160 -0.204068 0.326757 5.547578 2.049553 0.685798 0.666978 0.433327 0.000000 0.000000
5 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.672155 1.346830 0.650974 4.340934 0.575136 1.741411 1.269197 -2.618409 0.697847 0.679313 0.431545 0.000000 0.000000
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.098235 -1.176204 0.261295 -0.203123 0.206074 0.033572 -0.203283 12.420422 0.693654 0.673464 0.417832 0.000000 0.000000
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.852438 16.554474 18.913603 19.171849 22.804202 22.919912 6.327503 4.245205 0.666967 0.638175 0.408346 0.000000 0.000000
9 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.351621 -1.078695 -0.561040 0.289361 1.970030 2.008864 2.493281 9.583244 0.670305 0.648556 0.408405 0.000000 0.000000
10 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.727509 4.143752 -1.037037 8.197244 0.741359 6.788105 33.686573 31.711270 0.652332 0.625117 0.417904 0.000000 0.000000
15 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.072586 0.576446 1.098391 0.700377 0.606410 0.932523 2.911744 5.554690 0.704776 0.686426 0.438525 5.167148 5.061904
16 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.286804 -1.751055 -0.554140 -0.476796 -0.699201 -0.719240 5.628432 6.877466 0.708768 0.693405 0.431428 15.136862 14.709997
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 28.95% 21.05% 0.120973 0.562835 0.464529 0.483049 -0.263881 -0.169678 3.667298 1.992705 0.708044 0.693056 0.413582 0.771546 0.808167
18 N01 RF_maintenance 100.00% 0.00% 37.63% 0.00% 100.00% 0.00% 3.499850 2.595169 2.846203 -0.490648 5.060387 4.869955 73.938464 142.954828 0.688636 0.516102 0.454664 59.119464 14.707447
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.458152 -0.970153 5.148398 0.000336 3.325529 0.679283 8.494382 1.275046 0.697904 0.678073 0.407426 90.415451 56.374833
20 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 18.42% 36.84% -1.442469 -0.114430 -1.028281 -0.443852 1.319831 1.963338 -0.586160 -0.640080 0.683027 0.655754 0.401810 1.039282 1.013944
21 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 10.53% 44.74% 0.019620 1.444523 0.397854 1.297659 -0.602564 1.035377 0.534835 1.410663 0.666640 0.641192 0.411638 0.835391 0.797926
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.219906 24.279531 54.396874 55.411429 32.558163 32.053087 29.631844 25.920747 0.044209 0.049498 0.004005 0.000000 0.000000
28 N01 RF_maintenance 100.00% 37.63% 100.00% 0.00% 100.00% 0.00% 13.022274 15.106034 7.995497 9.967421 29.473009 34.457671 32.119975 184.716692 0.468824 0.245850 0.292414 0.000000 0.000000
29 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.895283 -0.332874 0.781369 -0.372852 0.392281 -0.344746 -0.348796 6.982788 0.723268 0.706973 0.439289 0.000000 0.000000
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.372287 -0.621807 0.179769 -0.694306 0.245675 0.351669 36.049869 0.173384 0.715273 0.698638 0.420306 0.000000 0.000000
31 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.719027 -0.808148 -1.040898 -0.183706 -0.554493 -1.295174 6.543205 9.101299 0.712524 0.689204 0.413508 0.000000 0.000000
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 31.865396 18.912641 2.623787 4.588721 10.020674 14.086180 137.956789 519.680334 0.641556 0.642726 0.286866 0.000000 0.000000
33 N02 RF_maintenance 100.00% 0.00% 37.63% 0.00% 100.00% 0.00% -0.644143 3.624012 -0.937938 0.266296 6.875663 9.024847 168.887027 250.971611 0.677793 0.508620 0.485326 0.000000 0.000000
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.978535 5.963292 -0.039121 0.631206 1.615169 0.813129 0.976219 4.004299 0.682786 0.665989 0.414198 0.000000 0.000000
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.504650 0.900310 -0.671101 -0.034309 0.231627 0.215077 0.355783 11.438705 0.703172 0.689595 0.416204 0.000000 0.000000
38 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.934288 0.018422 -0.839318 -0.759630 2.407867 0.372317 19.987763 10.819745 0.717073 0.705076 0.427860 0.000000 0.000000
40 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 63.394139 77.433828 118.105539 128.895039 30.078057 34.227784 1512.233588 3106.424089 0.016641 0.016337 0.000374 0.000000 0.000000
41 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 127.463888 94.907635 116.950177 130.295904 29.714894 49.627797 1828.963150 2914.185992 0.018783 0.017178 0.001089 0.000000 0.000000
42 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 63.527720 59.845274 120.633859 108.416927 21.811384 41.308851 1976.719843 1551.808999 0.017117 0.016870 0.000288 0.000000 0.000000
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.770605 0.151682 -1.062092 1.074781 -0.867570 -0.469281 0.900449 15.419019 0.704387 0.677753 0.426958 0.000000 0.000000
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.371182 -0.890242 0.708102 -0.864430 -0.308634 -1.114558 -0.939076 3.563592 0.689347 0.663736 0.433086 0.000000 0.000000
50 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.182408 2.070140 -0.505304 2.842981 1.016698 2.960709 6.328233 1.582728 0.690868 0.675199 0.391092 0.000000 0.000000
51 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.660060 17.779964 2.306929 19.645819 2.272376 23.376617 1.133126 4.311062 0.708068 0.671996 0.411484 0.000000 0.000000
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.102773 17.531826 2.812369 20.162065 1.081512 23.977497 2.425397 5.528403 0.721104 0.684815 0.424420 0.000000 0.000000
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.784009 1.313413 -0.535712 -0.167441 -0.734996 0.573692 8.389599 21.405730 0.731314 0.721328 0.435577 0.000000 0.000000
54 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 55.978946 110.136908 114.215835 144.695249 37.373093 37.398687 2662.387634 3276.394068 0.017171 0.016428 0.000624 0.000000 0.000000
55 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 81.633577 93.019432 138.926685 131.058521 89.730062 37.910748 4350.365614 3261.923667 0.017331 0.016524 0.000742 0.000000 0.000000
56 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 83.096079 65.771780 120.387011 123.829303 35.311465 39.453035 2629.443578 2451.481375 0.018166 0.016891 0.000848 0.000000 0.000000
57 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 49.314503 76.490294 103.475003 128.954882 39.616561 51.160818 1570.328596 3690.108450 0.018607 0.016515 0.002007 0.000000 0.000000
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.647930 0.150208 -0.433232 0.403819 1.290589 1.150212 0.227612 2.131959 0.699498 0.682104 0.405164 0.297734 0.315229
66 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.235933 -0.191853 -0.623421 0.973255 0.656085 1.505535 0.306316 9.172978 0.715692 0.703073 0.395180 13.616885 17.757199
67 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.463717 -0.271440 -0.584821 0.364464 1.770169 1.546127 3.655533 10.319877 0.727967 0.718069 0.401045 12.154456 17.977487
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 28.95% 0.305660 -0.113317 0.109521 0.099592 1.724044 2.571840 -0.322001 0.137800 0.729296 0.720561 0.419279 0.602993 0.601992
69 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 71.017565 84.972552 133.689813 118.336404 61.381609 41.815685 3314.126889 2743.191453 0.017073 0.016636 0.000432 1.305624 1.309861
70 N04 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 55.145856 120.265359 117.314040 154.781368 41.265695 56.184033 3143.347089 4161.980031 0.016569 0.016324 0.000474 1.012115 1.008793
71 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 50.224093 75.348594 108.417950 125.440008 32.570400 57.863881 1828.509010 3164.875137 0.016725 0.016386 0.000375 1.243649 1.223075
72 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 71.806428 57.160248 121.459316 109.085667 48.934637 30.987774 2540.681634 1689.430705 0.018067 0.017018 0.000594 1.112673 1.101660
73 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 18.42% 81.58% 1.304546 1.840346 -0.793288 0.578325 -0.365288 0.104099 3.399015 -0.387421 0.721615 0.699097 0.480851 5.172317 4.516755
81 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.337561 8.126299 -0.735999 10.016260 0.652694 10.274357 1.267843 -1.951699 0.688922 0.670949 0.387515 0.000000 0.000000
82 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.387941 -0.951367 -0.334602 1.501365 -0.613767 0.057516 0.157435 0.418724 0.711395 0.697370 0.394449 0.000000 0.000000
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.847189 3.672395 2.255300 4.964549 1.522134 3.144653 -1.029325 -2.213522 0.727252 0.719269 0.396790 0.000000 0.000000
84 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.328494 7.373871 -0.100029 1.672589 -0.362751 0.072529 -0.280949 0.560666 0.089567 0.101689 0.019138 0.000000 0.000000
85 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.796342 4.093023 -0.244109 6.448451 -0.891612 5.053049 -0.605561 -2.825494 0.083164 0.096253 0.014498 0.000000 0.000000
86 N08 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.729166 2.648740 1.072651 -0.723788 0.430938 1.143072 1.068593 3.639759 0.074809 0.070059 0.007000 0.000000 0.000000
87 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 8.456702 8.868072 7.040656 0.300506 5.459464 -0.017346 -2.578013 -0.909592 0.084258 0.076871 0.009392 0.000000 0.000000
88 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
90 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
91 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
92 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 32.301335 47.996895 10.143893 13.608414 35.948650 36.321995 25.326642 38.289587 0.107876 0.103208 0.015099 0.000000 0.000000
93 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.049662 -0.254925 3.104358 -0.421921 2.015354 -0.170949 -1.702247 0.077080 0.108193 0.106296 -0.013882 0.000000 0.000000
94 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.674268 0.140302 -0.870756 -0.892594 -0.293882 1.300173 16.860032 4.617563 0.072048 0.073655 0.006905 0.000000 0.000000
98 N07 digital_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.092708 5.638895 10.048063 3.046118 9.472811 2.163242 0.647134 3.225975 0.688010 0.668843 0.390959 0.000000 0.000000
99 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.342283 5.673045 9.784700 7.920207 9.288823 6.247130 0.643310 -2.511561 0.703353 0.695126 0.384982 0.000000 0.000000
100 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.540353 0.066577 -0.265532 0.351377 -0.664864 -0.446472 -0.240413 0.190552 0.721457 0.710712 0.406680 0.000000 0.000000
101 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.551397 7.476346 3.757537 1.087700 2.406697 0.428182 3.237237 2.100790 0.108731 0.096186 0.018911 0.000000 0.000000
102 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.548348 2.515994 20.189866 11.926451 32.864175 19.306670 654.520876 379.422120 0.057972 0.066655 0.009167 0.000000 0.000000
103 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.079262 7.642636 -0.573981 0.105575 -0.103260 -0.370860 0.960764 1.150092 0.068671 0.069359 0.005363 0.000000 0.000000
104 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 5.197801 72.849623 0.366692 14.988177 0.240883 4.419568 1.059673 2.699522 0.083047 0.088960 0.009794 0.000000 0.000000
105 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
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% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
108 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
109 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.558246 -0.424282 0.300975 1.396125 -0.745323 1.312883 -0.731914 1.016247 0.095291 0.095491 0.018708 0.000000 0.000000
110 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 34.963878 3.612793 3.556745 3.406642 8.725316 10.367154 8.229413 48.731406 0.085444 0.088791 0.008341 0.000000 0.000000
111 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.268067 0.352501 -0.587460 1.224371 1.452952 1.697845 0.218351 0.600077 0.057034 0.070696 0.003948 0.000000 0.000000
112 N10 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.672204 -0.676777 -0.890019 0.525859 -0.113622 -0.617436 -0.453823 -2.043530 0.061209 0.070512 0.005313 0.000000 0.000000
116 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.587843 6.881429 -0.901640 8.380024 -0.157416 8.104761 0.647318 -2.163637 0.681152 0.667338 0.397319 0.000000 0.000000
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.091472 3.523828 9.686090 5.392616 9.152015 2.835910 -2.498010 -2.977253 0.706130 0.694876 0.408963 0.000000 0.000000
118 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.092764 0.529182 2.560715 0.274739 1.324401 1.284787 6.273812 9.121623 0.709684 0.700055 0.410865 0.000000 0.000000
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.305981 0.264305 8.225507 0.174866 8.071437 -0.805336 -2.274875 -0.357845 0.723796 0.714496 0.431609 0.000000 0.000000
120 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.658206 29.308713 9.620333 61.288364 29.709514 32.768568 17.315901 37.218169 0.121301 0.042852 0.060843 0.000000 0.000000
121 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 4.642002 4.469590 4.793028 0.371134 1.910511 0.043233 74.112351 53.598315 0.080921 0.070354 0.006969 0.000000 0.000000
122 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.158297 6.526209 1.972132 1.446111 2.148728 0.708452 1.453078 1.269983 0.096982 0.087176 0.011327 0.000000 0.000000
123 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.965732 7.114590 1.225166 -0.060789 1.505226 0.537882 -0.058386 0.235982 0.124695 0.121535 0.029314 0.000000 0.000000
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.695788 -1.136581 0.337359 -0.090947 0.543476 -0.162903 0.127648 0.669445 0.093028 0.089406 0.019078 0.000000 0.000000
128 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.067398 0.552121 -0.634890 1.300180 -0.809820 0.499951 -0.407977 -1.274861 0.083843 0.082080 0.010225 0.000000 0.000000
129 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.441233 -1.616340 -0.804952 -1.133532 0.042783 -0.260173 -0.845211 -0.679536 0.068828 0.066257 0.004904 0.000000 0.000000
130 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.022036 -0.032377 0.798391 1.184313 0.164721 1.329963 1.226768 15.510998 0.073999 0.059716 0.004692 0.000000 0.000000
135 N12 digital_ok 0.00% 18.82% 18.82% 0.00% 18.42% 2.63% -0.848435 -1.571859 -1.031706 -1.111168 -0.690540 -0.815125 0.742421 -0.430587 0.598991 0.582662 0.374814 -1.130860 -57.002539
136 N12 RF_maintenance 100.00% 18.82% 18.82% 0.00% 100.00% 0.00% 1.738025 10.289075 -0.621141 0.427887 4.235553 2.511981 6.312840 17.550124 0.598127 0.580458 0.355492 7.047756 7.999076
137 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.297995 21.784784 47.013425 48.433761 32.624725 32.055929 25.304313 30.787468 0.039851 0.050900 0.006030 1.159723 1.164709
138 N07 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 26.478287 2.366482 46.783903 2.045618 32.713745 0.837847 27.357820 1.446267 0.047687 0.702326 0.453606 1.318875 6.866210
140 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 81.58% 3.937798 3.098129 0.088280 1.007572 2.468523 3.124875 1.521989 0.804044 0.711256 0.703107 0.434115 0.743768 1.208967
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.600026 3.903983 -0.795280 12.105697 1.369750 3.929040 1.025776 19.830667 0.709723 0.692254 0.443197 1.080857 1.319973
142 N13 digital_ok 100.00% 40.32% 100.00% 0.00% 100.00% 0.00% 21.627438 25.629095 10.209064 55.927092 29.848730 32.242500 19.824287 25.641824 0.447884 0.045950 0.257299 9.639323 1.370106
143 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 50.00% 31.58% -0.419297 -0.713873 1.699948 0.489085 1.117393 -0.365886 0.619232 -2.057962 0.715742 0.705063 0.432639 0.000000 0.000000
144 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 81.58% 0.072696 0.452075 -0.647887 0.116513 -0.414036 -0.273203 2.747646 0.012544 0.713897 0.700456 0.441863 71.095219 25.779269
145 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.458473 22.242341 54.757421 56.306406 32.531765 31.987331 26.308099 30.826743 0.036245 0.038961 -0.000468 0.977884 0.932085
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.897197 24.028416 54.544680 57.247195 32.533293 31.869606 27.843562 29.476610 0.061239 0.063856 0.001486 0.000000 0.000000
155 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.347761 23.066788 53.433020 55.233385 32.450969 31.844360 28.268549 28.260348 0.042815 0.043484 -0.000641 1.143632 1.168252
156 N12 RF_maintenance 100.00% 18.82% 18.82% 0.00% 100.00% 0.00% 0.732544 2.753115 1.836691 5.602587 1.529443 3.765770 11.967046 27.515511 0.598931 0.583432 0.376002 3.238578 3.076756
157 N12 RF_maintenance 0.00% 18.82% 18.82% 0.00% 100.00% 0.00% -0.725827 0.835585 -0.097434 3.030678 1.453324 1.689527 0.657118 -1.803400 0.603798 0.592339 0.380656 9.081305 9.403429
158 N12 RF_maintenance 0.00% 18.82% 18.82% 0.00% 100.00% 0.00% -0.014313 -1.168699 -0.951607 -0.353429 -0.052324 0.717330 -0.658361 0.606509 0.616884 0.604966 0.387599 2.524686 2.686020
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.753557 19.883585 54.154069 55.748152 32.511602 32.047583 26.809122 30.710501 0.045378 0.045776 0.002708 1.378268 1.364830
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.893461 39.382630 -0.383048 3.662770 0.334025 7.586710 0.420171 3.067045 0.713428 0.631627 0.407130 46.272508 50.235816
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.385153 -0.043283 -0.078675 -0.885127 3.366323 1.831533 0.446525 -0.274012 0.710139 0.702778 0.417519 0.463407 0.439593
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 7.89% 0.463177 -0.359194 -0.017411 -1.006799 -0.014498 -1.509385 -0.230862 -0.937756 0.715287 0.706182 0.416163 0.751514 0.721362
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.454548 -0.930908 -0.987038 -0.519348 -0.827085 -0.631985 -0.662744 1.098471 0.710643 0.698697 0.416305 0.483773 0.469944
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.354970 0.729627 6.711757 -0.911794 5.331480 -1.264350 -0.380042 -0.224583 0.708282 0.694292 0.414343 25.309778 22.135424
166 N14 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.323071 1.539789 -0.285035 1.159715 8.879907 1.274842 73.697924 4.266828 0.676360 0.684046 0.393536 0.000000 0.000000
167 N15 digital_ok 100.00% 21.51% 16.13% 0.00% 100.00% 0.00% 18.322147 21.828153 16.992465 18.269437 23.234319 24.515865 218.592814 37.487077 0.603570 0.589429 0.257766 0.000000 0.000000
168 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 16.690452 19.428029 19.053709 21.170147 22.829320 25.677255 3.636741 6.335595 0.651223 0.622230 0.412885 0.000000 0.000000
169 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 18.685097 17.770134 20.999028 19.912128 25.706351 24.129609 5.940798 4.299057 0.628263 0.603644 0.406129 0.000000 0.000000
170 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 18.784867 16.643715 21.117654 19.216303 25.859653 22.562740 6.587143 4.206118 0.611570 0.595158 0.405132 0.000000 0.000000
176 N12 digital_ok 0.00% 18.82% 18.82% 0.00% 68.42% 0.00% -0.300878 -0.196423 -0.888959 0.575495 0.147297 0.087462 -0.718814 -1.451302 0.579917 0.565636 0.375373 0.000000 0.000000
177 N12 digital_ok 100.00% 18.82% 18.82% 0.00% 100.00% 0.00% 1.344990 1.009976 1.253857 6.356900 0.485774 7.511528 1.009564 47.456013 0.591307 0.572781 0.381408 0.000000 0.000000
178 N12 digital_ok 0.00% 18.82% 18.82% 0.00% 68.42% 0.00% -0.602478 -1.198161 0.725363 -0.793166 -0.319608 -0.684118 1.461767 3.103301 0.604353 0.590869 0.386885 0.000000 0.000000
179 N12 digital_ok 100.00% 18.82% 18.82% 0.00% 100.00% 0.00% 0.114023 -0.345839 -0.539706 -0.002072 1.410296 0.152165 10.196677 0.280624 0.614489 0.599580 0.399831 0.000000 0.000000
180 N13 RF_maintenance 100.00% 0.00% 40.32% 0.00% 100.00% 0.00% -0.300218 13.678310 0.336420 50.267929 -0.004852 20.705394 -0.639672 18.832343 0.705315 0.498293 0.511772 0.000000 0.000000
181 N13 digital_ok 100.00% 100.00% 61.83% 0.00% 100.00% 0.00% 22.764599 44.632454 54.936380 7.222127 32.566828 31.746710 26.242442 23.342333 0.047243 0.321719 0.167355 0.000000 0.000000
182 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.983203 16.955287 19.087505 19.501316 22.681488 23.277294 3.137544 4.202707 0.687981 0.673136 0.435100 0.000000 0.000000
183 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.309403 -1.171391 -0.088724 -1.086045 -0.324118 -1.297384 0.247770 9.173369 0.709536 0.699187 0.422998 0.000000 0.000000
184 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.213853 0.014313 0.017411 0.701095 0.168959 0.529186 -0.012544 -0.733333 0.708206 0.696361 0.406049 0.000000 0.000000
185 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 68.42% 31.58% 0.732646 0.582821 2.524892 1.280299 0.979085 0.014498 -2.301743 -0.553840 0.704834 0.692020 0.404512 0.000000 0.000000
186 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.325159 0.569663 3.911318 2.075848 0.575761 0.130847 5.251697 0.586889 0.693909 0.682331 0.398250 0.000000 0.000000
187 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.202470 0.285747 0.014283 0.580933 0.376020 -0.419329 7.341968 2.211635 0.692153 0.680605 0.402690 0.000000 0.000000
189 N15 digital_ok 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.841021 3.206912 0.246505 -0.442401 -0.298729 -0.708172 0.397094 -0.513948 0.654574 0.637276 0.407434 0.000000 0.000000
190 N15 digital_ok 100.00% 32.26% 100.00% 0.00% 100.00% 0.00% 40.996664 24.507828 5.568268 56.342900 14.284826 32.135278 226.592081 29.185147 0.527751 0.050706 0.303428 0.000000 0.000000
191 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.293903 -0.394225 -0.834958 -0.973624 -0.463991 -0.729514 3.417740 9.379714 0.623287 0.596252 0.418874 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% 11.810461 4.890670 13.914259 1.572900 16.904859 4.726972 57.955438 82.886783 0.666797 0.643623 0.395888 0.000000 0.000000
206 N19 RF_ok 100.00% 0.00% 5.38% 0.00% 100.00% 0.00% 2.382250 8.014937 -0.068810 8.749335 5.323960 27.706854 58.207602 167.779389 0.645915 0.629474 0.384419 0.000000 0.000000
207 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.843184 11.040640 15.875565 13.224244 18.964142 15.225631 19.498215 17.572774 0.644226 0.635402 0.389937 1.190562 1.187761
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% 9.432693 6.090893 85.971646 88.682725 2435.928709 2858.216662 29204.766182 40398.015699 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.768655 12.711286 8.248792 15.114315 9.628099 16.895872 -0.973816 -0.263358 0.658614 0.637075 0.410056 0.000000 0.000000
224 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 21.585167 21.133065 23.728215 23.061676 29.504908 28.177359 7.902455 6.750152 0.609562 0.596912 0.389816 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% 7.286938 12.159095 inf inf 3383.496372 3382.941891 48796.528391 48787.697222 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.971945 24.946497 40.288440 40.845216 32.808263 31.975688 38.118522 29.184309 0.060069 0.069995 0.003341 0.000000 0.000000
321 N02 not_connected 100.00% 18.82% 56.99% 0.00% 100.00% 0.00% 10.430057 8.188270 12.713985 11.396739 15.829016 13.418260 79.102650 79.447902 0.506204 0.426337 0.327919 0.000000 0.000000
323 N02 not_connected 100.00% 34.95% 62.37% 0.00% 100.00% 0.00% 19.727206 11.884725 2.257332 14.842089 11.903134 15.827533 21.815985 7.095634 0.430969 0.395324 0.271848 0.000000 0.000000
324 N04 not_connected 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 27.203620 29.255514 60.010451 60.526746 27.601623 28.916066 747.038984 779.758827 0.023938 0.023379 0.000473 0.000000 0.000000
329 N12 dish_maintenance 100.00% 53.76% 73.12% 0.00% 100.00% 0.00% 3.837385 6.989460 6.367700 11.068504 7.174679 12.271350 4.144884 -1.301761 0.413246 0.341273 0.270262 0.000000 0.000000
333 N12 dish_maintenance 100.00% 67.74% 100.00% 0.00% 100.00% 0.00% 2.028900 7.031442 3.866048 10.085348 2.817073 9.856052 4.546181 -1.313461 0.363687 0.310672 0.228136 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, 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, 163, 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: [65, 162, 164]

golden_ants: [65, 162, 164]
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_2459794.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 [ ]: