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 = "2459828"
data_path = "/mnt/sn1/2459828"
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-5-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/2459828/zen.2459828.25316.sum.auto_metrics.h5.

Load Ant Metrics¶

In [7]:
use_ant_metrics = False

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

# if they exist, load as many of them as possible
if len(ant_metrics_files) > 0:
    print(f'Found {len(ant_metrics_files)} ant_metrics files matching glob {glob_str}')
    ant_metrics_apriori_exants = {}
    ant_metrics_xants_dict = {}
    ant_metrics_dead_ants_dict = {}
    ant_metrics_crossed_ants_dict = {}
    ant_metrics_dead_metrics = {}
    ant_metrics_crossed_metrics = {}
    dead_cuts = {}
    crossed_cuts = {}
    for amf in ant_metrics_files:
        with h5py.File(amf, "r") as infile: # use h5py directly since it's much faster than load_metric_file
            # get out results for this file
            dead_cuts[amf] = infile['Metrics']['dead_ant_cut'][()]
            crossed_cuts[amf] = infile['Metrics']['cross_pol_cut'][()]
            xants = infile['Metrics']['xants'][:]
            dead_ants = infile['Metrics']['dead_ants'][:]
            crossed_ants = infile['Metrics']['crossed_ants'][:]        
            try:
                # look for ex_ants in history
                ex_ants_string = infile['Header']['history'][()].decode()
                ex_ants_string = ex_ants_string.split('--apriori_xants')[1]
                ex_ants_string = ex_ants_string.split('--')[0].strip()
            except:
                ex_ants_string = ''
                    
            # This only works for the new correlation-matrix-based ant_metrics
            if 'corr' in infile['Metrics']['final_metrics'] and 'corrXPol' in infile['Metrics']['final_metrics']:
                ant_metrics_dead_metrics[amf] = {eval(ant): infile['Metrics']['final_metrics']['corr'][ant][()]
                                                 for ant in infile['Metrics']['final_metrics']['corr']}
                ant_metrics_crossed_metrics[amf] = {eval(ant): infile['Metrics']['final_metrics']['corrXPol'][ant][()]
                                                    for ant in infile['Metrics']['final_metrics']['corrXPol']}                       
            else:
                raise(KeywordError)
        
        # organize results by file
        ant_metrics_xants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in xants]
        ant_metrics_dead_ants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in dead_ants]
        ant_metrics_crossed_ants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in crossed_ants]
        ant_metrics_apriori_exants[amf] = [int(ant) for ant in ex_ants_string.split()]
    
    dead_cut = np.median(list(dead_cuts.values()))
    crossed_cut = np.median(list(crossed_cuts.values()))
        
    use_ant_metrics = True
else:
    print(f'No files found matching glob {glob_str}. Skipping ant_metrics.')
Found 372 ant_metrics files matching glob /mnt/sn1/2459828/zen.2459828.?????.sum.ant_metrics.hdf5

Load chi^2 info from redcal¶

In [8]:
use_redcal = False
glob_str = os.path.join(data_path, f'zen.{JD}.?????.sum{redcal_ext}')

redcal_files = sorted(glob.glob(glob_str))
if len(redcal_files) > 0:
    print(f'Found {len(redcal_files)} ant_metrics files matching glob {glob_str}')
    post_redcal_ant_flags_dict = {}
    flagged_by_redcal_dict = {}
    cspa_med_dict = {}
    for cal in redcal_files:
        hc = io.HERACal(cal)
        _, flags, cspa, chisq = hc.read()
        cspa_med_dict[cal] = {ant: np.nanmedian(cspa[ant], axis=1) for ant in cspa}

        post_redcal_ant_flags_dict[cal] = {ant: np.all(flags[ant]) for ant in flags}
        # check history to distinguish antennas flagged going into redcal from ones flagged during redcal
        tossed_antenna_lines =  hc.history.replace('\n','').split('Throwing out antenna ')[1:]
        flagged_by_redcal_dict[cal] = sorted([int(line.split(' ')[0]) for line in tossed_antenna_lines])
        
    use_redcal = True
else:
    print(f'No files found matching glob {glob_str}. Skipping redcal chisq.')
Found 38 ant_metrics files matching glob /mnt/sn1/2459828/zen.2459828.?????.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 2459828
Date 9-5-2022
LST Range 18.491 -- 20.491 hours
X-Engine Status ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
Number of Files 372
Total Number of Antennas 147
OPERATIONAL STATUS SUMMARY
Antenna A Priori Status Count dish_maintenance: 3
RF_maintenance: 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 N02, N04
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 61 / 147 (41.5%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 112 / 147 (76.2%)
Redcal Done? ✅
Redcal Flagged Antennas 6 / 147 (4.1%)
Never Flagged Antennas 22 / 147 (15.0%)
A Priori Good Antennas Flagged 75 / 95 total a priori good antennas:
7, 9, 10, 16, 17, 19, 20, 21, 30, 31, 37, 38,
40, 41, 42, 45, 46, 53, 54, 55, 56, 65, 66,
68, 69, 71, 72, 73, 81, 84, 86, 88, 91, 98,
99, 101, 103, 105, 106, 107, 108, 111, 116,
117, 118, 121, 122, 123, 130, 140, 141, 142,
143, 144, 156, 158, 160, 161, 163, 164, 165,
167, 169, 170, 176, 177, 179, 181, 183, 184,
186, 187, 189, 190, 191
A Priori Bad Antennas Not Flagged 2 / 52 total a priori bad antennas:
90, 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_2459828.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.682368 -0.508153 -0.662242 -0.279927 -0.237386 -0.874803 -0.671637 1.102550 0.783406 0.513414 0.566486 1.711929 1.442925
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.184153 5.331611 -0.878511 1.891111 -0.452021 -0.726821 6.142774 1.106254 0.799673 0.510352 0.572385 6.665361 8.860879
5 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.183287 0.099455 -0.840915 3.430280 -1.127894 1.114726 0.331137 -2.640210 0.802282 0.519480 0.576681 1.626886 1.460876
7 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.534263 -0.946048 0.003253 -0.483329 0.004711 0.762367 4.706579 42.021504 0.059284 0.070430 0.014360 1.312584 1.304109
8 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 10.770088 12.593488 16.120606 16.560479 25.522193 24.804059 1.072393 -2.189615 0.102391 0.084468 0.012392 1.151943 1.155751
9 N02 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.429017 -0.878098 0.649131 -0.772724 -0.739264 -0.530625 -0.001930 -0.271457 0.070403 0.054942 0.004821 19.170608 21.727650
10 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.617837 -0.490914 -0.482961 -0.036162 4.163129 3.638256 29.765854 27.160405 0.084494 0.063437 0.008873 12.467905 8.747301
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.098196 1.643322 1.488373 0.654657 -0.092920 -0.186222 0.725187 3.888141 0.800145 0.520235 0.568113 1.770503 1.485636
16 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.765583 -0.601481 -0.705208 -0.546092 -0.817320 0.147497 5.815147 12.592008 0.801898 0.526867 0.562641 5.170435 5.916994
17 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.270494 0.723198 0.534845 0.741403 0.585891 0.522696 6.120552 6.902170 0.803614 0.522729 0.575925 4.978292 5.051602
18 N01 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 11.625579 14.176884 0.004151 0.414713 21.705207 7.995045 480.738480 206.359302 0.742640 0.275976 0.597728 3.174876 2.112981
19 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.959438 1.065092 -0.653295 6.324351 -0.248794 27.539046 28.735900 11.050499 0.057879 0.067551 0.011135 1.281621 1.257556
20 N02 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.409534 1.400766 -0.200329 -0.720344 0.788679 0.409943 0.250721 -0.641273 0.070296 0.057465 0.005098 1.140409 1.130011
21 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.973554 -0.565739 0.456384 1.290962 -0.263760 0.326828 2.719809 11.018822 0.073474 0.059460 0.006787 14.252112 21.703165
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.348217 28.808751 31.548592 32.333994 36.695343 33.153678 14.655764 11.852638 0.038769 0.043015 0.002939 1.280716 1.288200
28 N01 RF_maintenance 100.00% 32.26% 100.00% 0.00% 100.00% 0.00% 16.786313 35.123930 0.237935 2.228143 26.419989 27.118276 10.532015 158.858357 0.418549 0.163180 0.286109 8.158640 2.778998
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.121534 -0.484507 0.000406 -0.002064 -0.852459 -0.659971 -0.503141 0.544269 0.806884 0.527980 0.569398 1.564083 1.511696
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.371793 -0.229500 -0.181119 -0.077978 -0.317467 0.094005 14.513027 1.803096 0.798594 0.526080 0.568906 4.711004 4.233313
31 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.734187 -0.958822 -0.433519 1.372845 1.419545 1.782223 5.000282 2.806009 0.076281 0.086624 0.020267 1.165025 1.167826
32 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 50.657228 0.052921 2.534774 2.545347 8.399044 5.958020 53.846806 41.172779 0.093486 0.083374 0.013812 0.939388 0.929780
33 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.197193 9.774033 0.906625 -0.278314 32.250918 29.828482 277.936963 293.875855 0.054297 0.092927 0.037255 14.127906 8.007195
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 12.488536 9.188533 -0.032083 -0.313139 2.050127 -0.141140 1.430899 2.525041 0.801702 0.539438 0.548401 4.578186 3.378252
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.716983 1.586791 0.093236 0.551624 -0.764048 -0.444479 0.386254 35.774621 0.810424 0.551385 0.546049 5.629180 3.959219
38 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.427979 -0.386898 -0.127629 -0.171086 1.031998 0.374083 18.271422 6.967025 0.809137 0.555013 0.549949 9.227733 5.048105
40 N04 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.698139 -0.155548 0.206029 -0.109481 1.764587 0.475484 0.469414 -0.819052 0.074557 0.094783 0.018753 1.273287 1.274489
41 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.139941 -0.496282 2.377872 1.402866 4.469710 -0.877929 -0.641480 1.925892 0.040605 0.079920 0.012119 1.230702 1.228936
42 N04 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.517864 0.853057 1.507593 1.129695 -0.151897 -0.278920 -0.435354 -0.473184 0.092640 0.087810 0.021446 1.228978 1.212900
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.169639 0.988667 -0.149323 0.624699 1.914056 0.315033 1.021389 22.031588 0.796750 0.507959 0.580188 3.378966 2.386230
46 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.086278 -0.261767 -0.309252 -0.413490 0.098044 0.300081 0.680272 6.783467 0.797564 0.497147 0.593924 2.802278 2.032128
50 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.440263 3.919042 0.771658 1.827799 0.258114 0.366697 5.874430 -0.537832 0.760601 0.555392 0.476261 5.939379 5.022713
51 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 2.110460 2.881711 -0.686740 -0.657673 0.724490 -0.923079 -0.304344 2.850698 0.806909 0.574321 0.524777 1.666283 1.431507
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.142289 8.176693 2.526502 0.281375 1.964637 -0.868571 4.112226 3.496295 0.813163 0.573824 0.528678 5.340046 5.260242
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.331925 2.300723 -0.726692 0.000646 -0.607777 -0.439232 9.475584 17.965803 0.808294 0.578682 0.534015 3.608072 3.439011
54 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.866973 11.643199 1.028494 1.823077 0.059000 3.400357 2.502953 0.119643 0.076182 0.089848 0.016934 1.252671 1.250877
55 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.233297 1.412588 0.605343 0.417904 0.838430 -0.522142 10.066535 1.019621 0.065680 0.061217 0.006291 1.275098 1.268664
56 N04 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.657266 0.001563 0.660262 0.263383 1.624674 -0.807449 -0.859893 -0.472651 0.061116 0.056052 0.005933 1.269497 1.260895
57 N04 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 36.581251 -0.272343 10.066689 1.841372 16.428973 2.929756 13.737570 4.650430 0.114589 0.074489 0.017953 1.238395 1.253940
65 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.725999 0.800343 0.991574 1.254019 0.481143 0.188995 0.306652 5.271475 0.810731 0.558930 0.543502 3.928716 3.958239
66 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.028892 1.388962 -0.732024 0.965504 0.087055 2.203386 0.276269 7.849303 0.812154 0.583960 0.517623 5.702732 5.630875
67 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.753552 -0.652602 -0.254465 -0.853736 1.049033 2.938252 2.135560 3.645786 0.812187 0.596131 0.504705 1.663791 1.481240
68 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.942555 1.505835 -0.260115 9.322643 1.699308 5.968515 0.564285 5.522492 0.809632 0.585465 0.511347 4.504674 4.762824
69 N04 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.061600 -1.033993 -0.766283 -0.000406 -0.015139 3.375789 1.264593 2.126029 0.089952 0.097679 0.024487 1.218223 1.211915
70 N04 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 10.352550 -1.088280 -0.199719 -0.480246 0.952293 2.344704 0.077749 12.159684 0.078914 0.070161 0.010845 1.258343 1.251926
71 N04 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.629962 -0.367974 -0.844709 -0.793633 0.792327 -0.902544 -0.366707 0.001930 0.081559 0.078613 0.012043 1.295633 1.281942
72 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.606530 -0.616560 -0.618729 0.504790 3.976918 -0.594447 4.823386 -1.053786 0.101404 0.077077 0.015781 1.246435 1.248741
73 N05 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 25.486553 0.308492 30.939032 3.305048 36.565384 2.291144 9.012941 -1.773532 0.036914 0.547925 0.303728 1.124267 3.976304
81 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.026908 1.912141 -0.252656 2.967620 0.618291 2.691045 16.003105 5.027754 0.801290 0.553271 0.529668 3.792528 4.189075
82 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.004692 0.933351 1.440371 0.469326 -0.046502 -1.160611 -0.074405 -0.130404 0.815830 0.575432 0.533832 4.998168 5.077549
83 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.538611 1.684048 1.357299 3.255663 0.704613 2.019863 -1.436626 -2.258855 0.813972 0.599313 0.507250 1.598835 1.426338
84 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.516768 13.037399 0.823678 1.044612 -0.153946 0.709234 0.125889 -0.249453 0.818929 0.603886 0.497842 5.238958 6.936172
85 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.652657 0.124433 1.065577 1.758454 -0.813295 -1.178219 -0.234884 0.048297 0.806616 0.593856 0.518465 1.552021 1.565384
86 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.323416 4.647797 -0.120579 -0.606398 1.366355 2.386348 2.178132 1.617519 0.803751 0.564450 0.524060 5.207347 4.568178
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.932550 13.891469 2.306867 1.557480 40.710547 -0.084829 23.215085 0.778519 0.775418 0.591134 0.504544 3.604990 3.206388
88 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.815164 13.060016 19.394735 16.901464 32.266273 23.296991 0.751864 -3.680952 0.768540 0.556578 0.544425 2.027891 1.964864
90 N09 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.991783 0.232370 -0.082907 3.195680 -0.179876 -0.377042 0.572238 2.885119 0.806991 0.548142 0.572103 6.279915 3.926512
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% 51.869428 67.196648 3.192258 4.353779 30.530702 43.417216 7.373035 22.043717 0.321817 0.219781 0.143974 11.571467 11.481304
93 N10 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.807572 -0.221173 3.498930 0.099164 3.200447 -0.044212 1.979028 -1.684118 0.731452 0.455030 0.529106 2.003902 1.656355
94 N10 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.486147 -1.414414 0.030110 0.095460 -0.717554 3.153513 3.772003 1.383776 0.729257 0.433389 0.536519 1.983420 1.653411
98 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.644231 3.620381 0.147665 1.681561 -0.202129 0.101915 7.886388 3.234408 0.801797 0.540582 0.542704 4.131771 4.993211
99 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 26.32% 1.133581 0.319296 2.288218 -0.742912 0.915043 0.138517 -1.414310 -0.545021 0.809513 0.568083 0.532946 1.834955 1.647339
100 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.393982 -0.133425 0.486345 0.379055 1.709837 -0.545179 -0.808489 0.458373 0.814667 0.584083 0.526612 1.697030 1.424352
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.451264 12.333165 2.376438 -0.100366 0.540796 -0.246449 14.896707 4.482221 0.821853 0.602724 0.514294 4.804938 4.602651
102 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 28.948927 29.458389 1.170627 1.490314 594.623398 591.689291 18545.033189 18446.907174 0.723931 0.457902 0.502363 0.000000 0.000000
103 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.814327 12.187956 0.403469 -0.092604 0.027908 0.281760 1.370236 1.780142 0.814781 0.602605 0.514960 4.134567 3.745621
104 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.774056 92.892405 1.316782 10.899428 2.035488 1.085616 7.496092 2.785024 0.817999 0.590221 0.545131 3.644265 2.944552
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% 0.00% 0.00% 0.00% 100.00% 0.00% 15.737649 11.477690 17.266553 15.970206 27.239543 22.470150 -2.046666 -2.209838 0.792503 0.551500 0.553501 3.418773 3.672352
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.00% 0.00% -0.158162 0.516605 -0.279096 0.789499 -0.647754 0.606927 -0.663599 0.193819 0.741932 0.481652 0.533645 1.941254 1.806998
110 N10 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 55.772017 9.597379 2.747278 0.443403 5.111931 15.582834 1.021416 9.571216 0.656377 0.458143 0.410471 8.652034 6.387176
111 N10 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.761229 2.357461 0.153408 0.642646 -0.212418 1.553428 1.307278 11.997166 0.739269 0.459954 0.526340 5.679504 6.664986
112 N10 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.064142 -0.165695 -0.317061 0.527513 0.015139 -1.188114 -0.562633 -1.569387 0.728260 0.448267 0.534133 1.791392 1.735434
116 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% 0.463492 2.305035 -0.118562 -0.715507 -0.432434 0.734956 0.142794 -0.676210 0.802044 0.543072 0.550709 4.341134 3.956274
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.654793 1.017515 4.172508 4.289003 4.446967 2.379093 -1.547389 -2.301147 0.811618 0.563304 0.542374 3.874788 3.670239
118 N07 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 2.444997 31.984556 1.137538 27.940176 -0.961446 33.596489 -0.519601 4.428474 0.816422 0.050207 0.522252 4.769563 1.245459
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.092762 0.865388 6.146359 0.092877 5.326251 -1.027888 -2.434669 -0.383094 0.826268 0.582194 0.536275 4.097393 3.276905
120 N08 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 21.201212 43.304027 1.222144 36.065146 25.771195 33.265424 6.010027 21.831351 0.470916 0.046860 0.323640 3.685797 1.247056
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.934943 7.638969 -0.636306 1.012287 0.129792 0.152961 75.923504 61.074281 0.823724 0.605922 0.516077 3.592711 2.754746
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.851952 9.622128 0.465991 0.736978 -0.560515 -0.089811 -0.146665 -1.003435 0.824793 0.604903 0.526316 0.000000 0.000000
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.924315 12.741841 0.233677 0.508499 -0.639083 -1.133400 2.345567 2.909195 0.818383 0.601925 0.530029 3.035312 2.315812
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 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.001563 0.087592 -0.262080 -0.317677 0.157869 0.837549 0.675669 1.288078 0.742022 0.491041 0.530108 1.952817 1.470940
128 N10 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.234239 3.323639 0.181865 1.248138 -0.060445 1.357354 0.925747 -0.435647 0.740290 0.485988 0.520626 2.231852 1.756546
129 N10 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.929201 -1.033672 -0.530706 -0.274608 0.544044 0.689011 -0.469086 -0.021463 0.737684 0.474524 0.519657 2.096769 1.785985
130 N10 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.172348 0.025238 0.383981 1.304211 2.569263 1.080399 1.353337 16.987596 0.728364 0.455724 0.525285 5.613228 6.435953
135 N12 digital_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.691716 0.570654 -0.697732 -0.751137 0.131768 -0.648938 3.243314 1.942140 0.732751 0.479061 0.507761 6.402862 3.200042
136 N12 digital_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.561295 13.643911 -0.718988 0.122365 4.073436 3.042441 0.824527 9.192209 0.735171 0.471155 0.491539 6.936564 3.127677
137 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.925575 4.600172 18.618027 9.476191 30.841597 6.647719 -0.209175 -2.154293 0.788982 0.564596 0.531250 3.582583 3.095136
138 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.727552 0.873150 12.429921 0.973279 16.785367 -0.551278 -2.878288 -0.122672 0.809098 0.574500 0.536717 3.943731 2.923006
140 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 24.255251 27.511609 30.814057 32.398787 36.680908 33.295884 7.595239 6.932101 0.040994 0.043515 0.001962 1.141697 1.137341
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.883248 3.340048 -0.103845 7.291701 1.387250 3.327442 1.721418 61.258787 0.818465 0.570965 0.536152 6.727250 5.087120
142 N13 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 29.569770 33.256778 1.283136 32.544275 31.937624 33.247138 9.586605 10.665924 0.483536 0.044555 0.268755 0.000000 0.000000
143 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% -0.348696 -1.033064 0.854497 0.702458 0.338614 -0.404753 -0.288882 -0.910805 0.810376 0.593073 0.526422 4.103826 3.374512
144 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% -1.434755 -0.447511 0.903187 -0.048718 -0.038000 0.633642 -0.673313 0.691995 0.815071 0.581041 0.546917 4.237250 3.821627
145 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.812805 28.551124 31.736176 32.793893 36.741558 33.282099 12.320504 15.776048 0.035164 0.036130 -0.000225 0.000000 0.000000
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 28.923647 31.957804 31.616360 33.456452 36.836185 33.425072 14.643685 14.976787 0.049604 0.051002 0.000891 1.207337 1.196516
155 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.887356 27.040748 30.897216 32.091207 36.606029 33.173499 14.624222 12.776758 0.040055 0.038659 0.000041 0.000000 0.000000
156 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.715442 1.004720 0.914386 -0.180091 0.558388 -0.059372 -0.193088 30.198214 0.747483 0.472660 0.516285 0.000000 0.000000
157 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.177973 -0.730379 0.196745 2.129037 1.372649 0.190424 0.707049 -1.394608 0.743037 0.495520 0.507432 0.000000 0.000000
158 N12 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 25.376154 -1.532532 31.512272 -0.268180 36.799579 0.857900 7.956672 2.006051 0.037519 0.502195 0.273629 0.000000 0.000000
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.449237 26.661153 31.370412 32.438663 36.774058 33.282024 13.586753 14.796774 0.041736 0.044704 0.003997 0.000000 0.000000
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.205524 51.540714 -0.594704 2.506795 -0.407746 2.782781 0.589796 -0.462290 0.807081 0.476500 0.519340 0.000000 0.000000
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.829113 0.478211 -0.217435 -0.850969 1.864751 0.745193 0.113284 -0.351968 0.813387 0.579593 0.545746 0.000000 0.000000
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% 0.637727 -0.401309 0.164774 -0.822043 -0.636341 -0.125017 0.295332 1.259164 0.807479 0.583107 0.534319 0.000000 0.000000
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 55.26% 44.74% -0.955536 -1.353628 -0.936985 -0.580691 -0.724465 0.393878 0.456196 1.254847 0.810023 0.573578 0.548793 0.000000 0.000000
165 N14 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
166 N14 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
167 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.963278 21.991358 15.805777 15.868155 27.306635 25.058034 13.616681 26.897860 0.693980 0.429046 0.390765 4.383455 2.647757
168 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 12.181383 15.469786 16.510869 18.387335 25.872175 27.232688 -3.322787 -3.748390 0.788277 0.519150 0.542180 7.708441 4.235763
169 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.222338 14.324788 18.092255 17.296528 29.429517 25.848133 -1.767780 -3.128471 0.785349 0.504439 0.557329 5.438919 3.054721
170 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.524138 12.527109 18.303187 16.540631 29.806492 23.210966 -1.485292 -3.030671 0.779882 0.503531 0.563495 4.512433 2.884583
176 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.700245 -0.884160 -0.763922 -0.051525 0.432563 0.517416 0.858279 9.661708 0.745186 0.449437 0.538835 0.000000 0.000000
177 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.099218 1.219333 0.333537 1.629622 -0.292340 1.920381 -0.053327 15.146312 0.738766 0.465420 0.520630 0.000000 0.000000
178 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.525989 -1.271013 1.095077 -0.045976 -0.966941 -0.184710 1.229609 -0.087266 0.737839 0.481354 0.514862 0.000000 0.000000
179 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.485859 1.062711 -0.527006 0.123087 4.961027 -0.701746 5.909206 -0.669232 0.738370 0.489423 0.521049 0.000000 0.000000
180 N13 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 0.596565 22.018623 0.314459 30.466377 0.527105 25.746369 -0.190280 10.417717 0.806625 0.268478 0.635830 0.000000 0.000000
181 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 27.201615 67.281480 31.856792 5.128245 36.768153 32.677817 12.127891 16.123007 0.045874 0.308431 0.148062 0.000000 0.000000
182 N13 RF_maintenance 100.00% 0.00% 38.17% 0.00% 100.00% 0.00% 11.438031 5.858220 16.299139 17.982697 25.060113 125.565569 -3.737757 219.170447 0.794434 0.411389 0.568332 0.000000 0.000000
183 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.774300 -0.876580 -0.050787 -0.497521 -1.256601 -0.517279 0.092835 19.697754 0.806717 0.563319 0.555283 0.000000 0.000000
184 N14 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
185 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.058343 0.153472 1.826197 1.230667 0.170742 -0.519980 -0.026722 -0.744512 0.807995 0.562549 0.551738 0.000000 0.000000
186 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.882717 -0.118963 2.420944 1.704035 0.535889 -0.676931 22.402278 1.649037 0.799003 0.557301 0.542860 0.000000 0.000000
187 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.165804 1.213419 0.235383 0.338708 -0.166333 -1.056257 5.816909 2.382474 0.798138 0.556350 0.541532 8.839093 3.623260
189 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.015717 4.129082 0.678516 -0.360235 1.186314 1.033388 1.842084 14.897083 0.794437 0.524739 0.566162 4.782985 2.273110
190 N15 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 58.106853 32.265009 2.821107 32.799617 14.959246 33.339987 79.317400 13.415901 0.651188 0.045069 0.447823 0.000000 0.000000
191 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.565260 1.196416 -0.440456 1.881034 0.853992 0.312998 4.735241 53.820062 0.797174 0.508971 0.588549 0.000000 0.000000
203 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
205 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 23.418051 22.824505 10.655814 0.518307 18.093517 10.038691 51.778401 73.323576 0.798238 0.489620 0.577898 0.000000 0.000000
206 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 21.337228 21.469948 0.562135 6.837186 9.298003 10.607351 56.062376 69.125696 0.771450 0.505555 0.560511 0.000000 0.000000
207 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 24.502760 22.795346 12.830220 10.458904 20.028370 13.894247 19.722520 20.417951 0.775909 0.496868 0.556317 3.827307 2.533763
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% 44.861257 44.797198 inf inf 4552.126211 5365.064163 23400.663040 32155.892430 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 21.769713 22.988952 5.805177 11.795964 7.545788 14.795476 -1.138375 -5.013404 0.784346 0.497630 0.574680 0.000000 0.000000
224 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 29.338128 29.630599 19.771700 19.211054 34.559393 30.185356 -2.789833 -5.461316 0.740764 0.450807 0.553666 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% 45.595445 45.542052 inf inf 6293.529991 6293.485571 38429.016588 38433.183645 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 33.644143 30.929179 22.002008 22.368681 36.476819 33.281689 21.216463 14.613437 0.054978 0.050346 0.004234 0.000000 0.000000
321 N02 not_connected 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.459457 4.316181 10.954907 9.646944 17.976710 14.725277 64.824058 64.965900 0.098145 0.073784 0.050425 0.000000 0.000000
323 N02 not_connected 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.134766 7.777355 0.743689 12.824901 12.926407 13.242461 8.830020 3.513624 0.096299 0.074289 0.044288 0.000000 0.000000
324 N04 not_connected 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 9.593701 6.102939 13.627833 8.783444 18.417457 9.675413 -0.363177 -3.019431 0.108862 0.075716 0.056518 0.000000 0.000000
329 N12 dish_maintenance 100.00% 0.00% 96.77% 0.00% 100.00% 0.00% 5.328772 4.320213 -0.556755 9.065991 9.388607 11.504917 3.966788 -3.375385 0.665732 0.345666 0.525612 0.000000 0.000000
333 N12 dish_maintenance 100.00% 0.00% 96.77% 0.00% 100.00% 0.00% 5.100178 4.652993 -0.191346 8.520233 5.363255 8.702441 5.676131 2.286702 0.649608 0.334745 0.516759 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, 7, 8, 9, 10, 16, 17, 18, 19, 20, 21, 27, 28, 30, 31, 32, 33, 36, 37, 38, 40, 41, 42, 45, 46, 50, 52, 53, 54, 55, 56, 57, 65, 66, 68, 69, 70, 71, 72, 73, 81, 82, 84, 86, 87, 88, 90, 91, 92, 98, 99, 101, 102, 103, 104, 105, 106, 107, 108, 110, 111, 116, 117, 118, 119, 120, 121, 122, 123, 125, 126, 130, 135, 136, 137, 138, 140, 141, 142, 143, 144, 145, 150, 155, 156, 157, 158, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 189, 190, 191, 203, 205, 206, 207, 220, 221, 222, 223, 224, 241, 242, 243, 320, 321, 323, 324, 329, 333]

unflagged_ants: [3, 5, 15, 29, 51, 67, 83, 85, 93, 94, 100, 109, 112, 127, 128, 129]

golden_ants: [3, 5, 15, 29, 51, 67, 83, 85, 93, 94, 100, 109, 112, 127, 128, 129]
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_2459828.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.dev11+g90102fb
In [ ]: