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 = "2459806"
data_path = "/mnt/sn1/2459806"
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-14-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/2459806/zen.2459806.25322.sum.auto_metrics.h5.

Load Ant Metrics¶

In [7]:
use_ant_metrics = False

# get a list of all ant_metrics files
glob_str = os.path.join(data_path, f'zen.{JD}.?????.sum{ant_metrics_ext}')
ant_metrics_files = sorted(glob.glob(glob_str))

# if they exist, load as many of them as possible
if len(ant_metrics_files) > 0:
    print(f'Found {len(ant_metrics_files)} ant_metrics files matching glob {glob_str}')
    ant_metrics_apriori_exants = {}
    ant_metrics_xants_dict = {}
    ant_metrics_dead_ants_dict = {}
    ant_metrics_crossed_ants_dict = {}
    ant_metrics_dead_metrics = {}
    ant_metrics_crossed_metrics = {}
    dead_cuts = {}
    crossed_cuts = {}
    for amf in ant_metrics_files:
        with h5py.File(amf, "r") as infile: # use h5py directly since it's much faster than load_metric_file
            # get out results for this file
            dead_cuts[amf] = infile['Metrics']['dead_ant_cut'][()]
            crossed_cuts[amf] = infile['Metrics']['cross_pol_cut'][()]
            xants = infile['Metrics']['xants'][:]
            dead_ants = infile['Metrics']['dead_ants'][:]
            crossed_ants = infile['Metrics']['crossed_ants'][:]        
            try:
                # look for ex_ants in history
                ex_ants_string = infile['Header']['history'][()].decode()
                ex_ants_string = ex_ants_string.split('--apriori_xants')[1]
                ex_ants_string = ex_ants_string.split('--')[0].strip()
            except:
                ex_ants_string = ''
                    
            # This only works for the new correlation-matrix-based ant_metrics
            if 'corr' in infile['Metrics']['final_metrics'] and 'corrXPol' in infile['Metrics']['final_metrics']:
                ant_metrics_dead_metrics[amf] = {eval(ant): infile['Metrics']['final_metrics']['corr'][ant][()]
                                                 for ant in infile['Metrics']['final_metrics']['corr']}
                ant_metrics_crossed_metrics[amf] = {eval(ant): infile['Metrics']['final_metrics']['corrXPol'][ant][()]
                                                    for ant in infile['Metrics']['final_metrics']['corrXPol']}                       
            else:
                raise(KeywordError)
        
        # organize results by file
        ant_metrics_xants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in xants]
        ant_metrics_dead_ants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in dead_ants]
        ant_metrics_crossed_ants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in crossed_ants]
        ant_metrics_apriori_exants[amf] = [int(ant) for ant in ex_ants_string.split()]
    
    dead_cut = np.median(list(dead_cuts.values()))
    crossed_cut = np.median(list(crossed_cuts.values()))
        
    use_ant_metrics = True
else:
    print(f'No files found matching glob {glob_str}. Skipping ant_metrics.')
Found 1862 ant_metrics files matching glob /mnt/sn1/2459806/zen.2459806.?????.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 187 ant_metrics files matching glob /mnt/sn1/2459806/zen.2459806.?????.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 2459806
Date 8-14-2022
LST Range 17.047 -- 3.068 hours
X-Engine Status ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
Number of Files 1862
Total Number of Antennas 147
OPERATIONAL STATUS SUMMARY
Antenna A Priori Status Count dish_maintenance: 3
RF_maintenance: 32
RF_ok: 11
digital_maintenance: 3
digital_ok: 95
not_connected: 3
Commanded Signal Source None
Antennas in Commanded State 0 / 147 (0.0%)
Cross-Polarized Antennas
Total Number of Nodes 15
Nodes Registering 0s N18
Nodes Not Correlating N09, N14, N19
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 75 / 147 (51.0%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 117 / 147 (79.6%)
Redcal Done? ✅
Redcal Flagged Antennas 11 / 147 (7.5%)
Never Flagged Antennas 13 / 147 (8.8%)
A Priori Good Antennas Flagged 82 / 95 total a priori good antennas:
5, 7, 9, 15, 16, 19, 20, 30, 31, 37, 38, 41,
45, 46, 53, 54, 55, 56, 65, 66, 68, 69, 71,
72, 73, 81, 83, 84, 85, 86, 88, 91, 93, 94,
98, 99, 100, 101, 103, 105, 106, 107, 108,
109, 111, 112, 117, 118, 121, 122, 123, 127,
128, 129, 130, 140, 141, 142, 143, 144, 156,
157, 160, 161, 162, 163, 164, 165, 167, 169,
170, 177, 179, 181, 183, 184, 185, 186, 187,
189, 190, 191
A Priori Bad Antennas Not Flagged 0 / 52 total a priori bad antennas:
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_2459806.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 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 3.477639 -0.680691 -0.851975 -1.149818 1.566465 -0.995635 -0.140363 0.516446 0.723356 0.629420 0.419349 1.467462 1.227348
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.250182 5.148201 -0.957942 1.941387 -0.692529 0.626403 8.293343 2.007127 0.738737 0.626027 0.422996 6.369143 6.562591
5 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.080449 1.298295 -0.577322 5.516583 -0.454950 4.867892 1.616502 -1.123605 0.740969 0.638955 0.415940 5.464978 5.194306
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.512980 -1.214814 0.397849 0.019339 -0.528069 0.293852 3.601592 37.380942 0.732572 0.630974 0.417346 4.586084 4.919167
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 12.611877 12.548269 23.714886 24.495548 32.724557 33.827192 0.951136 -3.811357 0.725273 0.606773 0.424786 5.818063 6.496601
9 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.14% -0.240917 -1.440470 0.609911 -0.383712 1.117117 -0.112762 -0.372945 0.540823 0.723731 0.619300 0.429543 2.058152 1.737331
10 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.249098 -0.939198 -0.422084 0.673282 -0.537657 -0.098201 0.402025 1.115573 0.712608 0.606109 0.444584 1.882323 1.677202
15 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.943867 2.195961 1.682292 0.569121 0.750948 0.130949 0.598002 7.468081 0.741712 0.633895 0.414142 6.183832 5.182876
16 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.550617 -0.688009 -1.164156 0.131011 -1.310543 0.051892 7.401898 7.111016 0.748167 0.650844 0.409500 5.529218 5.747668
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.230296 1.947340 0.166142 0.185078 0.013893 -0.039676 -0.067108 -1.400803 0.740370 0.649994 0.406151 1.799806 1.691703
18 N01 RF_maintenance 100.00% 0.00% 77.34% 0.00% 100.00% 0.00% 17.000035 16.197327 0.473058 1.650490 6.819494 8.930516 92.161743 121.144362 0.657556 0.393717 0.431590 2.997092 2.269690
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.709125 4.873522 -1.188476 10.510794 3.448086 99.296561 13.697214 3.353945 0.736888 0.646007 0.417764 4.051514 5.059247
20 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.14% -1.730683 1.742299 -0.182415 -0.923517 0.233288 0.029473 0.455933 -0.783571 0.733927 0.621562 0.423390 2.016808 1.839360
21 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.823384 -0.405300 0.674945 1.520538 1.833494 -0.321422 0.500586 -1.576559 0.718536 0.621029 0.433514 2.025619 1.736727
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.733236 23.571242 42.276714 43.391290 45.378676 45.315441 10.622709 8.005114 0.041847 0.047385 0.003570 1.241058 1.238431
28 N01 RF_maintenance 100.00% 44.04% 100.00% 0.00% 100.00% 0.00% 16.418523 39.417833 1.542078 4.409417 27.539658 35.696849 9.044148 40.345797 0.406789 0.182290 0.246022 6.817221 2.088293
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.787676 -1.311581 0.592887 -0.663625 -1.577739 -1.594350 -0.573617 0.649339 0.750070 0.659753 0.404425 1.548305 1.512472
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.119041 -0.427095 0.594409 -0.914008 -0.139322 1.115154 20.762213 1.233446 0.744655 0.658633 0.403769 4.468130 4.663028
31 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.465719 0.306375 -0.762499 2.704566 6.078006 11.006781 60.551060 58.384881 0.751819 0.649513 0.418115 4.596461 4.024362
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 45.144935 7.077022 3.014861 2.605178 14.774503 19.320443 85.063275 148.911634 0.639684 0.634250 0.339862 5.386776 4.685038
33 N02 RF_maintenance 100.00% 0.00% 32.76% 0.00% 100.00% 0.00% -0.042904 11.290018 0.739286 -0.201655 34.155535 31.667323 386.301798 367.398222 0.724517 0.445299 0.520067 4.895772 2.318715
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 12.423884 9.596003 -0.030495 0.053366 1.862211 0.441186 2.456739 1.492777 0.748355 0.646619 0.414913 6.501675 4.819179
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.322237 1.281817 -0.411815 0.138924 -1.091854 -0.099939 0.877314 26.082750 0.752985 0.661994 0.404062 5.737409 4.991915
38 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.246501 -0.478556 -0.213105 -0.343406 2.549189 4.032875 11.667570 4.312618 0.756529 0.669302 0.402627 4.776628 4.550870
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.615418 0.047755 0.047952 -0.688705 -0.013893 -0.192899 0.545474 -1.004191 0.750561 0.669647 0.400593 1.735749 1.676141
41 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.237138 -0.240912 3.628478 1.224182 4.395844 -0.871727 -0.257475 1.285765 0.755976 0.667952 0.403905 4.758414 5.400970
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.200220 2.080105 2.539270 0.774071 0.227992 -0.456954 -0.184348 -1.062853 0.755257 0.662710 0.410326 1.645849 1.603127
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.075584 1.278895 -0.359174 0.052285 0.142547 2.224395 0.418275 15.459876 0.741062 0.636358 0.423450 4.041161 3.570223
46 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.051631 0.085497 0.000842 -1.099973 -1.461015 -1.074703 0.760240 6.931325 0.736197 0.634136 0.432955 4.101731 3.479304
50 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 24.677519 17.072469 1.742505 1.298387 13.335001 13.453305 124.241839 156.925573 0.696507 0.604615 0.358369 6.547399 6.592390
51 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.917328 3.118195 -1.066244 -0.651608 0.112289 0.156965 -0.720698 2.390031 0.755905 0.674672 0.396480 1.606049 1.528945
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.674446 8.908285 0.800196 -0.170783 5.033154 -0.036866 4.243545 4.534979 0.762216 0.683293 0.389073 5.120707 5.083276
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.065481 2.187801 -0.631642 -0.532344 -1.260765 0.019362 7.558881 12.562250 0.766508 0.691031 0.389901 4.439738 4.283051
54 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.700450 16.196448 0.678750 3.963476 -0.478302 21.440954 3.368472 9.798678 0.759729 0.661941 0.381992 4.357168 4.019800
55 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.068169 1.783110 0.721521 1.103350 3.866413 1.004136 11.567918 0.197646 0.753546 0.678060 0.394746 4.268391 3.854844
56 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.812448 1.169345 1.192419 0.811209 0.953151 -0.205441 -0.049283 5.934710 0.754184 0.682672 0.397516 4.780476 4.214249
57 N04 RF_maintenance 100.00% 100.00% 55.85% 0.00% 100.00% 0.00% 19.129084 17.882293 39.653888 1.137299 45.795457 36.745074 4.733379 12.007963 0.048657 0.394917 0.210366 1.198437 3.916057
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 9.63% 0.904033 0.503253 1.111078 0.902058 2.483066 1.053377 0.067108 2.028116 0.746529 0.660363 0.414155 1.758675 1.662539
66 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.348499 0.848119 -0.767305 1.021608 -1.340095 2.057228 0.558423 8.211503 0.757883 0.679403 0.394108 4.927404 6.674800
67 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.066156 -0.668291 -0.054249 0.246552 2.673508 1.217888 1.705139 2.527286 0.763044 0.691743 0.380684 1.822663 1.566057
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.67% 0.918770 0.719759 -0.173613 0.442668 0.595203 2.778655 1.701762 2.976824 0.765637 0.695740 0.374484 1.835483 1.574046
69 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 22.46% 0.094370 -0.456005 -1.041842 -0.542128 0.052280 0.485670 0.931400 2.938262 0.765326 0.697070 0.381947 2.289718 1.821990
70 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.531826 -1.111261 0.054209 -0.939422 7.491639 1.476299 2.132238 1.295303 0.759929 0.683511 0.401445 11.901100 10.225637
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 88.24% 0.391642 -0.438269 -1.076462 -1.017446 0.015551 1.138500 -0.437033 0.251243 0.761584 0.692925 0.391819 14.338732 17.417364
72 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.563151 -0.249811 -0.855184 1.390354 1.768509 0.420648 8.548489 1.090080 0.745935 0.677119 0.410191 4.200300 3.766464
73 N05 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 19.591867 2.640351 41.481948 -0.085803 45.439077 1.605807 5.157465 0.135776 0.036467 0.652750 0.387625 1.191730 3.681983
81 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.141044 3.018335 -0.931371 4.327687 2.269377 5.718361 12.578506 4.469009 0.728148 0.648716 0.410947 4.905330 4.751318
82 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.619124 -0.303284 0.444323 0.975336 -0.990892 -0.519173 0.545017 -0.387959 0.738850 0.663834 0.402923 4.452744 4.203699
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.334285 2.672808 2.344118 5.408152 0.745799 3.403486 0.184492 -1.259954 0.757815 0.691224 0.390070 4.242489 4.673420
84 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.893853 12.365660 0.106171 1.614457 -1.227970 1.207440 1.542962 -0.640376 0.699828 0.621565 0.356837 5.204587 7.056493
85 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.14% -0.175328 1.521040 1.013108 2.056631 -0.865051 -0.403064 -0.475094 -0.520126 0.683946 0.608445 0.363966 1.981458 1.877950
86 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.390311 5.893417 -0.139845 -0.301882 5.909761 3.669121 1.211174 1.995557 0.685441 0.586078 0.368265 5.283256 6.037171
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.238098 13.062144 4.031583 1.110255 8.159329 2.116157 2.270074 0.152201 0.657355 0.615809 0.377134 3.643897 4.393297
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.286360 22.384383 35.764831 37.249751 46.004009 46.054417 15.880365 8.051212 0.032415 0.032721 0.002148 1.156913 1.155403
90 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.742374 20.461727 35.641863 36.860503 45.996357 46.042066 4.205462 2.226595 0.032990 0.031345 0.001020 1.163991 1.159718
91 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.791678 22.153303 35.647348 37.894545 45.911289 45.711485 10.925953 8.858206 0.030906 0.031316 0.000080 1.140876 1.142683
92 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 52.900797 68.677220 4.183287 5.777436 33.551848 38.064366 3.583490 18.706401 0.228815 0.180544 0.074720 3.337434 2.956720
93 N10 digital_ok 100.00% 7.52% 33.83% 0.00% 100.00% 0.00% 1.055091 7.225020 4.342400 18.172288 4.516916 22.720090 1.894244 -3.053893 0.566260 0.453890 0.361519 3.446964 3.456319
94 N10 digital_ok 100.00% 7.52% 35.45% 0.00% 100.00% 0.00% -0.660230 -1.365346 -0.088225 0.125567 0.025437 0.767185 6.828989 3.651287 0.563311 0.442019 0.359381 3.950276 3.663109
98 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.561486 4.232996 0.270848 -0.829735 0.778718 3.701601 1.099525 1.824894 0.727030 0.632065 0.420206 4.846989 4.652179
99 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.381925 0.285624 3.466628 -1.051723 3.698338 0.571780 8.767783 0.240366 0.735129 0.651450 0.402991 4.486370 4.602807
100 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 6.42% 0.512833 -0.363232 1.115695 -0.215708 1.634408 -1.030529 -0.746690 -1.044092 0.752108 0.669019 0.406423 1.682898 1.592574
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 12.043908 11.888706 3.435439 -0.005559 0.694658 -1.163422 16.778804 2.981821 0.698516 0.611692 0.373157 4.315272 4.375211
102 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 18.278740 17.029085 0.314228 0.210264 401.724222 391.472568 14968.643119 14837.381758 0.530845 0.512652 0.323568 0.000000 0.000000
103 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.278545 11.543627 0.062033 -0.245577 2.842902 0.775093 1.196822 0.234426 0.694664 0.604259 0.369637 5.671551 4.948941
104 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.784155 95.838289 1.704664 12.475068 4.291008 15.242171 4.221101 0.744271 0.688446 0.595873 0.385661 6.079209 4.746127
105 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.980908 28.375192 35.590521 37.811836 46.038449 45.971637 6.797614 5.774493 0.033345 0.032004 0.001054 1.165552 1.163505
106 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.037993 23.869898 34.972537 37.285791 45.639996 45.750597 8.725897 3.962487 0.029784 0.028368 0.000945 1.040297 1.037826
107 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.617199 19.004934 36.202033 37.513385 46.004772 46.055385 7.977046 8.280969 0.030576 0.029933 0.001207 0.910386 0.906303
108 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.799386 20.330198 35.075260 37.457439 45.986002 46.052430 3.041956 2.540557 0.031110 0.032330 0.001803 0.865056 0.863934
109 N10 digital_ok 0.00% 5.37% 33.30% 0.00% 33.69% 0.53% -0.392925 0.463668 -0.060789 0.128442 -1.242459 -0.526592 0.808512 1.684537 0.582386 0.462782 0.373343 0.559795 0.549137
110 N10 RF_maintenance 100.00% 28.46% 49.95% 0.00% 100.00% 0.00% 44.619036 32.594878 2.975077 1.424989 10.154363 21.868820 3.470993 23.027179 0.477680 0.404328 0.230537 5.902587 4.892181
111 N10 digital_ok 100.00% 7.52% 34.37% 0.00% 100.00% 0.00% 0.640276 1.074640 0.039267 1.609247 -0.321797 1.126019 1.207020 5.845040 0.567952 0.446625 0.356427 4.572767 4.897411
112 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 388.758261 389.242861 inf inf 9091.857309 9094.926274 30285.100916 30300.233354 nan nan nan 0.000000 0.000000
116 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.626592 2.135268 -0.146512 -0.771324 -0.681888 2.953906 0.297148 -0.469179 0.720869 0.631220 0.420343 1.568208 1.473337
117 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
118 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
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.567530 0.992664 9.496443 2.801576 9.318017 -0.561201 -1.467713 -0.767235 0.760291 0.657190 0.415081 5.076130 4.089368
120 N08 RF_maintenance 100.00% 75.73% 100.00% 0.00% 100.00% 0.00% 20.567640 37.189483 3.662879 48.699176 28.008076 45.699675 2.752284 16.478625 0.360787 0.046523 0.253214 3.069858 1.229422
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.667555 6.854608 -0.832555 0.966218 0.966960 1.607405 54.589383 43.642311 0.698038 0.600595 0.374826 4.128020 3.477798
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.041398 10.372634 0.934142 1.754482 0.126571 -0.005142 1.983854 3.954434 0.693743 0.593640 0.381846 4.694035 3.498688
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.187729 11.262068 0.146927 -0.054865 -0.526633 0.081161 1.067394 2.329525 0.688934 0.586325 0.392089 4.522025 3.350101
125 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.320077 21.870805 36.281807 38.150588 46.132531 46.061267 4.921998 10.083701 0.028901 0.029325 0.000596 0.907084 0.901305
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.171127 22.690431 35.729071 38.496578 46.004217 46.025270 7.640710 9.438137 0.028998 0.029196 0.000885 0.000000 0.000000
127 N10 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
128 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 368.385051 368.852552 inf inf 6707.900358 6636.469614 18987.397394 18251.330235 nan nan nan 0.000000 0.000000
129 N10 digital_ok 0.00% 7.52% 33.83% 0.00% 35.29% 0.00% -0.047755 -1.013056 -0.633806 -0.905037 -0.785342 -0.277530 -0.546758 -0.322232 0.572073 0.449169 0.359679 0.740894 0.718165
130 N10 digital_ok 100.00% 9.13% 34.37% 0.00% 100.00% 0.00% 0.905494 0.546881 0.323162 0.875364 0.453659 0.107100 2.077925 10.847467 0.554792 0.439539 0.349649 5.102093 5.331045
135 N12 digital_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.659632 0.015108 -1.199467 -1.015418 -0.750154 -0.642025 4.962087 3.039846 0.662448 0.557940 0.397368 4.440143 3.716412
136 N12 digital_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.975937 13.141574 -0.907565 0.743216 2.178284 2.345964 2.850257 10.815639 0.663593 0.544904 0.386480 5.454478 4.389159
137 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
138 N07 RF_maintenance 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 25.129913 2.328549 34.793861 1.504999 45.805501 -0.297894 9.131195 0.543399 0.047490 0.638275 0.419407 1.135072 3.172433
140 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.039620 20.779979 41.278910 43.624326 45.424761 45.475357 3.986631 4.143318 0.041581 0.044594 0.001792 1.156100 1.152692
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.854974 4.471085 0.111797 9.126120 0.847384 4.480624 2.366897 46.505714 0.749242 0.627134 0.415707 2.643525 2.113439
142 N13 digital_ok 100.00% 48.34% 100.00% 0.00% 100.00% 0.00% 30.978924 26.689565 2.769959 43.809343 29.798324 45.477912 6.163880 7.492474 0.398567 0.047272 0.229986 2.146480 1.138415
143 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.191421 -0.723309 0.699101 1.482063 -0.635588 -0.193701 -0.237603 -1.177091 0.087814 0.089024 0.017155 0.000000 0.000000
144 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.753552 1.187786 -0.548227 1.706669 6.945901 2.100729 4.084642 1.672984 0.080036 0.091087 0.016890 0.000000 0.000000
145 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.324471 22.623879 42.552663 44.249747 45.548836 45.521961 8.413880 10.970455 0.030602 0.031608 -0.000247 0.000000 0.000000
150 N15 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
155 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.110997 21.610762 41.436752 43.233710 45.327865 45.376573 10.004580 8.185820 0.041908 0.040288 0.000312 1.360696 1.354142
156 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.033398 0.728155 1.504572 -0.881317 -0.308099 -0.058877 0.305675 25.312826 0.670543 0.550194 0.399863 7.427491 7.481475
157 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 4.28% -0.121484 -0.054784 0.203406 3.423978 0.100725 1.330745 0.710788 0.558540 0.671689 0.564377 0.394148 2.315603 1.775501
158 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.188789 -1.201167 0.412069 0.391792 1.509174 1.262428 3.912152 0.796901 0.681028 0.571248 0.396943 2.100655 1.768440
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.263752 23.885191 42.034629 43.693188 45.647660 45.786752 9.076609 11.132678 0.045218 0.047408 0.003125 1.287011 1.275121
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.672523 50.656508 -0.495738 3.457490 -1.419660 12.241257 0.808865 0.430645 0.745684 0.522725 0.410620 6.024283 5.775699
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 1.07% 1.290337 1.060345 0.292142 -0.594471 1.100656 0.423483 0.162721 -0.546012 0.744425 0.632473 0.434487 1.718987 1.784997
163 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.940815 -0.170348 -0.047952 -1.141051 -1.371253 0.221384 -0.154806 0.919005 0.058543 0.067053 0.009152 1.279780 1.253505
164 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.263210 -1.461016 -1.007277 -1.255429 -1.661534 -0.927895 0.911871 1.064070 0.064411 0.060619 0.005532 1.283949 1.274880
165 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.517459 1.053493 6.302965 -1.007781 3.699166 -1.107068 5.880338 2.918218 0.068682 0.059885 0.005675 1.273951 1.271343
166 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 35.625705 31.065876 2.114679 1.612338 15.953414 13.191676 14.164220 11.031892 0.095156 0.093762 0.011460 1.310520 1.310654
167 N15 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
168 N15 RF_maintenance 100.00% 0.00% 3.22% 0.00% 100.00% 0.00% 13.950506 15.747587 24.250189 27.303463 33.290113 38.243507 -4.113841 -6.497664 0.707846 0.572989 0.448346 6.195829 4.830389
169 N15 digital_ok 100.00% 0.00% 3.22% 0.00% 100.00% 0.00% 15.945850 14.283562 26.797768 25.620984 37.115222 35.524073 -4.875211 -3.828011 0.698161 0.563983 0.446519 4.029262 2.785728
170 N15 digital_ok 100.00% 0.00% 3.22% 0.00% 100.00% 0.00% 15.777864 12.543000 27.201107 24.413675 37.937009 33.590294 -4.172600 -5.010334 0.686015 0.574542 0.442340 3.417818 3.214148
176 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.695156 -0.442787 -0.674036 0.747995 -0.893021 0.358322 -0.528024 -0.857884 0.654903 0.537509 0.402555 1.953630 1.744650
177 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.201962 1.994654 0.770201 -0.963823 -0.927695 38.752984 0.302469 13.883664 0.664095 0.534528 0.406108 6.826740 8.533150
178 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.642490 -1.501318 1.220445 -0.575049 -0.667093 -0.636730 -0.099619 -0.543077 0.665802 0.553278 0.399190 2.071815 1.815011
179 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.448507 0.940929 -0.936929 -0.335227 2.030875 -0.657150 5.215969 -0.698968 0.675747 0.558563 0.407419 5.845601 6.354183
180 N13 RF_maintenance 100.00% 0.00% 85.93% 0.00% 100.00% 0.00% 0.848635 17.342979 0.773590 41.124871 -0.094864 37.495976 -0.222801 6.843970 0.740243 0.300178 0.528235 13.364122 2.650509
181 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.851753 71.386215 42.723373 5.789603 45.562621 36.348355 8.088322 10.254412 0.049004 0.248133 0.120471 1.250423 2.837297
182 N13 RF_maintenance 100.00% 0.00% 19.87% 0.00% 100.00% 0.00% 12.859316 11.881083 23.817331 11.075792 31.980602 149.341938 -3.742803 6.898234 0.733321 0.549538 0.452466 6.576453 6.206559
183 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.762647 -0.718343 -0.409728 -1.129448 -1.537583 -0.200879 0.366963 17.735009 0.735309 0.615122 0.447871 6.188343 5.051873
184 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.473656 -0.109697 -0.836402 0.553860 -1.003682 -0.890229 0.904524 -0.308336 0.068724 0.062182 0.006687 1.325765 1.325800
185 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.410860 0.478995 2.874275 1.161856 1.023023 -0.356693 -0.699643 -1.308195 0.049365 0.051354 0.003091 1.284492 1.288661
186 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.335257 -0.172863 2.821331 1.615465 -0.106791 -0.608841 7.648389 0.088977 0.078015 0.069587 0.010840 0.910998 0.909893
187 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.302797 0.733593 -0.197848 0.888848 -0.610332 -0.629141 14.259845 11.447781 0.092567 0.086364 0.019590 0.000000 0.000000
189 N15 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
190 N15 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
191 N15 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
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% 100.00% 100.00% 0.00% 100.00% 0.00% 9.997320 5.701697 16.442129 -0.032656 21.342308 10.763783 56.568827 79.507080 0.049030 0.043913 0.003224 0.000000 0.000000
206 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 4.210088 6.763426 -0.364970 10.856207 6.861196 12.864683 52.186741 53.125400 0.049662 0.043888 0.004451 0.000000 0.000000
207 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 12.176126 8.944152 19.948293 16.316951 27.332616 25.880955 21.085373 18.522057 0.053267 0.053586 0.004980 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% 10.865156 9.332722 74.467652 78.087234 2514.876841 2957.730346 18448.556183 25264.569841 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 5.976002 8.380994 9.020557 15.508477 9.837229 35.978466 0.525349 2.475400 0.042278 0.054019 0.002543 0.000000 0.000000
224 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.344352 17.020466 31.006532 30.027462 43.711758 42.278125 -7.577999 -8.019557 0.062107 0.063048 0.006289 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% 10.345725 12.112099 96.963869 89.907015 3446.448534 3529.783144 30201.329481 30195.058153 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 27.023367 25.562891 28.998475 29.602703 45.218450 45.407663 16.892927 10.888965 0.058661 0.052690 0.003147 0.000000 0.000000
321 N02 not_connected 100.00% 0.00% 15.04% 0.00% 100.00% 0.00% 7.800195 5.897950 16.191564 14.372795 23.963678 20.345497 61.001713 58.956873 0.645370 0.489449 0.434905 0.000000 0.000000
323 N02 not_connected 100.00% 36.09% 24.70% 0.00% 100.00% 0.00% 26.020076 9.034577 1.072141 18.917019 22.272514 25.081854 8.785181 1.327349 0.464402 0.467076 0.337240 0.000000 0.000000
324 N04 not_connected 100.00% 0.54% 19.33% 0.00% 100.00% 0.00% 11.876815 12.598367 21.761038 22.218575 30.318196 30.511390 2.625195 -0.209349 0.640983 0.484620 0.422426 0.000000 0.000000
329 N12 dish_maintenance 100.00% 12.35% 29.54% 0.00% 100.00% 0.00% 3.339925 4.995415 3.255062 13.763017 45.749513 18.367309 10.501700 -0.419074 0.558296 0.435039 0.378270 0.000000 0.000000
333 N12 dish_maintenance 100.00% 29.54% 43.50% 0.00% 100.00% 0.00% 3.933949 5.248651 -0.799997 12.790748 11.389121 16.788953 3.943437 3.069755 0.517967 0.413470 0.359685 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: [4, 5, 7, 8, 9, 15, 16, 18, 19, 20, 27, 28, 30, 31, 32, 33, 36, 37, 38, 41, 45, 46, 50, 52, 53, 54, 55, 56, 57, 65, 66, 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, 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, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 177, 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: [3, 10, 17, 21, 29, 40, 42, 51, 67, 116, 158, 176, 178]

golden_ants: [3, 10, 17, 21, 29, 40, 42, 51, 67, 116, 158, 176, 178]
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_2459806.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.3.dev44+g7d4aa18
3.1.4.dev3+g68bd8c3
In [ ]: