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 = "2459799"
data_path = "/mnt/sn1/2459799"
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-7-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/2459799/zen.2459799.25315.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/2459799/zen.2459799.?????.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/2459799/zen.2459799.?????.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 2459799
Date 8-7-2022
LST Range 16.586 -- 2.607 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: 31
RF_ok: 11
digital_maintenance: 3
digital_ok: 96
not_connected: 3
Commanded Signal Source antenna
Antennas in Commanded State 107 / 147 (72.8%)
Cross-Polarized Antennas 93
Total Number of Nodes 15
Nodes Registering 0s N18
Nodes Not Correlating N08, N09
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 72 / 147 (49.0%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 111 / 147 (75.5%)
Redcal Done? ✅
Redcal Flagged Antennas 23 / 147 (15.6%)
Never Flagged Antennas 6 / 147 (4.1%)
A Priori Good Antennas Flagged 91 / 96 total a priori good antennas:
5, 7, 10, 15, 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,
85, 86, 88, 91, 93, 94, 98, 99, 100, 101, 103,
105, 106, 107, 108, 109, 111, 112, 116, 117,
118, 121, 122, 123, 127, 128, 129, 130, 140,
141, 142, 143, 144, 145, 156, 157, 158, 160,
161, 162, 163, 164, 165, 167, 169, 170, 176,
177, 178, 179, 181, 183, 186, 187, 189, 190,
191
A Priori Bad Antennas Not Flagged 1 / 51 total a priori bad antennas:
67
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_2459799.csv

Build DataFrame¶

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

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

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

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

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

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

Table 2: RTP Per-Antenna Metrics Summary Table¶

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

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

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

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

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

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

In [21]:
HTML(table.render())
Out[21]:
Ant Node A Priori Status Auto Metrics Flags Dead Fraction in Ant Metrics (Jee) Dead Fraction in Ant Metrics (Jnn) Crossed Fraction in Ant Metrics Flag Fraction Before Redcal Flagged By Redcal chi^2 Fraction ee Shape Modified Z-Score nn Shape Modified Z-Score ee Power Modified Z-Score nn Power Modified Z-Score ee Temporal Variability Modified Z-Score nn Temporal Variability Modified Z-Score ee Temporal Discontinuties Modified Z-Score nn Temporal Discontinuties Modified Z-Score Average Dead Ant Metric (Jee) Average Dead Ant Metric (Jnn) Average Crossed Ant Metric Median chi^2 Per Antenna (Jee) Median chi^2 Per Antenna (Jnn)
3 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 3.168996 -0.474828 -0.534224 -0.831177 2.490439 -0.596556 0.964243 0.811796 0.722007 0.625193 0.417763 1.683073 1.466373
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.169699 4.582294 -0.648479 1.664303 0.830351 1.076113 5.330989 0.825888 0.740015 0.623730 0.424576 5.172924 4.631326
5 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.205464 1.285169 -0.274476 4.799260 -0.398795 4.618603 1.686051 -1.134799 0.745290 0.638055 0.421676 4.380948 3.978111
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.224399 -1.145971 0.543090 0.606268 -0.061937 2.910416 0.401844 5.849635 0.736388 0.632489 0.421853 4.396672 4.944107
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.918683 12.247828 21.597855 22.223141 42.878561 43.525151 -0.091802 -2.504503 0.726256 0.604521 0.428377 5.319505 5.276921
9 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 2.14% 0.00% -0.219026 -0.807235 0.223541 -0.123632 1.857612 0.354799 -0.669722 -0.866807 0.723321 0.617769 0.426601 1.701633 1.492255
10 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.14% -0.109834 -1.100947 -0.673177 0.756074 0.014316 1.685575 0.097536 -0.583200 0.711974 0.604422 0.439544 1.731202 1.562720
15 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.498140 1.733260 1.472520 0.497614 0.919434 1.072909 1.373159 10.779112 0.743052 0.630662 0.417859 5.253443 4.788023
16 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 1.07% 0.00% -0.878225 -0.678193 -0.946547 -0.052361 -1.261661 -0.892823 2.485895 2.460260 0.751016 0.649750 0.414186 1.589142 1.456781
17 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.286493 0.949650 0.282016 0.489491 0.946191 0.938040 7.599994 2.071759 0.744328 0.647407 0.407505 4.260908 4.625356
18 N01 RF_maintenance 100.00% 0.00% 73.68% 0.00% 100.00% 0.00% 13.956285 12.697665 0.328952 0.091582 19.426868 10.707703 84.127646 44.223036 0.671448 0.400817 0.438393 2.863191 2.113734
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.837914 9.329608 3.883758 17.811658 3.517826 31.366062 0.065934 -2.029932 0.742335 0.641339 0.418748 4.669788 5.824216
20 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 1.07% 2.14% -1.221252 1.570890 -0.087775 -0.336940 0.988861 0.637533 1.873995 -0.951499 0.732706 0.618116 0.424008 1.848396 1.703811
21 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.397549 1.216173 0.510216 -0.325822 -0.729865 13.516039 -0.199023 0.096825 0.717533 0.611909 0.429660 4.796054 4.398664
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.095812 23.514118 38.631404 39.684267 60.366549 58.903424 3.507420 2.379972 0.041152 0.046890 0.004006 1.264997 1.260587
28 N01 RF_maintenance 100.00% 44.68% 100.00% 0.00% 100.00% 0.00% 15.245327 33.848121 1.918358 3.703983 34.447403 42.016717 3.918758 27.903919 0.403569 0.184680 0.240796 7.272235 2.077144
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 1.07% 5.35% -0.399474 -0.704020 0.675805 -0.386907 -1.424990 -1.092314 -0.653506 0.183718 0.754597 0.656301 0.406479 1.601888 1.484197
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.550948 -0.224481 0.446509 -0.488219 0.158014 -0.425550 9.969291 -0.593621 0.747896 0.655841 0.404193 4.731687 5.048394
31 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.520555 -0.423895 -0.758267 0.902197 3.490149 4.549763 1.903351 0.409111 0.754077 0.648321 0.417561 4.311283 4.300929
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 40.049298 12.821821 2.658495 1.707330 17.669465 24.024939 42.286333 167.120394 0.637749 0.617013 0.319339 4.803280 4.395635
33 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.962507 16.839770 inf inf 4424.599005 4405.521826 11823.940699 11823.337339 nan nan nan 0.000000 0.000000
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.985883 9.379634 0.141279 0.411743 1.980281 1.687616 0.144219 -0.314331 0.737599 0.635653 0.414371 4.767689 3.693331
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.865541 1.354998 -0.629440 0.232905 0.552521 2.040013 -0.061235 10.566946 0.743180 0.651980 0.405914 4.343644 3.937914
38 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.379627 0.052160 -0.464909 -0.894765 4.133253 3.001237 5.160231 0.307578 0.750215 0.663649 0.406650 4.481498 4.599573
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 1.07% 20.86% 0.936627 -0.274936 -0.034774 -0.336627 0.678074 -0.021540 -0.407668 -0.725441 0.746023 0.661951 0.401124 1.770600 1.598649
41 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.056097 -0.556901 2.962731 1.292031 4.505598 -1.154899 -0.714756 0.660117 0.755932 0.660984 0.409176 5.027333 5.027339
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 19.25% -0.075860 1.707591 2.215423 0.874258 0.104175 -0.377670 -0.017618 -0.577819 0.758617 0.658118 0.416189 1.713229 1.540785
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.303551 0.841819 -0.638449 0.329672 -1.378600 0.314494 -0.330098 7.241087 0.743812 0.631681 0.423750 3.930568 3.529652
46 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.671124 -0.132501 0.592839 -0.937101 -1.156748 -0.752967 -0.130352 4.710681 0.736298 0.629908 0.429078 4.013263 3.421680
50 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 37.456386 1.708449 3.122494 2.984579 18.718423 2.932651 33.540198 3.203061 0.654167 0.640467 0.352334 7.143155 5.124013
51 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 2.14% 13.90% 1.067902 2.974800 -0.793920 -0.694454 0.275502 -0.867217 -0.846288 1.786809 0.743165 0.659198 0.401786 1.665611 1.559969
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.740458 8.880516 -0.192187 0.084355 5.014256 1.283457 0.487312 0.291372 0.750738 0.668912 0.398264 4.251038 4.522501
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.970186 2.390269 -0.530795 -0.090906 0.995962 0.369020 2.309468 6.147201 0.756481 0.677692 0.401027 4.038170 4.076770
54 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 67.91% 0.791664 -0.124855 0.915457 1.200727 -0.126731 2.069628 -0.164151 1.835990 0.751798 0.671522 0.398033 3.994250 3.891707
55 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.140944 1.482203 -0.718663 1.066113 9.101355 2.167096 5.696499 -0.600373 0.752477 0.668422 0.400044 4.501145 4.049683
56 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 58.29% -0.976595 2.056072 1.236861 1.063293 1.785176 -0.513719 -0.336854 2.248327 0.754165 0.672026 0.401499 1.960467 1.985379
57 N04 digital_ok 100.00% 100.00% 59.72% 0.00% 100.00% 0.00% 19.068712 17.946099 36.344038 1.677815 60.681618 37.682779 1.295872 3.256583 0.048894 0.384068 0.234956 1.232278 3.845121
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 5.35% 9.63% 1.125101 0.685574 0.664375 0.776619 2.710269 2.184251 0.642104 0.854909 0.735204 0.641752 0.412999 1.721248 1.533480
66 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 16.04% 1.421015 0.977227 -0.797942 1.100424 0.106052 3.303190 -0.265353 1.805231 0.744948 0.659482 0.402310 1.673142 1.460899
67 N03 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.110093 -0.233756 0.170343 -0.357854 0.428366 -0.109131 0.059099 0.850614 0.748461 0.671077 0.394506 4.823390 5.048111
68 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.317187 1.042693 0.031838 0.379346 1.161844 3.439450 0.960080 7.259729 0.750026 0.673552 0.394313 4.684812 4.783113
69 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 51.87% 0.027778 -0.587571 -0.647420 -0.243403 -0.257450 -0.049936 -0.181514 -0.057074 0.750913 0.675879 0.399841 3.939621 3.170182
70 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.148046 -1.218809 0.103814 -0.759676 4.691566 -0.901640 -0.327733 -0.369404 0.757244 0.667257 0.411804 15.868382 10.410755
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% 0.409360 -0.618808 -0.913994 -0.248316 0.670908 -0.725146 -0.713827 -0.714426 0.750317 0.674807 0.405123 14.557667 12.954291
72 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.897365 -0.054517 -0.623355 1.455231 2.941527 0.614195 8.310630 4.292199 0.748658 0.666495 0.411265 5.009392 3.829691
73 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.865225 2.167148 -0.582250 -0.397038 0.310430 1.403256 6.546626 5.309534 0.746170 0.646167 0.426251 4.679265 3.590754
81 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.516160 2.915005 -0.640819 3.842545 2.385516 6.042818 8.097377 0.083979 0.717484 0.630690 0.406273 4.614290 4.631962
82 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.810184 -0.148079 -0.098615 1.464070 6.348366 1.480844 7.760758 2.532869 0.723047 0.640997 0.404708 5.331288 4.481164
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.229695 2.889424 2.155539 4.934476 1.206923 4.417711 -0.193700 -1.330962 0.741458 0.663862 0.396513 4.524703 4.412089
84 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 11.105581 11.913869 0.141617 1.732071 -1.039106 0.830229 2.251834 -1.021031 0.051716 0.063586 0.005120 1.244424 1.238261
85 N08 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.134317 1.754999 1.042752 2.026819 -0.831215 0.289439 -0.916222 -1.019340 0.069623 0.067643 0.007212 1.224003 1.220997
86 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.932723 5.450581 -0.778807 -0.217438 0.822768 5.608038 0.453275 0.826946 0.080119 0.078476 0.011330 1.234206 1.235572
87 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.703037 12.825147 4.048288 1.184595 30.456187 1.572002 191.703118 -0.169430 0.082955 0.084993 0.018301 1.236740 1.232624
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.298903 21.907054 32.835668 34.248455 60.855226 59.463103 5.753571 2.361075 0.032011 0.030515 0.001725 1.204912 1.204524
90 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.787335 21.014273 32.728014 33.873582 60.735718 59.338892 1.101928 0.139126 0.031755 0.028739 0.001050 1.124093 1.122409
91 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.949690 21.991612 32.733224 34.859146 60.732271 59.212778 3.565483 2.916692 0.030999 0.031204 0.000181 0.876965 0.888745
92 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 49.870470 63.424510 4.047264 5.567960 45.133966 50.323118 2.584566 13.335164 0.238632 0.187698 0.076138 2.846731 2.520834
93 N10 digital_ok 100.00% 8.59% 8.59% 91.41% 100.00% 0.00% 0.047165 1.750175 3.480959 -0.554017 8.344040 6.260451 -0.145635 0.603544 0.246068 0.245145 -0.252711 3.677737 3.836537
94 N10 digital_ok 100.00% 9.13% 26.32% 0.00% 100.00% 0.00% -0.589138 -1.668669 -0.305788 -0.466373 0.881563 1.796324 4.961724 3.844644 0.576316 0.458061 0.357078 4.248754 3.625544
98 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.672866 7.534634 0.516956 -0.393221 3.229712 4.067515 2.643980 1.607490 0.717193 0.612485 0.412228 5.047941 5.129608
99 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.151690 0.950971 3.327558 -0.331764 8.750431 -0.213393 5.307592 2.900057 0.721017 0.632911 0.400566 5.328934 5.369001
100 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 3.21% 14.97% 0.621522 0.031951 0.777119 0.156579 1.352511 -1.291489 -0.442257 -1.001076 0.737537 0.644628 0.410969 1.585807 1.418484
101 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 11.313930 11.508071 3.285981 0.035426 0.924011 -1.048183 3.973579 2.595074 0.071901 0.065928 0.009777 1.309686 1.278821
102 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.749199 2.553912 13.914333 2.924648 123.148519 29.392186 255.614495 72.327165 0.061830 0.053477 0.004401 1.222884 1.225917
103 N08 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
104 N08 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
105 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.000107 27.510732 32.711211 34.778221 60.786535 59.302147 2.147767 1.584608 0.033330 0.032035 0.000975 1.200646 1.199723
106 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.565640 24.516545 32.058967 34.218836 60.599218 59.116234 2.929946 1.466591 0.030884 0.030765 0.001479 1.213605 1.204834
107 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.710638 19.085558 33.248886 34.498457 60.801282 59.440404 2.489587 2.579116 0.029426 0.031904 0.001360 1.168902 1.165025
108 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.279872 20.458220 32.225251 34.448059 60.784653 59.424669 0.666013 0.363802 0.030957 0.031617 0.001381 0.981188 0.975683
109 N10 digital_ok 0.00% 2.69% 25.24% 0.00% 25.13% 4.81% -0.749508 0.404833 0.204617 0.403759 -1.291932 -0.221074 0.428955 -0.049020 0.600942 0.480072 0.361654 1.926000 2.018968
110 N10 RF_maintenance 100.00% 23.63% 42.96% 0.00% 100.00% 0.00% 43.063784 20.370205 2.885295 0.674915 13.637344 20.593722 18.097619 141.902229 0.498039 0.423390 0.226825 6.777503 7.159039
111 N10 digital_ok 100.00% 8.06% 25.78% 0.00% 100.00% 0.00% 1.079149 0.912525 -0.019925 1.456501 1.628509 1.224963 7.792458 2.109799 0.581337 0.466182 0.349506 4.545782 4.875201
112 N10 digital_ok 0.00% 9.13% 25.78% 0.00% 29.41% 0.00% -0.145571 -0.395272 -0.476129 1.063028 -0.827884 -0.498899 0.437031 -1.308650 0.571470 0.460726 0.354374 1.837730 1.952825
116 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 10.16% 2.67% 0.820969 2.056938 -0.641595 -0.780820 1.832887 3.563066 3.307123 0.398800 0.709542 0.617436 0.418865 1.510300 1.358980
117 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
118 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
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.184312 4.455198 10.453020 0.029930 15.245432 1.432011 -1.287478 -0.859568 0.743126 0.635669 0.421817 5.011840 4.227522
120 N08 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
121 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.822997 6.926365 -0.572256 0.913933 0.861205 3.565118 23.829800 17.815501 0.065371 0.068120 0.008566 1.221815 1.218351
122 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 10.339943 8.981072 1.195507 1.432830 0.124420 -0.092258 0.006503 0.304688 0.077459 0.076315 0.013418 1.351638 1.341166
123 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 9.885034 11.157113 0.536979 0.144019 -0.430950 0.954611 0.137150 -0.904132 0.083626 0.082772 0.019194 1.299015 1.294626
125 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.549246 21.679258 33.325485 35.067018 60.777651 59.384292 1.406715 3.284240 0.029192 0.029623 0.000335 1.275589 1.270328
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.216449 22.127022 32.813997 35.395466 60.808999 59.403891 2.292230 2.895720 0.029469 0.029599 0.000501 1.225090 1.219140
127 N10 digital_ok 0.00% 2.69% 24.70% 0.00% 25.13% 0.53% 0.045864 -0.194096 0.037520 -0.217633 -0.292184 0.759398 0.024733 0.005776 0.601308 0.486896 0.358096 2.178901 2.012454
128 N10 digital_ok 0.00% 2.69% 25.24% 0.00% 25.13% 0.00% -1.226601 3.441911 -0.098701 2.087326 -0.611595 3.167313 -0.210734 -0.901454 0.599410 0.478078 0.351529 1.859638 1.684445
129 N10 digital_ok 0.00% 6.98% 25.24% 0.00% 27.81% 0.00% -0.027778 -1.112514 -0.481796 -0.827289 -0.862127 -0.302468 -0.794720 -0.666929 0.591522 0.476125 0.349614 2.009588 1.701227
130 N10 digital_ok 0.00% 9.67% 25.78% 0.00% 29.95% 0.00% 0.733698 0.586768 0.290225 1.138498 0.864707 0.597364 -0.358776 2.987429 0.573459 0.462076 0.347223 2.094023 1.859999
135 N12 digital_maintenance 0.00% 0.00% 0.54% 0.00% 100.00% 0.00% -0.620803 -0.194419 -0.982250 -0.948558 -0.477693 -0.371415 2.273220 0.989071 0.639841 0.533063 0.395763 3.735021 3.281001
136 N12 digital_maintenance 100.00% 0.00% 0.54% 0.00% 100.00% 0.00% 3.031594 11.951747 -0.708009 0.528601 3.572794 4.027819 0.659315 5.056625 0.640687 0.519540 0.389818 7.239952 5.915806
137 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
138 N07 RF_maintenance 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 25.932376 3.104390 29.814308 -0.699565 60.602585 0.008105 2.875846 -0.332846 0.049769 0.625996 0.465741 1.334774 4.949261
140 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.124030 21.309908 37.709706 39.917393 60.412772 59.086627 1.030658 0.936486 0.041643 0.044295 0.002117 1.174311 1.164750
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.560517 3.590847 0.199302 9.520008 2.115083 4.075759 2.221431 35.422066 0.736532 0.621178 0.423459 7.443328 6.872907
142 N13 digital_ok 100.00% 50.59% 100.00% 0.00% 100.00% 0.00% 29.128214 26.217480 3.061017 40.109595 40.565395 58.993585 2.410911 2.164421 0.396885 0.046154 0.251706 6.766582 1.332318
143 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 5.35% 11.76% 0.249458 -0.196418 1.032772 1.052019 -0.101158 0.048945 -0.394589 -0.417356 0.744017 0.661732 0.412221 1.299111 1.399792
144 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.406671 0.893082 -0.557553 -0.514056 -0.630870 1.154476 3.742375 4.741897 0.749093 0.654402 0.420516 9.153991 8.816139
145 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.628780 21.863622 38.919172 40.452290 60.500540 59.169154 2.558830 3.572171 0.036923 0.038113 0.000143 1.370106 1.335453
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.175748 25.161449 38.726890 41.279670 60.392026 58.950068 3.234213 3.189860 0.053844 0.055547 0.001727 1.252429 1.251896
155 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.346740 21.553396 37.826722 39.545617 60.307193 58.920342 3.277257 2.886270 0.040078 0.037840 0.000715 1.403252 1.390454
156 N12 digital_ok 100.00% 0.00% 2.15% 0.00% 100.00% 0.00% 1.478554 1.026148 1.503619 0.994447 0.019881 15.583133 0.551990 17.944706 0.646117 0.524126 0.404462 5.024791 5.094591
157 N12 digital_ok 0.00% 0.00% 0.54% 0.00% 3.21% 0.00% -0.167763 -0.046170 0.087853 3.244487 0.245186 1.738251 1.348641 -0.005776 0.647149 0.543200 0.401407 1.793113 1.563478
158 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 1.60% 1.07% -0.504241 -1.525499 0.034774 0.160540 -0.517124 -0.515573 1.397390 0.560882 0.657635 0.553080 0.404418 1.755479 1.601318
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.297922 20.165330 38.424976 39.970566 60.491769 59.150973 2.835538 3.476002 0.043158 0.046889 0.003999 1.267855 1.262774
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.789628 46.184457 -0.370653 3.203586 -0.748884 15.549786 0.863087 0.507414 0.739250 0.537979 0.407640 5.422006 6.634696
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.53% 2.14% 1.305311 0.670789 0.098107 -0.810791 0.954793 1.071123 -0.125339 1.528902 0.742892 0.653921 0.412884 2.113568 1.939435
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.53% 0.53% 0.844425 0.260995 0.143939 -0.824707 -0.831878 -1.472208 0.373298 0.337502 0.748603 0.661241 0.407644 1.916445 1.671017
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.53% 0.53% -1.107762 -1.061635 -0.798607 -0.718232 -1.424158 0.524103 0.912553 0.808705 0.749380 0.659407 0.409496 2.018716 1.832647
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.466262 0.967748 6.215519 -0.837780 5.797389 -1.351263 4.528980 0.933652 0.754739 0.659522 0.409754 4.911922 5.173341
166 N14 RF_maintenance 100.00% 0.00% 4.30% 0.00% 100.00% 0.00% 33.255186 29.364531 2.088954 1.745735 22.603470 19.010086 14.908819 14.538188 0.638526 0.532311 0.234596 3.589372 2.882163
167 N15 digital_ok 100.00% 6.44% 3.76% 0.00% 100.00% 0.00% 32.730086 19.464904 18.759661 21.542776 56.185112 46.350268 158.926758 39.769518 0.555994 0.510327 0.206984 2.652975 2.349294
168 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.473310 15.212319 21.957032 24.725077 42.916068 49.067553 -1.501048 -2.907404 0.735552 0.616589 0.417172 5.604736 4.164631
169 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.255918 13.880188 24.378397 23.256363 48.790369 45.952699 -2.419226 -1.578547 0.722156 0.602132 0.423531 5.803949 3.787109
170 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.259887 12.381508 24.676725 22.111066 49.785039 42.472055 -1.588197 -2.285789 0.707029 0.607666 0.428526 4.954382 3.875528
176 N12 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
177 N12 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
178 N12 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
179 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 1.60% 3.74% -0.290225 1.072842 -0.867554 -0.048430 3.862761 -0.559388 0.775944 -1.392994 0.657760 0.546999 0.408054 1.740386 1.751251
180 N13 RF_maintenance 100.00% 0.00% 87.65% 0.00% 100.00% 0.00% 0.583081 17.165665 0.631374 37.673500 -0.377672 48.191057 -0.047810 2.309490 0.734841 0.311181 0.540441 13.021014 2.769575
181 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.891121 65.080284 39.047210 5.023968 60.493468 46.717650 2.595253 12.162117 0.046032 0.257053 0.143841 1.223466 3.511241
182 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 12.205082 12.928997 21.709355 22.603221 42.193035 43.560699 -1.595077 -1.995902 0.733047 0.629482 0.431675 4.742851 5.561607
183 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.540946 -0.699735 -0.195828 -0.667354 -1.011743 -0.661645 1.389893 10.215906 0.742400 0.647448 0.420054 4.561974 4.477325
184 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 1.60% 0.00% 0.377886 -0.051895 -0.332027 0.617638 -0.341904 -0.208213 0.098384 -0.622220 0.750070 0.656362 0.410740 2.016886 1.719077
185 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 1.60% 0.00% 1.950789 0.479613 2.681390 1.262611 0.978253 -0.014316 -0.323213 2.228745 0.755268 0.654723 0.411745 1.790670 1.579303
186 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.858064 0.214517 2.963016 1.767070 0.183619 0.150789 4.661138 3.155093 0.742503 0.648072 0.405776 5.249682 5.440181
187 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.263923 1.376318 -0.012249 0.599508 -0.409158 -1.352280 12.562992 2.426049 0.741858 0.653471 0.408979 4.535445 3.549152
189 N15 digital_ok 0.00% 0.00% 0.00% 0.00% 24.06% 68.45% 3.576824 3.870086 0.550864 -0.657755 1.091760 0.518042 0.679259 -0.465336 0.724262 0.625437 0.423336 4.281470 3.227617
190 N15 digital_ok 100.00% 11.28% 100.00% 0.00% 100.00% 0.00% 55.179041 25.422852 3.684478 40.438149 34.495265 59.100220 135.991667 2.987028 0.548903 0.050405 0.393869 2.845659 1.280324
191 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.440989 0.417750 -0.753649 -0.905295 0.389375 -1.348591 17.468177 0.725988 0.715451 0.609376 0.440676 3.241647 2.626830
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.532172 5.157242 15.030206 4.161246 27.199922 11.094107 20.641241 32.280055 0.730325 0.608811 0.417471 6.682814 4.826532
206 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.836750 6.662880 -0.359690 10.257493 11.597969 18.014902 24.005566 24.179109 0.685006 0.614505 0.409867 4.399614 4.415781
207 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.641999 8.791069 18.104087 14.855483 35.422843 27.794681 7.859908 5.111628 0.708183 0.613344 0.401243 4.213687 3.410638
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% 9.967034 8.362035 68.756482 70.794268 3179.627724 3558.545472 7207.702488 9162.672748 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.923101 9.698676 8.753453 16.494537 14.684107 28.028217 0.283811 -1.594136 0.711685 0.607509 0.420997 4.512731 3.154021
224 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.712260 16.510563 28.225027 27.245524 57.664885 54.623521 -3.342844 -3.703089 0.680516 0.571882 0.406090 4.828074 3.689345
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.454554 10.837189 87.110453 79.431882 4220.208404 4262.945656 11182.422533 11313.701533 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.607159 25.191512 26.488499 27.104736 60.180523 58.828443 5.474481 3.243176 0.058928 0.055255 0.002033 0.000000 0.000000
321 N02 not_connected 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 8.334770 10.960120 86.762112 79.196769 4228.770040 4272.575329 11792.813426 11791.337205 nan nan nan 0.000000 0.000000
323 N02 not_connected 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
324 N04 not_connected 100.00% 0.00% 19.33% 0.00% 100.00% 0.00% 11.538341 12.027650 19.863920 20.075114 39.437243 38.996761 4.133216 2.992946 0.639112 0.480562 0.414960 0.000000 0.000000
329 N12 dish_maintenance 100.00% 16.65% 36.52% 0.00% 100.00% 0.00% 4.818456 4.909575 10.545259 12.411485 20.658068 23.015566 7.287846 0.310250 0.566049 0.423973 0.374579 0.000000 0.000000
333 N12 dish_maintenance 100.00% 33.94% 49.41% 0.00% 100.00% 0.00% 4.097267 5.006241 -0.477389 11.325635 16.099684 20.409475 0.794997 0.248444 0.507903 0.402450 0.348810 0.000000 0.000000
In [22]:
# print ex_ants for easy copy-pasting to YAML file
proposed_ex_ants = [ant for i, ant in enumerate(ants) if np.any([col[i] > 0 for col in bar_cols.values()])]
print('ex_ants: [' + ", ".join(str(ant) for ant in proposed_ex_ants) + ']')
print(f'\nunflagged_ants: [{", ".join([str(ant) for ant in ants if ant not in proposed_ex_ants])}]')
# "golden" means no flags and good a priori status
golden_ants = ", ".join([str(ant) for ant in ants if ((ant not in proposed_ex_ants) and (a_priori_statuses[ant] in good_statuses.split(',')))])
print(f'\ngolden_ants: [{golden_ants}]')
ex_ants: [4, 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, 162, 163, 164, 165, 166, 167, 168, 169, 170, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 189, 190, 191, 203, 205, 206, 207, 220, 221, 222, 223, 224, 241, 242, 243, 320, 321, 323, 324, 329, 333]

unflagged_ants: [3]

golden_ants: [3]
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_2459799.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 [ ]: