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 = "2459816"
data_path = "/mnt/sn1/2459816"
ant_metrics_ext = ".ant_metrics.hdf5"
redcal_ext = ".known_good.omni.calfits"
nb_outdir = "/home/obs/src/H6C_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-24-2022
In [5]:
# Per-season options
def ant_to_report_url(ant):
    return f'https://htmlpreview.github.io/?https://github.com/HERA-Team/H6C_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/2459816/zen.2459816.25313.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 424 ant_metrics files matching glob /mnt/sn1/2459816/zen.2459816.?????.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 43 ant_metrics files matching glob /mnt/sn1/2459816/zen.2459816.?????.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 2459816
Date 8-24-2022
LST Range 17.702 -- 20.851 hours
X-Engine Status ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
Number of Files 505
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 N10
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 50 / 147 (34.0%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 106 / 147 (72.1%)
Redcal Done? ✅
Redcal Flagged Antennas 10 / 147 (6.8%)
Never Flagged Antennas 25 / 147 (17.0%)
A Priori Good Antennas Flagged 73 / 95 total a priori good antennas:
5, 7, 16, 19, 30, 31, 37, 38, 41, 42, 45, 51,
53, 55, 56, 65, 66, 67, 69, 71, 72, 73, 81,
83, 84, 86, 88, 91, 93, 94, 98, 101, 103, 105,
106, 107, 108, 109, 111, 112, 116, 117, 118,
121, 122, 123, 127, 128, 129, 130, 140, 141,
142, 143, 144, 156, 158, 160, 161, 162, 165,
167, 169, 170, 177, 179, 181, 185, 186, 187,
189, 190, 191
A Priori Bad Antennas Not Flagged 3 / 52 total a priori bad antennas:
82, 90, 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/H6C_Notebooks/_rtp_summary_/array_health_table_2459816.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% 2.301238 -0.878324 -0.936657 -0.832343 -0.286897 -0.187931 -0.660776 1.124186 0.828786 0.571277 0.608745 1.645711 1.346757
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.300323 3.855616 -0.969442 1.553311 -0.988273 0.288621 0.478284 -0.511318 0.842135 0.570769 0.612015 3.983026 4.128719
5 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.030752 0.540236 -1.044860 4.152624 -0.799248 3.072806 0.381296 -0.993933 0.845719 0.585963 0.608404 3.932030 3.688829
7 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.102272 -1.019148 -0.118711 -0.332840 -0.487832 0.464190 0.518610 18.403619 0.838952 0.582669 0.607548 3.427020 3.444825
8 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.021273 10.970738 24.088461 24.516419 33.795211 34.216324 -0.093063 -3.889375 0.837283 0.557081 0.615120 3.386776 3.932298
9 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.250090 -1.478167 -0.265177 -0.251458 -0.487350 -0.837695 0.006513 -0.182026 0.843213 0.573503 0.620117 1.922994 1.583943
10 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.139031 -0.764777 -1.162512 -0.008904 -0.351031 0.260739 2.515742 0.217801 0.834431 0.555957 0.629498 1.834214 1.607911
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.534576 0.414122 1.542363 1.218075 0.843893 -0.217650 2.045204 1.713855 0.843485 0.575548 0.604828 1.749866 1.542021
16 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.700800 -1.318322 -0.098189 -1.279848 -0.096780 -0.306051 9.570347 7.365016 0.846716 0.589437 0.596813 3.905188 4.589187
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.408655 0.377059 0.698874 0.984189 2.187376 2.427293 0.629549 0.273959 0.848709 0.596833 0.596595 1.851956 1.587777
18 N01 RF_maintenance 100.00% 0.00% 84.91% 0.00% 100.00% 0.00% 6.627433 8.827936 3.946398 1.177094 5.967196 9.575842 19.697602 70.502166 0.829362 0.387802 0.640764 3.341424 2.068560
19 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.032997 6.705938 -1.221880 18.137325 -0.592377 23.273595 13.688536 3.003146 0.844721 0.592076 0.601696 3.187919 3.683836
20 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.821970 0.588807 -0.416513 -0.228537 -0.574263 1.734832 0.636751 -0.182513 0.846354 0.573017 0.610587 1.887190 1.633758
21 N02 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.546299 1.147769 1.084186 1.334159 -0.204888 1.219769 1.812849 0.421903 0.839186 0.567243 0.618637 1.890998 1.554697
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.377470 20.581395 43.235765 44.489298 46.769307 45.276556 9.383095 7.384057 0.039841 0.044316 0.002891 1.244782 1.236372
28 N01 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 12.746953 23.943176 0.734717 1.612514 37.463171 42.487893 13.567631 59.263339 0.461880 0.206048 0.313033 7.235637 3.017174
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.354149 0.154455 -0.033192 -0.209772 -0.721792 0.247160 -0.546220 3.128319 0.853116 0.600746 0.589531 1.650284 1.496155
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.110596 0.188747 0.616287 -0.933839 0.607607 -0.146862 13.490380 0.708062 0.846213 0.602131 0.581841 3.724818 3.790440
31 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.596535 -1.132881 -0.905179 -0.952338 3.247810 0.564306 4.930629 5.186673 0.851174 0.600131 0.596267 3.620703 3.413927
32 N02 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 32.557568 29.850488 2.322337 1.856119 13.446395 15.464851 38.597595 51.830294 0.760314 0.542482 0.404418 5.543261 4.011910
33 N02 RF_maintenance 100.00% 0.00% 80.19% 0.00% 100.00% 0.00% 0.224575 8.594751 1.111999 -0.530777 33.488412 28.954821 204.015214 197.490950 0.840229 0.405887 0.684229 3.974793 2.069556
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.440527 8.222723 0.128244 -0.066921 1.739510 -0.076520 0.041431 1.374649 0.839013 0.575161 0.604801 3.271200 2.850943
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.206069 1.077283 -1.033048 -0.843635 -0.397914 -0.281676 0.161518 25.340625 0.845896 0.593564 0.596788 3.908752 3.410264
38 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.870867 -0.205724 -1.048194 -1.147589 0.368523 2.739605 15.107424 3.377757 0.847727 0.606968 0.592507 3.680652 3.427036
40 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.024846 -0.048763 -0.621987 -0.355997 0.472905 -0.631324 0.753720 1.917741 0.846201 0.608358 0.579090 1.919063 1.632400
41 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
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 9.30% -0.038439 0.753746 1.615341 1.213165 0.170600 0.197159 -0.834886 -0.582170 0.850664 0.606579 0.584381 1.803835 1.540317
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.419645 0.658961 -1.133848 0.875653 -0.750437 0.036013 0.410800 15.197941 0.847041 0.580250 0.604110 3.341161 3.191153
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.018579 0.116721 0.405575 -0.759875 -0.272423 -0.687698 -0.420665 1.931068 0.844564 0.573230 0.616445 1.569837 1.417207
50 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.152801 1.163179 -0.800447 2.663711 1.117049 2.394054 10.413045 6.364542 0.839062 0.581403 0.591078 3.201023 2.720632
51 N03 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
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.712973 7.448970 0.281801 -0.080330 1.054136 -0.961280 1.139650 2.265762 0.850415 0.613319 0.581817 3.530607 3.194201
53 N03 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
54 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.657856 -0.685763 1.846962 0.832313 0.967530 1.487681 1.246738 -0.570147 0.849978 0.626159 0.566151 1.911709 1.596301
55 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 72.09% 1.690102 0.815812 1.022490 0.647189 0.717153 0.558034 3.936234 -0.131956 0.851496 0.616946 0.566578 3.899331 3.423936
56 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.871823 -0.237026 1.577534 1.944800 1.766603 1.231476 -0.183877 11.565925 0.850783 0.623847 0.568131 3.540010 3.228699
57 N04 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
65 N03 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
66 N03 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
67 N03 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
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.171532 0.953705 -0.083661 -0.154167 0.683593 2.070924 -0.117763 -0.458911 0.848489 0.631739 0.555805 1.928593 1.681280
69 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 39.53% 0.022235 -0.812629 0.166322 0.652640 -0.016882 1.245177 -0.142815 0.763016 0.853148 0.638360 0.554789 3.082515 3.328307
70 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.864484 -1.257250 1.418474 -1.229696 1.044804 -0.123882 0.439381 1.797906 0.853417 0.632746 0.552038 13.914767 9.832704
71 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 100.00% 0.349427 -0.133988 -0.498314 -0.800990 -0.536328 -0.697703 -0.011670 2.644135 0.850852 0.642579 0.548901 16.294652 14.036255
72 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 76.74% 3.548312 -0.959766 -0.845555 1.809948 0.976436 1.360679 0.905524 -1.138694 0.849418 0.629267 0.558595 3.821007 3.293824
73 N05 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 18.239146 -0.696655 42.351710 0.158921 46.582541 0.956424 4.923122 1.705398 0.037417 0.611507 0.361967 1.226511 3.269667
81 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.014240 1.880976 -0.520492 3.936131 -0.004250 4.970214 2.038547 -0.629299 0.834923 0.579231 0.593973 3.232673 3.185014
82 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.235587 0.211896 1.970368 0.030074 1.401869 -0.651377 -0.888960 -0.863057 0.845089 0.601089 0.594739 3.621809 3.177733
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.904574 2.251964 2.340664 4.994552 1.619464 3.129430 -0.570299 -0.888557 0.848815 0.629357 0.569657 3.530372 3.578635
84 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.016819 10.402937 0.901336 1.113647 -0.038009 1.124988 -0.493928 3.231141 0.855835 0.635480 0.554828 4.033310 4.099301
85 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.683823 0.289683 -1.041939 -0.661196 -1.406629 -0.795673 -0.701225 -0.960724 0.853783 0.645409 0.555543 1.794319 1.515242
86 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.094268 4.381410 2.085095 -0.538196 0.773369 3.920911 -0.146613 -0.325818 0.852923 0.619457 0.549617 4.801198 3.401965
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.655782 11.537240 7.574768 1.458208 9.412707 1.890074 5.827708 -0.482623 0.852098 0.652952 0.547814 3.858276 3.469047
88 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.151243 12.234496 29.305572 25.815052 41.689800 35.433524 -3.815053 -5.158146 0.821336 0.622104 0.553765 3.102079 2.841739
90 N09 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.063458 -0.076339 -0.179295 3.118265 -0.398627 0.284725 0.052863 3.159730 0.849072 0.600572 0.588842 3.698495 2.830027
91 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.798775 13.216992 26.463347 27.108052 37.349923 37.580415 -4.122786 -5.446901 0.831254 0.572680 0.609037 3.083295 2.522924
92 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 38.905453 50.269447 3.993150 5.640063 42.386575 50.166137 4.519433 15.603660 0.092351 0.090057 0.011253 0.895638 0.892452
93 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.608297 -0.024967 3.385306 -0.023211 3.962888 -0.834550 4.583553 -0.470627 0.069524 0.088369 0.018128 1.175327 1.170168
94 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.440170 -0.739282 -0.621665 -1.204784 -0.407642 3.449304 6.009291 8.233591 0.072909 0.088617 0.020869 23.977953 20.318179
98 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.898450 0.155929 1.488156 4.082724 2.096638 0.546343 3.937933 3.253416 0.838745 0.565217 0.608538 4.001535 4.459679
99 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.803030 0.922334 3.623422 0.675870 2.901548 -0.542058 -0.801276 -0.892731 0.846558 0.596140 0.592311 1.687889 1.472251
100 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.300254 -0.093850 -0.673112 0.371315 2.139420 -1.116100 -0.012986 -0.483650 0.850840 0.610704 0.586885 1.665793 1.503270
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.872780 10.560368 3.794161 -0.046008 1.191833 -0.355139 7.386872 2.962531 0.858002 0.636163 0.568206 3.757147 3.659470
102 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.064903 7.087395 24.356219 23.813105 170.558236 169.463978 975.897184 966.411353 0.739080 0.537193 0.526031 2.643713 2.725591
103 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.618690 10.452629 -0.563133 0.095461 0.192177 -0.523198 -0.212382 -0.670661 0.858813 0.650881 0.556124 4.368552 3.641816
104 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.242857 77.883359 0.222687 15.281224 1.766897 7.009606 0.693843 -0.170568 0.861414 0.640379 0.574090 4.031813 3.370884
105 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.840625 5.311814 9.185166 15.194336 10.303648 19.541426 0.224061 -2.476351 0.858494 0.647419 0.559626 3.974387 3.190170
106 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.148872 12.741994 5.030913 26.042591 0.779791 35.774862 2.120522 -5.153754 0.843750 0.616049 0.572233 3.594422 2.891095
107 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.354242 9.629805 25.818143 23.094548 36.120730 31.938338 -3.888969 -1.856613 0.844753 0.614199 0.578186 3.805516 3.013517
108 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.139621 5.042184 3.752970 1.390017 1.457873 1.194940 0.072229 0.533731 0.839871 0.601940 0.587314 3.638077 2.947332
109 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.898271 0.445945 0.394811 1.150407 -0.867756 1.134557 -0.792197 -0.006513 0.065876 0.079291 0.016649 1.429166 1.370774
110 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 42.103240 2.032533 3.433780 1.339186 9.823899 -0.539308 0.463111 -1.041632 0.093526 0.064265 0.006266 1.065561 1.029590
111 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.155845 0.986779 -0.692725 0.672692 -0.506060 1.027780 -0.525120 0.646471 0.060565 0.057657 0.005670 1.235084 1.224540
112 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.142115 -0.265314 -0.645989 0.008904 -0.377935 -0.678762 -0.261776 -1.008714 0.060061 0.069218 0.012395 1.356606 1.351090
116 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 6.98% 0.608670 1.998893 -0.508578 -0.565251 -0.321141 0.362650 2.386871 -0.754861 0.841897 0.570885 0.603308 1.933499 1.697959
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.834542 1.218014 5.347671 4.228469 5.006655 3.066430 -0.676319 -1.102527 0.849343 0.592722 0.597461 4.426738 4.187427
118 N07 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 3.253228 23.599998 2.741401 38.498190 1.560346 45.704915 1.076637 2.525416 0.854146 0.052018 0.646345 5.231166 1.270027
119 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.936926 2.681790 10.774875 0.356437 12.955743 0.747132 -1.660106 -0.809250 0.859896 0.610459 0.587434 4.349680 3.833602
120 N08 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 19.853967 31.947468 2.607285 49.952623 36.177970 45.679090 2.568152 15.683161 0.503435 0.049574 0.399586 2.971837 1.173753
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.437009 6.134736 -0.835129 0.825796 0.629094 1.163022 74.314825 39.119380 0.861275 0.641645 0.559574 4.314137 3.485202
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.959407 7.931058 1.697313 0.805615 -0.405549 0.176679 0.900059 0.516718 0.862989 0.642392 0.563209 4.618745 3.792424
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.235007 9.633245 -0.286317 -0.003954 -0.919490 -0.257699 0.144544 1.791749 0.860719 0.645015 0.559781 5.290550 4.149223
125 N09 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.002293 13.144482 13.794907 18.724007 16.914112 24.860926 -0.982263 -2.544744 0.852253 0.618998 0.558073 5.637328 4.042983
126 N09 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 22.406582 4.162664 9.748533 6.905332 23.141792 6.738846 0.418499 -1.143941 0.739331 0.607440 0.459954 3.772239 3.550208
127 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.074158 -0.048224 0.950517 0.481692 0.720419 0.975797 0.145351 0.496775 0.092102 0.082506 0.018698 1.401095 1.381536
128 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.155387 2.296611 -0.458293 0.788060 0.367074 1.301152 0.452611 2.126169 0.080944 0.066403 0.009963 1.367847 1.362872
129 N10 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.492754 -0.993876 0.969907 0.928825 -0.526392 -0.914285 -0.906950 -0.598291 0.056010 0.058528 0.005869 0.000000 0.000000
130 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.132552 0.153693 0.383258 1.761804 1.486919 -0.073261 0.713472 7.545616 0.077315 0.069570 0.010508 1.466227 1.457585
135 N12 digital_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.884608 -0.072239 -1.187488 -0.768549 -0.450321 -1.421174 2.556973 0.268362 0.839781 0.570466 0.608213 5.033270 3.898425
136 N12 digital_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.142140 11.015356 -0.948001 0.089899 1.840895 1.477814 0.956478 1.718839 0.841236 0.546918 0.594805 5.183418 4.056720
137 N07 RF_maintenance 100.00% 25.94% 100.00% 0.00% 100.00% 0.00% 14.534489 39.947192 28.710872 36.386551 44.390695 48.282402 -4.090170 9.162276 0.429512 0.065838 0.257307 4.063054 1.345583
138 N07 RF_maintenance 100.00% 100.00% 37.74% 0.00% 100.00% 0.00% 20.614992 21.307393 33.734515 2.233440 47.082540 40.869758 8.320377 5.493717 0.048024 0.423137 0.265036 1.268455 3.873091
140 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 16.607250 19.147245 42.159904 44.535411 46.724815 45.345411 4.011357 4.258682 0.042112 0.044708 0.000945 1.160285 1.160214
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.044658 3.741543 -0.896930 10.708423 0.932257 3.298483 1.640677 35.054148 0.858025 0.594253 0.578263 5.854701 4.183522
142 N13 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 22.756219 24.543665 2.155470 44.808990 39.767981 45.369020 4.544483 7.462963 0.512220 0.044834 0.335990 8.700276 1.296904
143 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.33% 0.326186 -1.138979 2.118010 -0.017114 1.030465 -0.915315 -0.286297 -1.277737 0.847023 0.630626 0.556140 1.837578 1.535315
144 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 6.98% -0.690456 -0.847904 2.183127 -0.256035 0.585707 -0.263776 -0.070045 0.110955 0.854405 0.625804 0.567355 1.887969 1.593661
145 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 18.680370 20.588121 43.558438 45.239475 46.797922 45.128690 7.736229 10.434667 0.035355 0.036838 -0.000413 1.542492 1.600009
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 19.810865 22.627726 43.424915 46.179207 46.858403 45.366772 9.186605 10.483065 0.047425 0.049931 0.001461 1.366524 1.348305
155 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.624955 18.312062 42.290336 44.175817 46.698024 45.185457 9.447206 10.343320 0.043156 0.037909 0.002838 1.319615 1.307611
156 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.591832 20.653869 1.208053 3.634595 0.325896 17.104702 11.162585 49.797782 0.850829 0.486378 0.611153 5.514842 4.598162
157 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.080685 0.774731 -0.106537 2.966784 0.670219 1.627446 0.655265 -0.688206 0.844641 0.581770 0.602259 1.704519 1.436287
158 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.415495 -1.620182 -0.994670 -1.167039 -0.220554 -0.649756 0.917902 6.847053 0.847554 0.593470 0.601632 3.917975 3.728611
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 17.435279 18.502754 43.013929 44.613249 46.813250 45.374868 8.051447 10.609346 0.043413 0.044538 0.002700 1.207263 1.204377
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.283495 40.214213 -0.500380 3.289582 -0.883631 12.938910 0.125598 0.940348 0.846502 0.511262 0.557808 4.223013 5.730492
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 6.98% -0.095414 -0.488099 -1.179799 -0.668229 0.560898 0.016882 2.907465 2.106232 0.850475 0.613903 0.583695 2.009145 1.722190
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.791655 -0.022235 0.015823 -0.230319 -0.026581 1.769969 -0.228758 3.151570 0.847553 0.618414 0.571992 2.005463 1.658412
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.157818 -1.188442 -1.290107 -0.092556 -1.204611 -0.460462 0.497902 0.342429 0.848616 0.614467 0.578217 2.129774 1.819360
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.755249 1.629402 7.871287 -0.998600 7.386317 -0.634456 -1.042028 -0.484486 0.847419 0.617249 0.573124 4.583295 4.574417
166 N14 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.351637 5.249843 0.305393 -0.098374 6.516220 21.634064 5.522271 13.524698 0.829308 0.578416 0.549310 6.039142 4.493477
167 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.654457 17.972673 23.253792 24.326709 39.038375 37.461448 2.073521 3.582126 0.725178 0.476522 0.381708 5.596781 3.462404
168 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.858552 13.953891 24.269030 27.400955 34.007943 38.111135 -4.567298 -5.290690 0.829645 0.557724 0.607296 4.635153 3.352919
169 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 12.810117 12.577292 27.154867 25.657806 38.310486 35.861654 -4.574350 -4.838867 0.825314 0.544030 0.616582 3.870969 2.766173
170 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 12.873160 10.813053 27.491647 24.333597 39.031705 33.604327 -4.263506 -3.113818 0.816874 0.546677 0.618818 3.391211 2.811788
176 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.718341 -0.498855 -1.096652 -0.075920 -0.755124 -0.871004 -0.327792 -0.997452 0.845585 0.547945 0.631815 1.828548 1.445884
177 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.658014 0.941476 0.934937 -0.110776 0.152750 1.866995 0.045742 13.605429 0.839820 0.557714 0.613597 4.725934 4.573893
178 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.986424 -1.114019 0.897569 -0.629457 0.192310 -0.088421 -0.321639 -1.069642 0.838181 0.576364 0.608161 1.600460 1.344726
179 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.829031 0.639867 -0.669125 0.375458 4.316428 0.418771 9.245096 -0.186388 0.838867 0.583529 0.605578 3.693647 3.710528
180 N13 RF_maintenance 100.00% 0.00% 88.21% 0.00% 100.00% 0.00% 0.437769 15.505904 -0.204303 41.880726 0.017429 35.151098 0.023085 6.540838 0.844140 0.300140 0.677305 11.967116 2.634683
181 N13 digital_ok 100.00% 100.00% 88.21% 0.00% 100.00% 0.00% 19.327644 53.458374 43.742599 6.932672 46.831780 44.135913 7.703082 9.046676 0.047908 0.341073 0.202221 1.207030 3.163903
182 N13 RF_maintenance 100.00% 0.00% 88.21% 0.00% 100.00% 0.00% 10.207241 19.580018 24.404789 42.743077 33.911830 39.422087 -4.549940 8.226924 0.837071 0.231063 0.655100 3.798290 1.652686
183 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.551872 -0.665158 0.446322 -1.200663 -0.507514 -1.386035 -0.463899 3.877739 0.842951 0.603846 0.592489 1.827392 1.626584
184 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.237146 -0.128159 0.710927 0.935387 0.245724 0.647251 1.839309 -0.506671 0.841686 0.606584 0.578202 2.097630 1.581521
185 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.598812 0.412561 1.032743 1.383686 -0.373131 0.917810 5.083744 -0.677993 0.845777 0.605067 0.580896 4.444794 4.172289
186 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.440415 0.023368 4.785338 2.902518 1.455683 0.628559 2.637596 -0.285691 0.836313 0.600538 0.576360 4.326520 4.092071
187 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 27.91% 0.996786 0.487764 0.337566 0.364200 0.519668 -1.038951 2.917940 2.509910 0.838920 0.602485 0.576744 0.131733 0.130450
189 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.792466 3.061501 0.544485 2.130892 0.989717 1.419890 2.071712 20.118274 0.830479 0.567114 0.610130 4.901379 3.648693
190 N15 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 43.926725 23.350212 3.278840 45.250507 24.135977 45.365555 31.022669 9.114476 0.721660 0.045160 0.560365 2.595323 0.945403
191 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.859708 2.007374 -0.683515 9.805866 1.602201 3.835367 0.890467 12.988675 0.831853 0.537930 0.638481 3.445046 2.504704
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% 19.087476 18.854382 15.686324 0.730776 24.559122 10.003481 33.843199 52.673663 0.841752 0.531140 0.625813 5.227023 3.364465
206 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.475116 18.063730 4.537035 10.649577 12.947028 17.532493 34.543741 40.290342 0.824417 0.552824 0.612613 3.703507 3.102331
207 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 20.566336 19.046653 19.040834 14.715127 29.199125 22.522686 12.680836 13.561065 0.821372 0.547017 0.603035 6.347615 4.200114
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% 37.453763 38.054062 inf inf 4356.571473 5122.562265 17049.556383 22919.700260 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 17.754964 17.623005 9.290439 8.289445 14.535029 12.469759 -0.707992 8.151835 0.828095 0.537281 0.626343 4.172725 3.144267
224 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 25.574182 26.453720 29.675229 28.884131 43.564067 41.429927 -5.639492 -6.367809 0.792660 0.502903 0.611119 3.191507 2.737207
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% 36.786712 37.327959 inf inf 5972.858057 5972.602973 27177.202987 27176.083367 nan nan nan 0.000000 0.000000
320 N03 dish_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
321 N02 not_connected 100.00% 0.00% 18.87% 0.00% 100.00% 0.00% 5.090103 3.815301 15.705513 13.979477 23.914625 21.132749 43.929134 42.633822 0.790003 0.441259 0.643353 0.000000 0.000000
323 N02 not_connected 100.00% 0.00% 42.45% 0.00% 100.00% 0.00% 21.506967 7.102141 1.074886 18.547586 22.132626 24.660842 3.753983 0.771105 0.623582 0.415157 0.489515 0.000000 0.000000
324 N04 not_connected 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
329 N12 dish_maintenance 100.00% 0.00% 16.51% 0.00% 100.00% 0.00% 5.038488 2.973374 0.699965 12.969006 11.386278 17.344214 11.549492 -0.691977 0.750918 0.440319 0.606663 0.000000 0.000000
333 N12 dish_maintenance 100.00% 0.00% 28.30% 0.00% 100.00% 0.00% 4.397947 3.387759 -0.096782 11.828705 8.697238 15.479641 4.183134 -1.004329 0.734392 0.417787 0.597509 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, 16, 18, 19, 27, 28, 30, 31, 32, 33, 36, 37, 38, 41, 42, 45, 50, 51, 52, 53, 55, 56, 57, 65, 66, 67, 69, 70, 71, 72, 73, 81, 82, 83, 84, 86, 87, 88, 90, 91, 92, 93, 94, 98, 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, 158, 160, 161, 162, 165, 166, 167, 168, 169, 170, 177, 179, 180, 181, 182, 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, 17, 20, 21, 29, 40, 46, 54, 68, 85, 99, 100, 157, 163, 164, 176, 178, 183, 184]

golden_ants: [3, 9, 10, 15, 17, 20, 21, 29, 40, 46, 54, 68, 85, 99, 100, 157, 163, 164, 176, 178, 183, 184]
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/H6C_Notebooks/_rtp_summary_/rtp_summary_table_2459816.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 [ ]: