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 = "2459829"
data_path = "/mnt/sn1/2459829"
ant_metrics_ext = ".ant_metrics.hdf5"
redcal_ext = ".known_good.omni.calfits"
nb_outdir = "/home/obs/src/H6C_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: 9-6-2022
In [5]:
# Per-season options
def ant_to_report_url(ant):
    return f'https://htmlpreview.github.io/?https://github.com/HERA-Team/H6C_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/2459829/zen.2459829.25311.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/2459829/zen.2459829.?????.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 153 ant_metrics files matching glob /mnt/sn1/2459829/zen.2459829.?????.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 2459829
Date 9-6-2022
LST Range 18.556 -- 4.577 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 N09, N18
Nodes Not Correlating N02, N04
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 74 / 147 (50.3%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 121 / 147 (82.3%)
Redcal Done? ✅
Redcal Flagged Antennas 9 / 147 (6.1%)
Never Flagged Antennas 8 / 147 (5.4%)
A Priori Good Antennas Flagged 89 / 95 total a priori good antennas:
3, 5, 7, 9, 10, 15, 16, 17, 19, 20, 21, 29,
30, 31, 37, 38, 40, 41, 42, 45, 46, 51, 53,
54, 55, 56, 65, 66, 67, 68, 69, 71, 72, 73,
81, 83, 84, 85, 86, 88, 91, 93, 94, 98, 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, 158, 160, 161,
162, 165, 167, 169, 170, 176, 177, 178, 179,
181, 183, 185, 186, 187, 189, 190, 191
A Priori Bad Antennas Not Flagged 2 / 52 total a priori bad antennas:
82, 135
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/H6C_Notebooks/_rtp_summary_/array_health_table_2459829.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 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.136659 -1.166878 -0.424100 -0.634728 1.242542 -0.685451 0.050673 4.663183 0.729300 0.632494 0.436715 inf inf
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.553483 7.027887 1.015237 1.667639 3.505067 0.602102 2.176082 -0.514601 0.742299 0.625007 0.442660 62.766421 35.376029
5 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.699793 0.614772 1.057750 4.161099 4.274179 1.347159 1.158616 -1.086933 0.740997 0.634406 0.443420 51.479384 36.542062
7 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.704266 -1.890707 -0.164774 -0.491524 0.143087 0.228500 3.283286 29.713488 0.061611 0.063796 0.009136 19.151250 12.037044
8 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 8.704247 9.904925 21.115828 21.877220 17.904970 21.030198 5.815049 -4.488470 0.090076 0.084161 0.010628 43.023015 23.018940
9 N02 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.311469 -2.148696 0.360482 -0.508341 1.090141 0.191111 -0.286092 0.302423 0.079545 0.063700 0.007329 46.821467 33.017590
10 N02 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.231626 -1.163740 -0.807659 -0.140742 0.797843 0.605320 2.287715 3.247062 0.089290 0.071754 0.012323 36.312933 30.211786
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 99.35% 0.850048 1.481534 1.626675 0.628049 -0.756527 1.680408 0.311472 2.711252 0.746039 0.637374 0.434666 5.812405 1.824813
16 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.478250 0.181846 -0.555954 -0.439591 0.162767 1.134113 5.928143 5.462129 0.751414 0.639725 0.437098 22.035343 12.696388
17 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.043539 2.028695 0.713378 0.528685 -0.097261 -0.346147 6.416193 4.594362 0.737806 0.632025 0.438783 26.461982 18.745434
18 N01 RF_maintenance 100.00% 0.00% 81.10% 0.00% 100.00% 0.00% 22.742231 29.693569 0.473306 0.328919 25.893616 9.521046 167.485811 109.975523 0.664846 0.361185 0.483625 9.904555 6.866045
19 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.248092 -1.193629 1.922742 0.535224 3.829092 4.662891 34.019845 28.999335 0.047739 0.058291 0.005771 27.351713 18.525388
20 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -3.133968 5.407693 0.081746 -0.197301 0.541674 0.071833 2.311848 0.662210 0.064506 0.059803 0.005342 38.472454 20.084753
21 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.026870 -1.880146 1.095492 1.134229 0.947640 11.543057 4.316912 15.585586 0.079043 0.068595 0.010105 33.447843 19.745371
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 29.717577 33.899539 29.288380 30.220037 28.785888 31.822004 9.946328 7.080164 0.039235 0.043200 0.002395 1.116852 1.112361
28 N01 RF_maintenance 100.00% 52.09% 100.00% 0.00% 100.00% 0.00% 31.283539 64.397130 0.413847 2.205594 14.211468 18.799982 10.486719 61.246613 0.376889 0.149273 0.246415 1.105670 1.101224
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 75.82% 24.18% -1.302913 -1.946102 -0.213190 -0.145999 -0.946912 -1.381105 0.010411 0.226938 0.746968 0.638575 0.436391 1.107111 1.097755
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.630690 -0.514255 0.378077 -0.369303 -0.439570 -0.031398 31.627271 2.340068 0.739470 0.638088 0.439395 0.900616 0.898108
31 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.449159 -1.827647 -0.006157 1.162414 3.592254 5.253950 4.816451 5.037266 0.081499 0.088866 0.017877 1.272835 1.285809
32 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 59.902570 22.803635 2.244033 1.400890 11.698670 25.821387 74.503435 105.353687 0.096003 0.086019 0.009949 0.000000 0.000000
33 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.258748 24.049209 2.744191 1.454863 50.543811 44.889318 529.934265 487.644568 0.067765 0.097401 0.030501 -0.000000 -0.000000
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 21.218160 15.506743 0.000109 -0.275395 2.881206 1.431390 1.679626 2.186121 0.766739 0.661746 0.412062 35.035553 22.350227
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.980440 2.119847 1.057259 0.701528 -0.598020 -0.516678 1.096330 41.648591 0.766126 0.669971 0.408297 30.020803 24.674382
38 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.227257 0.195695 0.083633 -0.367059 2.939268 6.348236 13.930166 6.758382 0.766511 0.669711 0.417241 26.316628 20.846894
40 N04 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.556188 -0.238219 0.074968 -0.405593 -0.223252 -1.032502 0.580840 -0.929360 0.080222 0.088336 0.014970 40.425205 20.658126
41 N04 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.652703 0.394626 2.563777 1.136700 1.831691 -1.551024 -0.574215 -1.181218 0.050619 0.083712 0.007406 39.435717 24.325847
42 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.078622 4.414393 1.421906 0.913535 -0.806385 0.211464 0.977025 0.269644 0.088698 0.100467 0.017212 44.532430 29.535897
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.305120 2.334292 -0.073563 0.242086 1.306643 3.606556 1.026370 72.763894 0.738022 0.621261 0.451429 0.000000 0.000000
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 92.16% 7.19% -1.510065 -0.108924 -0.572812 -0.673325 1.337229 -0.698660 0.693861 0.704559 0.732977 0.624338 0.457395 -0.000000 -0.000000
50 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 24.973465 5.015949 0.426221 2.404543 3.395058 1.601751 7.397752 0.426651 0.741608 0.672363 0.370617 23.440555 14.370476
51 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.354073 5.339917 -0.423978 -0.611432 0.361023 1.751567 1.387081 4.319885 0.769033 0.683453 0.394156 20.661594 18.035679
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 16.061188 14.063229 3.177883 0.211435 8.988212 -0.553395 5.505592 2.048000 0.770692 0.684283 0.393819 16.508811 14.445772
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.883869 4.487640 -0.763500 0.207928 -0.151530 -0.884935 8.484933 17.226394 0.768883 0.682239 0.405140 6.943204 8.044259
54 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.887994 35.378165 1.133631 1.168500 0.949517 4.816593 1.734312 2.038527 0.093954 0.102056 0.017908 34.971879 22.095003
55 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.953196 5.354521 0.133820 0.680861 8.985363 -0.970833 7.341387 0.164093 0.068880 0.065694 0.006512 71.642859 38.446961
56 N04 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.143091 1.990655 0.918462 0.704343 -0.076485 1.470372 0.344597 -0.823391 0.049173 0.056374 0.003870 49.556684 38.193254
57 N04 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 63.536297 0.093389 10.764298 0.319359 14.447397 -0.272346 14.994163 6.959132 0.109374 0.079014 0.023185 12.614907 24.542665
65 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.121926 1.678685 3.395589 0.889498 6.448648 1.880517 1.340321 3.022060 0.761371 0.678424 0.405865 16.884646 12.527787
66 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.043141 3.293751 -0.546713 1.136572 0.869699 2.313590 0.972199 5.673217 0.770519 0.690982 0.387147 13.949290 11.799677
67 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.359704 -0.476589 -0.605658 -0.980899 2.303330 0.507167 3.494888 8.380084 0.771544 0.696569 0.377537 17.505768 15.202540
68 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.596359 2.042374 3.085392 4.858339 14.403664 17.915248 3.449397 11.330341 0.764995 0.689014 0.375427 20.439425 17.340923
69 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.381977 -0.556269 -0.810677 0.038499 2.349237 1.689385 1.862574 8.103281 0.100849 0.101688 0.022643 1.075944 1.079068
70 N04 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 14.999299 -2.182727 -0.266502 -0.834072 10.225175 1.853197 1.766844 3.442189 0.074737 0.068460 0.008301 0.934302 0.924239
71 N04 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.001709 0.001709 -0.905252 -0.717591 -0.044571 1.639768 0.380920 0.969846 0.086448 0.081272 0.012827 -0.000000 -0.000000
72 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.729247 -0.271854 -0.631210 0.825063 1.512398 0.555522 7.736295 -0.995937 0.079230 0.070870 0.011128 6.216159 10.771415
73 N05 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 26.813804 1.441966 28.680898 0.250282 28.597988 15.644194 4.525425 3.182383 0.034650 0.642322 0.369781 0.000000 0.000000
81 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.272043 2.361848 -0.739230 4.073973 1.209317 3.385381 1.816421 -0.259877 0.744025 0.670324 0.407498 8.478023 7.080784
82 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.415672 0.694852 1.763229 0.272775 0.583046 -0.027267 -1.008693 -1.256019 0.756591 0.681356 0.395750 12.992428 8.446682
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.461122 1.515704 1.845289 4.424291 -0.983373 -0.246316 -0.065852 -0.945488 0.767541 0.701233 0.384747 8.242352 8.135374
84 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.762379 20.770730 1.729179 0.996610 11.286684 0.800048 0.273621 0.794915 0.770010 0.702385 0.374433 7.016006 8.908049
85 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.65% 75.82% 0.018479 0.122469 1.043228 1.431996 -0.203692 -0.540061 -0.097247 -0.656496 0.754078 0.684693 0.390478 inf inf
86 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.663327 12.982525 -0.720383 -0.078496 10.204960 2.901369 1.953404 0.189436 0.754162 0.656769 0.399064 11.414523 12.058478
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 12.042437 21.011945 3.466695 1.322287 26.256180 -0.017152 15.415779 2.612669 0.731969 0.688232 0.382705 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 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 84.974618 101.229852 3.137456 4.486266 16.356608 19.291581 3.547780 15.008535 0.271434 0.206166 0.102771 6.762776 6.330348
93 N10 digital_ok 100.00% 0.00% 0.54% 0.00% 100.00% 0.00% 0.549366 -0.232742 4.066331 0.296638 2.754107 -0.851814 6.479326 -0.576738 0.663151 0.576657 0.414058 5.126944 4.715735
94 N10 digital_ok 100.00% 0.00% 1.61% 0.00% 100.00% 0.00% -2.043486 -1.021965 0.060251 -0.396546 0.012244 1.808906 5.855955 13.544735 0.660677 0.556950 0.418653 12.210351 8.188964
98 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.804069 53.377554 1.432529 2.050138 9.653216 13.924766 3.475260 12.638944 0.731753 0.635883 0.392633 15.203077 19.777291
99 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 2.545127 0.031435 2.814840 -0.785486 1.687026 2.404517 0.465971 -0.949577 0.754661 0.676550 0.402517 1.138686 1.023828
100 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.176256 -0.912725 0.637542 -0.096475 2.286300 -0.358074 0.135204 -0.352137 0.761808 0.686287 0.395784 0.980845 0.848467
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 18.294091 19.065974 2.784474 0.907671 -0.406692 2.840288 25.380328 1.590994 0.777120 0.702617 0.382413 7.747039 7.710751
102 N08 RF_maintenance 100.00% 0.00% 0.54% 0.00% 100.00% 0.00% 35.526916 34.909687 3.062913 2.547840 434.131516 431.593267 15833.635311 15727.446451 0.651792 0.540528 0.376336 0.000000 0.000000
103 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.347570 18.417985 0.203636 -0.196887 3.054448 1.270966 0.883899 1.253408 0.769403 0.693931 0.384812 11.139481 10.372936
104 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.581037 137.869936 1.328637 11.550778 5.566084 0.667233 3.468173 -0.248636 0.764816 0.688530 0.404608 18.292168 35.504780
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% 0.00% 0.00% 0.00% 0.65% 99.35% 0.980410 -0.070953 -0.312226 0.708690 -0.937996 -1.095363 -0.468835 -0.605490 0.684466 0.591644 0.420671 14.892859 14.887592
110 N10 RF_maintenance 100.00% 6.44% 15.57% 0.00% 100.00% 0.00% 62.753237 62.922491 2.294377 1.733154 7.177482 11.274513 0.614894 3.485840 0.570099 0.491123 0.252082 13.308760 11.740498
111 N10 digital_ok 0.00% 0.00% 0.54% 0.00% 0.65% 0.00% 0.428095 3.062358 -0.027876 0.955194 0.234586 0.779604 -0.189923 3.567716 0.671142 0.577266 0.413923 1.106396 0.970673
112 N10 digital_ok 0.00% 0.00% 1.61% 0.00% 0.65% 0.00% -0.238478 0.080341 -0.294787 0.675657 -0.476476 0.565873 -0.471302 -1.560556 0.658527 0.571364 0.425654 1.051752 0.994064
116 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.65% 0.00% -0.342658 2.918011 -0.175594 -0.785936 0.474671 3.526187 2.644515 -0.774819 0.730402 0.658463 0.418236 0.818972 0.610881
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.640250 0.849415 5.249329 5.302716 1.981477 0.600922 -0.513071 -1.526467 0.754137 0.681860 0.413884 13.573597 16.474962
118 N07 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 5.127107 38.310607 1.697722 25.318606 -0.749940 32.997746 1.583298 0.753700 0.757984 0.050118 0.458651 17.085589 1.349106
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.147641 1.225407 9.304529 0.283866 3.371766 -0.167985 -1.106543 0.229384 0.773998 0.688944 0.402676 10.120122 7.295037
120 N08 RF_maintenance 100.00% 36.52% 100.00% 0.00% 100.00% 0.00% 32.422213 55.887080 0.794248 34.252447 15.736303 32.119739 5.226570 16.978694 0.427627 0.045340 0.289607 6.741644 1.064753
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.768559 11.164460 -0.607257 3.466552 1.359832 5.026227 106.883623 45.887998 0.779663 0.705649 0.386238 0.000000 0.000000
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 16.948846 13.365645 0.524485 1.150128 1.645627 -0.527269 1.148417 0.515199 0.777730 0.703593 0.391195 -0.000000 -0.000000
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.560208 16.929082 0.489177 2.546355 0.134958 4.440897 0.566736 0.333041 0.773773 0.699199 0.399085 9.965225 24.074205
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 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.835193 -0.446342 0.092521 -0.437171 0.251197 0.111736 5.258446 2.624562 0.682597 0.602472 0.419041 5.028418 5.119571
128 N10 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.855415 8.909812 0.185143 1.762505 0.092037 3.240444 1.542590 -0.310421 0.681162 0.589757 0.415613 9.326170 13.706101
129 N10 digital_ok 0.00% 0.00% 0.54% 0.00% 0.65% 0.00% -0.613957 -1.734322 -0.447592 -0.472691 0.300806 -0.024275 -0.366816 -0.373377 0.675690 0.585718 0.419216 1.187391 0.958513
130 N10 digital_ok 100.00% 0.00% 0.54% 0.00% 100.00% 0.00% 2.515825 -0.013387 0.368211 1.137683 0.958247 0.064000 1.625469 10.454150 0.656818 0.570828 0.417940 17.699214 19.032031
135 N12 digital_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.327892 0.697708 -0.933558 -0.901711 0.024275 0.408488 0.947434 -0.282335 0.672805 0.597237 0.400870 8.092853 6.742973
136 N12 digital_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.747786 19.169866 -0.754372 0.230828 1.444136 1.176032 4.516228 8.554994 0.682577 0.591146 0.383339 7.580894 6.562743
137 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.120143 -0.681242 14.942373 -0.548944 12.623561 45.063343 1.446221 9.958486 0.757369 0.667393 0.419105 0.000000 0.000000
138 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.615762 0.930731 3.188505 0.864952 37.055277 3.664983 3.092266 -0.586977 0.764799 0.680642 0.416366 0.000000 0.000000
140 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.287151 32.167252 28.494336 30.288581 28.738823 31.839754 3.258565 3.243401 0.039931 0.043711 0.001912 0.000000 0.000000
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.710150 5.623689 2.657248 6.762318 11.336877 1.324904 5.886479 47.253044 0.758647 0.669854 0.391622 0.000000 0.000000
142 N13 digital_ok 100.00% 30.08% 100.00% 0.00% 100.00% 0.00% 51.675096 40.359856 1.361335 30.437867 15.343505 31.843730 5.770636 6.520201 0.441056 0.044766 0.234080 -0.000000 -0.000000
143 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 99.35% 1.098176 -0.654129 1.142783 0.576182 0.712272 -1.207323 -0.190796 -1.080284 0.760417 0.701807 0.400501 31.250365 5.744279
144 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.324587 -0.724137 0.662954 -0.227785 3.877989 2.028785 0.838115 20.877046 0.762436 0.688289 0.414678 0.000000 0.000000
145 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 29.973045 33.880626 29.486145 30.728641 28.960016 32.126804 7.732048 10.585756 0.035436 0.036022 -0.000231 0.000000 0.000000
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 33.430372 38.529864 29.355043 31.440418 28.976383 32.065284 9.304355 9.904118 0.044796 0.045036 0.000742 0.000000 0.000000
155 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 28.676620 30.549573 28.595871 29.969735 28.579406 31.866893 9.375689 8.853993 0.039123 0.034875 0.001559 1.227630 1.180914
156 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.352879 0.232418 0.876645 -0.253642 -0.140515 0.701644 3.708576 32.507356 0.685495 0.593702 0.395594 16.139110 20.148276
157 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.65% 99.35% -0.787942 0.102340 0.404665 2.561647 0.080083 -0.829704 1.176486 0.692486 0.690488 0.606754 0.394229 -0.000000 -0.000000
158 N12 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 28.549416 -2.432715 29.238714 -0.138600 29.175813 1.153705 3.723308 5.399819 0.038352 0.621397 0.327936 1.166497 47.578462
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 29.141939 32.805982 29.091690 30.341797 28.917374 32.019344 8.573902 10.410573 0.042230 0.044515 0.001523 inf inf
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.534655 67.837109 -0.574766 2.670522 -0.851723 7.016131 1.660569 -0.419870 0.763570 0.577374 0.390249 15.558675 11.754189
162 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.577627 1.619915 -0.440953 -0.820541 2.386211 -0.121737 3.239134 0.842534 0.766756 0.690220 0.404595 7.913262 8.255253
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.591502 -0.483318 0.374213 -0.833291 -0.778491 0.628998 -0.292609 2.866453 0.765310 0.692740 0.405483 0.999127 0.865650
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.591805 -1.744314 -1.013155 -0.613822 -0.998354 -0.444845 1.132919 3.860297 0.761248 0.688344 0.411342 1.266030 1.045948
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.004122 1.050590 5.506038 -0.875040 1.376307 -0.656178 3.665435 4.753793 0.763451 0.682644 0.415541 11.607440 13.630972
166 N14 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 52.275603 20.601806 1.323468 0.822722 8.884726 12.144342 7.799717 23.306692 0.671473 0.630892 0.367802 0.000000 0.000000
167 N15 digital_ok 100.00% 6.98% 4.83% 0.00% 100.00% 0.00% 39.917092 34.851708 20.498451 21.522425 25.979905 23.518532 20.898287 14.388688 0.569860 0.505211 0.230569 2.131586 1.862610
168 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
169 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
170 N15 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 527.888624 528.153479 inf inf 7557.200320 7651.921300 19793.169681 20625.073114 nan nan nan 0.000000 0.000000
176 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.65% 99.35% 1.049615 -0.460621 -0.909602 0.223768 -0.493882 0.513220 -0.010411 3.177897 0.674696 0.581702 0.411551 6.713401 28.812654
177 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.840611 1.971398 0.335841 1.533304 0.193840 17.618547 2.866324 18.062466 0.683869 0.580667 0.406968 -0.000000 -0.000000
178 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 1.31% 98.69% -0.326691 -1.299330 1.070919 -0.126906 -1.487336 -0.281466 0.147375 -1.037213 0.689027 0.604327 0.405755 -0.000000 -0.000000
179 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.714255 2.195250 -0.417459 0.088382 3.693709 -1.706710 10.711215 -0.868631 0.697343 0.612594 0.407770 8.797915 5.291812
180 N13 RF_maintenance 100.00% 0.00% 88.18% 0.00% 100.00% 0.00% 1.551241 28.714922 0.052335 29.015137 -0.342044 26.307828 1.163995 7.269553 0.762260 0.324683 0.545307 10.528193 4.968810
181 N13 digital_ok 100.00% 100.00% 98.93% 0.00% 100.00% 0.00% 30.790504 98.235320 29.600012 8.540334 28.972621 22.676954 7.744878 12.046667 0.043108 0.266990 0.116459 1.054754 1.881540
182 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.732104 11.121478 21.218625 19.006246 16.754160 6.986638 -5.444980 62.718553 0.761363 0.591152 0.455559 8.696794 6.049350
183 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -2.431303 -1.314014 0.185752 -0.837149 -1.244915 -0.642100 0.136268 25.845549 0.760542 0.677122 0.416596 13.242711 15.844296
184 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.65% 0.00% 0.752784 -0.615372 0.027876 0.787924 0.650322 -0.275879 2.891889 -0.269991 0.759219 0.678127 0.409604 0.839409 0.648226
185 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.419630 -0.171169 1.229882 0.907525 -1.232141 -1.117167 24.191036 -0.876092 0.764476 0.676700 0.417819 13.515691 14.847181
186 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.895209 -0.926024 2.973084 1.766975 2.294444 -0.617538 10.635940 0.071964 0.750709 0.669111 0.421557 0.000000 0.000000
187 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.217369 2.141575 0.314203 0.502404 -0.259736 -1.009658 7.222698 3.435065 0.746746 0.672510 0.422752 0.000000 0.000000
189 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.995157 5.076919 0.915698 0.155355 0.795978 1.339233 2.209296 13.726266 0.731253 0.644730 0.450497 0.000000 0.000000
190 N15 digital_ok 100.00% 11.82% 100.00% 0.00% 100.00% 0.00% 99.097545 39.078679 3.766669 30.707748 18.167801 32.183343 10.562182 8.733263 0.528321 0.042052 0.352713 0.000000 0.000000
191 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.881757 0.901645 -0.361618 1.645440 -0.117259 3.073897 5.295244 11.520639 0.726997 0.631553 0.473593 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% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
206 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
207 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 31.357030 30.953119 16.744631 13.523186 13.891978 12.577769 33.543810 33.949507 0.713139 0.619246 0.430114 26.510583 27.102934
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% 60.765330 60.695878 inf inf 3876.178287 3878.047972 31987.671086 31986.370291 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 30.283107 29.633971 7.225815 14.713322 1.418887 7.000411 -0.157390 -2.328024 0.715433 0.621640 0.440722 0.000000 0.000000
224 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 36.316951 35.272176 26.683517 25.960524 27.321841 29.123855 -9.297019 -10.125019 0.688348 0.588744 0.434741 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% 60.466071 60.389495 inf inf 3871.898934 3872.438703 31973.710255 31976.720790 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 40.618095 37.978538 18.798716 19.234986 28.388504 31.744966 15.844092 9.663066 0.054496 0.051154 0.002988 0.000000 0.000000
321 N02 not_connected 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.340787 1.967578 13.945892 12.424933 13.555295 11.409961 77.904123 77.808417 0.099397 0.088488 0.041979 0.000000 0.000000
323 N02 not_connected 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 49.218564 4.999326 1.549994 16.359061 14.653178 13.411595 5.854413 0.857758 0.085944 0.090579 0.036409 0.000000 0.000000
324 N04 not_connected 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 8.044607 5.587497 17.975386 11.389339 11.888346 7.504183 -0.636125 3.367454 0.103422 0.091075 0.044890 0.000000 0.000000
329 N12 dish_maintenance 100.00% 20.41% 17.72% 0.00% 100.00% 0.00% 12.015084 0.871071 0.198617 11.721894 11.887397 9.250214 8.450069 -1.094299 0.539994 0.498411 0.407156 0.000000 0.000000
333 N12 dish_maintenance 100.00% 25.24% 23.09% 0.00% 100.00% 0.00% 11.871114 2.530220 0.106822 10.847892 9.982580 8.558435 7.882280 1.674087 0.527694 0.481924 0.398214 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, 65, 66, 67, 68, 69, 70, 71, 72, 73, 81, 82, 83, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 98, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 116, 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130, 135, 136, 137, 138, 140, 141, 142, 143, 144, 145, 150, 155, 156, 157, 158, 160, 161, 162, 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: [99, 100, 163, 164]

golden_ants: [99, 100, 163, 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/H6C_Notebooks/_rtp_summary_/rtp_summary_table_2459829.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.dev47+ga570afb
3.1.4.dev14+g122e1cb
In [ ]: