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 = "2459805"
data_path = "/mnt/sn1/2459805"
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-13-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/2459805/zen.2459805.25305.sum.auto_metrics.h5.

Load Ant Metrics¶

In [7]:
use_ant_metrics = False

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

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

Load chi^2 info from redcal¶

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

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

        post_redcal_ant_flags_dict[cal] = {ant: np.all(flags[ant]) for ant in flags}
        # check history to distinguish antennas flagged going into redcal from ones flagged during redcal
        tossed_antenna_lines =  hc.history.replace('\n','').split('Throwing out antenna ')[1:]
        flagged_by_redcal_dict[cal] = sorted([int(line.split(' ')[0]) for line in tossed_antenna_lines])
        
    use_redcal = True
else:
    print(f'No files found matching glob {glob_str}. Skipping redcal chisq.')
Found 38 ant_metrics files matching glob /mnt/sn1/2459805/zen.2459805.?????.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 2459805
Date 8-13-2022
LST Range 16.977 -- 18.977 hours
X-Engine Status ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
Number of Files 372
Total Number of Antennas 147
OPERATIONAL STATUS SUMMARY
Antenna A Priori Status Count dish_maintenance: 3
RF_maintenance: 32
RF_ok: 11
digital_maintenance: 3
digital_ok: 95
not_connected: 3
Commanded Signal Source None
Antennas in Commanded State 0 / 147 (0.0%)
Cross-Polarized Antennas
Total Number of Nodes 15
Nodes Registering 0s N18
Nodes Not Correlating N09, N14, N19
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 75 / 147 (51.0%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 96 / 147 (65.3%)
Redcal Done? ✅
Redcal Flagged Antennas 15 / 147 (10.2%)
Never Flagged Antennas 24 / 147 (16.3%)
A Priori Good Antennas Flagged 74 / 95 total a priori good antennas:
5, 7, 9, 16, 17, 19, 21, 30, 41, 42, 45, 46,
54, 55, 56, 67, 68, 69, 71, 72, 73, 81, 83,
84, 85, 86, 88, 91, 93, 94, 101, 103, 105,
106, 107, 108, 109, 111, 112, 117, 118, 121,
122, 123, 127, 128, 129, 130, 140, 141, 142,
143, 144, 156, 157, 158, 160, 161, 163, 164,
165, 167, 169, 170, 176, 179, 181, 184, 185,
186, 187, 189, 190, 191
A Priori Bad Antennas Not Flagged 3 / 52 total a priori bad antennas:
52, 82, 135
In [19]:
# write to csv
outpath = os.path.join(nb_outdir, f'array_health_table_{JD}.csv')
print(f'Now saving Table 2 to a csv at {outpath}')
df.replace({'\u2705': 'Y'}, regex=True).replace({'\u274C': 'N'}, regex=True).replace({'<br>': ' '}, regex=True).to_csv(outpath)
Now saving Table 2 to a csv at /home/obs/src/H5C_Notebooks/_rtp_summary_/array_health_table_2459805.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% 0.467516 -0.369553 -0.563279 -0.947430 -0.708006 -0.782695 -0.338879 -0.505154 0.730794 0.687832 0.478379 1.988226 1.610689
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.442778 3.555516 -0.934709 1.998105 -0.787654 0.812427 5.553779 0.968730 0.743954 0.693650 0.470029 5.507901 4.906939
5 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.389398 1.084431 -0.601780 5.420394 -0.974713 2.548887 0.988210 -1.233411 0.754076 0.702511 0.470864 4.084142 3.831609
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.707682 -0.914446 0.614261 0.474214 0.414535 1.826619 0.815946 7.465067 0.758846 0.704463 0.469517 3.626805 3.665452
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 12.604284 13.548643 18.994853 19.969402 13.837773 15.724916 1.000520 0.674649 0.738179 0.672326 0.472073 4.039556 4.633328
9 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% -0.230963 -1.078063 0.658728 0.135668 2.512372 1.540735 -0.410532 -0.678805 0.744631 0.683353 0.476112 3.483946 2.735337
10 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.097110 -1.154744 -0.663197 0.944076 -1.005680 0.647616 -0.114063 -0.932224 0.726676 0.659912 0.488874 2.406501 2.071858
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.596032 1.075674 1.979372 0.998522 0.631541 1.123712 0.370992 2.854065 0.765546 0.716420 0.464836 2.695855 2.215106
16 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.484079 -0.475864 -0.961466 0.348761 -0.908651 -0.891836 1.846666 6.613356 0.770723 0.729579 0.461349 5.563722 6.681424
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% 0.475479 1.321672 0.250764 0.012736 -0.146802 0.004859 0.107309 -0.742685 0.778324 0.733462 0.460873 2.964370 3.045892
18 N01 RF_maintenance 100.00% 0.00% 19.35% 0.00% 100.00% 0.00% 4.934819 3.670566 0.652977 1.968147 3.749539 2.222275 55.998988 30.275119 0.722564 0.567428 0.500828 2.841329 2.070544
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.738018 4.055681 1.689047 9.282011 1.131714 13.261571 3.599053 0.214962 0.768700 0.719070 0.462773 5.169051 4.526702
20 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.159364 -0.217282 -0.212737 -0.567380 1.798716 0.865975 0.591587 -0.848956 0.755548 0.698393 0.460590 3.150358 2.347131
21 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% 0.339481 1.319779 0.644525 1.709541 -0.852221 0.475623 -0.322374 -1.296867 0.739105 0.675966 0.486824 3.641442 2.391528
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.420344 19.098689 61.241256 61.872614 20.616356 22.305265 5.754295 4.974421 0.040849 0.046803 0.003860 1.187357 1.188064
28 N01 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 10.464793 13.414185 8.726069 13.848718 19.668373 22.163713 5.905461 20.329479 0.538768 0.287486 0.339716 15.355056 3.389052
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.180212 -0.550325 0.669971 -0.645375 -1.128323 -0.768420 -0.403573 -0.237163 0.793968 0.757430 0.456186 2.504883 2.645517
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.514181 -0.244615 4.601941 -0.913631 4.758278 0.296640 11.849120 -0.380875 0.786393 0.750067 0.450259 4.177149 4.474931
31 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.692010 -0.005348 -0.986611 1.352588 -0.549281 0.366383 0.795750 -0.121720 0.785221 0.738754 0.466204 2.309095 1.976375
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 26.975831 21.836734 3.146225 2.344758 7.376561 10.116015 32.141522 138.433439 0.716513 0.676398 0.283363 11.024659 8.990229
33 N02 RF_maintenance 100.00% 0.00% 19.35% 0.00% 100.00% 0.00% -0.185708 2.653071 0.297104 0.673218 -0.378154 0.596995 4.410964 7.329607 0.747863 0.553913 0.573262 3.738784 2.248381
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.551724 4.430772 0.101036 0.181584 1.907264 1.002081 1.061640 -0.444534 0.742807 0.696924 0.459013 8.701482 8.642562
37 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.902911 0.704628 0.126145 -0.012736 -0.241471 0.653462 -0.379760 3.521334 0.764437 0.719315 0.453745 2.772931 2.941377
38 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.904196 -0.272964 -0.427717 -0.862733 2.298413 -0.210135 2.929745 -0.290795 0.779537 0.741164 0.446812 2.456338 2.263172
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.187868 -0.842551 0.730909 -0.679010 2.056909 1.071476 -0.351427 1.163492 0.795310 0.765868 0.442615 2.917009 2.754110
41 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% 0.614286 -0.959016 2.957725 1.292109 1.723618 -0.543497 -0.843473 1.145737 0.801695 0.774843 0.446582 3.111017 2.812457
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% -0.193608 0.205543 2.563962 1.113985 0.506549 -0.676041 -0.648175 -0.579348 0.805473 0.772167 0.460025 2.804844 2.879605
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.636617 0.345505 -0.349344 0.807949 -0.459678 -0.084280 -0.304802 7.535400 0.773975 0.722776 0.483047 3.314391 3.018219
46 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.943191 -0.635191 0.248205 -0.984442 -0.701777 -0.531560 -0.171154 4.694557 0.758384 0.698752 0.500181 3.384933 3.116536
50 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.963027 10.306378 -0.385696 0.729042 4.067029 6.667959 86.432468 78.520663 0.744435 0.677363 0.412661 5.622739 9.512662
51 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.095429 1.178530 -0.806432 -0.491369 0.660532 -0.454977 -0.749382 0.308125 0.769794 0.732690 0.437886 2.423561 2.569830
52 N03 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.814766 3.832803 0.100319 -0.194698 0.186057 -0.367874 0.164848 0.531479 0.789423 0.753810 0.434963 7.834627 6.818043
53 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.427182 0.821026 -0.388216 -0.695550 -1.301845 -0.820484 1.034128 3.893430 0.802982 0.776921 0.433681 2.458339 2.440084
54 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.617056 2.138798 1.083250 3.912007 0.482292 12.864070 -0.029282 14.273867 0.815060 0.779341 0.426898 5.191649 5.949549
55 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.588573 -0.132193 0.672394 1.128043 0.908413 2.242645 5.878369 -0.312003 0.813864 0.788712 0.447404 5.506045 5.089075
56 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.687912 0.261518 0.965458 1.354230 0.367942 -0.124302 -0.546298 5.494153 0.811396 0.785686 0.452895 4.120924 3.562999
57 N04 RF_maintenance 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 17.735761 9.650534 58.319758 2.018392 20.565102 19.318271 4.160842 11.114093 0.050133 0.546509 0.305183 1.307219 3.673951
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.737310 -0.064609 0.908439 0.839130 1.882887 0.845070 0.021469 -0.021238 0.763760 0.712997 0.461525 2.843518 2.499932
66 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.332413 -0.461843 -0.600089 0.699184 0.454405 0.278250 -0.258342 1.206206 0.779681 0.741834 0.435824 3.171719 2.730614
67 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 13.16% -0.687261 -0.273920 -0.275576 -0.018049 0.866964 0.726651 0.207446 0.313056 0.799065 0.767917 0.422235 3.346690 3.499098
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 28.95% -0.192656 0.094594 0.031460 -0.023333 2.137038 1.859163 0.053649 1.979659 0.811127 0.787554 0.418429 2.811940 4.046654
69 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% 0.061815 -0.785478 -0.858627 -0.421127 -0.764700 0.527091 -0.447941 -1.080345 0.820948 0.798711 0.438432 4.091981 4.318963
70 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.107748 -1.172616 -0.023972 -0.998146 -0.854986 0.018800 -0.612380 -0.519167 0.816668 0.790957 0.459014 30.871217 28.194972
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% -0.016346 -1.131937 -0.883806 -0.547353 -0.362629 -0.705428 -0.417889 -0.081748 0.823224 0.800495 0.445181 54.616425 48.910015
72 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.423589 -0.795374 -0.166174 1.604607 0.321544 0.425221 7.391243 0.438991 0.806457 0.773670 0.483012 3.147881 2.905037
73 N05 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 18.907041 2.435214 60.257731 -0.003182 20.456476 0.825380 4.236651 -0.479889 0.036155 0.750376 0.438938 1.160060 2.807873
81 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.254336 2.581197 -0.294272 4.034140 -0.304963 2.532017 8.069954 0.862734 0.761610 0.712827 0.452002 7.445811 5.780743
82 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.916801 -0.925296 1.014172 0.629632 -0.150266 -0.326777 3.175365 -0.187642 0.787402 0.743731 0.450919 5.515842 4.410013
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.573604 3.061056 2.175916 5.346180 -0.143736 1.980268 -0.377155 -1.427773 0.801611 0.769699 0.425252 4.772816 5.527567
84 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.620273 5.977918 0.314547 1.408387 -0.645362 0.085826 0.587771 -0.994720 0.758392 0.729422 0.413216 3.813205 3.502222
85 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 86.84% 0.040573 0.237705 -0.881213 -0.375210 -1.291665 -0.526266 -0.794679 -1.140935 0.754453 0.725650 0.436793 2.548050 2.408365
86 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% 0.341667 2.221335 -0.443228 -0.543543 1.662606 0.419402 1.232358 1.376066 0.751899 0.715926 0.430065 3.193949 2.648379
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.531309 6.675716 5.977452 1.013710 2.759206 0.767927 7.713910 -0.733210 0.749852 0.722013 0.455443 2.946617 2.609424
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 16.893125 17.074649 53.909564 54.891545 20.860786 22.422521 7.450327 5.014327 0.032001 0.032754 0.002248 1.163915 1.161448
90 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.966731 18.011544 53.776579 54.448844 20.667710 22.210146 4.102152 3.555221 0.033055 0.031342 0.000965 1.163435 1.162184
91 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.116750 17.427965 53.756121 55.512118 20.754197 22.258728 5.855802 5.421158 0.030702 0.031107 0.000681 1.042882 1.036401
92 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.368195 38.376772 11.831507 14.010330 20.887704 25.220455 6.842164 11.594299 0.242157 0.193450 0.095904 3.061932 2.147405
93 N10 digital_ok 100.00% 8.06% 43.55% 0.00% 100.00% 0.00% 1.179614 9.455882 4.609261 15.661542 1.171682 11.863087 0.245075 -0.531621 0.560749 0.473109 0.400577 3.039796 2.692836
94 N10 digital_ok 100.00% 8.06% 43.55% 0.00% 100.00% 0.00% -0.827754 -1.011252 -0.016856 -0.570022 0.105331 0.085978 2.801535 6.325531 0.540460 0.464009 0.377361 3.055283 2.711227
98 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.718085 1.589091 -0.161298 -0.470181 -0.740786 -0.658211 2.181048 0.976105 0.764454 0.705492 0.462919 2.710706 2.851625
99 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 2.140004 0.005348 3.158266 -0.629948 1.501195 -0.211056 1.143205 1.618169 0.782665 0.738563 0.447885 2.563990 2.352562
100 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.514453 -0.150545 0.755574 0.100727 -0.955911 -0.740372 -0.597548 -0.819349 0.801943 0.763043 0.454430 2.518793 2.755197
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.067802 5.649415 3.752301 0.321601 0.445609 -0.695794 2.337488 1.192503 0.756118 0.716626 0.438466 3.263169 3.149239
102 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.288239 15.091319 9.518175 8.003192 258.651313 238.769586 4749.732996 4659.523857 0.612086 0.681908 0.452987 0.000000 0.000000
103 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.021596 5.782854 0.072480 -0.010260 1.195248 -0.590959 1.013603 0.065887 0.745575 0.712317 0.438818 3.010279 2.725065
104 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.338041 58.534419 1.652637 15.358221 0.539829 2.741742 1.668734 0.134934 0.737219 0.699263 0.461965 2.774919 2.534629
105 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.094392 22.188754 53.732357 55.530401 20.917366 22.674923 4.787422 4.565300 0.032924 0.031549 0.001035 1.176592 1.176047
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% 17.192489 16.970691 51.841788 52.668684 20.770019 22.226662 5.054854 5.388947 0.031834 0.029960 0.001508 1.088263 1.087658
108 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.352549 17.240331 53.128183 55.130081 20.673322 22.290166 3.787768 3.734487 0.030818 0.031271 0.001385 0.000000 0.000000
109 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
110 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
111 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
112 N10 digital_ok 0.00% 8.06% 43.55% 0.00% 44.74% 0.00% -0.661720 -0.512605 -0.221594 1.658692 -0.223408 0.287482 0.769477 -1.373437 0.522716 0.450474 0.357001 1.725204 1.690457
116 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.464740 1.386612 0.142743 -0.685411 -0.784002 0.492414 0.523376 -0.438313 0.760722 0.704814 0.460851 2.236117 2.501182
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.981884 2.821068 5.967644 6.286143 2.542952 3.193119 -0.750514 -1.356140 0.784852 0.734163 0.476058 5.756962 6.678847
118 N07 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 1.535748 19.455175 2.495682 54.944348 1.105191 22.337427 1.468294 3.485490 0.795507 0.047988 0.515272 4.485195 1.230750
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.710859 0.448061 8.582307 3.372413 4.633136 0.221838 -0.692569 -0.368352 0.808559 0.764296 0.474505 3.840671 3.529284
120 N08 RF_maintenance 100.00% 22.04% 100.00% 0.00% 100.00% 0.00% 14.687144 24.310545 11.281867 67.893896 18.480252 22.957444 3.426219 7.361162 0.480349 0.055539 0.351598 2.620070 1.164689
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.126717 3.814553 -0.526210 0.734141 -0.436224 -0.320168 12.070141 8.005290 0.737624 0.700405 0.440038 3.414079 3.020534
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.363357 4.996163 1.225117 1.915000 0.349603 0.019175 -0.167088 0.833176 0.728732 0.685780 0.453461 3.251837 2.770177
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.108952 5.693206 0.361698 0.088023 -0.044594 0.578637 -0.063050 -0.554098 0.715256 0.671869 0.460912 2.891432 2.457027
125 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
127 N10 digital_ok 0.00% 2.69% 38.17% 0.00% 39.47% 0.00% -0.158537 -0.398123 -0.013306 -0.591765 0.078751 0.513525 0.168477 0.136267 0.577598 0.504357 0.411963 1.656982 1.661279
128 N10 digital_ok 0.00% 8.06% 40.86% 0.00% 42.11% 0.00% -0.760347 0.813363 0.083780 2.436006 -0.680075 0.989818 -0.425353 -1.142351 0.562708 0.483341 0.392125 1.794813 1.674930
129 N10 digital_ok 0.00% 8.06% 43.55% 0.00% 44.74% 0.00% -0.361049 -1.346018 -0.466029 -1.075531 -0.221049 -0.120529 -0.381014 -0.635156 0.545297 0.468783 0.375228 1.830738 1.621567
130 N10 digital_ok 0.00% 8.06% 43.55% 0.00% 44.74% 0.00% -0.407976 0.223566 1.160370 1.107981 0.294231 0.567581 -0.478310 1.879334 0.525888 0.451903 0.359660 1.721811 1.746161
135 N12 digital_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.823322 -0.652854 -0.994862 -0.725823 -0.758377 -0.503248 2.843407 0.886881 0.698096 0.638024 0.461744 5.418615 4.627117
136 N12 digital_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.702342 7.360495 -0.497543 0.946746 4.359000 4.279087 2.365259 5.918557 0.705450 0.651959 0.434598 5.515086 5.106305
137 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.581813 16.619619 53.231014 54.142561 20.782640 22.294553 5.021656 5.813548 0.039465 0.041942 0.003996 1.172775 1.205065
138 N07 RF_maintenance 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 21.595128 2.016622 52.747870 1.893558 20.928453 0.443577 5.244598 0.193295 0.047326 0.745560 0.469887 1.282677 4.028300
140 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.413938 16.386761 60.061072 62.033735 20.489352 22.248293 3.969550 4.006926 0.041420 0.043482 0.000401 1.148486 1.174119
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.378326 4.569215 0.535255 11.349577 2.909742 4.163085 1.071183 17.441578 0.775398 0.728374 0.480588 3.747464 3.031872
142 N13 digital_ok 100.00% 22.04% 100.00% 0.00% 100.00% 0.00% 16.799112 21.127389 9.957278 62.258947 21.464270 22.434761 4.812104 4.899512 0.466833 0.044310 0.285581 2.910391 1.176053
143 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.296306 -0.169184 1.158306 1.717075 -0.028781 1.203619 -0.161279 -1.052109 0.100095 0.104278 0.023193 0.000000 0.000000
144 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.834708 1.303074 -0.094747 1.381029 -1.082159 -0.004859 0.729560 -0.086050 0.094103 0.089456 0.018821 0.000000 0.000000
145 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.026665 17.289008 61.563108 62.709389 20.623904 22.276764 5.069519 5.777145 0.033477 0.034596 -0.000453 0.000000 0.000000
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.928682 19.771399 61.330194 63.718288 20.577611 22.184566 5.508415 5.844534 0.045025 0.046474 0.001999 1.302741 1.297342
155 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.291042 19.055110 60.211244 61.555055 20.590426 22.188448 5.551615 5.426528 0.042582 0.042438 0.000549 1.322979 1.320920
156 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% 0.833995 0.575389 1.684275 -0.708807 -0.423130 -0.297685 0.095321 3.860247 0.699226 0.634699 0.456643 3.350444 3.044677
157 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% 0.207777 0.652323 0.405830 3.672649 0.672025 1.919876 1.012290 1.044999 0.701450 0.647668 0.453606 3.173193 2.990358
158 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% -0.757919 -1.095508 0.201364 0.693145 -0.419786 0.309088 0.000934 -0.892713 0.708778 0.652929 0.454650 2.962074 2.968573
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 16.881451 16.567829 60.970274 62.143785 20.635131 22.353607 5.230066 5.858549 0.044946 0.043989 0.001204 1.256549 1.252594
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.847806 34.171656 -0.408267 4.524192 -0.416141 7.262690 0.941417 0.355553 0.753066 0.630471 0.423134 4.287467 5.438909
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.966212 0.814923 0.166411 -0.366954 1.411203 1.305613 -0.336480 -0.239000 0.748035 0.690659 0.488771 1.707612 1.462084
163 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.188231 -0.578796 0.176347 -0.733488 -0.763455 -0.856133 -0.460027 -0.819503 0.063759 0.081197 0.011626 1.260402 1.258911
164 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.099374 -0.829239 -1.021014 -1.003322 -0.903441 0.196951 0.771474 0.600937 0.067358 0.066580 0.005074 1.263926 1.262094
165 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.812389 0.174346 6.250125 -0.827137 2.418754 -1.033472 4.930415 0.080038 0.080477 0.056790 0.004547 1.273283 1.273324
166 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 16.118004 12.951073 4.976199 3.585765 5.157205 8.231426 14.900006 19.456080 0.071104 0.073155 0.004290 1.214739 1.215501
167 N15 digital_ok 100.00% 0.00% 24.73% 0.00% 100.00% 0.00% 13.139396 16.083227 17.332431 18.543806 18.801721 17.527188 96.499843 30.497309 0.627301 0.531365 0.275278 5.324597 4.083594
168 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
169 N15 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
170 N15 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
176 N12 digital_ok 0.00% 0.00% 2.69% 0.00% 2.63% 0.00% -0.429406 -0.468115 -0.554750 1.024818 0.672941 0.802942 0.442958 0.721141 0.672106 0.603074 0.453706 2.932087 2.654094
177 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.787332 1.219066 1.046958 0.591105 -0.851421 1.091825 0.191019 2.220890 0.676086 0.610016 0.449459 3.145804 3.155576
178 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.767361 -1.234166 1.488574 -0.859238 -0.132794 -0.813233 1.041276 -0.971039 0.679597 0.618330 0.442523 2.856441 2.770205
179 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.595903 0.081968 -0.789246 -0.489578 1.139656 -0.778116 8.642575 -0.518065 0.677078 0.619221 0.444208 3.887088 3.878565
180 N13 RF_maintenance 100.00% 0.00% 38.17% 0.00% 100.00% 0.00% 0.574032 11.338632 0.843175 55.955138 -0.157795 13.542200 -0.059484 3.314338 0.736887 0.474891 0.538567 142.372471 35.996330
181 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.412833 41.724079 61.746376 6.925402 20.662679 25.575094 5.127725 8.873959 0.049829 0.312653 0.160808 1.238751 2.615653
182 N13 RF_maintenance 100.00% 0.00% 29.57% 0.00% 100.00% 0.00% 13.095766 8.082714 19.248395 48.437369 14.163889 56.498868 0.547345 29.732651 0.713561 0.496210 0.502739 5.058062 3.207306
183 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.133919 -0.760863 -0.096633 -0.879742 -0.582456 -1.048705 0.898912 3.098581 0.739408 0.673768 0.506302 1.484769 1.313224
184 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.478383 -0.165726 -0.351982 0.560821 0.605051 0.193658 0.006026 -0.920774 0.060185 0.058407 0.003925 1.281492 1.277764
185 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.859955 0.430956 1.561968 1.221915 3.229300 0.021685 -0.000934 -0.916982 0.050148 0.051102 0.002454 1.315590 1.310251
186 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.235127 -0.020222 3.686286 1.772598 0.233051 0.285668 7.176524 4.108980 0.067113 0.071278 0.009640 1.271539 1.275041
187 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.501568 0.479705 0.161114 1.181002 -0.236165 -0.750118 8.481358 0.522325 0.086209 0.084942 0.016024 1.288005 1.295137
189 N15 digital_ok 0.00% 0.00% 5.38% 0.00% 5.26% 10.53% 3.057382 3.401083 0.829611 -0.402876 -0.657430 -0.732969 1.431647 -0.670177 0.672229 0.590143 0.480608 2.391468 1.687879
190 N15 digital_ok 100.00% 2.69% 100.00% 0.00% 100.00% 0.00% 29.598178 20.152749 4.525262 62.673943 10.948990 22.370128 115.428841 5.636942 0.578020 0.043504 0.399208 6.131334 1.475075
191 N15 digital_ok 100.00% 0.00% 8.06% 0.00% 100.00% 0.00% -0.369146 0.436485 -0.767529 -0.731960 -0.737083 -0.824984 8.500578 7.728648 0.648763 0.553571 0.467471 4.696384 3.944581
203 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
205 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 9.832742 4.960677 13.977547 -0.151313 10.576999 3.695767 12.815586 18.953589 0.054193 0.035469 0.004032 0.933262 0.944259
206 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.153302 6.866148 0.314461 9.968935 4.294789 8.729755 14.316843 13.574439 0.036922 0.046707 0.001594 1.055714 1.049246
207 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 11.461933 9.609488 16.163920 14.165949 12.378838 11.314141 4.556014 3.520751 0.052966 0.056679 0.004565 1.329796 1.329727
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.704266 7.076377 95.815562 97.795559 1983.487086 2278.614683 5951.271962 7907.179285 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 5.836680 6.408169 7.993254 9.945212 5.358972 20.471508 1.842384 3.165055 0.040404 0.046992 0.001765 0.957802 0.951183
224 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.406021 17.060396 23.838900 23.856943 18.487755 19.527600 1.622975 1.395883 0.061277 0.061870 0.004619 0.000000 0.000000
241 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
242 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
243 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 9.222036 9.981063 119.022439 115.615303 2743.116763 2743.216769 9791.026756 9790.224836 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.196157 20.351746 45.942429 45.946329 20.850790 22.167420 7.500380 5.765136 0.066681 0.060360 -0.002462 0.000000 0.000000
321 N02 not_connected 100.00% 0.00% 62.37% 0.00% 100.00% 0.00% 8.706910 6.870995 13.273946 12.333030 10.969861 10.406871 13.069182 12.456448 0.543483 0.397435 0.374032 0.000000 0.000000
323 N02 not_connected 100.00% 2.69% 67.74% 0.00% 100.00% 0.00% 16.300531 10.003729 3.283096 16.022776 8.716350 13.215504 13.344166 0.199235 0.464059 0.360478 0.313298 0.000000 0.000000
324 N04 not_connected 100.00% 0.00% 62.37% 0.00% 100.00% 0.00% 12.083833 12.560004 17.614513 18.310891 12.614350 14.408809 2.445456 0.538799 0.534769 0.388700 0.382088 0.000000 0.000000
329 N12 dish_maintenance 100.00% 34.95% 73.12% 0.00% 100.00% 0.00% 2.635478 6.422073 9.363059 11.938673 4.372195 8.150538 11.849648 0.631306 0.442693 0.334408 0.298723 0.000000 0.000000
333 N12 dish_maintenance 100.00% 34.95% 100.00% 0.00% 100.00% 0.00% 0.209905 6.161612 1.323296 11.102082 1.471789 8.128934 0.535378 -0.480678 0.435696 0.296909 0.292758 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, 16, 17, 18, 19, 21, 27, 28, 30, 32, 33, 36, 41, 42, 45, 46, 50, 52, 54, 55, 56, 57, 67, 68, 69, 70, 71, 72, 73, 81, 82, 83, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 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, 163, 164, 165, 166, 167, 168, 169, 170, 176, 179, 180, 181, 182, 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, 10, 15, 20, 29, 31, 37, 38, 40, 51, 53, 65, 66, 98, 99, 100, 116, 162, 177, 178, 183]

golden_ants: [3, 10, 15, 20, 29, 31, 37, 38, 40, 51, 53, 65, 66, 98, 99, 100, 116, 162, 177, 178, 183]
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_2459805.csv
In [24]:
# Load antenna positions
data_list = sorted(glob.glob(os.path.join(data_path, f'zen.{JD}.?????.sum.uvh5')))
hd = io.HERAData(data_list[len(data_list) // 2])

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Metadata¶

In [27]:
from hera_qm import __version__
print(__version__)
from hera_cal import __version__
print(__version__)
2.0.3.dev44+g7d4aa18
3.1.4.dev3+g68bd8c3
In [ ]: