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 = "2459796"
data_path = "/mnt/sn1/2459796"
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-4-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/2459796/zen.2459796.25309.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/2459796/zen.2459796.?????.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/2459796/zen.2459796.?????.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 2459796
Date 8-4-2022
LST Range 16.387 -- 18.387 hours
X-Engine Status ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
Number of Files 372
Total Number of Antennas 147
OPERATIONAL STATUS SUMMARY
Antenna A Priori Status Count dish_maintenance: 3
RF_maintenance: 42
RF_ok: 11
digital_maintenance: 1
digital_ok: 87
not_connected: 3
Commanded Signal Source antenna
Antennas in Commanded State 97 / 147 (66.0%)
Cross-Polarized Antennas 93
Total Number of Nodes 15
Nodes Registering 0s N18
Nodes Not Correlating N04, N08, N09
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 80 / 147 (54.4%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 119 / 147 (81.0%)
Redcal Done? ✅
Redcal Flagged Antennas 12 / 147 (8.2%)
Never Flagged Antennas 10 / 147 (6.8%)
A Priori Good Antennas Flagged 81 / 87 total a priori good antennas:
5, 7, 9, 10, 16, 19, 20, 21, 30, 37, 40, 41,
42, 45, 46, 50, 51, 53, 54, 55, 56, 57, 65,
66, 68, 69, 71, 72, 73, 81, 83, 84, 88, 91,
92, 93, 99, 101, 103, 105, 106, 107, 108, 109,
111, 117, 118, 121, 122, 123, 128, 129, 130,
135, 138, 140, 141, 142, 143, 144, 145, 160,
161, 163, 164, 165, 167, 169, 170, 176, 177,
178, 179, 181, 183, 185, 186, 187, 189, 190,
191
A Priori Bad Antennas Not Flagged 4 / 60 total a priori bad antennas:
3, 67, 100, 158
In [19]:
# write to csv
outpath = os.path.join(nb_outdir, f'array_health_table_{JD}.csv')
print(f'Now saving Table 2 to a csv at {outpath}')
df.replace({'\u2705': 'Y'}, regex=True).replace({'\u274C': 'N'}, regex=True).replace({'<br>': ' '}, regex=True).to_csv(outpath)
Now saving Table 2 to a csv at /home/obs/src/H5C_Notebooks/_rtp_summary_/array_health_table_2459796.csv

Build DataFrame¶

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

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

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

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

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

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

Table 2: RTP Per-Antenna Metrics Summary Table¶

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

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

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

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

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

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

In [21]:
HTML(table.render())
Out[21]:
Ant Node A Priori Status Auto Metrics Flags Dead Fraction in Ant Metrics (Jee) Dead Fraction in Ant Metrics (Jnn) Crossed Fraction in Ant Metrics Flag Fraction Before Redcal Flagged By Redcal chi^2 Fraction ee Shape Modified Z-Score nn Shape Modified Z-Score ee Power Modified Z-Score nn Power Modified Z-Score ee Temporal Variability Modified Z-Score nn Temporal Variability Modified Z-Score ee Temporal Discontinuties Modified Z-Score nn Temporal Discontinuties Modified Z-Score Average Dead Ant Metric (Jee) Average Dead Ant Metric (Jnn) Average Crossed Ant Metric Median chi^2 Per Antenna (Jee) Median chi^2 Per Antenna (Jnn)
3 N01 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.688261 -0.509593 -0.630471 -0.824831 -0.772564 -0.911439 -0.018787 0.030653 0.680534 0.666505 0.427871 4.140740 3.883192
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.210097 3.385858 -0.082922 2.085301 -0.350485 -0.450497 10.480884 2.420096 0.692632 0.672608 0.424218 18.633578 22.063843
5 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.734308 1.168108 0.879923 5.470202 -0.105431 0.982810 1.149029 -1.981322 0.706871 0.686469 0.425734 6.143152 6.328513
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.821047 -1.260530 1.072549 -0.010396 0.036112 0.456006 0.821791 10.229029 0.707556 0.685699 0.416034 4.691294 4.271156
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.544599 14.844861 22.932834 22.957076 16.536793 16.857426 5.864865 3.803593 0.682661 0.653134 0.409055 8.244966 8.438143
9 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 92.11% -0.263807 -0.864389 -0.514980 0.646616 1.606806 1.527449 -0.038492 -0.496569 0.687030 0.663955 0.408825 1.607930 1.582922
10 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 2.63% 65.79% -0.998050 -1.076102 -0.217264 1.168813 -0.727195 -0.098413 1.300876 -0.848743 0.668239 0.641826 0.416805 1.697660 2.116839
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 7.89% 0.00% 0.113552 1.000813 1.456550 1.405168 -0.142172 0.172726 0.762615 1.847783 0.708396 0.687435 0.427521 1.257089 1.359542
16 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.252743 -0.809867 -0.576151 -0.164119 -0.703476 -0.792607 5.184821 13.077456 0.714889 0.699335 0.423761 7.639497 11.992843
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.789625 0.997128 0.252906 1.158095 0.255789 0.637722 3.601041 2.710747 0.717386 0.700389 0.407505 1.246494 1.368444
18 N01 RF_maintenance 100.00% 0.00% 32.26% 0.00% 100.00% 0.00% 2.966637 2.446001 4.053947 -0.394190 2.991052 3.954923 36.818471 80.004124 0.702345 0.526611 0.452981 7.336334 4.053974
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.564486 1.106594 -0.474887 3.541622 -0.300980 7.333177 8.789185 16.593652 0.711471 0.690035 0.405843 101.372320 89.165236
20 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 50.00% -0.958851 0.233813 -0.869795 -0.422428 0.681040 1.408648 0.662727 0.645726 0.698146 0.670265 0.401673 0.989350 1.018260
21 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 65.79% -0.042406 1.363131 0.657387 1.812013 -0.894033 0.284915 0.308224 -1.005155 0.683202 0.656276 0.412637 16.257852 17.072801
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.968986 21.589310 65.204117 66.716685 23.891322 23.720959 19.474196 17.491593 0.045694 0.051456 0.004289 1.563853 1.583980
28 N01 RF_maintenance 100.00% 32.26% 100.00% 0.00% 100.00% 0.00% 11.747707 12.051691 9.393923 11.707269 20.687450 24.244856 19.863601 75.916911 0.471845 0.254518 0.283020 7.606118 3.863991
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 15.79% 0.00% -0.801193 -0.018645 1.561684 -0.142493 -0.554798 -0.231539 -1.149256 3.478956 0.729305 0.712260 0.429166 1.326126 1.444017
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.301327 0.239243 0.583989 -0.327942 0.320664 0.419233 38.622391 0.999075 0.723523 0.707127 0.411464 9.151874 13.653279
31 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 7.89% 0.00% -0.817845 -0.287885 -0.496392 0.826428 0.244546 -0.688938 3.673331 0.541089 0.724801 0.700824 0.410819 1.219541 1.371176
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 26.603167 31.145511 3.299577 9.887336 7.059029 7.282545 43.925719 76.926352 0.657359 0.635078 0.231201 6.747521 5.369889
33 N02 RF_maintenance 100.00% 0.00% 29.57% 0.00% 100.00% 0.00% 0.372403 2.998603 1.007766 0.836011 5.605685 5.864699 115.913520 138.656869 0.693074 0.527517 0.488608 20.260245 8.865570
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.404771 5.633411 0.562989 1.144678 1.930706 0.292255 0.480164 2.110416 0.682050 0.659739 0.400563 1.819058 1.735762
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.617426 0.810414 -0.143881 0.510463 0.066606 -0.291517 0.533187 11.232247 0.699987 0.681027 0.400475 0.000000 0.000000
38 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.684256 -0.299366 -0.475175 -0.604484 1.884253 0.241072 11.977938 3.229799 0.713515 0.698790 0.410763 1.464856 1.345624
40 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 59.567179 100.941195 155.109234 199.989234 28.120532 52.406769 2347.624906 4216.003041 0.016593 0.016146 0.000561 1.080680 1.065105
41 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 207.755061 79.250947 183.833593 139.736614 27.288866 33.793994 1112.821101 1545.436513 0.018146 0.017949 0.000310 1.029856 1.037437
42 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 55.401723 54.718881 145.544433 131.816194 31.229680 29.216323 1656.756645 1080.524710 0.017268 0.016874 0.000358 0.979574 0.980612
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.378306 0.697978 -0.845788 1.677707 -0.989411 -0.124634 0.373223 12.862297 0.718401 0.690932 0.424954 7.174325 7.759058
46 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.624831 -0.904731 1.711123 -0.768250 -0.771920 -0.536589 -0.092415 6.082587 0.705045 0.678580 0.430954 8.397062 7.205531
50 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.678425 1.677623 2.866012 3.675822 2.705064 1.904659 10.282055 1.934657 0.663895 0.665219 0.362338 70.686150 60.235633
51 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 7.89% 76.32% 0.173792 1.292556 -0.744609 -0.292279 0.663259 -0.159961 -0.401637 0.686254 0.704025 0.688282 0.384514 1.193724 1.159820
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.942889 5.348126 0.639007 0.297150 -0.077406 -0.764990 1.090718 1.863370 0.716344 0.702467 0.395777 4.220131 4.493970
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.002285 1.211011 0.222464 0.093065 -1.089547 -0.475239 4.212326 9.490614 0.728540 0.716198 0.420169 1.599980 1.287565
54 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 51.130148 102.472132 139.803376 183.951090 33.065300 30.382562 1445.955593 1757.840262 0.017196 0.016279 0.000626 1.043231 0.909415
55 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 124.645958 83.346607 216.121403 164.671697 52.119190 26.112056 4001.890969 1962.887161 0.017130 0.016308 0.000693 0.569673 0.769258
56 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 57.576844 52.697370 132.287205 115.285081 21.561125 21.538344 1190.250337 655.374520 0.018168 0.018081 0.000239 0.000000 0.000000
57 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 45.426691 81.816561 123.864461 172.780851 30.800216 28.149677 1016.445770 2205.648789 0.018606 0.016266 0.002046 0.000000 0.000000
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 76.32% 0.661579 0.045488 -0.364488 1.102999 0.814956 0.580692 -0.045744 0.957532 0.695160 0.671496 0.389812 43.567041 48.827125
66 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.367132 -0.232777 -0.710486 1.438796 0.871327 1.287796 0.304524 4.810858 0.710710 0.693542 0.380342 6.375057 6.238201
67 N03 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.920114 -0.454885 -0.643155 0.691245 0.992589 2.950447 1.434558 3.429384 0.724602 0.710996 0.385986 5.046109 4.436832
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 76.32% 0.086688 0.103628 0.820491 0.703092 1.405779 2.420169 -0.165195 -0.259497 0.727128 0.715522 0.405840 0.125885 0.128931
69 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 48.424201 153.136660 140.165261 237.847175 19.873134 66.046660 1571.476766 4582.219827 0.017426 0.016305 0.001064 1.039816 0.779632
70 N04 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 42.780128 202.525770 125.203284 252.821310 39.409912 43.647992 1087.431613 2936.519867 0.016886 0.015966 0.000937 0.000000 0.000000
71 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 47.143788 60.751338 132.455500 136.076861 36.837444 29.789083 1258.155115 1401.328083 0.016908 0.016507 0.000332 1.079923 1.070136
72 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 103.634602 46.767804 167.299942 130.060724 39.415463 28.159430 2054.477986 1131.156955 0.017974 0.017263 0.000603 0.000000 0.000000
73 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.285359 2.316079 -0.434128 0.350135 -0.412299 0.566264 10.204129 2.347680 0.731760 0.710481 0.478191 2.794199 2.643473
81 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.181566 2.839695 -0.594628 4.156302 0.089532 2.031539 3.451848 -0.208051 0.685855 0.663634 0.373903 106.464998 56.274532
82 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.136896 -0.588416 0.181892 2.373164 -0.711763 -0.030409 0.300575 -0.031562 0.706757 0.688218 0.383073 7.163494 9.931053
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.671617 2.990832 3.332395 6.101700 0.777347 2.166478 -0.032290 -1.117910 0.722588 0.709533 0.384544 3.637219 4.500618
84 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.657231 7.085629 0.351041 2.255893 -0.562639 -0.469425 -0.330226 0.905593 0.085927 0.098673 0.016063 0.833214 0.822788
85 N08 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.345996 1.188852 -0.317702 0.051265 -1.094416 -1.159205 -0.881045 -1.034757 0.071706 0.075023 0.007662 0.868875 0.832626
86 N08 RF_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.671716 2.623239 2.028796 -0.391769 1.307197 0.428135 -0.697972 -0.345949 0.080864 0.071001 0.006526 0.000000 0.000000
87 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.048947 7.932174 8.324711 0.631539 14.106235 -0.786820 189.472698 -0.554057 0.066819 0.073492 0.010846 0.000000 0.000000
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.669542 18.520122 57.400587 59.414651 23.955637 23.733013 25.907009 18.686210 0.032995 0.032742 0.002454 0.000000 0.000000
90 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.940743 20.079741 57.229098 58.885235 23.781974 23.484079 14.652176 13.044520 0.032352 0.030118 0.000837 0.000000 0.000000
91 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.931147 19.074216 57.222671 60.157470 23.897343 23.790320 19.574768 18.918011 0.030681 0.030070 0.000754 1.066372 1.055779
92 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 28.515932 39.857045 12.078233 16.150285 25.200169 25.998230 16.974036 29.611026 0.271622 0.218552 0.093996 2.605716 2.222079
93 N10 digital_ok 100.00% 24.19% 24.19% 75.81% 100.00% 0.00% 0.368717 0.102777 4.415895 -0.598100 1.262909 -0.023213 -0.542017 1.182727 0.210547 0.211531 -0.269059 0.000000 0.000000
94 N10 RF_maintenance 100.00% 24.19% 24.19% 0.00% 100.00% 0.00% 0.556289 0.413414 -0.562649 -0.727069 -0.454340 0.977541 8.289558 1.811393 0.530626 0.505049 0.333704 3.096605 3.101950
98 N07 digital_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.844932 3.026953 12.454062 3.863924 7.199580 1.105007 -0.464876 1.132410 0.685789 0.660869 0.384533 203.648579 137.686165
99 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.635376 5.024636 12.237905 9.789015 6.717062 5.035978 1.983938 -1.417654 0.697748 0.684472 0.373691 0.000000 0.000000
100 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.593425 0.227106 0.793969 0.657736 -0.537227 -0.329068 -0.893224 0.175029 0.719028 0.702106 0.395190 20.496712 11.832382
101 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 7.066209 6.963375 5.287994 0.381624 1.562771 -0.856829 3.737365 2.236909 0.110289 0.091401 0.016374 2.382485 1.380339
102 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.725634 0.988470 15.800737 3.915945 16.500532 12.700199 261.244525 119.536283 0.055226 0.063761 0.005483 962.255722 230.628460
103 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.840218 6.907028 -0.281676 0.550006 -0.277476 -0.607974 0.985508 0.872841 0.074900 0.073982 0.004984 0.000000 0.000000
104 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 4.865783 62.736094 0.578572 17.773372 -0.461124 3.125414 2.226721 1.618064 0.084058 0.091387 0.011964 411.791172 215.491554
105 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.016771 23.914594 54.343751 57.321320 23.918392 23.842277 16.483974 16.770716 0.035017 0.032682 0.001435 0.000000 0.000000
106 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.399968 20.585655 56.245761 59.216686 23.858190 23.612844 18.910833 14.642355 0.029244 0.028714 0.000716 1.074499 1.079825
107 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.771401 18.698348 55.119909 56.991524 23.862923 23.531618 17.703144 18.853233 0.030912 0.031150 0.000851 1.312570 1.309638
108 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.452870 19.158170 56.565317 59.735236 23.773641 23.578921 13.747114 13.846812 0.030379 0.030023 0.000926 0.966511 0.973188
109 N10 digital_ok 100.00% 24.19% 24.19% 0.00% 100.00% 0.00% -0.594173 0.275436 1.075078 1.897091 -0.317262 1.351201 14.370205 8.000154 0.558798 0.538862 0.358299 6.346537 8.293322
110 N10 RF_maintenance 100.00% 29.57% 24.19% 0.00% 100.00% 0.00% 33.226917 1.263781 4.677820 2.518085 5.744145 -0.582129 2.338651 -1.576896 0.520568 0.532006 0.302950 0.000000 0.000000
111 N10 digital_ok 0.00% 24.19% 24.19% 0.00% 23.68% 0.00% 0.667643 0.449202 -0.426768 1.873973 1.079709 -0.044848 0.210494 1.389401 0.541850 0.515915 0.333537 0.495297 0.479632
112 N10 RF_maintenance 0.00% 24.19% 24.19% 0.00% 100.00% 0.00% -0.575160 -0.492791 -0.716591 0.897576 0.044848 -0.645344 1.215572 -1.124418 0.530500 0.503687 0.331528 0.000000 0.000000
116 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.663404 5.987938 -0.672730 10.040065 -0.035275 5.526973 0.135397 -1.288707 0.681597 0.660120 0.393382 11.564582 9.408016
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.057242 3.025489 7.207296 6.709757 2.828135 1.899882 -1.300680 -2.126489 0.706059 0.686598 0.406765 0.000000 0.000000
118 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.299407 1.101134 4.046481 0.576466 1.250083 1.312903 5.017763 4.340493 0.709401 0.694203 0.405066 149.567516 45.850266
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.552581 1.503862 12.458472 1.197044 7.486450 -1.011986 -0.869280 -0.132965 0.721718 0.705957 0.420665 2.812158 3.053281
120 N08 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 16.107650 25.698205 11.939818 73.679108 20.957059 24.270746 12.481156 26.305728 0.124303 0.045750 0.065646 50.002369 1.549422
121 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.653647 3.991667 -0.207533 0.918401 -0.678812 -0.314983 43.187327 35.793668 0.081671 0.071340 0.007051 5.829022 6.935166
122 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.585502 4.862555 3.036355 1.404891 1.650029 -0.039388 3.923768 3.049753 0.096859 0.094945 0.013750 0.000000 0.000000
123 N08 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.472693 6.514684 2.293631 0.370812 0.587954 -0.072019 -0.541565 -0.673162 0.122454 0.121759 0.027614 1.849174 1.175078
125 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.612044 19.305561 58.063597 60.535545 23.864591 23.653132 15.639513 20.168384 0.029313 0.031700 0.002018 0.952257 0.987223
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.505799 19.646763 57.330054 60.871020 23.918130 23.710336 17.350525 20.291751 0.030317 0.030552 0.000996 1.602947 1.884912
127 N10 RF_maintenance 0.00% 24.19% 24.19% 0.00% 100.00% 0.00% -0.402112 -0.234009 0.403346 0.290788 0.667941 1.118194 0.006700 -0.032218 0.565621 0.543372 0.360843 8.410540 7.748195
128 N10 digital_ok 0.00% 24.19% 24.19% 0.00% 23.68% 28.95% -1.157552 0.681339 -0.610582 2.008257 -0.767804 -0.081311 -0.082142 -1.349236 0.562834 0.537114 0.345459 0.000000 0.000000
129 N10 digital_ok 0.00% 24.19% 24.19% 0.00% 23.68% 0.00% -0.453359 -1.282762 -0.765345 -0.934367 -0.109204 -0.289107 -0.509628 0.231620 0.555579 0.530470 0.338269 0.482365 0.477109
130 N10 digital_ok 100.00% 24.19% 24.19% 0.00% 100.00% 0.00% -0.069344 0.522743 1.131962 1.808192 -0.215276 -0.247391 2.345784 8.282788 0.539055 0.515269 0.330524 0.000000 0.000000
135 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
136 N12 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
137 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.212141 19.431329 56.452049 58.439174 23.958107 23.764058 17.583662 20.395093 0.038744 0.048554 0.005426 1.264511 1.850068
138 N07 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 24.689670 2.133453 53.168389 -0.333894 24.011149 0.064848 18.121473 0.684262 0.051865 0.697614 0.481882 0.000000 0.000000
140 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.531803 3.812847 0.168059 1.527062 1.790149 2.920764 1.626958 1.717076 0.712385 0.698054 0.426685 0.000000 0.000000
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.783374 4.379735 -0.169371 14.186026 2.149583 5.584290 1.834692 17.209875 0.710618 0.689777 0.444132 0.000000 0.000000
142 N13 digital_ok 100.00% 37.63% 100.00% 0.00% 100.00% 0.00% 18.793910 22.788102 11.729413 67.339516 22.066635 23.886579 15.054407 17.114462 0.438094 0.048117 0.272293 0.000000 0.000000
143 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
144 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.899673 1.125637 -0.428752 -0.225853 0.600330 -0.996152 5.615190 0.615231 0.720947 0.702760 0.462864 1.048999 1.054305
145 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.285037 19.687705 65.653326 67.854193 23.888918 23.715527 17.796970 20.923231 0.033875 0.034979 -0.000790 0.996965 0.992756
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 20.915355 21.358740 65.377137 68.944142 23.949922 23.787652 19.010509 20.541805 0.058527 0.062803 0.001838 1.366453 1.406991
155 N12 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
156 N12 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.730535 0.461796 2.676429 0.207694 1.097159 -0.110078 18.723467 19.121131 0.617576 0.595777 0.379803 33.487238 24.919864
157 N12 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.028334 0.877173 -0.187163 3.923643 1.034704 1.246346 1.110571 -0.663302 0.625775 0.608978 0.382799 0.000000 0.000000
158 N12 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.387544 -1.075991 -0.465843 -0.133084 -0.582596 -0.092353 1.745530 0.751234 0.638815 0.621170 0.386511 0.000000 0.000000
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.808701 17.714734 64.935994 67.123678 23.870114 23.718454 17.907859 20.265005 0.046233 0.048234 0.003050 1.014987 1.037083
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.721450 35.051146 0.527780 4.908147 0.033097 5.973083 0.347621 1.793507 0.711094 0.621920 0.408510 0.000000 0.000000
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 55.26% 0.00% 1.663420 0.749133 0.712940 -0.614344 1.991391 0.734184 -0.462529 -0.513763 0.709466 0.695590 0.430311 0.000000 0.000000
163 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
164 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.549425 1.566159 8.732006 -0.552655 4.107223 -1.086599 9.144183 3.950670 0.720105 0.700749 0.443145 0.000000 0.000000
166 N14 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.207328 1.593631 0.038557 1.834738 6.449570 2.562218 110.478609 12.790353 0.700080 0.697665 0.405312 1.139095 1.135341
167 N15 digital_ok 100.00% 2.69% 13.44% 0.00% 100.00% 0.00% 19.228195 18.851132 21.607411 22.199238 18.159725 17.756082 55.536311 26.001257 0.636861 0.614625 0.269181 0.000000 0.000000
168 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.388103 17.391735 23.131974 25.268047 16.581672 18.914047 4.530560 5.191205 0.674454 0.642443 0.414775 1.929000 1.907316
169 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.220764 15.985319 25.402523 23.783511 18.767526 17.779953 5.665011 3.891314 0.651056 0.623111 0.407227 0.000000 0.000000
170 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.187651 14.836068 25.530245 22.988565 18.814743 16.559395 5.974532 3.698337 0.634865 0.612109 0.404045 0.000000 0.000000
176 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 55.26% 28.95% -0.142442 -0.201948 -0.391153 1.158318 0.429457 0.272255 -0.619134 -1.114306 0.594288 0.575174 0.377641 0.000000 0.000000
177 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.551026 1.319559 2.350861 -0.175735 0.300358 -0.715725 3.383026 5.753230 0.606813 0.583491 0.380139 0.952985 0.720434
178 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 28.95% 47.37% -0.830398 -1.092493 0.890286 -0.783551 -0.804574 -0.948115 -0.006700 -1.097947 0.620673 0.601480 0.383838 4.328548 3.431804
179 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.644381 0.222253 -0.433114 0.295832 1.498004 -0.095639 8.252285 0.037733 0.631145 0.608664 0.394683 0.000000 0.000000
180 N13 RF_maintenance 100.00% 0.00% 37.63% 0.00% 100.00% 0.00% 0.520250 12.019255 1.360727 60.418266 -0.319753 15.001609 -0.583959 12.243603 0.704182 0.489898 0.504222 0.000000 0.000000
181 N13 digital_ok 100.00% 100.00% 78.49% 0.00% 100.00% 0.00% 20.575213 41.509995 65.847745 7.756570 23.929917 23.763291 17.934510 20.572593 0.052234 0.320957 0.178477 0.000000 0.000000
182 N13 RF_maintenance 100.00% 0.00% 32.26% 0.00% 100.00% 0.00% 14.805690 11.798106 23.158345 55.606744 16.480595 15.029817 3.373479 38.689637 0.688580 0.546557 0.454128 0.000000 0.000000
183 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 78.95% 5.26% -1.342996 -0.860031 -0.135367 -0.719208 -0.873414 -1.563395 -0.293694 2.365868 0.713100 0.695908 0.442183 0.000000 0.000000
184 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 55.26% 0.00% 0.137521 0.018645 -0.051265 1.148729 0.860003 0.127789 0.904197 0.378162 0.713277 0.696028 0.432436 0.000000 0.000000
185 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
186 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
187 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
189 N15 digital_ok 0.00% 0.00% 0.00% 0.00% 42.11% 57.89% 3.426014 3.703989 0.427040 -0.111023 -0.624592 -0.859563 0.339058 -0.497132 0.670951 0.648642 0.410246 0.000000 0.000000
190 N15 digital_ok 100.00% 13.44% 100.00% 0.00% 100.00% 0.00% 26.267646 21.776345 3.322701 67.843214 15.284295 23.800029 127.721901 19.730520 0.599704 0.054236 0.399528 0.000000 0.000000
191 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.115616 0.628367 -0.780805 -0.621810 -1.000400 -1.106829 6.150445 11.292256 0.639634 0.605943 0.416441 0.000000 0.000000
203 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
205 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.919437 5.408222 17.043497 5.233658 12.386277 2.930252 36.940191 54.338795 0.666590 0.635306 0.416535 0.000000 0.000000
206 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.887528 7.682748 0.059723 11.833213 4.765192 8.404664 41.552851 38.296246 0.649666 0.640670 0.396566 0.000000 0.000000
207 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 12.939003 10.259814 19.447477 15.950122 13.794774 11.004666 13.466385 12.224021 0.650227 0.638372 0.399235 0.000000 0.000000
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.356577 6.655105 102.426270 106.302851 1942.608355 2306.566713 18672.376365 26090.314668 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.720804 3.895193 10.547586 4.896520 7.030542 6.627331 1.320874 2.036498 0.655707 0.631870 0.413392 0.000000 0.000000
224 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 19.586091 18.852220 28.441015 27.490542 21.415432 20.762488 6.640639 5.683779 0.604946 0.587754 0.387813 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% 7.338063 3.986831 inf inf 2689.398231 2689.339855 30962.312084 30963.937075 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.215759 22.060107 48.399831 49.384059 24.128362 23.651709 25.657420 20.474081 0.066541 0.061978 -0.001635 0.000000 0.000000
321 N02 not_connected 100.00% 2.69% 59.68% 0.00% 100.00% 0.00% 9.691704 7.497739 15.695734 13.810570 11.330843 9.955767 52.228721 51.414435 0.515659 0.425722 0.319952 0.000000 0.000000
323 N02 not_connected 100.00% 18.82% 65.05% 0.00% 100.00% 0.00% 17.353299 10.760920 3.033624 17.918200 9.045511 11.639556 34.682856 5.593924 0.442894 0.394980 0.263373 0.000000 0.000000
324 N04 not_connected 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 24.459147 25.810305 68.135786 72.402775 21.042948 26.147621 372.035388 433.031048 0.024945 0.023562 0.001000 0.000000 0.000000
329 N12 dish_maintenance 100.00% 45.70% 70.43% 0.00% 100.00% 0.00% 1.412176 6.411995 2.120196 13.287905 4.524508 9.107340 8.747433 -0.032842 0.431108 0.351979 0.264616 0.000000 0.000000
333 N12 dish_maintenance 100.00% 59.68% 100.00% 0.00% 100.00% 0.00% 1.138343 6.567661 1.481509 12.333989 1.640828 7.268389 2.601415 -0.624377 0.394149 0.319442 0.233438 0.000000 0.000000
In [22]:
# print ex_ants for easy copy-pasting to YAML file
proposed_ex_ants = [ant for i, ant in enumerate(ants) if np.any([col[i] > 0 for col in bar_cols.values()])]
print('ex_ants: [' + ", ".join(str(ant) for ant in proposed_ex_ants) + ']')
print(f'\nunflagged_ants: [{", ".join([str(ant) for ant in ants if ant not in proposed_ex_ants])}]')
# "golden" means no flags and good a priori status
golden_ants = ", ".join([str(ant) for ant in ants if ((ant not in proposed_ex_ants) and (a_priori_statuses[ant] in good_statuses.split(',')))])
print(f'\ngolden_ants: [{golden_ants}]')
ex_ants: [3, 4, 5, 7, 8, 9, 10, 15, 16, 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: [17]

golden_ants: [17]
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_2459796.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 [ ]: