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 = "2459808"
data_path = "/mnt/sn1/2459808"
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-16-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/2459808/zen.2459808.25312.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/2459808/zen.2459808.?????.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/2459808/zen.2459808.?????.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 2459808
Date 8-16-2022
LST Range 17.176 -- 19.176 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, N15, N19
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 81 / 147 (55.1%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 102 / 147 (69.4%)
Redcal Done? ✅
Redcal Flagged Antennas 10 / 147 (6.8%)
Never Flagged Antennas 22 / 147 (15.0%)
A Priori Good Antennas Flagged 75 / 95 total a priori good antennas:
5, 7, 21, 30, 31, 37, 38, 40, 42, 45, 46, 54,
55, 56, 67, 68, 69, 71, 72, 73, 81, 83, 84,
85, 86, 88, 91, 93, 94, 98, 100, 101, 103,
105, 106, 107, 108, 109, 111, 112, 117, 118,
121, 122, 123, 127, 128, 129, 130, 140, 141,
142, 143, 144, 156, 160, 161, 163, 164, 165,
167, 169, 170, 176, 177, 178, 179, 181, 184,
185, 186, 187, 189, 190, 191
A Priori Bad Antennas Not Flagged 2 / 52 total a priori bad antennas:
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_2459808.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.493558 -0.528883 -0.815192 -1.105284 -0.648503 -0.549366 -0.029958 -0.185549 0.741664 0.684449 0.492230 2.108473 1.869417
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.440740 3.560081 -1.063067 1.601406 -0.611086 0.263465 4.887541 0.951497 0.755977 0.688758 0.486281 10.702649 9.035532
5 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.256087 1.146091 -0.828213 5.138594 -0.829071 2.098005 2.524803 -1.213154 0.764396 0.698573 0.484463 6.846696 5.452267
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.080431 -0.963410 0.232268 0.495329 0.086215 0.148499 1.896046 8.550045 0.767335 0.697070 0.489915 3.689021 3.704944
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.997832 14.669807 21.383955 22.187642 19.966594 21.423114 1.613029 0.715842 0.747246 0.661431 0.497551 5.517753 5.552798
9 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.197967 -1.078296 0.058510 0.258836 1.949382 1.122412 -0.415142 -1.064799 0.753630 0.670469 0.503406 2.212007 2.401238
10 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.050475 -1.002691 -0.297966 0.397485 -0.669646 0.531339 0.188900 -0.643514 0.736447 0.647120 0.514572 2.092016 2.154458
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.535023 1.083132 1.879219 1.132884 0.511056 0.870069 0.097267 1.397208 0.774869 0.709197 0.480632 2.784987 2.549269
16 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.167835 -1.063514 -0.463241 -0.710098 -0.485292 -0.586302 1.659713 3.059390 0.779735 0.723080 0.474221 2.662492 2.612147
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.295338 1.331195 0.685779 0.403041 0.694986 0.399506 2.545268 -0.684286 0.785791 0.724649 0.478406 3.311072 2.901030
18 N01 RF_maintenance 100.00% 0.00% 27.42% 0.00% 100.00% 0.00% 2.616713 1.878557 3.135888 -0.743277 2.475513 4.950373 11.388072 30.474440 0.766283 0.565056 0.544008 4.731941 2.967336
19 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.796159 -0.571574 -0.204247 -0.355774 -0.753571 -0.371907 1.121853 3.757004 0.775258 0.708625 0.486254 2.287582 2.324799
20 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.125524 0.314835 -0.096657 -0.200924 1.645285 0.603488 -0.001476 -0.808377 0.763378 0.683101 0.489016 2.787330 2.489974
21 N02 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
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.209909 19.845090 63.048945 63.862538 29.393409 30.549243 7.300937 6.480437 0.039639 0.045301 0.003408 1.205674 1.212713
28 N01 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 11.505805 11.904807 8.670059 11.067268 24.199073 29.848786 8.909466 27.914152 0.535393 0.302676 0.339218 18.058845 4.292217
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.862695 0.258252 0.088698 -0.428921 -0.978569 -1.296786 -0.649485 -0.112258 0.800052 0.746326 0.470927 2.725528 2.634951
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.478867 -0.032222 1.479937 -0.869025 -0.124868 -0.791831 12.091700 0.239877 0.791654 0.735887 0.465826 4.715026 5.226815
31 N02 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
32 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 10.421878 9.152224 112.502221 103.958295 2307.327735 2099.744246 9425.737929 7088.571167 nan nan nan 0.000000 0.000000
33 N02 RF_maintenance 100.00% 0.00% 32.80% 0.00% 100.00% 0.00% 0.426365 2.622107 0.826327 0.275329 -0.478270 0.812153 2.148384 9.377065 0.755385 0.538329 0.593806 5.147952 2.568290
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.756901 4.990345 0.183349 0.446780 2.236401 -0.349610 0.954538 0.069410 0.754642 0.694810 0.468018 4.357224 4.159239
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.594990 1.083536 1.307375 0.368951 1.196727 0.655605 0.008454 7.491178 0.774292 0.716000 0.462085 5.464939 6.160808
38 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.729683 -0.228972 -0.821380 -0.923845 1.486081 0.176794 4.532388 0.408541 0.787657 0.737914 0.459207 4.120587 4.411810
40 N04 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
41 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.326016 -0.893018 2.068576 1.365637 0.689168 -0.778964 -0.808233 1.155013 0.806283 0.764176 0.460370 3.253150 2.590116
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 7.89% -0.263925 0.193012 2.125657 1.334475 -0.088610 -0.887511 -0.247904 -0.410839 0.806503 0.757154 0.475451 3.092277 2.717717
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.385516 0.638965 -0.842584 1.522368 -0.973232 -0.046335 -0.084790 15.682179 0.776488 0.701818 0.501465 4.436200 3.741092
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% -1.093038 -0.587219 0.205310 -1.053259 -0.357119 -0.877451 -0.340376 3.838287 0.763757 0.678848 0.523828 2.164971 1.765304
50 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.245008 1.312057 3.885775 2.867608 14.364410 4.579896 88.848862 18.430649 0.739898 0.698911 0.416481 8.167674 5.851174
51 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.344264 1.326877 -0.937983 -0.702179 0.060504 -0.166505 -0.483655 1.042798 0.782077 0.735238 0.444784 2.459895 2.470534
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.026086 4.825493 0.562279 0.439292 -0.382591 -1.158222 -0.204997 0.841499 0.799525 0.754986 0.446257 7.268707 6.468618
53 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.909591 0.999237 -0.775566 -0.381806 -0.546572 -0.166461 2.284784 3.341649 0.811791 0.777087 0.447448 2.072310 2.245021
54 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.135154 0.375185 1.976452 1.285479 1.731296 1.167907 6.111365 2.578816 0.819237 0.779679 0.455634 4.688783 6.576394
55 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.514326 -0.292662 -0.741287 1.035100 2.422605 1.930965 6.595682 -0.552871 0.819882 0.778598 0.465906 4.381264 4.576140
56 N04 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
57 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.594240 -0.742548 11.135811 3.240584 15.428487 1.978445 0.967526 2.512031 0.734149 0.751296 0.383086 6.219789 3.251157
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.094240 0.023952 0.281010 0.552463 1.332643 1.049885 -0.123920 -0.095540 0.775171 0.715459 0.464773 2.776365 2.379494
66 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.279424 -0.366361 -0.668992 0.325207 0.679335 0.487195 -0.310671 0.936854 0.791590 0.748519 0.440342 2.668880 2.544065
67 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 15.79% -0.742611 -0.605892 0.464237 -0.486308 0.967580 1.490691 -0.092571 1.503159 0.810447 0.774140 0.429322 2.859212 3.430801
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 31.58% 0.042643 -0.023918 0.094450 -0.315707 2.036868 1.434542 0.018008 -0.005551 0.820699 0.790973 0.429769 2.634739 4.016391
69 N04 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
70 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.082920 -1.502975 0.388371 -1.195540 0.689985 -0.371950 -0.000855 -0.217011 0.818885 0.779561 0.473117 29.060813 28.456140
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% 0.341457 -1.245941 -0.413712 -0.395683 -0.499627 -1.214594 -0.407882 0.240641 0.826258 0.791175 0.458618 49.670070 47.907505
72 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 97.37% 1.661862 -0.436743 -0.693852 1.988833 1.765598 1.186616 3.691086 -0.855161 0.809913 0.760421 0.488884 3.693767 3.123814
73 N05 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 19.078352 0.731432 62.085475 -0.738608 29.273289 -0.359341 5.369322 0.647965 0.031483 0.734589 0.369854 1.167078 3.326235
81 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 5.26% 0.031213 2.440868 -0.253001 3.946505 0.110540 2.588043 2.549636 -0.518837 0.772368 0.716813 0.456530 2.790629 2.660701
82 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.198611 -0.631084 2.056349 0.351216 -0.462697 -0.004410 0.001476 -0.184419 0.798406 0.748621 0.453247 8.940610 7.937435
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.858206 3.240647 2.584084 6.032490 -0.088536 2.089379 -0.776086 -1.464898 0.812003 0.774682 0.429469 5.149003 5.440232
84 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.542512 6.882510 0.151504 1.337710 -0.574836 -0.277242 0.894540 -0.595128 0.768469 0.732706 0.416658 3.903154 4.183182
85 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 76.32% 0.379793 -0.116672 -0.994838 -0.842426 -1.268745 -1.433406 -0.896016 -1.223991 0.759422 0.723369 0.440695 2.395546 2.254779
86 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 86.84% 1.954865 2.434191 0.858104 -0.636123 1.066846 0.191372 -0.185896 0.218391 0.756108 0.710091 0.434334 2.761773 2.531530
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.266599 7.913896 6.193040 1.284085 4.527437 0.942575 46.097609 -0.245218 0.739405 0.712179 0.444831 2.753670 2.613172
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.581043 18.855910 55.354852 56.353635 29.448102 30.563762 9.471797 6.763876 0.039657 0.035049 0.002447 1.173682 1.171041
90 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 11.898039 -0.008309 18.522298 1.263065 16.467437 -0.841041 -0.251503 -0.246105 0.054525 0.038707 0.003428 1.214164 1.230196
91 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 15.698345 18.888774 1.735852 57.267467 30.846497 30.503458 30.505383 7.458339 0.044836 0.039207 0.029918 1.433370 1.398080
92 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
93 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
94 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
98 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.544442 17.299563 0.392630 1.409252 -0.131206 0.818083 0.159724 3.413314 0.776670 0.699404 0.445999 9.373433 9.869120
99 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 3.060797 0.635757 3.417061 0.656876 2.479195 1.759876 -0.100567 1.266945 0.792547 0.741751 0.450173 2.339234 2.068960
100 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 23.68% 0.269638 -0.102205 0.329277 -0.058510 -0.956544 -1.140027 -0.947213 -0.718290 0.810062 0.764779 0.460017 2.509982 2.456816
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.274091 6.583445 4.136348 -0.002669 0.912884 -0.641455 3.814395 0.252943 0.762899 0.718338 0.438808 3.459448 3.256245
102 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 18.458144 17.406108 8.476428 8.057658 282.554595 275.930511 6229.910590 6192.332050 0.640389 0.661185 0.423108 0.000000 0.000000
103 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.839731 7.057888 -0.397399 0.351118 -0.484542 -0.509323 0.468730 -0.281737 0.749020 0.708569 0.439128 3.271352 2.995311
104 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.909461 62.881836 0.358001 16.437173 0.224332 3.587394 0.805185 -0.025072 0.744049 0.694129 0.464565 3.297793 2.875873
105 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 13.990305 16.562953 21.327653 24.292414 19.800879 23.973455 0.448536 1.052743 0.076166 0.059860 0.010101 1.229705 1.217834
106 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.608872 16.252560 6.133912 23.426895 4.228487 23.064181 -0.539196 0.874728 0.043213 0.050559 0.007179 1.198585 1.181926
107 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.657362 18.166517 17.794749 56.735211 27.153202 30.320278 2.506145 7.047142 0.055335 0.040098 0.034619 1.211528 1.210430
108 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.262390 18.154030 54.597347 56.752153 29.245225 30.402918 4.799372 4.985461 0.030255 0.040427 0.003976 0.865468 0.876552
109 N10 digital_ok 0.00% 0.00% 38.17% 0.00% 39.47% 0.00% -1.288583 0.376202 0.240967 0.670812 -0.156645 0.265795 1.425499 2.776249 0.602151 0.506993 0.428026 2.222623 2.354486
110 N10 RF_maintenance 100.00% 0.00% 40.86% 0.00% 100.00% 0.00% 32.787186 5.188968 4.047359 0.296367 8.221871 14.424258 27.890012 154.272663 0.532341 0.479554 0.325671 20.110908 6.540606
111 N10 digital_ok 100.00% 0.00% 40.86% 0.00% 100.00% 0.00% 0.136019 0.674591 -0.221030 1.327195 1.235939 0.459021 5.291351 6.344401 0.561661 0.463338 0.385053 4.777169 5.801509
112 N10 digital_ok 0.00% 0.00% 40.86% 0.00% 42.11% 0.00% -0.717350 -0.457295 -0.236170 0.972292 -0.053389 -0.836915 1.136673 -1.308237 0.536731 0.446548 0.371714 1.646359 1.808376
116 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.618721 1.762137 0.350481 -0.646042 -0.770583 0.349320 0.664695 -1.007000 0.773199 0.707478 0.475333 2.213011 1.974793
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.840774 2.852999 6.258874 6.627884 2.808368 3.460181 -1.263565 -1.685935 0.792487 0.734844 0.480162 5.453508 5.818526
118 N07 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 1.906458 19.808885 3.398230 56.648291 2.474905 30.384244 3.258005 4.567900 0.802680 0.044660 0.459803 4.223554 1.208227
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.922760 0.815714 9.302041 3.450668 5.768600 -0.318388 -1.127132 -0.311106 0.812917 0.757698 0.471081 3.526889 3.262598
120 N08 RF_maintenance 100.00% 30.11% 100.00% 0.00% 100.00% 0.00% 16.530286 25.590782 10.954861 70.251834 23.101982 31.151114 4.052987 9.764943 0.477072 0.054382 0.314352 2.465346 1.198838
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.268113 4.106653 -0.721825 0.627555 -0.248828 -0.404033 22.043680 11.209348 0.743961 0.698498 0.440306 3.517111 3.146054
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 6.583389 5.345126 1.756037 1.634416 0.163767 -0.626103 0.683019 1.878893 0.734621 0.681832 0.454196 3.062236 2.574544
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.479266 5.845048 0.066198 -0.079872 -1.076572 -1.069579 -0.444707 -0.443936 0.726422 0.671721 0.470953 3.104195 2.585485
125 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 16.077155 17.612568 23.221182 25.137564 22.128615 25.056888 1.044134 1.400095 0.073525 0.061310 0.007121 0.862784 0.858360
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 16.655285 14.433663 20.427096 21.138058 22.783828 20.175391 3.617860 0.192306 0.069489 0.043362 0.004554 0.847651 0.851741
127 N10 digital_ok 0.00% 0.00% 38.17% 0.00% 39.47% 0.00% 0.023918 -0.148999 0.732149 -0.362375 0.223384 0.493113 -0.228578 0.197477 0.595726 0.503888 0.422026 1.556690 1.673315
128 N10 digital_ok 0.00% 0.00% 40.86% 0.00% 42.11% 0.00% -0.981542 0.713225 -0.188343 1.714642 -0.756977 -0.629662 -0.557262 -1.305414 0.578629 0.481772 0.402264 1.987183 2.146316
129 N10 digital_ok 0.00% 0.00% 40.86% 0.00% 42.11% 0.00% -0.508259 -1.062723 -0.751150 -1.217744 -0.218283 -0.153568 -0.484160 2.091922 0.558804 0.465398 0.384722 1.722440 1.878646
130 N10 digital_ok 0.00% 0.00% 40.86% 0.00% 42.11% 0.00% -0.547816 0.393227 1.350308 1.543099 -0.169290 1.866501 0.438273 2.023018 0.536288 0.448832 0.368802 1.591658 1.834626
135 N12 digital_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.146030 -0.729351 -1.156082 -1.080397 -0.802686 -0.833990 2.419553 0.809500 0.705938 0.632269 0.472972 3.345220 2.856208
136 N12 digital_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.617529 9.193995 -0.685079 0.720436 4.004530 3.483403 2.125246 3.998810 0.713030 0.643552 0.442897 4.029719 3.640868
137 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.271607 20.326927 54.435923 55.500623 29.414367 30.541195 6.495966 7.707216 0.038901 0.043789 0.003592 1.181667 1.225555
138 N07 RF_maintenance 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 23.054476 1.979298 54.177190 1.457950 29.467333 -0.098003 6.688980 -0.174346 0.045572 0.739365 0.409596 1.248086 3.399819
140 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.429418 17.056199 61.798829 63.930425 29.352808 30.681817 5.047291 5.338658 0.039340 0.042229 0.000898 1.199990 1.211115
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.554096 4.703353 -0.479385 12.464654 1.562904 2.984040 0.912955 8.150389 0.782749 0.722776 0.488788 4.066069 3.387108
142 N13 digital_ok 100.00% 21.51% 100.00% 0.00% 100.00% 0.00% 17.664002 22.660571 10.100119 64.218101 23.460617 30.784936 5.676667 6.386969 0.472479 0.042375 0.265394 2.316758 1.155374
143 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.056447 -1.157721 1.800692 1.263192 0.650136 1.201670 -0.287436 -1.366967 0.112147 0.108655 0.028372 0.854940 0.850805
144 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.091244 0.048508 -0.811941 1.575989 0.136330 0.283265 1.208949 24.742441 0.095581 0.088531 0.018847 0.000000 0.000000
145 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.333303 19.393366 63.423613 64.731003 29.411305 30.539448 6.693332 7.777446 0.030295 0.032638 -0.000427 0.000000 0.000000
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.615351 20.266157 63.243206 65.847209 29.487729 30.689436 7.126048 7.548131 0.041571 0.039546 0.002086 1.210898 1.206508
155 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.923763 19.385139 61.949886 63.466708 29.370520 30.490228 7.292673 7.505709 0.038932 0.038204 0.000280 1.432666 1.411565
156 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.739534 4.110417 1.520346 2.925094 -0.364534 16.322456 2.044081 31.258099 0.700542 0.611386 0.468934 4.820737 4.980562
157 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.440077 0.912638 0.082984 3.682884 0.580464 2.218617 0.434706 0.752443 0.703101 0.634547 0.476985 1.548588 1.254274
158 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.911135 -1.232536 -0.935401 -0.194782 0.206403 0.118552 1.203219 -0.358788 0.709233 0.638353 0.473404 1.537343 1.330497
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.867436 17.389376 62.759289 64.018846 29.394468 30.589530 6.772950 7.704759 0.043262 0.042604 0.001442 1.286420 1.282682
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.713342 35.655933 -0.205198 4.597090 -0.352694 9.192878 0.370098 0.492511 0.758676 0.628622 0.428586 4.901858 6.365991
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.755776 0.942833 -0.678170 -0.904382 1.903415 1.348479 -0.276621 -0.566158 0.755839 0.685515 0.496684 1.618496 1.409527
163 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.519377 -0.408440 0.116555 -0.831874 -0.660728 -1.174003 1.200544 0.288842 0.071643 0.078835 0.012736 1.293041 1.286884
164 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.129513 -0.875538 -1.176574 -0.807092 -0.903757 -0.346493 1.408562 1.311080 0.073373 0.068997 0.005872 1.290652 1.290596
165 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.756469 1.137073 7.486275 -0.924099 4.637947 -1.010769 2.423196 2.177514 0.085182 0.063289 0.005407 1.285264 1.292834
166 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 10.072150 3.755021 1.792622 -0.029854 8.567179 10.553737 75.065687 50.062881 0.088215 0.092725 0.011553 1.200358 1.200819
167 N15 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 14.385798 17.168396 17.550672 21.242172 29.766307 24.811519 111.831778 34.827039 0.074899 0.071364 0.008924 1.163707 1.157013
168 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 14.639848 17.270161 21.630940 24.532626 20.184000 24.360605 0.568460 1.178469 0.072916 0.075442 0.011715 1.161714 1.151410
169 N15 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 16.526226 15.907585 23.805610 23.075993 22.748028 22.729940 1.123208 1.463397 0.078427 0.064392 0.005557 1.173122 1.177957
170 N15 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 16.558460 14.487143 24.004247 22.238563 23.312131 21.518003 1.734965 0.994329 0.080052 0.061143 0.005536 1.186078 1.197511
176 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
177 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
178 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
179 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.463087 0.478740 -0.481423 -0.270418 0.655259 -0.741549 17.691110 1.482721 0.679278 0.606782 0.461387 4.221381 3.886976
180 N13 RF_maintenance 100.00% 0.00% 38.17% 0.00% 100.00% 0.00% 0.418903 12.082158 0.258144 57.735015 -0.893892 19.467213 -0.806271 4.792611 0.744100 0.466478 0.548179 165.299816 52.401593
181 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.296845 43.444940 63.609174 6.779791 29.465346 30.786158 6.573240 14.022128 0.047524 0.315843 0.148198 1.275977 2.646226
182 N13 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.213338 4.948460 21.663668 10.640829 20.283793 7.324610 0.655686 8.951344 0.725129 0.671284 0.496469 8.946828 7.733396
183 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.331061 -0.800816 0.211347 -0.905800 0.437097 -1.672459 0.367028 0.509906 0.747671 0.668407 0.516699 1.451459 1.273521
184 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.851030 -0.206658 -0.107702 0.432097 0.004410 -0.249057 -0.239258 -0.462226 0.068270 0.060056 0.006376 1.303251 1.299346
185 N14 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.277237 0.233038 1.751775 0.953441 -0.273117 0.331846 0.748761 -0.811080 0.063156 0.068226 0.005800 1.267836 1.265904
186 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.095181 0.227545 5.336984 2.506780 1.735353 0.467780 6.854463 0.863220 0.066506 0.081824 0.012264 1.288814 1.279548
187 N14 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.183314 0.751252 0.431970 0.848450 -0.039304 -1.070931 5.177832 0.964215 0.093776 0.104193 0.021522 1.199779 1.202051
189 N15 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.416377 3.700395 0.642193 -0.092668 -0.633345 -0.170810 0.252751 -0.199210 0.050829 0.047054 0.003624 1.240444 1.237788
190 N15 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 30.245847 21.529234 5.349308 64.693338 14.746920 30.666431 117.824464 7.263022 0.050375 0.037321 0.040562 1.140087 1.117315
191 N15 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.331661 1.098001 -0.855660 2.897613 0.955748 1.467469 3.229681 3.352373 0.049832 0.044872 0.002826 1.105230 1.090927
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% 10.787310 5.288362 15.672262 -0.294047 13.990019 3.784551 17.931199 24.122912 0.054648 0.044220 0.004621 1.208254 1.220508
206 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.265226 7.803610 -0.688526 11.384291 6.747107 11.673168 18.914516 18.722699 0.041116 0.054341 0.001969 1.271659 1.269782
207 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 12.392086 9.989697 18.132815 15.219042 17.228741 13.840410 6.765527 5.335436 0.057911 0.060846 0.005618 1.115665 1.104854
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% 12.063649 11.523535 102.024651 105.438376 2138.006818 2496.993893 7839.846835 10653.663619 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.512086 2.247006 9.400847 1.076470 8.101264 1.414317 1.217091 15.876675 0.043279 0.044038 0.001983 0.951543 0.954456
224 N19 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.857327 18.707355 26.835752 26.771395 26.292419 26.905523 1.817139 1.692536 0.063329 0.066166 0.005418 1.163595 1.162775
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% 14.352558 13.695185 127.280149 142.004240 2956.952109 2956.805846 12893.387118 12894.356975 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.271533 21.782337 46.754435 46.830274 29.694437 30.543689 9.775539 7.431802 0.060042 0.057182 -0.002246 0.000000 0.000000
321 N02 not_connected 100.00% 0.00% 62.37% 0.00% 100.00% 0.00% 8.819209 7.272714 14.471571 13.492644 14.268131 12.861934 18.486802 18.165547 0.564063 0.399042 0.401254 0.000000 0.000000
323 N02 not_connected 100.00% 2.69% 65.05% 0.00% 100.00% 0.00% 16.967040 10.563000 2.934323 17.582350 12.133582 17.583689 14.372550 0.542088 0.470403 0.361960 0.326698 0.000000 0.000000
324 N04 not_connected 100.00% 0.00% 62.37% 0.00% 100.00% 0.00% 12.046180 7.590555 18.548549 12.409612 17.390293 10.780187 1.870358 0.246200 0.562699 0.403914 0.404115 0.000000 0.000000
329 N12 dish_maintenance 100.00% 29.57% 70.43% 0.00% 100.00% 0.00% 3.166444 6.800810 9.228590 12.990027 3.240202 10.452619 7.007833 -0.043448 0.454753 0.333229 0.312641 0.000000 0.000000
333 N12 dish_maintenance 100.00% 29.57% 91.94% 0.00% 100.00% 0.00% 0.496021 6.385018 1.412527 12.039421 2.242549 9.943866 2.809613 0.227289 0.448753 0.294904 0.308681 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, 18, 21, 27, 28, 30, 31, 32, 33, 36, 37, 38, 40, 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, 98, 100, 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, 160, 161, 163, 164, 165, 166, 167, 168, 169, 170, 176, 177, 178, 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, 9, 10, 15, 16, 17, 19, 20, 29, 41, 51, 53, 65, 66, 99, 116, 157, 158, 162, 183]

golden_ants: [3, 9, 10, 15, 16, 17, 19, 20, 29, 41, 51, 53, 65, 66, 99, 116, 157, 158, 162, 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_2459808.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 [ ]: