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 = "2459784"
data_path = "/mnt/sn1/2459784"
ant_metrics_ext = ".ant_metrics.hdf5"
redcal_ext = ".known_good.omni.calfits"
nb_outdir = "/home/obs/src/H5C_Notebooks/_rtp_summary_"
good_statuses = "digital_ok,calibration_maintenance,calibration_triage,calibration_ok"
In [4]:
from astropy.time import Time
utc = Time(JD, format='jd').datetime
print(f'Date: {utc.month}-{utc.day}-{utc.year}')
Date: 7-23-2022
In [5]:
# Per-season options
def ant_to_report_url(ant):
    return f'https://htmlpreview.github.io/?https://github.com/HERA-Team/H5C_Notebooks/blob/main/antenna_report/antenna_{ant}_report.html'

Load Auto Metrics¶

In [6]:
use_auto_metrics = False

# find the auto_metrics file
glob_str = os.path.join(data_path, f'zen.{JD}*.auto_metrics.h5')
auto_metrics_file = sorted(glob.glob(glob_str))

# if it exists, load and extract relevant information
if len(auto_metrics_file) > 0:
    auto_metrics_file = auto_metrics_file[0]
    print(f'Found auto_metrics results file at {auto_metrics_file}.')
    
    auto_metrics = load_metric_file(auto_metrics_file)
    mean_round_modz_cut = auto_metrics['parameters']['mean_round_modz_cut']
    auto_ex_ants = auto_metrics['ex_ants']['r2_ex_ants']
    
    use_auto_metrics = True
else:
    print(f'No files found matching glob {glob_str}. Skipping auto_metrics.')
Found auto_metrics results file at /mnt/sn1/2459784/zen.2459784.25306.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/2459784/zen.2459784.?????.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/2459784/zen.2459784.?????.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 2459784
Date 7-23-2022
LST Range 15.598 -- 17.598 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: 43
RF_ok: 11
digital_maintenance: 2
digital_ok: 85
not_connected: 3
Commanded Signal Source antenna
Antennas in Commanded State 110 / 147 (74.8%)
Cross-Polarized Antennas 104
Total Number of Nodes 15
Nodes Registering 0s N18
Nodes Not Correlating N10, N12
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 79 / 147 (53.7%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 112 / 147 (76.2%)
Redcal Done? ✅
Redcal Flagged Antennas 1 / 147 (0.7%)
Never Flagged Antennas 21 / 147 (14.3%)
A Priori Good Antennas Flagged 69 / 85 total a priori good antennas:
5, 7, 9, 10, 16, 19, 21, 30, 40, 41, 42, 45,
50, 51, 53, 54, 55, 56, 57, 69, 71, 72, 81,
83, 84, 88, 91, 92, 99, 101, 103, 105, 106,
107, 108, 109, 111, 117, 118, 121, 122, 123,
128, 129, 135, 138, 141, 142, 143, 144, 145,
160, 161, 162, 165, 167, 169, 170, 176, 177,
178, 179, 181, 183, 185, 187, 189, 190, 191
A Priori Bad Antennas Not Flagged 5 / 62 total a priori bad antennas:
3, 38, 67, 100, 116
In [19]:
# write to csv
outpath = os.path.join(nb_outdir, f'array_health_table_{JD}.csv')
print(f'Now saving Table 2 to a csv at {outpath}')
df.replace({'\u2705': 'Y'}, regex=True).replace({'\u274C': 'N'}, regex=True).replace({'<br>': ' '}, regex=True).to_csv(outpath)
Now saving Table 2 to a csv at /home/obs/src/H5C_Notebooks/_rtp_summary_/array_health_table_2459784.csv

Build DataFrame¶

In [20]:
# build dataframe
to_show = {'Ant': [f'<a href="{ant_to_report_url(ant)}" target="_blank">{ant}</a>' for ant in ants],
           'Node': [f'N{nodes[ant]:02}' for ant in ants], 
           'A Priori Status': [a_priori_statuses[ant] for ant in ants]}
           #'Worst Metric': worst_metrics, 'Worst Modified Z-Score': worst_zs}
df = pd.DataFrame(to_show)

# create bar chart columns for flagging percentages:
bar_cols = {}
if use_auto_metrics:
    bar_cols['Auto Metrics Flags'] = [float(ant in auto_ex_ants) for ant in ants]
if use_ant_metrics:
    if np.sum(list(a_priori_flag_frac.values())) > 0:  # only include this col if there are any a priori flags
        bar_cols['A Priori Flag Fraction in Ant Metrics'] = [a_priori_flag_frac[ant] for ant in ants]
    for ap in antpols:
        bar_cols[f'Dead Fraction in Ant Metrics ({ap})'] = [dead_ant_frac[ap][ant] for ant in ants]
    bar_cols['Crossed Fraction in Ant Metrics'] = [crossed_ant_frac[ant] for ant in ants]
if use_redcal:
    bar_cols['Flag Fraction Before Redcal'] = [redcal_prior_flag_frac[ant] for ant in ants]
    bar_cols['Flagged By Redcal chi^2 Fraction'] = [redcal_flagged_frac[ant] for ant in ants]  
for col in bar_cols:
    df[col] = bar_cols[col]

# add auto_metrics
if use_auto_metrics:
    for label, modz in all_modzs.items():
        df[label] = modz
z_score_cols = [col for col in df.columns if 'Modified Z-Score' in col]        
        
# add ant_metrics
ant_metrics_cols = {}
if use_ant_metrics:
    for ap in antpols:
        ant_metrics_cols[f'Average Dead Ant Metric ({ap})'] = [average_dead_metrics[ap][ant] for ant in ants]
    ant_metrics_cols['Average Crossed Ant Metric'] = [average_crossed_metrics[ant] for ant in ants]
    for col in ant_metrics_cols:
        df[col] = ant_metrics_cols[col]   

# add redcal chisq
redcal_cols = []
if use_redcal:
    for ap in antpols:
        col_title = f'Median chi^2 Per Antenna ({ap})'
        df[col_title] = [cspa[ant, ap] for ant in ants]
        redcal_cols.append(col_title)

# sort by node number and then by antenna number within nodes
df.sort_values(['Node', 'Ant'], ascending=True)

# style dataframe
table = df.style.hide_index()\
          .applymap(lambda val: f'background-color: {status_colors[val]}' if val in status_colors else '', subset=['A Priori Status']) \
          .background_gradient(cmap='viridis', vmax=mean_round_modz_cut * 3, vmin=0, axis=None, subset=z_score_cols) \
          .background_gradient(cmap='bwr_r', vmin=dead_cut-.25, vmax=dead_cut+.25, axis=0, subset=list([col for col in ant_metrics_cols if 'dead' in col.lower()])) \
          .background_gradient(cmap='bwr_r', vmin=crossed_cut-.25, vmax=crossed_cut+.25, axis=0, subset=list([col for col in ant_metrics_cols if 'crossed' in col.lower()])) \
          .background_gradient(cmap='plasma', vmax=4, vmin=1, axis=None, subset=redcal_cols) \
          .applymap(lambda val: 'font-weight: bold' if val < dead_cut else '', subset=list([col for col in ant_metrics_cols if 'dead' in col.lower()])) \
          .applymap(lambda val: 'font-weight: bold' if val < crossed_cut else '', subset=list([col for col in ant_metrics_cols if 'crossed' in col.lower()])) \
          .applymap(lambda val: 'font-weight: bold' if val > mean_round_modz_cut else '', subset=z_score_cols) \
          .applymap(lambda val: 'color: red' if val > mean_round_modz_cut else '', subset=z_score_cols) \
          .bar(subset=list(bar_cols.keys()), vmin=0, vmax=1) \
          .format({col: '{:,.4f}'.format for col in z_score_cols}) \
          .format({col: '{:,.4f}'.format for col in ant_metrics_cols}) \
          .format({col: '{:,.2%}'.format for col in bar_cols}) \
          .applymap(lambda val: 'font-weight: bold', subset=['Ant']) \
          .set_table_styles([dict(selector="th",props=[('max-width', f'70pt')])]) \

Table 2: RTP Per-Antenna Metrics Summary Table¶

This admittedly very busy table incorporates summary information about all antennas in the array. Its columns depend on what information is available when the notebook is run (i.e. whether auto_metrics, ant_metrics, and/or redcal is done). These can be divided into 5 sections:

Basic Antenna Info: antenna number, node, and its a priori status.

Flag Fractions: Fraction of the night that an antenna was flagged for various reasons. Note that auto_metrics flags antennas for the whole night, so it'll be 0% or 100%.

auto_metrics Details: If auto_metrics is included, this section shows the modified Z-score signifying how much of an outlier each antenna and polarization is in each of four categories: bandpass shape, overall power, temporal variability, and temporal discontinuities. Bold red text indicates that this is a reason for flagging the antenna. It is reproduced from the auto_metrics_inspect.ipynb nightly notebook, so check that out for more details on the precise metrics.

ant_metrics Details: If ant_metrics is included, this section shows the average correlation-based metrics for antennas over the whole night. Low "dead ant" metrics (nominally below 0.4) indicate antennas not correlating with the rest of the array. Negative "crossed ant" metrics indicate antennas that show stronger correlations in their cross-pols than their same-pols, indicating that the two polarizations are probably swapped. Bold text indicates that the average is below the threshold for flagging.

redcal chi^2 Details: If redcal is included, this shows the median chi^2 per antenna. This would be 1 in an ideal array. Antennas are thrown out when they they are outliers in their median chi^2, usually greater than 4-sigma outliers in modified Z-score.

In [21]:
HTML(table.render())
Out[21]:
Ant Node A Priori Status Auto Metrics Flags Dead Fraction in Ant Metrics (Jee) Dead Fraction in Ant Metrics (Jnn) Crossed Fraction in Ant Metrics Flag Fraction Before Redcal Flagged By Redcal chi^2 Fraction ee Shape Modified Z-Score nn Shape Modified Z-Score ee Power Modified Z-Score nn Power Modified Z-Score ee Temporal Variability Modified Z-Score nn Temporal Variability Modified Z-Score ee Temporal Discontinuties Modified Z-Score nn Temporal Discontinuties Modified Z-Score Average Dead Ant Metric (Jee) Average Dead Ant Metric (Jnn) Average Crossed Ant Metric Median chi^2 Per Antenna (Jee) Median chi^2 Per Antenna (Jnn)
3 N01 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.136938 -0.450932 0.256376 -0.573509 -0.211614 -0.564743 -0.188793 0.643546 0.569171 0.563746 0.355894 11.975314 12.071859
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.431262 4.755636 -0.694333 0.524529 -0.373383 -0.739949 4.034824 0.397217 0.584605 0.573193 0.357628 10.659401 10.506843
5 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.594935 2.662841 -0.427998 11.665385 -1.255034 8.804793 -0.043963 -1.443586 0.590644 0.578160 0.357696 21.164499 23.922392
7 N02 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
8 N02 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
9 N02 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
10 N02 digital_ok 0.00% 10.75% 13.44% 0.00% 13.16% 0.00% 1.559789 -0.358304 -0.636949 -0.920214 2.462759 2.436507 0.352285 -1.047270 0.523957 0.512476 0.336306 1.318518 1.754512
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.440440 1.526713 -0.899127 0.103840 -0.171002 0.308517 -0.593270 1.644080 0.605122 0.593425 0.364225 1.680548 1.834235
16 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.311613 0.801456 -0.970894 5.553104 -0.379745 1.818505 2.031809 0.423669 0.607704 0.601577 0.357707 21.280020 51.545165
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.202095 0.241860 0.077461 1.058247 -0.529154 -0.596032 0.977901 -0.581759 0.603742 0.598228 0.352847 1.466359 1.620617
18 N01 RF_maintenance 100.00% 0.00% 67.20% 0.00% 100.00% 0.00% 6.330818 8.175817 0.609347 4.051745 19.717073 14.497962 61.112533 21.949997 0.550570 0.385887 0.367732 12.109833 8.726799
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.829487 4.090160 1.939402 11.267403 0.982828 48.196814 -0.753999 3.401276 0.581418 0.572548 0.352803 24.485404 25.977574
20 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.602865 0.694377 -0.270911 0.472794 0.630265 -0.789568 2.072141 -0.994341 0.563878 0.544379 0.342335 1.774849 2.190590
21 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.584138 -0.413561 6.169650 1.441428 2.218467 2.983739 -0.415082 3.887796 0.541104 0.529251 0.339131 24.504187 31.104858
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.630511 27.490496 69.227076 69.273755 49.809071 47.534843 1.338990 0.777168 0.038138 0.042321 0.003124 1.270388 1.296814
28 N01 RF_maintenance 100.00% 61.83% 100.00% 0.00% 100.00% 0.00% 12.861346 24.135874 5.941147 8.895620 42.607589 53.229875 1.742933 21.584356 0.417349 0.221073 0.246997 13.252381 5.247736
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.686392 -0.521904 0.937673 -0.888162 -0.442082 -0.583312 -0.976061 -0.539960 0.623502 0.618706 0.356948 1.471012 1.575126
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.978237 -0.040154 -0.700923 -0.926083 0.392784 -0.934717 8.440033 -0.518208 0.608819 0.605920 0.351250 20.055731 46.682007
31 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.074404 -0.398386 -0.544304 0.281031 -1.076883 -0.466538 0.169932 -0.894415 0.604317 0.593793 0.346538 1.523140 1.733035
32 N02 RF_maintenance 100.00% 29.57% 13.44% 0.00% 100.00% 0.00% 36.904083 6.248000 3.987567 4.223254 17.594046 24.739349 34.580347 139.476744 0.502802 0.540751 0.272961 26.918412 34.643678
33 N02 RF_maintenance 100.00% 0.00% 67.20% 0.00% 100.00% 0.00% -0.507698 5.151649 0.376329 0.387659 -0.785142 4.500279 -0.225586 4.132523 0.555185 0.387760 0.395757 30.930388 12.447966
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.325041 8.481708 0.355714 0.689701 0.213668 -0.693357 -0.296795 1.058008 0.581052 0.565044 0.343029 5.081437 4.763849
37 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.694253 0.789198 1.016497 -0.772254 0.936281 0.604810 -0.476123 3.050469 0.610610 0.600145 0.350059 0.000000 0.000000
38 N03 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.426175 -0.006104 -0.609233 0.880298 1.011674 0.307850 1.590469 -0.286883 0.629463 0.621499 0.364563 6.499878 6.536478
40 N04 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
41 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.586151 -0.635573 7.702545 0.120667 7.426882 0.561056 -0.902129 -0.054132 0.637480 0.633309 0.352500 9.429457 9.112507
42 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.587803 0.288141 6.974383 0.050741 4.626426 -0.360444 -0.780344 -1.070436 0.640465 0.638237 0.362993 3.229608 3.345011
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.221909 0.797448 0.013042 0.817989 -1.018578 0.113520 -0.717725 9.064753 0.593742 0.581327 0.350555 20.704827 30.033814
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.888145 -0.812377 0.683787 -0.464278 -0.861010 -0.617581 -0.247442 1.579424 0.573901 0.565083 0.355329 1.615152 1.648920
50 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.270039 29.270118 -0.920613 2.884753 -0.216208 9.904926 3.153446 25.177524 0.589712 0.530417 0.308194 20.694133 20.455948
51 N03 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 8.792740 42.029287 20.064405 87.019920 23.131355 47.604043 -0.137052 3.127474 0.614887 0.043772 0.362894 18.549759 1.271093
52 N03 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 12.280654 43.315466 1.918912 83.488777 4.614702 48.184613 26.701350 1.983237 0.597919 0.037846 0.351029 13.076458 1.211314
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.085011 3.117691 6.999597 6.699815 4.759857 3.039768 1.889402 1.280298 0.653244 0.649954 0.358304 9.670975 9.902976
54 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.772024 2.991247 0.953238 -0.215058 4.618572 15.038805 -0.172390 39.927082 0.650438 0.646414 0.338759 11.616176 12.921518
55 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.393661 0.968771 0.449995 5.888121 3.201231 6.187157 3.390653 -0.863427 0.645245 0.647409 0.352098 16.235260 10.896994
56 N04 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
57 N04 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 26.215601 1.522957 65.480532 -0.426519 49.607686 2.797366 0.689860 0.484398 0.047017 0.641542 0.374858 1.202262 16.707600
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.701929 0.821037 0.201016 1.735384 -0.132328 0.570706 -0.621825 -0.503969 0.599273 0.594285 0.344253 1.016306 1.122499
66 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.668196 1.244381 -0.802882 0.501349 0.524716 -0.948640 -0.619573 0.143534 0.625783 0.621373 0.337933 1.385141 1.374511
67 N03 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.140434 -0.615926 0.902921 0.460600 -0.135406 0.212160 -0.444367 0.729920 0.645291 0.644251 0.341689 15.284283 37.493863
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.443707 0.726060 -0.472342 0.519486 1.244074 0.118782 -0.342097 1.623618 0.649826 0.648462 0.340545 1.587614 1.519820
69 N04 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
70 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.565554 -1.377931 0.306643 -0.961272 -0.160863 -0.969172 1.221613 0.446590 0.656095 0.655075 0.366464 10.567239 13.677535
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 34.21% 0.625972 -1.169729 -0.652826 1.202047 -0.401096 0.829742 0.089955 0.674622 0.654781 0.664219 0.353616 4.554249 3.801166
72 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.949205 -0.841490 -0.265688 7.491662 1.737467 5.900363 6.680841 1.631919 0.640647 0.648760 0.371251 8.766586 19.114588
73 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.012034 -0.434055 -0.254832 0.375720 0.901270 -0.480350 2.047935 0.616425 0.630773 0.623261 0.381598 2.154847 2.685107
81 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.130840 4.971849 -0.678244 11.116261 -0.248958 8.880023 6.209143 1.596424 0.580852 0.582152 0.325384 18.467664 33.215050
82 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.515021 1.120814 1.719806 -0.816837 3.561716 0.449156 11.698773 3.446141 0.608871 0.612778 0.327855 29.299441 23.660468
83 N07 digital_ok 100.00% 56.45% 0.00% 0.00% 100.00% 0.00% 15.542198 3.675514 52.060069 10.838710 51.381091 8.443478 3.055818 -0.922549 0.460898 0.640781 0.397922 4.820121 14.484460
84 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.580360 10.363406 3.479094 4.135694 1.779979 2.165193 0.724869 -1.404540 0.656777 0.660284 0.330028 10.506637 11.587327
85 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.045870 30.899026 4.110854 3.573297 2.078337 14.104039 -0.874525 5.219383 0.664956 0.600881 0.342216 10.474589 6.893461
86 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.430975 9.460415 -0.673379 14.838404 3.128358 16.503209 0.114569 0.099534 0.658880 0.652820 0.340291 21.193891 11.596774
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 21.051421 11.027417 2.945012 15.034904 17.043721 13.420367 62.683566 -0.968906 0.618634 0.668320 0.359356 8.838826 10.704839
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.120081 26.837167 59.996728 60.373608 50.001546 47.628808 1.380226 0.541033 0.037683 0.038060 -0.000334 1.168921 1.164243
90 N09 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.272956 4.664891 -0.569954 10.376826 -0.375559 9.495400 0.092416 -0.673007 0.606600 0.605952 0.377022 8.616634 10.235367
91 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 24.630420 25.936643 59.873107 61.461616 49.754204 47.397357 1.023917 0.565430 0.034018 0.036886 0.001121 1.209610 1.206670
92 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 40.818227 61.182087 8.437885 10.404199 51.714714 53.068430 1.066954 3.152131 0.098507 0.093620 0.011580 0.000000 0.000000
93 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.916838 0.809540 8.054946 -0.530995 10.172540 1.413016 -0.601220 -0.771045 0.096606 0.096748 -0.017092 1.452734 1.423112
94 N10 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.580868 -1.138825 -0.519634 -0.852735 -0.876461 1.416747 0.862576 -0.142537 0.059594 0.068624 0.005297 7.892250 7.751507
98 N07 digital_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.017763 16.255100 1.368967 1.088489 1.458254 0.262203 -0.211006 0.652859 0.566641 0.557689 0.313506 0.000000 0.000000
99 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.207729 -0.110703 7.919329 5.113088 9.469568 1.315560 -0.130682 3.015392 0.595123 0.592777 0.323082 6.674127 6.705545
100 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.468890 -0.135166 0.670475 -0.190426 -0.354207 -1.097646 0.153559 -0.971832 0.622422 0.624662 0.333799 4.977396 4.779046
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.744837 9.853563 5.138777 4.687635 2.742446 1.540858 3.412192 1.495940 0.649558 0.652416 0.340485 0.000000 0.000000
102 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.121828 1.002066 3.028915 -0.194616 6.048558 -0.310572 -0.246145 -0.909274 0.653029 0.657559 0.343207 10.259499 8.341960
103 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.931538 9.944822 1.126000 0.930962 -0.320312 -0.088789 -0.007152 -0.424814 0.663556 0.664221 0.345648 2.280411 2.321730
104 N08 RF_maintenance 100.00% 0.00% 0.00% 100.00% 100.00% 0.00% 7.239993 79.135900 0.151619 50.512753 3.456856 4.266572 -0.361470 -0.060596 0.287196 0.250622 -0.280108 1.980471 1.725429
105 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 27.367089 31.070537 56.565064 58.209320 49.665567 47.398515 0.727401 0.376629 0.034236 0.036907 0.002902 1.220637 1.211572
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% 24.755763 25.119583 60.625406 61.029667 49.701419 47.213210 0.782957 0.643007 0.041621 0.042263 0.002353 1.208106 1.215286
108 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.362209 4.755638 -0.894911 9.575385 -0.696365 7.840964 -0.632301 -1.412586 0.593229 0.596240 0.374425 3.456383 3.961990
109 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.398172 -0.614665 -0.125050 1.090999 -0.778474 -0.663200 1.714180 -0.089247 0.088671 0.090679 0.021184 34.543290 31.286873
110 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 35.124273 6.477469 3.736830 5.242851 38.203653 28.052592 61.418152 84.995779 0.077419 0.068074 0.009672 14.848244 23.955953
111 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.538580 1.280923 0.121995 7.643958 -0.029134 4.616347 0.246462 -0.601452 0.053437 0.061963 0.004019 88.413363 62.541401
112 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.697669 0.560859 0.175203 6.942694 0.303299 4.894017 1.423096 -1.378634 0.055413 0.072897 0.005749 40.886587 36.948608
116 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.700772 2.196472 0.164036 -0.424393 1.676715 2.007036 -0.747817 -1.145451 0.549834 0.547708 0.323339 4.888226 4.769573
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.914584 5.279353 11.516980 12.894412 10.729353 10.527487 -1.180499 -1.574998 0.588845 0.590030 0.346190 4.139485 4.130079
118 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.001645 1.873509 6.862795 0.232989 7.871495 0.166104 1.091775 3.859584 0.598227 0.601284 0.340399 4.612874 4.519934
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.078199 1.412550 17.576040 0.016798 19.402218 0.036229 -1.292161 -0.827723 0.620498 0.621786 0.340220 4.872015 4.817679
120 N08 RF_maintenance 100.00% 61.83% 100.00% 0.00% 100.00% 0.00% 18.779819 37.864086 4.059857 77.004322 43.496980 47.990932 0.369677 1.810046 0.423778 0.040462 0.274394 5.344772 1.057221
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.206590 6.177426 2.489512 1.284374 1.256535 0.469395 9.667135 6.137864 0.653079 0.655532 0.343438 10.358744 9.515692
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.201231 7.883589 2.179167 3.914436 0.919055 1.317415 0.362137 1.979844 0.652076 0.653690 0.352301 5.885522 6.926081
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.944359 9.439186 6.079199 7.292184 4.101682 5.130201 -0.439686 -0.229973 0.649057 0.650099 0.359071 0.000000 0.000000
125 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
127 N10 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.172487 -1.051957 0.269255 -0.883091 -0.981475 0.441216 -0.731331 -0.058232 0.093327 0.091170 0.023036 -0.000000 -0.000000
128 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.460969 1.829507 0.553387 7.362088 -0.131566 6.028193 -0.669089 -0.788444 0.079295 0.075253 0.014531 20.901391 65.201984
129 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.513311 -0.898376 1.183166 -0.799968 -0.638119 -1.008381 -0.744302 -0.719374 0.062225 0.055592 0.005475 0.000000 0.000000
130 N10 digital_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.070578 -0.296510 -0.742276 0.512491 1.781268 0.181675 -0.674360 0.723660 0.066929 0.068123 0.007256 0.000000 0.000000
135 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.747368 -0.809056 -0.999838 -0.008082 -0.692378 0.033159 2.161867 0.679785 0.086134 0.088971 0.021458 1.264656 1.264992
136 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.250205 10.984495 0.263300 1.164932 3.335912 2.621053 3.222727 6.558455 0.077331 0.084255 0.015561 0.827554 0.833630
137 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.748767 26.068939 59.020282 59.544209 49.767751 47.406759 0.786363 0.720344 0.032864 0.040521 0.003603 1.205354 1.212471
138 N07 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 29.623235 3.315250 55.502180 -0.490156 49.757392 1.185275 0.705488 4.210355 0.042109 0.594833 0.346793 1.314182 5.072349
140 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 3.799792 3.793167 0.008082 -0.159947 1.824976 1.820336 -0.002840 -0.030074 0.616022 0.613660 0.344836 1.723559 1.780603
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.564335 4.227191 -0.349975 32.982380 2.063210 6.507404 8.142852 23.802155 0.620939 0.579533 0.351951 7.851433 8.118596
142 N13 digital_ok 100.00% 67.20% 100.00% 0.00% 100.00% 0.00% 26.135536 29.822714 8.020212 69.757526 39.457161 47.582610 1.386313 0.676948 0.408853 0.043210 0.213673 3.144847 1.492669
143 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.594925 0.007236 -0.763385 6.493116 0.106109 5.093493 -0.681834 -1.299788 0.628083 0.626189 0.345380 4.819522 5.279913
144 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.159054 -0.149802 -0.606291 -0.398389 0.041313 1.301645 2.881490 4.737498 0.623449 0.619870 0.360481 0.000000 0.000000
145 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.778437 26.617174 69.541194 70.281066 49.817941 47.632216 1.116986 1.135548 0.033756 0.035446 -0.000629 1.214568 1.216018
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.448150 28.583725 69.710828 71.905240 49.878714 47.594108 1.867644 1.498269 0.046292 0.048398 0.001750 0.000000 0.000000
155 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.959382 27.291405 67.935126 68.838102 49.792016 47.369204 1.243339 1.002541 0.034496 0.036384 0.001316 0.927579 0.935396
156 N12 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.389006 0.603973 -0.879084 -0.248374 -0.726665 0.083287 0.827754 3.839106 0.052200 0.053216 0.004750 1.232876 1.235012
157 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.817944 1.940211 1.737413 9.340021 0.733831 8.891050 0.870466 -0.435404 0.053650 0.058849 0.004625 1.140716 1.147018
158 N12 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.523513 -0.557855 1.091959 -0.678506 2.125711 0.643756 1.585363 -0.134857 0.063298 0.060130 0.008664 1.232129 1.229569
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 24.047899 24.544269 68.900386 69.512061 49.774956 47.451808 1.122363 1.101481 0.040312 0.043350 0.002757 1.216086 1.219306
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.232759 48.024615 -0.484451 5.482830 -0.352918 10.186092 0.027636 0.753804 0.615071 0.519705 0.310013 4.865071 4.860710
162 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.306119 1.495978 0.925703 0.800109 1.619408 1.152798 4.805824 2.791294 0.612962 0.612138 0.343581 7.536747 11.475798
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 13.16% 0.00% 1.630074 0.051369 1.176346 1.634218 0.164470 1.260688 1.366627 1.777693 0.619226 0.615477 0.340622 0.701697 0.883381
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 13.16% 0.00% -1.265972 -0.982177 -1.091443 -0.902713 -1.173471 -0.352869 0.441565 0.633248 0.611074 0.607312 0.343721 1.232396 1.373633
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.769139 -0.140797 12.144624 -0.248997 13.214845 -0.213099 1.974317 0.517781 0.602092 0.598597 0.343707 16.092757 30.365006
166 N14 RF_maintenance 100.00% 21.51% 16.13% 0.00% 100.00% 0.00% 24.659412 23.712118 2.759721 2.184329 14.032700 16.600735 14.793293 13.530680 0.516023 0.504377 0.201896 11.501518 15.969064
167 N15 digital_ok 100.00% 56.45% 53.76% 0.00% 100.00% 0.00% 32.682386 18.701159 21.596702 28.407529 40.291945 38.383723 67.747600 28.101123 0.429698 0.449047 0.147967 0.000000 0.000000
168 N15 RF_maintenance 100.00% 13.44% 16.13% 0.00% 100.00% 0.00% 16.662459 19.544405 28.597433 33.250262 36.248063 39.340348 -0.884704 -1.190353 0.528006 0.513116 0.331267 26.130006 52.344904
169 N15 digital_ok 100.00% 16.13% 16.13% 0.00% 100.00% 0.00% 18.881359 18.080709 31.401649 31.543557 40.319564 37.038927 -0.884346 -0.516888 0.504774 0.498289 0.321958 37.967321 60.943119
170 N15 digital_ok 100.00% 21.51% 16.13% 0.00% 100.00% 0.00% 19.267038 16.732770 31.614294 30.154090 41.101674 35.338172 -0.840850 -1.336449 0.487077 0.490054 0.318175 0.000000 0.000000
176 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.109899 1.050873 -0.911795 6.221691 0.000654 5.478454 -0.659102 -1.253592 0.052402 0.059619 0.005524 0.964491 0.959091
177 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.855386 0.190599 1.435442 2.752701 -0.343651 3.456151 -0.418657 0.707135 0.060044 0.049907 0.004904 1.213831 1.220301
178 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.680785 -1.189950 -0.739916 -1.093147 -1.039002 -1.256509 -0.096957 -0.946356 0.061611 0.057112 0.008185 1.198380 1.199798
179 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.393273 0.696318 -0.405587 -0.629632 3.059353 -0.569176 1.093514 -0.685407 0.074724 0.078155 0.016454 1.280025 1.277463
180 N13 RF_maintenance 100.00% 0.00% 77.96% 0.00% 100.00% 0.00% -0.084973 20.602445 1.373679 65.664743 0.742587 37.638626 -0.640625 0.495709 0.593612 0.301260 0.417706 6.115583 2.077698
181 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.711518 60.098013 69.862590 14.860099 49.792125 45.124639 1.066984 7.741891 0.043714 0.246473 0.120922 1.239330 1.668910
182 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.462839 11.795811 28.309146 24.633573 36.019841 42.766133 -1.057699 4.678154 0.580367 0.579470 0.350701 5.973390 9.346859
183 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.090886 0.489989 0.508278 -0.853217 0.275699 -0.299950 1.378345 5.105345 0.605330 0.592962 0.351401 21.622589 33.105075
184 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 13.16% 0.00% 0.121974 -0.625020 0.896647 1.332877 -0.033159 -0.810697 0.002840 -0.692453 0.605398 0.594259 0.341808 1.251914 1.117046
185 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.818609 -0.751576 4.637421 0.479820 13.256817 -0.617260 2.794879 -0.181304 0.603217 0.597843 0.343651 21.049983 46.206635
186 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 13.16% 0.00% 0.006104 0.059971 1.230582 2.013951 0.740139 1.025416 0.260399 0.280644 0.588491 0.585208 0.336756 1.752093 1.800728
187 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.321717 1.501324 0.681195 6.561583 0.462698 3.426833 6.909601 0.355258 0.578851 0.582522 0.339670 -0.000000 -0.000000
189 N15 digital_ok 0.00% 13.44% 10.75% 0.00% 100.00% 0.00% 3.488861 3.866793 -0.032363 0.626099 0.153049 0.685782 -0.452511 0.510045 0.534625 0.530419 0.335013 0.000000 0.000000
190 N15 digital_ok 100.00% 48.39% 100.00% 0.00% 100.00% 0.00% 35.485642 28.982339 5.047479 70.320745 18.049492 47.523892 32.283094 1.008453 0.450157 0.045560 0.285871 46.200466 2.229809
191 N15 digital_ok 100.00% 18.82% 16.13% 0.00% 100.00% 0.00% -0.302148 0.564852 -0.591914 -0.760407 -0.402637 -0.474479 7.763760 0.292521 0.503038 0.495272 0.331074 -0.000000 -0.000000
203 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
205 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.979940 5.058681 30.476753 4.611613 39.858438 8.828151 6.431737 10.967596 0.542873 0.549517 0.324131 5.906331 7.883140
206 N19 RF_ok 100.00% 16.13% 5.38% 0.00% 100.00% 0.00% 3.919652 8.281983 2.212842 15.088817 11.467487 19.752873 8.038026 8.320637 0.520370 0.537142 0.313808 9.362386 12.666570
207 N19 RF_ok 100.00% 16.13% 10.75% 0.00% 100.00% 0.00% 19.476895 18.117823 31.762263 31.385816 41.977384 36.226029 1.961403 1.288426 0.509331 0.516243 0.306599 4.136896 4.902717
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% 16.786179 11.973338 108.157393 112.620426 3754.425110 4490.367576 3250.455107 4888.014188 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 0.00% 8.06% 0.00% 100.00% 0.00% 6.922904 18.790413 11.709987 32.589113 15.655944 38.535917 0.824953 -1.367187 0.544453 0.516337 0.344167 2.533708 2.226576
224 N19 RF_ok 100.00% 16.13% 16.13% 0.00% 100.00% 0.00% 21.984142 21.640855 35.444092 36.139048 45.755175 42.938416 -0.892527 -1.322757 0.497686 0.497379 0.309279 2.317092 2.309880
241 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
242 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
243 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 9.225956 18.274707 143.306272 123.599095 5280.203590 5279.727067 2929.998607 2928.932088 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 30.301002 29.881066 50.758218 49.855844 49.899875 47.419849 2.773862 0.778196 0.062963 0.053448 -0.000540 0.000000 0.000000
321 N02 not_connected 100.00% 48.39% 86.02% 0.00% 100.00% 0.00% 11.527240 9.465608 21.391311 21.101076 28.847903 25.278478 9.054318 8.391922 0.409862 0.362371 0.258522 0.000000 0.000000
323 N02 not_connected 100.00% 61.83% 91.40% 0.00% 100.00% 0.00% 22.508007 12.879779 3.236699 25.362300 22.251377 29.569414 7.631910 -0.752639 0.329206 0.342858 0.225091 0.000000 0.000000
324 N04 not_connected 100.00% 51.08% 88.71% 0.00% 100.00% 0.00% 15.494501 16.631885 27.435078 29.153738 34.413856 33.646319 -0.271230 -1.385119 0.392475 0.345986 0.256156 0.000000 0.000000
329 N12 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 4.991249 8.853978 0.731218 20.780612 2.876771 20.700016 4.682418 -1.044715 0.067156 0.066106 0.022347 0.000000 0.000000
333 N12 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 11.227264 8.855526 20.541678 19.126859 21.446688 21.101078 0.065200 -0.472129 0.063455 0.067222 0.021427 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, 16, 18, 19, 21, 27, 28, 30, 32, 33, 36, 37, 38, 40, 41, 42, 45, 50, 51, 52, 53, 54, 55, 56, 57, 67, 69, 70, 71, 72, 81, 82, 83, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 116, 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130, 135, 136, 137, 138, 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: [15, 17, 20, 29, 31, 46, 65, 66, 68, 73, 140]

golden_ants: [15, 17, 20, 29, 31, 46, 65, 66, 68, 73, 140]
In [23]:
# write to csv
outpath = os.path.join(nb_outdir, f'rtp_summary_table_{JD}.csv')
print(f'Now saving Table 2 to a csv at {outpath}')
df.to_csv(outpath)
Now saving Table 2 to a csv at /home/obs/src/H5C_Notebooks/_rtp_summary_/rtp_summary_table_2459784.csv
In [24]:
# Load antenna positions
data_list = sorted(glob.glob(os.path.join(data_path, f'zen.{JD}.?????.sum.uvh5')))
hd = io.HERAData(data_list[len(data_list) // 2])

# Figure out where to draw the nodes
node_centers = {}
for node in sorted(set(list(nodes.values()))):
    if np.isfinite(node):
        this_node_ants = [ant for ant in ants + unused_ants if nodes[ant] == node]
        if len(this_node_ants) == 1:
            # put the node label just to the west of the lone antenna 
            node_centers[node] = hd.antpos[ant][node] + np.array([-14.6 / 2, 0, 0])
        else:
            # put the node label between the two antennas closest to the node center
            node_centers[node] = np.mean([hd.antpos[ant] for ant in this_node_ants], axis=0)
            closest_two_pos = sorted([hd.antpos[ant] for ant in this_node_ants], 
                                     key=lambda pos: np.linalg.norm(pos - node_centers[node]))[0:2]
            node_centers[node] = np.mean(closest_two_pos, axis=0)
In [25]:
def Plot_Array(ants, unused_ants, outriggers):
    plt.figure(figsize=(16,16))
    
    plt.scatter(np.array([hd.antpos[ant][0] for ant in hd.data_ants if ant in ants]), 
                np.array([hd.antpos[ant][1] for ant in hd.data_ants if ant in ants]), c='w', s=0)

    # connect every antenna to their node
    for ant in ants:
        if nodes[ant] in node_centers:
            plt.plot([hd.antpos[ant][0], node_centers[nodes[ant]][0]], 
                     [hd.antpos[ant][1], node_centers[nodes[ant]][1]], 'k', zorder=0)

    rc_color = '#0000ff'
    antm_color = '#ffa500'
    autom_color = '#ff1493'

    # Plot 
    unflagged_ants = []
    for i, ant in enumerate(ants):
        ant_has_flag = False
        # plot large blue annuli for redcal flags
        if use_redcal:
            if redcal_flagged_frac[ant] > 0:
                ant_has_flag = True
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=7 * (2 - 1 * float(not outriggers)), fill=True, lw=0,
                                                color=rc_color, alpha=redcal_flagged_frac[ant]))
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=6 * (2 - 1 * float(not outriggers)), fill=True, color='w'))
        
        # plot medium green annuli for ant_metrics flags
        if use_ant_metrics: 
            if ant_metrics_xants_frac_by_ant[ant] > 0:
                ant_has_flag = True
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=6 * (2 - 1 * float(not outriggers)), fill=True, lw=0,
                                                color=antm_color, alpha=ant_metrics_xants_frac_by_ant[ant]))
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=5 * (2 - 1 * float(not outriggers)), fill=True, color='w'))
        
        # plot small red annuli for auto_metrics
        if use_auto_metrics:
            if ant in auto_ex_ants:
                ant_has_flag = True                
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=5 * (2 - 1 * float(not outriggers)), fill=True, lw=0, color=autom_color)) 
        
        # plot black/white circles with black outlines for antennas
        plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=4 * (2 - 1 * float(not outriggers)), fill=True, color=['w', 'k'][ant_has_flag], ec='k'))
        if not ant_has_flag:
            unflagged_ants.append(ant)

        # label antennas, using apriori statuses if available
        try:
            bgc = matplotlib.colors.to_rgb(status_colors[a_priori_statuses[ant]])
            c = 'black' if (bgc[0]*0.299 + bgc[1]*0.587 + bgc[2]*0.114) > 186 / 256 else 'white'
        except:
            c = 'k'
            bgc='white'
        plt.text(hd.antpos[ant][0], hd.antpos[ant][1], str(ant), va='center', ha='center', color=c, backgroundcolor=bgc)

    # label nodes
    for node in sorted(set(list(nodes.values()))):
        if not np.isnan(node) and not np.all(np.isnan(node_centers[node])):
            plt.text(node_centers[node][0], node_centers[node][1], str(node), va='center', ha='center', bbox={'color': 'w', 'ec': 'k'})
    
    # build legend 
    legend_objs = []
    legend_labels = []
    
    # use circles for annuli 
    legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markeredgecolor='k', markerfacecolor='w', markersize=13))
    legend_labels.append(f'{len(unflagged_ants)} / {len(ants)} Total {["Core", "Outrigger"][outriggers]} Antennas Never Flagged')
    legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markerfacecolor='k', markersize=15))
    legend_labels.append(f'{len(ants) - len(unflagged_ants)} Antennas {["Core", "Outrigger"][outriggers]} Flagged for Any Reason')

    if use_auto_metrics:
        legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markeredgewidth=2, markeredgecolor=autom_color, markersize=15))
        legend_labels.append(f'{len([ant for ant in auto_ex_ants if ant in ants])} {["Core", "Outrigger"][outriggers]} Antennas Flagged by Auto Metrics')
    if use_ant_metrics: 
        legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markeredgewidth=2, markeredgecolor=antm_color, markersize=15))
        legend_labels.append(f'{np.round(np.sum([frac for ant, frac in ant_metrics_xants_frac_by_ant.items() if ant in ants]), 2)} Antenna-Nights on' 
                             f'\n{np.sum([frac > 0 for ant, frac in ant_metrics_xants_frac_by_ant.items() if ant in ants])} {["Core", "Outrigger"][outriggers]} Antennas '
                             'Flagged by Ant Metrics\n(alpha indicates fraction of time)')        
    if use_redcal:
        legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markeredgewidth=2, markeredgecolor=rc_color, markersize=15))
        legend_labels.append(f'{np.round(np.sum(list(redcal_flagged_frac.values())), 2)} Antenna-Nights on' 
                             f'\n{np.sum([frac > 0 for ant, frac in redcal_flagged_frac.items() if ant in ants])} {["Core", "Outrigger"][outriggers]} Antennas '
                             'Flagged by Redcal\n(alpha indicates fraction of time)')

    # use rectangular patches for a priori statuses that appear in the array
    for aps in sorted(list(set(list(a_priori_statuses.values())))):
        if aps != 'Not Found':
            legend_objs.append(plt.Circle((0, 0), radius=7, fill=True, color=status_colors[aps]))
            legend_labels.append(f'A Priori Status:\n{aps} ({[status for ant, status in a_priori_statuses.items() if ant in ants].count(aps)} {["Core", "Outrigger"][outriggers]} Antennas)')

    # label nodes as a white box with black outline
    if len(node_centers) > 0:
        legend_objs.append(matplotlib.patches.Patch(facecolor='w', edgecolor='k'))
        legend_labels.append('Node Number')

    if len(unused_ants) > 0:
        legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markerfacecolor='grey', markersize=15, alpha=.2))
        legend_labels.append(f'Anntenna Not In Data')
        
    
    plt.legend(legend_objs, legend_labels, ncol=2, fontsize='large', framealpha=1)
    
    if outriggers:
        pass
    else:
        plt.xlim([-200, 150])
        plt.ylim([-150, 150])        
       
    # set axis equal and label everything
    plt.axis('equal')
    plt.tight_layout()
    plt.title(f'Summary of {["Core", "Outrigger"][outriggers]} Antenna Statuses and Metrics on {JD}', size=20)    
    plt.xlabel("Antenna East-West Position (meters)", size=12)
    plt.ylabel("Antenna North-South Position (meters)", size=12)
    plt.xticks(fontsize=12)
    plt.yticks(fontsize=12)
    xlim = plt.gca().get_xlim()
    ylim = plt.gca().get_ylim()    
        
    # plot unused antennas
    plt.autoscale(False)    
    for ant in unused_ants:
        if nodes[ant] in node_centers:
            plt.plot([hd.antpos[ant][0], node_centers[nodes[ant]][0]], 
                     [hd.antpos[ant][1], node_centers[nodes[ant]][1]], 'k', alpha=.2, zorder=0)
        
        plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=4, fill=True, color='w', ec=None, alpha=1, zorder=0))
        plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=4, fill=True, color='grey', ec=None, alpha=.2, zorder=0))
        if hd.antpos[ant][0] < xlim[1] and hd.antpos[ant][0] > xlim[0]:
            if hd.antpos[ant][1] < ylim[1] and hd.antpos[ant][1] > ylim[0]:
                plt.text(hd.antpos[ant][0], hd.antpos[ant][1], str(ant), va='center', ha='center', color='k', alpha=.2) 

Figure 1: Array Plot of Flags and A Priori Statuses¶

This plot shows all antennas, which nodes they are connected to, and their a priori statuses (as the highlight text of their antenna numbers). It may also show (depending on what is finished running):

  • Whether they were flagged by auto_metrics (red circle) for bandpass shape, overall power, temporal variability, or temporal discontinuities. This is done in a binary fashion for the whole night.
  • Whether they were flagged by ant_metrics (green circle) as either dead (on either polarization) or crossed, with the transparency indicating the fraction of the night (i.e. number of files) that were flagged.
  • Whether they were flagged by redcal (blue circle) for high chi^2, with the transparency indicating the fraction of the night (i.e. number of files) that were flagged.

Note that the last fraction does not include antennas that were flagged before going into redcal due to their a priori status, for example.

In [26]:
core_ants = [ant for ant in ants if ant < 320]
outrigger_ants = [ant for ant in ants if ant >= 320]
Plot_Array(ants=core_ants, unused_ants=unused_ants, outriggers=False)
if len(outrigger_ants) > 0:
    Plot_Array(ants=outrigger_ants, unused_ants=sorted(set(unused_ants + core_ants)), outriggers=True)

Metadata¶

In [27]:
from hera_qm import __version__
print(__version__)
from hera_cal import __version__
print(__version__)
2.0.2
3.1.1.dev2+g1b5039f
In [ ]: