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 = "2459792"
data_path = "/mnt/sn1/2459792"
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-31-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/2459792/zen.2459792.25308.sum.auto_metrics.h5.

Load Ant Metrics¶

In [7]:
use_ant_metrics = False

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

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

Load chi^2 info from redcal¶

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

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

        post_redcal_ant_flags_dict[cal] = {ant: np.all(flags[ant]) for ant in flags}
        # check history to distinguish antennas flagged going into redcal from ones flagged during redcal
        tossed_antenna_lines =  hc.history.replace('\n','').split('Throwing out antenna ')[1:]
        flagged_by_redcal_dict[cal] = sorted([int(line.split(' ')[0]) for line in tossed_antenna_lines])
        
    use_redcal = True
else:
    print(f'No files found matching glob {glob_str}. Skipping redcal chisq.')
Found 187 ant_metrics files matching glob /mnt/sn1/2459792/zen.2459792.?????.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 2459792
Date 7-31-2022
LST Range 16.124 -- 2.145 hours
X-Engine Status ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
Number of Files 1862
Total Number of Antennas 147
OPERATIONAL STATUS SUMMARY
Antenna A Priori Status Count dish_maintenance: 3
RF_maintenance: 42
RF_ok: 11
digital_maintenance: 1
digital_ok: 87
not_connected: 3
Commanded Signal Source antenna
Antennas in Commanded State 114 / 147 (77.6%)
Cross-Polarized Antennas
Total Number of Nodes 15
Nodes Registering 0s N18
Nodes Not Correlating N08, N10
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 71 / 147 (48.3%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 107 / 147 (72.8%)
Redcal Done? ✅
Redcal Flagged Antennas 19 / 147 (12.9%)
Never Flagged Antennas 15 / 147 (10.2%)
A Priori Good Antennas Flagged 76 / 87 total a priori good antennas:
5, 7, 10, 17, 19, 20, 21, 29, 30, 37, 40, 41,
42, 45, 46, 50, 51, 53, 54, 55, 56, 57, 68,
69, 71, 72, 73, 81, 83, 84, 88, 91, 92, 93,
99, 101, 103, 105, 106, 107, 108, 109, 111,
117, 121, 122, 123, 128, 129, 130, 135, 138,
140, 141, 142, 143, 144, 145, 160, 161, 162,
164, 165, 167, 169, 170, 176, 177, 178, 179,
181, 183, 187, 189, 190, 191
A Priori Bad Antennas Not Flagged 4 / 60 total a priori bad antennas:
3, 67, 82, 100
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_2459792.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.922288 -1.128387 -0.749341 -0.811507 1.121711 -0.594523 -0.441784 0.188643 0.726496 0.625097 0.416486 5.162525 3.995716
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.116813 4.701538 -0.751755 1.246412 -0.396593 0.576192 7.012813 2.286894 0.743796 0.623348 0.424239 6.130744 4.804190
5 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.469981 1.281052 0.680208 5.611552 0.098615 4.017679 0.282976 -0.958539 0.743904 0.636769 0.418043 6.061839 5.024860
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.371165 -1.378343 0.369551 0.459476 -0.100579 -0.308386 -0.371195 13.555836 0.734340 0.631765 0.416398 3.978616 3.675271
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.791738 12.633020 21.654889 22.938140 28.724187 29.486692 -0.272903 -1.772244 0.724661 0.607911 0.419082 4.411608 4.032763
9 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.150263 -1.559716 0.362932 0.382189 1.292576 0.595961 -0.300667 0.384095 0.722762 0.616928 0.421067 1.473985 1.423590
10 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.777857 1.848780 2.021976 8.839321 1.883498 7.941929 11.027203 10.766322 0.712406 0.606900 0.433071 3.801166 3.639789
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.192095 0.669319 1.568372 -0.479502 0.280024 0.245004 0.290178 0.836166 0.745384 0.638283 0.414801 1.967716 1.770021
16 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.293758 -1.082098 -0.770086 0.877568 -1.280627 -0.645433 3.580697 1.192562 0.752938 0.649900 0.411977 1.909752 1.709178
17 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.295779 0.721568 0.045962 -0.299231 -0.509700 -0.138099 7.179148 7.090902 0.744622 0.644758 0.406458 4.399232 4.534230
18 N01 RF_maintenance 100.00% 0.00% 80.13% 0.00% 100.00% 0.00% 15.318527 15.898033 0.654237 2.067997 3.821257 9.726692 24.101881 46.267828 0.657641 0.389570 0.431293 2.838959 1.905097
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.784475 -1.339353 7.826956 2.220361 5.808643 1.728483 -0.163160 1.109832 0.742883 0.642332 0.411939 4.292827 4.254399
20 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.785282 5.252512 -0.578331 10.248081 0.337351 9.729781 -0.412278 -1.184620 0.733122 0.623352 0.414882 4.523355 3.942723
21 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.059346 -0.984284 0.864156 -0.467593 1.819986 -0.102559 0.167800 4.334033 0.716588 0.614933 0.422145 4.479613 3.591894
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.675045 24.847253 40.562795 41.006524 40.639384 39.708854 4.199680 3.132292 0.041180 0.046677 0.003981 1.218286 1.224292
28 N01 RF_maintenance 100.00% 44.15% 100.00% 0.00% 100.00% 0.00% 14.879047 34.468797 1.600465 4.242825 22.952279 30.310730 3.066590 13.973339 0.412623 0.182889 0.246080 12.581836 3.132482
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 1.07% -0.801156 -0.932849 0.543153 -0.958182 -1.461674 -1.146554 -0.552611 0.328657 0.755585 0.656102 0.404521 1.966631 1.938283
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.995785 -0.921265 0.247237 -0.931438 -0.192990 -0.541752 8.993927 0.011222 0.749743 0.655684 0.404315 3.968963 4.432527
31 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.511014 -0.547066 -0.818379 -0.635388 0.818181 2.297700 -0.401335 -0.465458 0.754422 0.651682 0.412533 1.625520 1.612226
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 41.449733 8.331389 2.851804 0.345712 11.880963 19.710706 33.313909 69.236581 0.642484 0.623433 0.322987 4.698739 3.698568
33 N02 RF_maintenance 100.00% 0.00% 38.13% 0.00% 100.00% 0.00% -0.011503 10.672910 1.312348 -0.217062 -0.481318 6.446151 -0.308590 12.024592 0.724140 0.437750 0.512475 3.729273 2.093717
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.188914 9.115274 -0.001386 0.034561 0.619289 0.785131 -0.182876 0.596477 0.742666 0.631750 0.417400 4.430472 3.594753
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.386955 0.992362 0.210845 -0.557907 -0.482070 -0.070404 0.114224 9.822589 0.748215 0.649487 0.410939 4.243224 3.891236
38 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.202314 -0.243640 -0.370839 -0.727293 2.141763 1.300491 4.481145 1.102455 0.754700 0.660245 0.410642 4.063476 4.076198
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 6.42% 0.603330 0.102523 -0.180447 -0.944588 -0.925185 -0.662890 -0.403474 -0.835187 0.755707 0.664586 0.403551 1.939098 1.883424
41 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 9.09% 1.320644 -0.463677 3.295059 0.620633 1.960148 -0.922486 -0.795488 -0.430087 0.761631 0.661627 0.406354 1.806539 1.675471
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 9.63% -0.679662 0.372753 2.402573 -0.031082 0.093791 -0.392083 -0.219880 -0.440003 0.761100 0.668197 0.409303 1.844629 1.770553
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.193716 0.817831 -0.477424 -0.257340 -1.119181 0.750720 -0.374722 10.207280 0.742147 0.631483 0.418350 4.126933 3.537984
46 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.100583 -0.557077 0.251203 -0.669132 -1.377321 -0.903933 0.474125 5.894758 0.733756 0.631128 0.423420 4.224156 3.754913
50 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.558059 8.723841 -0.973508 2.608549 0.246589 10.707352 9.271731 34.078045 0.738884 0.625672 0.393490 5.381731 4.370436
51 N03 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 1.140229 40.384775 -0.349339 52.945679 -0.651149 39.316215 1.649158 11.842770 0.750570 0.041872 0.450336 4.104520 1.216921
52 N03 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 10.841789 45.368015 -0.061175 53.527820 5.850258 39.231019 21.525728 11.734303 0.725786 0.036940 0.422361 6.488174 1.185182
53 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 26.20% 1.851454 1.829825 -0.559502 -0.753105 -0.759601 -0.312196 1.676099 3.099030 0.762960 0.674580 0.401023 2.151863 1.825688
54 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.405345 18.539404 0.813137 2.503804 3.806336 9.779006 3.534134 1.553219 0.752272 0.614137 0.385779 5.653977 5.158392
55 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 68.98% 1.051124 0.636042 0.218735 1.598529 1.248005 1.279608 2.932596 -0.718748 0.755487 0.669401 0.397862 4.109105 3.743515
56 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.022591 0.807376 1.408302 1.385824 -0.371349 1.029510 -0.503647 8.005669 0.762078 0.672598 0.401722 5.603696 4.567134
57 N04 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 21.666538 0.836817 38.035969 1.535451 40.787795 9.278209 2.030450 1.213941 0.049196 0.657696 0.410106 1.374827 3.994662
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.412577 0.560686 1.029964 -0.063233 1.529881 1.425637 -0.218240 0.238740 0.744258 0.644934 0.412065 1.683776 1.591559
66 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.108114 0.294813 -0.661185 0.496715 -0.404833 0.686091 -0.220271 1.793914 0.753722 0.659564 0.403622 1.643823 1.524027
67 N03 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.835176 -0.513220 -0.006941 0.007799 0.495630 0.110301 0.316496 1.680984 0.757462 0.670946 0.398149 4.297027 4.608371
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 14.44% 0.779098 0.511435 -0.176383 0.043552 0.106608 1.513403 2.650851 0.783802 0.755521 0.670159 0.397910 1.864505 1.757411
69 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 50.80% -0.991160 -1.026561 -0.772509 -0.886248 -0.374226 0.483756 -0.078562 -0.106420 0.758380 0.671942 0.398681 3.710676 3.603909
70 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.645297 -1.888171 0.435378 -1.071432 3.810456 -0.535469 1.271492 0.705565 0.762847 0.670558 0.410426 17.720639 11.989828
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 99.47% -0.341912 -0.922739 -0.973492 -0.140158 -0.101750 -0.311665 -0.014948 0.708480 0.754042 0.672445 0.402660 17.180546 15.182956
72 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.458644 -0.645034 -0.695362 1.940826 0.593824 0.270167 6.016547 0.996856 0.755250 0.667948 0.408796 5.188869 4.288163
73 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 74.87% 0.766513 -0.194445 -0.397738 -0.604373 0.030310 0.383531 2.245398 1.654175 0.750253 0.644211 0.423136 4.148321 3.216864
81 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.595009 14.427103 -0.892838 23.544391 0.875703 30.637055 4.801500 -1.883406 0.731031 0.622028 0.406732 4.992428 4.085833
82 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.975144 -0.269621 0.775280 0.693876 0.945686 -0.520146 2.786033 -0.309457 0.729139 0.648245 0.399266 5.255189 4.252499
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.257991 3.043163 15.788331 5.634560 18.217939 4.080266 -1.183065 -0.179833 0.754798 0.668645 0.393794 4.601910 3.995585
84 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 10.927332 11.404382 0.092569 1.055369 -1.249826 -0.141446 0.657853 -0.696989 0.073603 0.081803 0.012087 1.193343 1.191109
85 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.934817 34.533310 0.658805 2.261173 -1.067178 12.284781 -0.116386 5.034205 0.077264 0.099310 0.012239 1.177762 1.178819
86 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.382371 5.070740 -0.398665 0.235941 1.192589 4.369205 1.123171 1.710604 0.072394 0.090263 0.010974 1.183368 1.182149
87 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.736060 13.805152 8.055626 12.416758 7.991439 11.596324 3.396662 -1.109036 0.088396 0.101099 0.016736 1.188694 1.185019
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.899893 22.683829 34.448244 35.268331 40.971866 40.084620 6.426655 3.098384 0.043149 0.044963 0.000363 1.183093 1.182359
90 N09 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.385312 2.481423 -0.143757 4.599366 0.510862 3.882832 1.652861 0.723431 0.738469 0.641040 0.417295 3.868861 3.262060
91 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.850981 22.266325 34.355146 35.916731 40.876709 39.971505 4.093987 3.483899 0.037402 0.039380 -0.000242 1.198429 1.192971
92 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 48.209155 68.454153 3.952074 5.742209 28.598470 33.732034 8.945372 8.659425 0.077623 0.077615 0.005244 0.000000 0.000000
93 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.014937 1.653445 3.659198 -0.602469 5.188654 3.738009 0.087216 0.944506 0.077451 0.078392 -0.007483 0.913264 0.914269
94 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.206751 -1.195275 -0.563460 -0.810958 -0.258498 1.369259 3.706407 4.728426 0.062326 0.071308 0.007075 0.000000 0.000000
98 N07 digital_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.448773 8.706981 22.533199 15.251531 30.382511 18.290446 -1.361275 -0.695048 0.723291 0.637734 0.405130 4.360841 3.991636
99 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.062481 12.242408 22.656950 21.539791 30.291107 26.731360 0.068454 -1.785844 0.728106 0.641126 0.391425 5.310656 4.149499
100 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.833987 -0.205168 1.151514 -0.798229 0.983501 -0.691821 -0.134771 -0.702570 0.750593 0.657944 0.400543 5.366796 4.183056
101 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 11.974539 11.298597 10.883969 0.485677 9.903078 -0.622225 3.112000 1.750732 0.104602 0.074342 0.018561 1.189730 1.191140
102 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 12.955318 3.881090 26.410416 17.392320 158.873248 94.684957 808.896158 493.936058 0.101426 0.076746 0.024746 1.170910 1.179050
103 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 4.368272 11.381350 -0.156736 0.163682 0.824960 -0.389881 0.553990 0.436509 0.066529 0.063270 0.005645 1.184933 1.188987
104 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 8.067882 89.707112 1.335072 10.207498 1.074846 4.125295 1.483877 -0.357579 0.072528 0.085084 0.009276 1.222455 1.221547
105 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.103824 29.648691 32.083446 33.624642 40.858271 39.883503 2.853477 2.280190 0.037645 0.038987 0.002341 1.190008 1.192538
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% 20.686741 19.857569 32.751331 33.465038 40.871684 39.983523 3.218183 3.218800 0.045229 0.046739 0.002526 1.209266 1.213015
108 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.293431 5.304688 -0.751032 3.983664 -0.974253 2.505411 0.039264 -0.726423 0.739642 0.635454 0.424432 4.410685 3.621996
109 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.833155 -0.441645 0.135736 -0.507450 -1.609144 -0.937558 0.777774 0.344187 0.064279 0.063803 0.009816 1.161319 1.164176
110 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 46.205434 9.960742 3.228180 2.006994 8.960042 12.112960 9.942499 92.640736 0.070542 0.059981 0.005488 1.353566 1.352988
111 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.409287 0.981820 -0.121668 2.099571 0.200248 0.877704 -0.160285 1.618688 0.051744 0.053862 0.003319 1.036202 1.006405
112 N10 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
116 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.015518 13.710538 -0.735492 22.711585 1.117347 29.471835 -0.226676 -2.225157 0.723417 0.624559 0.410492 5.081172 4.560278
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.892167 2.925513 22.826741 6.719755 30.601108 5.581405 -1.513056 -1.109375 0.731416 0.651300 0.410017 5.322822 5.683935
118 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 2.939340 1.342222 2.450241 -0.827009 0.554140 0.270372 1.817634 3.766642 0.741891 0.648336 0.405432 1.731954 1.585946
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.380637 2.145876 10.852465 -0.485909 10.652783 0.480219 -1.047973 -0.521709 0.753467 0.648934 0.413161 4.888601 4.514196
120 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.051428 36.880942 3.093383 45.968459 23.544273 39.834866 1.178339 6.306089 0.099877 0.035964 0.050272 1.239691 1.198351
121 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 4.312771 6.549258 -0.626302 0.455241 -0.117226 0.715535 18.087729 14.709352 0.078016 0.066492 0.009522 1.214172 1.210836
122 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 12.645761 9.378103 8.702851 2.222343 6.620130 0.767918 0.736701 1.566816 0.076523 0.067962 0.009038 1.203739 1.199782
123 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 9.355428 10.025484 1.581404 -0.121317 -0.808906 -0.801057 0.489336 0.794490 0.074656 0.089778 0.015990 1.237198 1.233830
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 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
128 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
129 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.342807 -1.664611 -0.399827 -1.044719 -1.066071 -1.056994 -0.635606 -0.682313 0.051088 0.057206 0.003503 1.063128 1.064397
130 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.244721 -0.157631 0.396282 0.332654 0.249923 0.436775 -0.325917 3.001646 0.059336 0.058517 0.005295 0.000000 0.000000
135 N12 digital_ok 0.00% 4.83% 5.37% 0.00% 5.35% 10.16% -0.730852 -0.798307 -0.997621 -0.320282 -0.609345 -0.327006 1.473285 0.692359 0.637230 0.535112 0.377548 2.410459 2.091450
136 N12 RF_maintenance 100.00% 4.83% 5.37% 0.00% 100.00% 0.00% 2.622606 11.921906 -0.757259 1.108083 2.233197 2.656394 3.536901 8.021796 0.636373 0.524244 0.371733 6.688434 7.809307
137 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.598624 23.547046 33.858400 34.658493 40.844512 40.019914 3.034614 4.424288 0.039886 0.049299 0.004444 1.344464 1.432102
138 N07 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 27.033741 2.850499 31.307458 -0.712069 40.703136 -0.138793 3.675219 -0.488216 0.051789 0.643335 0.448346 1.246005 5.700326
140 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.14% 3.259765 2.882281 0.186971 0.619279 1.218814 1.965242 0.535497 1.782672 0.738823 0.652681 0.410371 1.942481 1.876733
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.937918 4.379967 0.365674 9.747078 0.772944 2.940100 0.765338 8.202153 0.740387 0.623558 0.416177 5.532354 6.293704
142 N13 digital_ok 100.00% 43.07% 100.00% 0.00% 100.00% 0.00% 28.530916 27.283099 2.665957 41.437362 25.360079 39.737042 2.585933 2.952557 0.412856 0.044647 0.230737 7.635188 1.347654
143 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 1.07% 0.53% 0.616015 -1.232690 0.754951 1.911745 -0.299581 0.868780 -0.350437 -0.880671 0.745384 0.663493 0.407325 2.077455 1.847336
144 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 1.07% 2.14% -0.577626 -0.577571 2.373521 -0.458865 1.643247 -0.499834 1.417127 3.638408 0.745955 0.654996 0.413980 1.987294 1.824777
145 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.463660 22.501410 40.837723 41.840930 40.706896 39.763633 3.330842 4.477529 0.036657 0.037163 -0.000054 1.561244 1.559292
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.206745 25.617478 40.662238 42.657688 40.697551 39.785558 3.792960 4.048552 0.050342 0.052498 0.001513 1.362301 1.353947
155 N12 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.728849 22.767439 39.782030 40.908113 40.595049 39.675743 4.072304 3.492378 0.043023 0.041376 -0.000001 1.266460 1.318585
156 N12 RF_maintenance 100.00% 4.83% 5.91% 0.00% 100.00% 0.00% 5.193711 5.161030 11.246434 11.279067 11.007740 11.875864 2.578179 8.399779 0.645509 0.527535 0.382617 6.756213 5.037348
157 N12 RF_maintenance 100.00% 4.83% 5.37% 0.00% 100.00% 0.00% -0.097474 5.684711 0.133113 13.338465 -0.665791 13.669570 0.321627 -0.117749 0.646072 0.542941 0.380818 6.391582 4.829035
158 N12 RF_maintenance 100.00% 4.83% 5.37% 0.00% 100.00% 0.00% 0.416168 -1.353905 0.172184 1.129675 -0.474314 0.286473 0.735664 5.018167 0.652690 0.552037 0.382120 6.506516 5.419514
160 N13 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
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.790233 47.213993 -0.385673 3.388445 -0.880899 10.726506 0.436597 0.083246 0.745797 0.551867 0.397098 5.101245 6.521243
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 3.74% 0.819323 0.199284 0.312474 0.181254 0.560027 0.431236 -0.184597 -0.400439 0.744139 0.660179 0.406918 2.155771 2.208105
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.437942 -0.055759 0.006941 -0.369946 -0.943192 -0.773733 -0.457921 0.001716 0.750179 0.663629 0.402435 2.081834 1.987055
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.53% -1.721344 -1.591277 -0.863192 -0.681076 -1.695993 -0.563903 -0.234289 -0.001716 0.748538 0.660138 0.405802 2.138952 2.108243
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.168981 0.262976 5.952034 -0.333624 3.393226 -0.711546 0.815197 0.126302 0.751526 0.657718 0.405392 6.143494 7.003746
166 N14 RF_maintenance 100.00% 0.00% 0.54% 0.00% 100.00% 0.00% 30.996139 28.508139 1.742026 1.478111 14.158796 11.968451 20.917779 10.076402 0.643775 0.535326 0.259047 3.564494 3.673070
167 N15 digital_ok 100.00% 12.89% 3.22% 0.00% 100.00% 0.00% 33.788703 18.898687 18.793319 22.647685 35.428575 30.535043 109.586309 26.464703 0.552573 0.518893 0.239339 3.275039 3.906019
168 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.314895 15.744984 22.165271 25.451895 28.956139 33.172089 -1.122247 -2.064118 0.717105 0.601408 0.418163 4.444067 3.862329
169 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.328165 14.337860 24.448007 23.934090 32.789083 30.920630 -1.642939 -1.780671 0.705728 0.591008 0.419785 4.509960 3.629507
170 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.360074 12.891310 24.811211 22.828041 33.684400 28.937327 -1.334655 -2.029428 0.690199 0.595167 0.424157 4.317630 3.470963
176 N12 digital_ok 0.00% 4.83% 9.13% 0.00% 9.09% 4.81% 0.270167 -0.229553 -0.451691 1.400016 -0.629502 0.833784 -0.587469 -0.693368 0.632699 0.519826 0.384846 2.127304 1.919435
177 N12 digital_ok 0.00% 4.83% 8.59% 0.00% 8.56% 1.60% 0.604034 0.814064 0.785606 0.191212 -1.024283 0.568749 0.990294 1.237864 0.638755 0.516551 0.386462 2.048111 1.813237
178 N12 digital_ok 0.00% 4.83% 5.37% 0.00% 5.35% 0.00% -0.623418 -1.436541 1.054768 -1.039796 -0.879594 -1.101893 0.730905 -0.143755 0.640805 0.535972 0.383991 1.863572 1.616867
179 N12 digital_ok 0.00% 4.83% 5.37% 0.00% 5.35% 0.00% -0.187090 0.273376 -0.862136 -0.882266 0.732050 -1.126343 2.443892 -0.666668 0.650153 0.543738 0.390701 1.796089 1.797222
180 N13 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
181 N13 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
182 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 12.274016 1.962257 21.783168 0.024296 28.286008 13.388128 -1.536466 72.742205 0.734307 0.643611 0.421903 5.097354 4.751358
183 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.984675 1.051028 -0.338134 -0.868114 -1.360630 0.296462 1.427998 9.168695 0.743329 0.643485 0.414698 5.125918 4.746362
184 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.054516 -0.448671 -0.946910 0.250563 -0.780978 -0.309598 -0.102370 -0.203019 0.750042 0.649666 0.406526 2.286067 2.027895
185 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.039010 0.187892 2.038678 0.492734 -0.006857 -0.900078 0.733577 -0.789845 0.753720 0.655031 0.405183 2.004003 1.734328
186 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.054516 -0.418260 2.695021 1.088097 0.006857 -0.379214 1.655154 -0.697412 0.742286 0.647355 0.401590 2.012035 1.908322
187 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.830983 0.594889 5.891977 1.524453 3.793777 -0.474849 3.465934 4.535630 0.741540 0.648768 0.404639 6.506676 5.697062
189 N15 digital_ok 0.00% 0.00% 0.00% 0.00% 11.76% 11.23% 2.931035 3.484765 0.648013 -0.667905 -0.059590 0.061654 -0.285667 2.140601 0.716192 0.616539 0.418310 -0.044225 -0.041993
190 N15 digital_ok 100.00% 13.96% 100.00% 0.00% 100.00% 0.00% 46.618417 26.017823 2.811665 41.757954 17.845637 39.798180 94.790419 3.688213 0.563898 0.049452 0.372332 4.278220 1.749564
191 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.202662 0.057460 -0.932566 -0.862701 -0.257871 -0.919017 4.342115 5.781584 0.706275 0.600459 0.436163 4.261871 4.038587
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% 9.322695 4.939791 15.126292 -0.576183 18.135181 8.877315 22.215841 28.483941 0.727485 0.587892 0.422082 8.602783 5.489698
206 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.691646 6.423616 0.546556 10.513985 10.097952 12.120002 23.291661 23.529211 0.676892 0.613751 0.408541 3.587440 3.921127
207 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.555069 9.094335 18.284426 15.829319 23.675416 19.372021 8.097230 7.209955 0.704603 0.611396 0.396459 10.842047 8.588111
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% 8.889134 7.623793 70.015149 72.820464 2054.208338 2447.096810 7184.455185 10090.023845 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.494609 9.575804 8.350783 16.921038 9.173801 18.744412 0.966683 -0.640215 0.709289 0.608196 0.416413 4.830436 3.566975
224 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.612505 17.116407 28.040944 27.870607 38.589228 36.726546 -2.160172 -2.808555 0.679007 0.571075 0.402341 3.836269 2.838533
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% 8.215203 10.969054 90.160729 81.644661 2801.541889 2830.190952 11837.414111 11834.570659 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.874899 26.263088 28.152032 28.101049 40.511373 39.659900 6.016543 4.026996 0.059105 0.053070 -0.000708 0.000000 0.000000
321 N02 not_connected 100.00% 3.76% 23.09% 0.00% 100.00% 0.00% 7.864473 5.772269 14.734099 13.677961 19.787975 17.202480 27.999417 27.337669 0.648516 0.490207 0.420464 0.000000 0.000000
323 N02 not_connected 100.00% 32.87% 26.32% 0.00% 100.00% 0.00% 23.729735 8.986735 0.997210 17.779257 20.688276 22.081322 3.197618 0.487538 0.482018 0.469550 0.327331 0.000000 0.000000
324 N04 not_connected 100.00% 4.30% 23.63% 0.00% 100.00% 0.00% 11.357771 12.509813 19.914252 20.819669 26.233758 26.485287 -0.833932 -1.850386 0.641967 0.482275 0.409263 0.000000 0.000000
329 N12 dish_maintenance 100.00% 32.76% 45.11% 0.00% 100.00% 0.00% 4.735208 5.097291 0.472509 13.068295 9.899620 14.749142 3.055649 -0.884621 0.509315 0.412275 0.347761 0.000000 0.000000
333 N12 dish_maintenance 100.00% 40.92% 54.24% 0.00% 100.00% 0.00% 7.183931 5.281838 5.268578 12.165318 16.125162 14.702754 0.732362 0.280612 0.458155 0.393327 0.320177 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, 10, 17, 18, 19, 20, 21, 27, 28, 29, 30, 32, 33, 36, 37, 38, 40, 41, 42, 45, 46, 50, 51, 52, 53, 54, 55, 56, 57, 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, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130, 135, 136, 137, 138, 140, 141, 142, 143, 144, 145, 150, 155, 156, 157, 158, 160, 161, 162, 164, 165, 166, 167, 168, 169, 170, 176, 177, 178, 179, 180, 181, 182, 183, 187, 189, 190, 191, 203, 205, 206, 207, 220, 221, 222, 223, 224, 241, 242, 243, 320, 321, 323, 324, 329, 333]

unflagged_ants: [9, 15, 16, 31, 65, 66, 118, 163, 184, 185, 186]

golden_ants: [9, 15, 16, 31, 65, 66, 118, 163, 184, 185, 186]
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_2459792.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 [ ]: