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 = "2459795"
data_path = "/mnt/sn1/2459795"
ant_metrics_ext = ".ant_metrics.hdf5"
redcal_ext = ".known_good.omni.calfits"
nb_outdir = "/home/obs/src/H5C_Notebooks/_rtp_summary_"
good_statuses = "digital_ok,calibration_maintenance,calibration_triage,calibration_ok"
In [4]:
from astropy.time import Time
utc = Time(JD, format='jd').datetime
print(f'Date: {utc.month}-{utc.day}-{utc.year}')
Date: 8-3-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/2459795/zen.2459795.25314.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/2459795/zen.2459795.?????.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/2459795/zen.2459795.?????.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 2459795
Date 8-3-2022
LST Range 16.322 -- 18.322 hours
X-Engine Status ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
Number of Files 372
Total Number of Antennas 147
OPERATIONAL STATUS SUMMARY
Antenna A Priori Status Count dish_maintenance: 3
RF_maintenance: 42
RF_ok: 11
digital_maintenance: 1
digital_ok: 87
not_connected: 3
Commanded Signal Source antenna
Antennas in Commanded State 95 / 147 (64.6%)
Cross-Polarized Antennas 93
Total Number of Nodes 15
Nodes Registering 0s N18
Nodes Not Correlating N04, N08, N09
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 85 / 147 (57.8%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 110 / 147 (74.8%)
Redcal Done? ✅
Redcal Flagged Antennas 19 / 147 (12.9%)
Never Flagged Antennas 10 / 147 (6.8%)
A Priori Good Antennas Flagged 81 / 87 total a priori good antennas:
5, 7, 9, 10, 15, 16, 17, 19, 20, 21, 29, 30,
31, 37, 40, 41, 42, 45, 46, 50, 51, 53, 54,
55, 56, 57, 65, 66, 68, 69, 71, 72, 73, 81,
83, 84, 88, 91, 92, 93, 99, 101, 103, 105,
106, 107, 108, 109, 111, 117, 118, 121, 122,
123, 128, 129, 130, 138, 140, 141, 142, 143,
144, 145, 160, 161, 164, 165, 167, 169, 170,
176, 177, 178, 179, 181, 185, 186, 187, 190,
191
A Priori Bad Antennas Not Flagged 4 / 60 total a priori bad antennas:
3, 100, 157, 158
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_2459795.csv

Build DataFrame¶

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

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

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

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

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

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

Table 2: RTP Per-Antenna Metrics Summary Table¶

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

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

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

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

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

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

In [21]:
HTML(table.render())
Out[21]:
Ant Node A Priori Status Auto Metrics Flags Dead Fraction in Ant Metrics (Jee) Dead Fraction in Ant Metrics (Jnn) Crossed Fraction in Ant Metrics Flag Fraction Before Redcal Flagged By Redcal chi^2 Fraction ee Shape Modified Z-Score nn Shape Modified Z-Score ee Power Modified Z-Score nn Power Modified Z-Score ee Temporal Variability Modified Z-Score nn Temporal Variability Modified Z-Score ee Temporal Discontinuties Modified Z-Score nn Temporal Discontinuties Modified Z-Score Average Dead Ant Metric (Jee) Average Dead Ant Metric (Jnn) Average Crossed Ant Metric Median chi^2 Per Antenna (Jee) Median chi^2 Per Antenna (Jnn)
3 N01 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.600433 -0.322827 -0.714832 -0.682183 -0.829291 -0.887922 -0.763928 0.957708 0.674105 0.662836 0.427949 8.206402 7.723397
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.082863 4.260146 -0.720176 1.892692 -0.655531 -0.407959 2.814949 0.320011 0.686001 0.669593 0.423476 10.964111 11.494865
5 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.877526 1.334850 0.714753 3.985750 0.282409 0.793229 0.094535 -2.256394 0.699837 0.681795 0.425206 13.572856 11.469309
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.964208 -1.087653 0.220394 -0.444266 0.348713 0.359281 0.382549 13.878792 0.698482 0.679600 0.412150 8.823142 7.724218
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 16.326705 16.947015 18.151826 18.139316 18.643780 19.230442 5.574931 5.396735 0.673721 0.645823 0.404338 12.950507 15.389673
9 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 28.95% 0.188344 -0.904646 -0.267112 -0.147003 1.607372 1.465673 -0.273477 -1.209749 0.678435 0.657852 0.405544 4.971191 3.732567
10 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 18.42% -0.615683 -0.860842 -0.967088 0.304394 -0.832987 0.207935 3.277822 1.246473 0.659921 0.635534 0.414229 2.823856 2.860675
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 2.63% 15.79% -0.152429 0.831092 1.291163 0.820917 -0.203289 0.167974 0.561795 1.028507 0.702307 0.684489 0.428617 1.552676 1.482867
16 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.088355 -0.910846 -0.652097 -0.646042 -0.142864 -1.084363 7.807116 9.797036 0.708981 0.693645 0.423701 9.226282 10.157571
17 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.755668 1.491429 0.401648 0.750127 0.733337 0.571936 6.172649 4.122428 0.709920 0.694686 0.408359 14.962953 14.567321
18 N01 RF_maintenance 100.00% 0.00% 32.26% 0.00% 100.00% 0.00% 3.454698 3.483329 2.095599 -0.017996 6.338306 6.303877 146.891459 108.564749 0.688799 0.516687 0.447578 11.672709 4.618048
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.302859 0.782966 0.286465 11.128159 -0.152245 43.975739 9.533094 39.997226 0.703017 0.681483 0.402178 34.754378 25.428241
20 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 18.42% -1.065802 -0.040855 -0.715083 -0.933302 0.061650 1.016930 0.202766 0.152886 0.690550 0.664183 0.397275 2.501809 2.491551
21 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 18.42% 0.206888 0.925230 0.475316 0.850960 -0.807622 0.513669 1.865613 0.117815 0.674021 0.649872 0.408195 2.662742 2.714811
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.910311 25.109719 54.078306 55.367017 26.952899 26.827886 18.824931 16.908821 0.045238 0.051589 0.004338 1.271411 1.278009
28 N01 RF_maintenance 100.00% 34.95% 100.00% 0.00% 100.00% 0.00% 13.483730 15.068313 7.659999 10.294010 22.315077 29.074581 23.921894 112.883647 0.467550 0.248580 0.282515 10.196831 2.773804
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 2.63% 15.79% -0.901905 0.126819 0.789485 0.007351 -0.735037 -0.024505 -1.202047 0.335147 0.723512 0.707966 0.429223 1.610213 1.327141
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.038162 -0.030790 -0.549334 -0.225868 6.409710 0.364229 18.928155 0.904273 0.716618 0.702449 0.408815 26.982351 22.791684
31 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.599161 0.101368 -0.883794 1.209143 0.341645 -0.703986 4.700100 6.930019 0.717323 0.694658 0.405862 16.018541 15.199819
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 33.287701 24.043496 2.692302 5.190063 7.592424 17.168599 43.379229 92.364896 0.648399 0.638361 0.272636 26.214950 22.973772
33 N02 RF_maintenance 100.00% 0.00% 32.26% 0.00% 100.00% 0.00% -0.093834 3.704928 0.185626 0.703722 7.409620 6.117903 106.464749 133.219353 0.685598 0.520178 0.486227 24.436815 6.870960
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.229254 6.209613 0.036374 0.889542 1.476569 0.611775 -0.017234 1.000706 0.675966 0.657586 0.404565 13.002000 12.244019
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.553281 1.102926 -0.675646 0.389493 0.240097 -0.036724 0.179977 17.917524 0.695671 0.680293 0.404406 19.425389 17.062423
38 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.150009 -0.026671 -0.827329 -0.937150 1.722948 0.035474 13.120165 4.729178 0.709095 0.697403 0.414602 30.757459 22.339728
40 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 56.571423 125.656744 111.323397 171.795072 30.913502 44.440413 1291.876552 3404.132170 0.016769 0.016291 0.000644 1.099277 1.094786
41 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 234.615580 99.956507 157.051279 137.100975 33.984596 26.726703 1562.594415 2316.787126 0.018166 0.016951 0.001057 1.095986 1.100408
42 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 69.788877 60.694074 124.493618 107.113883 38.894939 32.836869 1795.707366 985.186195 0.016959 0.016926 0.000321 1.121390 1.130569
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.257990 0.547525 -0.823896 1.272838 -0.993783 -0.125389 0.268599 9.818490 0.708913 0.684005 0.419260 16.474397 14.531087
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 5.26% 13.16% -0.568161 -0.303717 0.459752 -0.584403 -0.723626 -0.383003 -0.193494 0.896271 0.695993 0.670973 0.424256 1.332697 1.199272
50 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 13.16% 2.455202 1.951267 -0.623767 2.436712 1.024481 1.958233 2.305701 -0.872668 0.680419 0.663204 0.381432 1.179127 1.153938
51 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.451664 9.201063 -0.834312 9.768127 0.348072 7.235322 -0.018329 -0.633061 0.699161 0.682415 0.393366 16.590859 19.888343
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.614760 9.453706 0.124687 11.128719 -0.496485 9.653559 1.732377 -0.111242 0.712829 0.695746 0.405858 16.996937 16.745820
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.895785 1.625818 -0.409209 0.106640 -0.788086 -0.197098 4.725400 13.932330 0.725863 0.716397 0.427694 11.990870 11.146506
54 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 265.923733 116.257387 213.918712 145.259079 54.857087 52.616617 3015.472099 2983.520867 0.015899 0.016440 0.001119 1.121160 1.121571
55 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 104.835920 110.646561 150.867756 161.171921 66.492622 58.335514 3330.136696 2822.006619 0.017484 0.016394 0.000992 1.109160 1.109324
56 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 85.553609 64.709469 117.638084 119.182769 41.509929 26.290696 1584.844300 1558.474846 0.018036 0.017054 0.000550 1.132896 1.131504
57 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 55.113765 135.164441 109.219677 161.415259 33.460614 36.649601 1090.462358 2563.587254 0.017895 0.016491 0.001380 1.142787 1.136824
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 13.16% 1.251389 0.243711 0.000606 0.974762 0.803981 0.810883 -0.266148 1.827831 0.687731 0.668655 0.401483 1.498610 1.468255
66 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.225828 -0.221968 -0.830241 1.376328 1.675727 1.540287 -0.320453 4.856149 0.705461 0.691773 0.392252 19.268145 19.042362
67 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.663491 -0.184584 -0.336982 0.579383 1.246080 1.495167 1.927516 5.512094 0.720637 0.709568 0.396751 16.336050 17.846651
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 2.63% 2.63% 0.238078 0.222765 0.009842 0.824171 1.535511 2.250806 -0.407709 -0.544624 0.723612 0.715116 0.412257 1.352093 1.327813
69 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 60.705691 122.390309 121.380272 138.819799 35.922252 39.252896 1950.642290 2545.450935 0.017233 0.016517 0.000601 1.146929 1.135742
70 N04 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 51.425382 105.148270 107.102610 126.064044 35.936232 24.859436 1392.371962 1465.739617 0.016724 0.016375 0.000414 1.143666 1.140415
71 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 53.009135 85.949133 109.828231 126.526951 24.337602 34.810677 1216.425098 1686.633021 0.016709 0.016376 0.000418 1.144333 1.143239
72 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 80.483448 71.111209 122.620677 122.877946 33.582903 27.960588 1765.001929 1666.657628 0.017913 0.016845 0.000712 1.140372 1.138479
73 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 15.79% 2.63% 2.062986 2.417293 -0.682987 0.714582 -0.435235 0.711164 0.757508 -0.020010 0.724689 0.704066 0.474192 1.361523 1.330508
81 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 13.16% -0.741355 2.955849 -0.698677 2.897243 0.057387 1.939601 0.616158 -1.952434 0.678439 0.660408 0.390187 1.334259 1.278070
82 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.776905 -1.081159 -0.327101 1.801692 -1.069955 0.275315 -0.747759 -0.385563 0.701188 0.686851 0.397261 21.369009 16.747803
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.969941 3.593348 2.092253 4.341313 0.604308 2.227345 -1.426012 -2.033162 0.719936 0.710883 0.395922 16.398561 15.049780
84 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.681257 7.495959 -0.081200 2.403886 -0.454484 -0.374218 -0.738507 0.429931 0.078614 0.086094 0.015332 1.211553 1.213665
85 N08 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.472748 0.371374 -0.850528 -0.233675 -1.251910 -1.212921 -1.062932 -1.103578 0.086450 0.077767 0.010399 1.231415 1.232516
86 N08 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.730453 2.893421 0.440125 -0.666799 2.685891 0.224346 -0.821902 -1.009480 0.081032 0.071597 0.006267 1.213842 1.217448
87 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 4.174044 8.749193 -0.248650 0.083529 5.134982 -0.892832 49.423398 -0.943810 0.061191 0.072963 0.010107 1.201515 1.200584
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.612920 21.641097 47.589775 49.262734 26.978262 26.802951 24.100987 17.265157 0.033890 0.033052 0.002507 1.185594 1.186222
90 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.674406 23.110274 47.457792 48.869306 26.770393 26.514205 13.627889 12.220869 0.032378 0.030958 0.000666 1.251772 1.251875
91 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.615839 22.012118 47.431160 49.874571 26.869016 26.644974 18.945644 18.610522 0.031090 0.031551 0.000915 1.210970 1.208977
92 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 32.969060 46.615119 9.824563 12.942581 27.076762 27.284228 16.056929 30.036812 0.273954 0.222171 0.101851 3.651860 2.740658
93 N10 digital_ok 0.00% 29.57% 29.57% 70.43% 100.00% 0.00% 0.617087 0.281417 3.073282 -0.864652 1.022620 0.271806 -1.015025 2.377874 0.204319 0.205063 -0.270669 5.675378 5.102245
94 N10 RF_maintenance 100.00% 29.57% 32.26% 0.00% 100.00% 0.00% 0.143046 -0.155205 -0.647101 -0.586821 -0.450486 1.031232 4.451619 7.274179 0.518312 0.493771 0.332211 34.335464 30.921390
98 N07 digital_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
99 N07 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
100 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.742911 0.303405 -0.000606 0.755934 -0.778885 -0.715112 0.383237 0.161573 0.717402 0.705247 0.409131 13.652238 12.097341
101 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 8.131927 7.855422 3.766829 -0.039631 2.133433 -0.620339 4.414957 0.490232 0.116259 0.091626 0.018373 1.222653 1.225976
102 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.402307 1.363848 16.311488 2.432654 20.175121 7.227227 298.346325 100.018102 0.061835 0.065016 0.008246 1.185030 1.184565
103 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.980874 7.760406 -0.515609 -0.101762 -0.337888 -0.810230 0.305115 -0.187031 0.074548 0.073100 0.005234 1.138280 1.140097
104 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 5.636765 74.228136 0.558213 14.675628 -0.359286 3.575885 1.830857 2.472983 0.079352 0.101008 0.012654 1.193856 1.189281
105 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 24.229022 28.147990 45.037027 47.533982 26.880479 26.843767 15.800859 15.791596 0.033492 0.032884 0.001491 1.182702 1.176872
106 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.910008 23.579891 46.668295 49.213981 26.896066 26.769022 17.249935 13.675994 0.029576 0.029378 0.001005 1.222347 1.218739
107 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.360150 21.670397 45.703967 47.291920 26.836893 26.554232 16.626030 17.725190 0.031010 0.029733 0.001135 1.211515 1.209686
108 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.160492 21.757695 46.898567 49.523493 26.798149 26.662620 12.725386 12.915723 0.031084 0.031271 0.001137 1.221931 1.217911
109 N10 digital_ok 0.00% 29.57% 32.26% 0.00% 31.58% 0.00% -0.500718 0.096977 0.251515 1.418381 -0.605933 1.192311 -0.766943 0.209666 0.552238 0.529417 0.362486 2.696648 2.856052
110 N10 RF_maintenance 100.00% 29.57% 32.26% 0.00% 100.00% 0.00% 38.220135 1.588050 3.390976 1.468788 6.733535 -0.976415 10.096949 -1.807711 0.510539 0.520753 0.302561 32.150465 14.039294
111 N10 digital_ok 100.00% 29.57% 32.26% 0.00% 100.00% 0.00% 0.761748 0.502229 -0.346529 0.979208 0.770069 0.839097 -0.118675 5.089082 0.526113 0.500767 0.329748 18.757939 16.549778
112 N10 RF_maintenance 0.00% 29.57% 32.26% 0.00% 100.00% 0.00% -0.800172 -0.430026 -0.558419 0.205964 0.273665 -1.072299 -0.159110 -1.616340 0.510624 0.487249 0.323753 6.403735 5.722865
116 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.089620 3.734610 5.332228 4.875037 2.816446 1.961849 -1.837339 -2.299775 0.704786 0.689574 0.417229 19.026323 17.397593
118 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 5.26% 13.16% 2.649551 0.922740 2.408772 0.653474 1.675893 1.046143 -0.120102 0.998161 0.707797 0.696628 0.414214 0.891476 0.796891
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.206449 0.658207 9.567785 1.008869 8.081173 -0.890459 -1.521258 -0.577182 0.722647 0.711624 0.432517 8.947067 10.682265
120 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.887497 30.385977 9.795563 61.069686 23.213222 27.327044 11.215298 24.012086 0.129750 0.046993 0.066372 1.235277 1.189035
121 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.081288 4.462992 -0.557410 0.823168 -0.483838 0.826023 47.101291 30.861870 0.082747 0.079447 0.008793 1.207921 1.213138
122 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.500632 5.798784 1.749758 0.923054 1.774709 -0.403596 0.942999 1.199003 0.100661 0.096628 0.014581 1.268601 1.265819
123 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.342725 7.173125 1.274195 0.024677 0.478536 -0.059918 -1.067862 -0.850982 0.121334 0.125849 0.029887 1.270410 1.267350
125 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.206070 22.688095 48.149102 50.231206 26.838789 26.677084 14.417628 19.080479 0.029950 0.031104 0.000701 1.285896 1.292218
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.075846 22.957369 47.537857 50.523700 26.921455 26.768671 16.603044 18.282217 0.029818 0.030226 0.000593 1.295031 1.289799
127 N10 RF_maintenance 0.00% 29.57% 32.26% 0.00% 100.00% 0.00% -0.327236 -0.511661 0.230618 0.114292 0.953857 0.385667 -0.004337 0.641081 0.555950 0.533339 0.361683 10.971369 13.602824
128 N10 digital_ok 0.00% 29.57% 32.26% 0.00% 31.58% 0.00% -0.968417 1.084140 -0.389480 1.171070 -0.517367 -0.593579 0.004337 -1.340725 0.548721 0.522387 0.345080 2.135541 2.132015
129 N10 digital_ok 0.00% 29.57% 32.26% 0.00% 31.58% 0.00% -0.350494 -1.481680 -0.573354 -0.657359 -0.033147 -0.383641 -0.886877 -0.701335 0.534783 0.512703 0.336864 2.263346 2.265989
130 N10 digital_ok 100.00% 29.57% 32.26% 0.00% 100.00% 0.00% 0.626016 0.681295 0.882957 1.513821 0.219801 0.573041 0.411230 10.376580 0.518815 0.495242 0.326934 12.477063 12.298137
135 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 18.42% 0.00% -0.643854 -0.817428 -0.954756 -0.745316 -0.822644 -0.585449 -0.274969 -0.689923 0.613110 0.595775 0.390362 1.584746 1.427508
136 N12 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.746489 9.703060 -0.534777 0.340721 4.200746 2.908266 8.395682 12.924980 0.620721 0.599837 0.366449 18.574886 29.211279
137 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.920138 21.922945 46.843639 48.529380 26.986360 26.808602 16.781610 19.662371 0.038420 0.046370 0.003742 1.365166 1.454783
138 N07 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 28.315836 2.688278 44.077870 -0.120714 26.855255 -0.067899 17.932203 -0.412032 0.045611 0.703223 0.471101 1.290181 12.027086
140 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.755236 4.012469 0.214956 1.546539 2.348454 2.661975 1.314932 0.780704 0.712927 0.704133 0.428875 11.520271 13.070203
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.298082 5.346821 -0.365927 11.889973 1.704465 3.236305 1.877430 19.114823 0.712670 0.696975 0.436816 7.466009 7.989739
142 N13 digital_ok 100.00% 37.63% 100.00% 0.00% 100.00% 0.00% 21.599591 26.508594 9.380545 55.870253 23.898135 26.958769 14.679576 16.335421 0.449696 0.048826 0.289240 13.140088 1.339762
143 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 18.42% -0.196767 -0.488627 1.466964 0.339402 1.311763 -0.103386 0.106517 -1.829802 0.718523 0.707077 0.437859 2.783856 2.460162
144 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 23.68% 0.573200 0.834718 -0.829386 -0.619616 -0.566493 -0.103349 0.047340 -0.659058 0.717532 0.702949 0.446691 3.386558 3.287248
145 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.119320 22.909708 54.434575 56.258996 26.931609 26.800774 16.800940 20.024867 0.036014 0.038835 -0.000115 1.607909 1.938741
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.779400 24.677074 54.210621 57.203538 27.018324 26.909980 17.784216 19.191430 0.051064 0.050902 0.001868 1.226582 1.209503
155 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.142403 24.183700 53.127151 55.190304 26.925021 26.716363 18.511845 17.846761 0.045341 0.047404 -0.000397 1.339342 1.474885
156 N12 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.022735 2.988644 1.621828 5.160851 0.848949 2.773768 2.121117 9.736081 0.619829 0.604199 0.380263 15.160340 12.172166
157 N12 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.081059 1.818011 0.012202 2.462683 1.253216 0.574066 0.515863 -0.184386 0.628320 0.617642 0.382718 25.069549 21.282815
158 N12 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.075918 -1.097672 -0.878526 -0.609889 0.378535 0.120061 -0.147608 0.467873 0.642924 0.634130 0.389944 26.793651 16.935506
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.365978 20.496234 53.851760 55.709882 26.925152 26.841655 17.413261 20.105577 0.048027 0.049889 0.003735 1.256242 1.262521
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.520716 41.470451 -0.360342 3.748403 -0.154248 6.034210 0.021806 1.513613 0.711685 0.629184 0.405533 9.167907 24.813437
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.123228 0.705128 0.095876 -0.840482 2.069127 1.034380 0.494535 -0.360415 0.708457 0.699743 0.414821 2.754184 2.507960
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.800033 -0.154277 0.038096 -0.454573 -0.264564 -0.546682 0.164888 0.449377 0.715459 0.704473 0.423712 3.148461 2.833273
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 7.89% -1.213458 -0.860639 -0.878448 -0.251125 -0.804603 -0.114159 0.205718 1.834901 0.709948 0.696610 0.430697 2.880052 2.758830
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.364858 1.178026 6.369358 -0.754393 4.843858 -0.972051 -0.644945 -0.027772 0.707485 0.690326 0.436391 21.168299 25.106748
166 N14 RF_maintenance 100.00% 2.69% 0.00% 0.00% 100.00% 0.00% 16.957995 1.393675 3.267705 0.772983 5.516962 1.502610 13.822058 0.411768 0.658476 0.682216 0.387906 4.877415 5.139483
167 N15 digital_ok 100.00% 21.51% 21.51% 0.00% 100.00% 0.00% 19.308596 22.187775 15.900591 17.251866 21.126837 21.480786 24.878621 10.790760 0.601805 0.590273 0.267032 4.150604 4.960784
168 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
169 N15 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
170 N15 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
176 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 18.42% -0.179009 -0.290517 -0.810269 0.212354 0.281255 0.024505 -0.864913 1.228083 0.597130 0.584367 0.380219 1.832256 1.697425
177 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.524854 1.365502 1.012814 4.405501 0.317601 9.378407 2.079291 25.068190 0.609581 0.592676 0.381801 14.965912 17.392586
178 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 18.42% -0.486409 -0.956084 0.933012 -0.419628 -0.610781 -0.907859 0.412420 -0.633618 0.624840 0.612299 0.387390 1.590280 1.534213
179 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.013920 0.143442 -0.844473 0.401390 2.838529 0.170583 12.736860 0.319866 0.636024 0.621361 0.401009 8.275369 19.361302
180 N13 RF_maintenance 100.00% 0.00% 37.63% 0.00% 100.00% 0.00% 0.116130 13.947524 0.609573 50.123740 -0.518220 17.134171 -0.806051 12.639738 0.702032 0.493088 0.497759 575.887329 199.611156
181 N13 digital_ok 100.00% 100.00% 65.05% 0.00% 100.00% 0.00% 23.393641 49.815228 54.610833 6.617304 26.947650 27.017214 17.083124 14.795137 0.052769 0.327666 0.187805 1.240594 4.248496
182 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 16.413127 15.688883 18.296681 15.317718 18.614723 30.234912 3.170345 27.114077 0.684815 0.676694 0.428492 16.932105 16.611499
183 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.321336 -0.918521 -0.127451 -0.930721 -0.298698 -1.481056 -0.693173 3.576251 0.708954 0.697048 0.428414 3.036067 2.815978
184 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.346173 -0.398521 0.056078 1.238725 0.637818 0.358582 3.284862 3.274600 0.706599 0.691676 0.424385 2.950509 2.761778
185 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
186 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
187 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
189 N15 digital_ok 0.00% 0.00% 0.00% 0.00% 50.00% 0.00% 3.585958 3.757704 0.419444 -0.270455 -0.547678 -0.505843 0.194666 -0.974521 0.644655 0.621624 0.426842 2.285997 2.071480
190 N15 digital_ok 100.00% 18.82% 100.00% 0.00% 100.00% 0.00% 34.534635 25.420413 2.936440 56.267175 15.643664 26.840245 149.720412 18.862744 0.565656 0.046505 0.373911 8.695413 1.193512
191 N15 digital_ok 0.00% 0.00% 5.38% 0.00% 34.21% 15.79% -0.865399 0.040855 -0.791471 -0.893389 -0.583778 -1.273516 -0.356254 -0.958612 0.615327 0.583853 0.423406 1.625245 1.465474
203 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
205 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
206 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
207 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.407464 11.419240 15.292130 12.372019 15.808400 12.651703 18.939743 17.790266 0.623768 0.610701 0.413483 5.821645 5.279639
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% 13.232542 9.924868 97.830705 100.281231 2780.289220 2780.178020 30057.534159 30060.030181 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.190175 12.957537 7.802564 13.949159 7.905581 13.386302 -0.741346 0.466349 0.634299 0.609130 0.419118 5.661602 5.022690
224 N19 RF_ok 100.00% 13.44% 16.13% 0.00% 100.00% 0.00% 22.128006 21.538196 22.790937 21.849108 24.318476 23.552029 6.419833 5.990769 0.579442 0.564646 0.390165 2.066019 2.038814
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% 24.639854 26.698159 inf inf 2779.878504 2779.359523 29625.668753 29627.102117 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.729104 25.741778 40.233738 41.066115 27.196568 26.768298 24.659229 18.900900 0.065129 0.065625 -0.002189 0.000000 0.000000
321 N02 not_connected 100.00% 8.06% 62.37% 0.00% 100.00% 0.00% 10.797031 8.564924 12.345067 10.741723 13.003820 11.170400 48.948676 47.442098 0.504128 0.421697 0.319670 0.000000 0.000000
323 N02 not_connected 100.00% 29.57% 67.74% 0.00% 100.00% 0.00% 20.381412 12.153974 2.523711 13.952023 10.063957 13.082085 22.728199 4.459773 0.431799 0.391061 0.264141 0.000000 0.000000
324 N04 not_connected 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 27.688185 30.107508 58.380203 58.714290 26.673565 26.238416 504.798890 373.759509 0.024302 0.023823 0.000479 0.000000 0.000000
329 N12 dish_maintenance 100.00% 51.08% 70.43% 0.00% 100.00% 0.00% 3.501300 7.198288 3.258676 10.227497 23.279409 9.797030 15.352803 -1.250034 0.422672 0.355438 0.266984 0.000000 0.000000
333 N12 dish_maintenance 100.00% 59.68% 89.25% 0.00% 100.00% 0.00% 1.264162 7.341439 1.485150 9.328328 1.779250 7.542688 8.174095 -0.797127 0.389264 0.323284 0.235581 0.000000 0.000000
In [22]:
# print ex_ants for easy copy-pasting to YAML file
proposed_ex_ants = [ant for i, ant in enumerate(ants) if np.any([col[i] > 0 for col in bar_cols.values()])]
print('ex_ants: [' + ", ".join(str(ant) for ant in proposed_ex_ants) + ']')
print(f'\nunflagged_ants: [{", ".join([str(ant) for ant in ants if ant not in proposed_ex_ants])}]')
# "golden" means no flags and good a priori status
golden_ants = ", ".join([str(ant) for ant in ants if ((ant not in proposed_ex_ants) and (a_priori_statuses[ant] in good_statuses.split(',')))])
print(f'\ngolden_ants: [{golden_ants}]')
ex_ants: [3, 4, 5, 7, 8, 9, 10, 15, 16, 17, 18, 19, 20, 21, 27, 28, 29, 30, 31, 32, 33, 36, 37, 38, 40, 41, 42, 45, 46, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70, 71, 72, 73, 81, 82, 83, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 116, 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130, 135, 136, 137, 138, 140, 141, 142, 143, 144, 145, 150, 155, 156, 157, 158, 160, 161, 164, 165, 166, 167, 168, 169, 170, 176, 177, 178, 179, 180, 181, 182, 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: [162, 163, 183, 184]

golden_ants: [162, 163, 183, 184]
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_2459795.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 [ ]: