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 = "2459826"
data_path = "/mnt/sn1/2459826"
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: 9-3-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/2459826/zen.2459826.25305.sum.auto_metrics.h5.

Load Ant Metrics¶

In [7]:
use_ant_metrics = False

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

# if they exist, load as many of them as possible
if len(ant_metrics_files) > 0:
    print(f'Found {len(ant_metrics_files)} ant_metrics files matching glob {glob_str}')
    ant_metrics_apriori_exants = {}
    ant_metrics_xants_dict = {}
    ant_metrics_dead_ants_dict = {}
    ant_metrics_crossed_ants_dict = {}
    ant_metrics_dead_metrics = {}
    ant_metrics_crossed_metrics = {}
    dead_cuts = {}
    crossed_cuts = {}
    for amf in ant_metrics_files:
        with h5py.File(amf, "r") as infile: # use h5py directly since it's much faster than load_metric_file
            # get out results for this file
            dead_cuts[amf] = infile['Metrics']['dead_ant_cut'][()]
            crossed_cuts[amf] = infile['Metrics']['cross_pol_cut'][()]
            xants = infile['Metrics']['xants'][:]
            dead_ants = infile['Metrics']['dead_ants'][:]
            crossed_ants = infile['Metrics']['crossed_ants'][:]        
            try:
                # look for ex_ants in history
                ex_ants_string = infile['Header']['history'][()].decode()
                ex_ants_string = ex_ants_string.split('--apriori_xants')[1]
                ex_ants_string = ex_ants_string.split('--')[0].strip()
            except:
                ex_ants_string = ''
                    
            # This only works for the new correlation-matrix-based ant_metrics
            if 'corr' in infile['Metrics']['final_metrics'] and 'corrXPol' in infile['Metrics']['final_metrics']:
                ant_metrics_dead_metrics[amf] = {eval(ant): infile['Metrics']['final_metrics']['corr'][ant][()]
                                                 for ant in infile['Metrics']['final_metrics']['corr']}
                ant_metrics_crossed_metrics[amf] = {eval(ant): infile['Metrics']['final_metrics']['corrXPol'][ant][()]
                                                    for ant in infile['Metrics']['final_metrics']['corrXPol']}                       
            else:
                raise(KeywordError)
        
        # organize results by file
        ant_metrics_xants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in xants]
        ant_metrics_dead_ants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in dead_ants]
        ant_metrics_crossed_ants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in crossed_ants]
        ant_metrics_apriori_exants[amf] = [int(ant) for ant in ex_ants_string.split()]
    
    dead_cut = np.median(list(dead_cuts.values()))
    crossed_cut = np.median(list(crossed_cuts.values()))
        
    use_ant_metrics = True
else:
    print(f'No files found matching glob {glob_str}. Skipping ant_metrics.')
Found 372 ant_metrics files matching glob /mnt/sn1/2459826/zen.2459826.?????.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/2459826/zen.2459826.?????.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 2459826
Date 9-3-2022
LST Range 18.357 -- 20.357 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 N02, N04, N12
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 74 / 147 (50.3%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 113 / 147 (76.9%)
Redcal Done? ✅
Redcal Flagged Antennas 8 / 147 (5.4%)
Never Flagged Antennas 9 / 147 (6.1%)
A Priori Good Antennas Flagged 87 / 95 total a priori good antennas:
5, 7, 9, 10, 15, 16, 19, 20, 21, 29, 30, 31,
37, 38, 40, 41, 42, 45, 46, 53, 54, 55, 56,
67, 68, 69, 71, 72, 73, 81, 83, 84, 86, 88,
91, 93, 94, 98, 99, 100, 101, 103, 105, 106,
107, 108, 109, 111, 112, 116, 117, 118, 121,
122, 123, 127, 128, 129, 130, 140, 141, 142,
143, 144, 156, 157, 158, 160, 161, 162, 164,
165, 167, 169, 170, 176, 177, 178, 179, 181,
183, 184, 185, 186, 187, 189, 190
A Priori Bad Antennas Not Flagged 1 / 52 total a priori bad antennas:
90
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_2459826.csv

Build DataFrame¶

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

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

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

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

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

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

Table 2: RTP Per-Antenna Metrics Summary Table¶

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

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

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

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

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

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

In [21]:
HTML(table.render())
Out[21]:
Ant Node A Priori Status Auto Metrics Flags Dead Fraction in Ant Metrics (Jee) Dead Fraction in Ant Metrics (Jnn) Crossed Fraction in Ant Metrics Flag Fraction Before Redcal Flagged By Redcal chi^2 Fraction ee Shape Modified Z-Score nn Shape Modified Z-Score ee Power Modified Z-Score nn Power Modified Z-Score ee Temporal Variability Modified Z-Score nn Temporal Variability Modified Z-Score ee Temporal Discontinuties Modified Z-Score nn Temporal Discontinuties Modified Z-Score Average Dead Ant Metric (Jee) Average Dead Ant Metric (Jnn) Average Crossed Ant Metric Median chi^2 Per Antenna (Jee) Median chi^2 Per Antenna (Jnn)
3 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 3.302315 -0.775620 -0.331428 -0.822916 -0.604101 -0.764743 -0.844329 1.913531 0.778220 0.528729 0.543759 1.449985 1.098983
4 N01 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.508512 4.671550 -0.444778 1.461919 -0.769471 -0.994033 -0.093765 -0.588002 0.793927 0.527935 0.547887 10.125242 14.443908
5 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.093345 0.243584 -0.597923 4.960569 -1.426904 1.458792 0.431009 -1.246911 0.796400 0.538236 0.552568 9.260164 10.248108
7 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
8 N02 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
9 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
10 N02 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.329814 -0.656352 -0.588076 0.503748 0.274080 2.075135 2.057956 0.997595 0.072916 0.072495 0.013046 0.000000 0.000000
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% 0.672683 1.140176 1.369220 0.662181 -0.732769 -0.715615 0.460531 0.162492 0.797452 0.539345 0.544423 1.876973 1.458928
16 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.440484 -1.038509 -0.529779 -0.358891 -0.304103 0.551256 6.093559 1.150376 0.798302 0.541931 0.537886 10.412854 14.657204
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.099342 0.332493 0.736541 0.676141 0.825354 0.465386 3.481399 0.991428 0.797792 0.540767 0.548723 1.678971 1.309775
18 N01 RF_maintenance 100.00% 0.00% 91.94% 0.00% 100.00% 0.00% 6.680568 9.935981 4.089961 0.928596 7.316633 6.989249 21.244985 83.339514 0.773951 0.315023 0.603161 6.762484 3.241140
19 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.909291 -1.160142 -0.916118 -0.695835 -0.283256 5.072301 4.156832 8.296958 0.046219 0.045144 0.003203 1.215725 1.211332
20 N02 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -1.728658 1.071918 -0.489308 0.428095 0.642158 1.750266 -0.001553 -0.915144 0.057184 0.049222 0.003929 1.128391 1.116439
21 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.114766 -0.668658 0.697379 2.171253 -0.727920 0.785222 4.003178 0.576300 0.061431 0.054927 0.006904 0.000000 0.000000
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 24.842043 26.194913 39.837316 40.659172 48.982357 45.024101 8.891619 7.124562 0.039034 0.042451 0.002344 1.339972 1.358363
28 N01 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 15.696895 28.391023 0.576442 1.664842 37.274911 40.803980 9.228993 55.310869 0.431947 0.189029 0.282512 13.920556 4.199067
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% -0.811766 -0.257464 0.581237 -0.531394 -0.396553 -0.127391 -0.253233 0.043539 0.803727 0.549537 0.543049 1.588814 1.255100
30 N01 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.403762 -0.103128 -0.459196 -0.837233 -0.355210 1.987433 7.236491 1.100022 0.794477 0.547949 0.542316 10.981437 14.249079
31 N02 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.386654 -0.792055 -0.811466 0.026045 2.360801 1.166774 0.555232 1.182994 0.059005 0.052664 0.004793 1.268278 1.273262
32 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 41.707145 33.159303 2.898309 2.068498 11.267753 15.114198 35.271350 42.951242 0.074633 0.064572 0.003232 1.345798 1.336421
33 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.131589 7.761617 -0.523185 -0.299241 34.092924 35.347631 148.911144 182.185848 0.053180 0.075094 0.020758 1.419335 1.401785
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.066510 8.427223 0.536569 -0.092161 0.871691 0.679118 0.961996 3.058709 0.793330 0.549449 0.523347 6.474282 4.612829
37 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.354567 1.150706 -0.672278 -0.215193 1.379085 -0.323334 0.464032 21.261328 0.805795 0.565346 0.523972 5.499101 4.297642
38 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.075708 -0.099563 -0.712038 -0.642800 0.141242 -0.177535 12.620605 5.202848 0.805266 0.573646 0.525854 5.092489 3.795976
40 N04 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.117709 -0.269652 -0.265033 -0.481482 2.842618 -0.144254 -0.344776 -0.767305 0.069685 0.087253 0.018028 1.474658 1.481823
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% 100.00% 100.00% 0.00% 100.00% 0.00% -0.589425 0.475602 2.232004 1.063372 -0.590714 -1.055549 -0.814664 -0.669702 0.088411 0.094683 0.025859 1.238421 1.229531
45 N05 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.162480 0.612062 -0.820218 0.051157 -1.336178 0.005720 0.272498 14.181210 0.790673 0.529468 0.553006 7.294896 7.503187
46 N05 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 2.63% -1.082649 -0.721218 0.896764 -0.735209 -0.491848 -1.105421 -0.010786 -0.309709 0.791379 0.516441 0.566696 0.786214 0.523758
50 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 38.501784 1.242156 3.511017 3.202584 7.605777 2.115725 2.274792 -1.222873 0.686766 0.561292 0.385677 13.829876 13.533088
51 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 2.63% 0.00% 1.478230 2.684612 -0.715361 -0.405165 2.566452 0.100709 0.491489 1.145510 0.803188 0.587227 0.505396 1.350237 1.030595
52 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.826469 7.650326 1.103716 0.006731 2.723052 -1.407010 2.424307 1.818370 0.811396 0.590629 0.507567 8.996297 10.436701
53 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.293173 2.076123 -0.452757 0.048415 -0.637768 -0.105614 4.987265 16.653457 0.807082 0.600249 0.510639 6.871195 6.997181
54 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.357972 15.447347 1.626663 2.287286 1.295870 5.727232 0.563729 -0.082438 0.066447 0.072148 0.011944 1.147168 1.135188
55 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.896971 0.741068 -0.196837 1.452309 2.144480 -1.096515 10.053465 -0.301504 0.060614 0.056349 0.005067 0.000000 0.000000
56 N04 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.311477 0.650492 1.943179 1.870155 1.047993 -0.404390 -1.011707 0.679280 0.049324 0.062775 0.007328 0.000000 0.000000
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 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.919196 0.731884 0.332046 1.030114 -0.200937 0.012712 -0.538800 1.203613 0.805086 0.565152 0.529377 1.540953 1.095291
66 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.525870 0.931245 -0.612794 0.532906 0.546839 1.499041 -0.466711 2.233071 0.806484 0.591814 0.501060 1.513045 1.115815
67 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.475162 -0.780287 0.813800 -0.504142 2.411748 2.129597 1.658996 6.374921 0.810182 0.608690 0.490297 9.065269 12.161502
68 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.567081 1.027846 0.656463 8.919044 1.873120 5.339033 -0.157081 0.712369 0.808048 0.605913 0.491558 6.071136 6.500946
69 N04 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.023112 -1.247919 0.383520 -0.010189 -0.429686 3.669230 -0.271155 2.820727 0.070115 0.060643 0.010980 1.258466 1.254717
70 N04 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 8.596313 -0.987261 0.824853 -0.616144 3.393499 -0.999831 1.135454 6.851849 0.070610 0.056110 0.006177 1.228996 1.227665
71 N04 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.676299 -0.432358 -0.771119 0.111116 2.345571 -0.892563 -0.386671 0.172118 0.067359 0.054640 0.004961 0.948102 0.955810
72 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 3.869640 -0.951539 -0.332650 2.025250 4.323041 -0.567175 5.332582 -1.111612 0.088584 0.078526 0.017187 0.951513 0.953645
73 N05 digital_ok 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 24.062087 -0.150438 39.048206 3.721807 48.821368 2.471402 5.377118 -0.294839 0.035702 0.580915 0.285914 0.000000 0.000000
81 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.337222 1.590679 -0.557115 4.532236 2.021621 4.978538 0.951084 -0.916974 0.793381 0.548545 0.516052 8.189087 9.256673
82 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.490508 0.989447 1.896089 0.256720 0.704349 -0.873610 -0.234942 -0.598354 0.806146 0.573447 0.523033 10.732130 8.728361
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.721276 1.976640 2.711984 5.517362 1.003490 1.839593 -0.893805 -1.442627 0.808275 0.605715 0.496789 7.555245 8.649175
84 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.629806 11.535787 1.963192 1.034986 0.366545 1.216126 -0.486848 0.615419 0.815689 0.613080 0.487359 8.223320 9.309866
85 N08 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.578945 0.920453 0.763259 1.852152 -1.505742 -1.162741 -0.609819 -0.749105 0.803993 0.612766 0.502170 1.324825 1.139889
86 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.197533 4.685873 0.998254 -0.105191 1.635787 3.394852 -0.048792 -0.380855 0.804639 0.589735 0.500564 8.870678 8.046481
87 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 32.703543 12.764866 2.413893 1.289429 36.797680 0.419237 42.738862 -0.538473 0.722831 0.622781 0.414310 4.666758 4.709614
88 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 15.831281 13.136361 26.081105 23.296066 43.237149 32.454441 2.869210 2.259185 0.771763 0.594821 0.504913 4.897120 4.373831
90 N09 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.868852 0.310819 0.757193 3.297613 -0.277979 2.405825 0.228472 1.431660 0.808403 0.588281 0.526899 0.000000 0.000000
91 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.324931 14.572339 23.727793 24.511483 37.927952 36.435453 0.792029 3.510764 0.784852 0.561960 0.531996 0.000000 0.000000
92 N10 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 46.537724 63.728542 4.069330 5.609858 40.811805 54.390436 7.057482 30.464661 0.319834 0.234867 0.130570 4.872220 3.507552
93 N10 digital_ok 100.00% 16.13% 16.13% 0.00% 100.00% 0.00% 0.614934 -0.136545 3.672744 0.931988 3.999640 -0.473538 2.622787 -0.977836 0.656750 0.426219 0.455983 6.440174 7.233009
94 N10 digital_ok 100.00% 16.13% 16.13% 0.00% 100.00% 0.00% -1.014022 -1.297624 -0.727914 -0.945261 -0.660514 3.629647 3.400309 10.484137 0.656934 0.410700 0.462499 8.806617 9.109334
98 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.618929 4.408798 1.381404 2.855589 0.947464 0.998754 0.573400 2.185840 0.791578 0.522984 0.540592 0.000000 0.000000
99 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.206355 1.047676 3.632061 0.617186 2.244269 0.685927 4.572136 -0.524750 0.798523 0.557967 0.524392 3.672452 2.896402
100 N07 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
101 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 10.110294 11.184287 3.852856 0.183314 0.795427 -0.497540 7.232435 0.769262 0.816014 0.602735 0.511486 6.725801 6.005747
102 N08 RF_maintenance 100.00% 0.00% 38.17% 0.00% 100.00% 0.00% 26.611581 27.477988 1.560770 1.779323 711.141044 723.225961 11574.931365 11541.415004 0.744435 0.428030 0.530628 0.000000 0.000000
103 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.430455 11.102472 -0.159342 0.183606 -0.348490 0.178017 -0.291573 -0.466944 0.812520 0.622566 0.495970 8.370390 6.806945
104 N08 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.853526 84.029357 0.361730 13.672735 2.175410 1.730440 0.034603 -0.080228 0.818280 0.620005 0.514846 5.176273 4.540465
105 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.098958 6.699610 11.297572 15.825188 11.439025 17.939068 -1.040475 -1.092120 0.818673 0.628022 0.503743 6.370515 4.973111
106 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.602825 13.756607 5.561900 23.587636 0.944584 33.177677 3.306526 2.844978 0.802944 0.603838 0.511704 4.636421 3.571039
107 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.693332 9.605213 23.303009 21.547274 35.925628 30.182228 0.526335 4.958649 0.800542 0.597578 0.501350 8.737602 13.269271
108 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.906525 4.754708 16.535769 0.898731 2.147203 -0.888665 1.013769 0.871089 0.767778 0.603584 0.497995 4.965277 9.968237
109 N10 digital_ok 0.00% 16.13% 16.13% 0.00% 15.79% 0.00% -0.835091 -0.007480 0.740172 0.612190 -1.033502 0.393463 -1.020567 -0.290278 0.662805 0.453547 0.450080 1.549987 1.250815
110 N10 RF_maintenance 100.00% 16.13% 16.13% 0.00% 100.00% 0.00% 42.138319 29.355459 3.193249 1.827633 3.119876 12.093307 -0.486709 0.275052 0.596249 0.389954 0.307630 10.807184 10.079040
111 N10 digital_ok 100.00% 16.13% 16.13% 0.00% 100.00% 0.00% -0.014833 1.910442 -0.526428 1.399427 0.159220 3.232217 0.016379 4.783827 0.661914 0.433728 0.451351 10.240988 16.020616
112 N10 digital_ok 0.00% 16.13% 16.13% 0.00% 15.79% 0.00% -0.761529 -0.144399 -0.635034 1.019675 0.327517 -0.771069 -0.689917 -1.314160 0.656140 0.419895 0.460752 1.037254 0.611340
116 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 84.21% 15.79% 0.292185 2.101001 0.091024 -0.672841 1.493029 -0.891154 3.190803 -0.867689 0.787126 0.519621 0.547304 0.000000 0.000000
117 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.049196 1.230287 6.040814 6.291068 6.737155 3.667565 -1.150888 -1.584958 0.797216 0.540748 0.543132 0.000000 0.000000
118 N07 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 2.186042 29.029873 2.950854 35.174598 -0.926287 45.570619 -0.215537 3.069430 0.806459 0.049146 0.489320 0.000000 0.000000
119 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
120 N08 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 20.248984 39.132412 1.391734 45.503788 35.098032 45.309927 4.116826 14.071655 0.466379 0.047356 0.301674 0.000000 0.000000
121 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.231482 6.985438 -0.439110 0.673932 0.143666 0.550885 63.119088 29.983795 0.818146 0.614676 0.496843 0.000000 0.000000
122 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 9.604653 8.902226 1.722419 1.622153 -0.133389 1.201413 -0.138706 -0.284811 0.824137 0.621420 0.499538 0.000000 0.000000
123 N08 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 8.698761 11.367688 0.268798 0.300757 -1.204304 -1.613234 0.569932 0.832701 0.822286 0.635947 0.494779 4.577056 3.891100
125 N09 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.500291 14.675817 12.672942 17.338923 12.827877 21.856215 -1.786159 3.552148 0.817169 0.612840 0.494466 10.007952 15.316859
126 N09 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 24.246590 2.889430 8.567628 7.302586 17.993949 5.827157 -0.063476 -1.520457 0.704778 0.614351 0.390535 3.150541 2.695414
127 N10 digital_ok 0.00% 16.13% 16.13% 0.00% 15.79% 0.00% -0.082620 -0.310761 0.010189 -0.528570 0.483186 1.066386 0.038470 1.092256 0.662258 0.464829 0.445101 1.531857 1.110363
128 N10 digital_ok 0.00% 16.13% 16.13% 0.00% 15.79% 0.00% -1.352573 2.522602 -0.409308 1.822125 0.354994 1.435053 0.061478 -0.946639 0.663197 0.455217 0.446106 1.340337 0.848195
129 N10 digital_ok 0.00% 16.13% 16.13% 0.00% 15.79% 0.00% -0.543030 -1.050806 -0.899709 -0.928814 0.553598 1.090882 -0.000447 0.255527 0.658716 0.442182 0.446740 1.647825 1.248637
130 N10 digital_ok 100.00% 16.13% 16.13% 0.00% 100.00% 0.00% 0.013998 -0.361424 0.409815 1.427967 3.132765 2.207168 0.675176 6.632760 0.653410 0.427418 0.453409 9.671028 15.165247
135 N12 digital_maintenance 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.187826 -0.022717 -0.805722 -0.833903 -0.012712 -0.649264 0.582925 -0.369614 0.090124 0.096451 0.023954 4.801142 7.110972
136 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.291779 13.907137 -0.477459 0.807481 4.030179 2.736778 2.278397 3.467288 0.080569 0.093103 0.021616 0.936606 0.951268
137 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.771131 6.747419 24.817210 16.036975 40.838561 10.070244 0.322144 1.583744 0.773178 0.529869 0.539735 3.328310 2.459322
138 N07 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
140 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.534772 24.760660 38.895767 40.714191 48.977231 45.139376 4.657574 4.572101 0.039003 0.042752 0.002260 0.000000 0.000000
141 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.556702 2.969637 0.482685 9.522345 1.952994 3.052109 1.468391 32.789249 0.816050 0.579691 0.515651 0.000000 0.000000
142 N13 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 26.191429 30.512535 1.889163 40.940310 41.652206 45.090219 5.549476 6.834801 0.504078 0.043676 0.260568 0.000000 0.000000
143 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 92.11% 7.89% -0.770523 -0.755588 1.395475 1.177486 0.168586 -0.467078 -0.235727 -1.342941 0.813535 0.628238 0.485396 0.000000 0.000000
144 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.891885 -0.709840 2.375411 -0.441658 -0.482175 1.730629 -0.252048 24.328511 0.819883 0.625006 0.499417 9.402231 9.506917
145 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.104239 26.268427 40.098552 41.295345 49.069550 45.268313 8.031363 9.568767 0.034682 0.035811 -0.000484 0.000000 0.000000
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 26.937441 29.214018 39.968816 42.130518 49.176933 45.284280 8.686394 9.545877 0.046450 0.048672 0.001396 1.282367 1.282218
155 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.679907 23.345044 38.999537 40.373196 48.961391 45.085352 8.477381 9.207630 0.035322 0.036359 0.000806 1.147432 1.316705
156 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.357817 0.423599 1.516251 -0.161969 1.151882 0.433350 8.680598 18.048588 0.054188 0.063613 0.005031 0.000000 0.000000
157 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.007480 -0.584359 -0.247831 3.546215 0.682953 0.704772 0.442329 -0.679970 0.065073 0.059286 0.005289 0.000000 0.000000
158 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.785336 -1.322335 39.854839 -0.208916 49.124525 1.583303 5.002922 12.463379 0.034755 0.061307 0.052576 0.000000 0.000000
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.823709 24.275278 39.617422 40.775900 49.107870 45.173105 8.136608 9.395173 0.041173 0.044073 0.003655 0.000000 0.000000
161 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.573727 46.767091 0.140852 3.568694 -0.342235 4.507760 0.236950 -0.371639 0.803381 0.483510 0.492693 -0.000000 -0.000000
162 N13 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 84.21% 0.349673 0.307854 -0.311391 -0.580375 2.696297 1.274075 1.703142 0.000447 0.810443 0.592639 0.517751 17.746246 35.810179
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 84.21% 0.00% 0.568436 0.044568 -0.131778 -0.771030 -1.227215 -0.315620 -0.274563 1.682189 0.808412 0.607557 0.498561 0.000000 0.000000
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 28.95% 55.26% -1.165266 -1.311671 -0.845106 -0.732171 -1.133669 -0.284489 3.102420 1.610292 0.811713 0.607986 0.505831 inf inf
165 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.199518 1.967452 7.418819 -0.652339 3.503238 -0.662102 -0.070589 0.081214 0.810185 0.609437 0.497746 26.451370 36.070623
166 N14 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 26.412084 1.989937 1.397560 1.631485 11.329413 9.619445 10.401595 12.238303 0.718643 0.588349 0.413690 3.690963 2.786567
167 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 38.203012 19.937845 17.688660 22.100281 34.053960 35.661441 4.900779 4.293258 0.646474 0.473713 0.334703 0.000000 0.000000
168 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 11.884040 15.039681 22.043883 24.834871 33.729190 36.512764 -1.650510 2.292262 0.785597 0.549578 0.519799 0.000000 0.000000
169 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.138238 13.944232 24.287056 23.428817 39.010082 34.747988 0.695365 2.293756 0.779680 0.531382 0.532550 5.186373 3.225279
170 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 14.438864 12.071480 24.575115 22.360357 39.263803 30.987109 1.179582 2.064463 0.773634 0.529287 0.539203 6.705210 4.178793
176 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.621108 -0.446415 -0.460702 0.821804 -0.120189 0.666029 -0.376210 1.952170 0.042815 0.068426 0.005513 18.669294 18.911151
177 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.051367 1.072025 1.203451 3.380727 -0.348177 2.479084 -0.050508 8.227384 0.066223 0.063410 0.006333 0.000000 0.000000
178 N12 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.964679 -1.064543 0.852431 -0.615597 -1.554411 -0.549548 -0.439987 -1.023105 0.076411 0.059196 0.008472 0.000000 0.000000
179 N12 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.421057 0.313596 -0.570132 -0.080555 8.117856 -1.329655 14.226338 -0.358397 0.071073 0.083140 0.017754 0.000000 0.000000
180 N13 RF_maintenance 100.00% 0.00% 91.94% 0.00% 100.00% 0.00% 0.293425 19.380742 0.856557 38.001862 0.762048 34.662745 -0.014999 6.633674 0.799954 0.285205 0.610796 0.000000 0.000000
181 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 25.732457 60.965462 40.274811 7.330228 49.123572 47.261068 7.751448 5.867358 0.045200 0.310048 0.137436 0.000000 0.000000
182 N13 RF_maintenance 100.00% 0.00% 86.56% 0.00% 100.00% 0.00% 11.438567 18.412693 22.020084 36.067249 33.308063 33.218514 -1.718336 11.530607 0.791314 0.334989 0.573540 0.000000 0.000000
183 N13 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.407114 -1.012496 0.144734 -0.799066 -1.741055 -1.714453 -0.159423 7.549377 0.804343 0.580878 0.522352 0.000000 0.000000
184 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 84.21% 2.63% 0.161540 0.049882 -0.124282 0.355315 -0.113056 0.461673 2.088135 -0.592594 0.804805 0.594643 0.507894 0.000000 0.000000
185 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.416993 0.246281 1.412345 0.855555 -0.094568 -0.333808 40.395364 -0.701874 0.806420 0.594045 0.510753 0.000000 0.000000
186 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.024921 -0.218000 3.843862 2.281641 0.933365 -0.827788 4.892949 0.120858 0.799643 0.588227 0.507013 0.000000 0.000000
187 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.018049 1.212439 0.234772 1.158764 -0.053832 -0.823318 4.441230 -0.625749 0.800018 0.591861 0.501704 6.167923 3.751802
189 N15 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.765493 3.761849 0.331993 0.431053 1.388266 1.341506 2.579832 5.955987 0.791899 0.552011 0.537888 0.000000 0.000000
190 N15 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 58.927464 29.204004 4.756377 41.312234 22.050304 45.246022 2.495538 8.734999 0.649073 0.044878 0.424522 0.000000 0.000000
191 N15 digital_ok 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.944238 -0.175921 -0.607984 -0.855324 -0.439817 -0.589397 0.204108 -0.635217 0.788775 0.529148 0.563681 0.000000 0.000000
203 N18 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
205 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 22.056484 20.720972 16.062343 2.705453 26.852080 13.242288 32.578198 47.829783 0.791527 0.510843 0.547955 -0.000000 -0.000000
206 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 18.781516 19.179917 3.475008 10.237495 13.900493 13.801700 32.753251 34.075347 0.771486 0.532038 0.531127 5.520921 5.037990
207 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 22.734270 20.508592 17.521752 14.298343 28.460117 18.259612 12.401817 11.727098 0.770844 0.526356 0.524777 4.580231 3.037313
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% 42.016854 41.807751 inf inf 5484.073070 6402.085301 14037.116968 19417.702012 nan nan nan 0.000000 0.000000
223 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 19.583151 18.765016 8.781306 4.160384 9.797718 3.511396 -0.995015 46.952622 0.777877 0.497500 0.551890 0.000000 0.000000
224 N19 RF_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 27.598732 27.767804 26.367360 26.005600 45.522129 40.716339 -1.399063 -1.169303 0.734120 0.470925 0.527071 15.201537 8.445186
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% 44.510739 44.295447 inf inf 7631.258157 7631.056814 23697.287746 23696.697636 nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 30.902969 28.774777 27.530976 27.799440 48.764629 44.993157 14.395784 8.898971 0.054201 0.049838 0.003928 0.000000 0.000000
321 N02 not_connected 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.308227 4.268597 14.842320 13.395798 24.354757 20.077210 40.622880 40.403155 0.076603 0.060508 0.031916 0.000000 0.000000
323 N02 not_connected 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.930488 7.293914 1.301371 17.412496 16.824445 17.770314 4.928937 -0.704074 0.077645 0.061561 0.030553 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% 100.00% 100.00% 0.00% 100.00% 0.00% 10.241725 4.014051 6.570808 12.444946 18.118785 13.980944 4.954816 -1.648675 0.095260 0.072161 0.037146 0.000000 0.000000
333 N12 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 5.316068 4.275046 0.032006 11.577389 7.121148 10.172190 7.090754 -0.852340 0.091661 0.073857 0.041844 0.000000 0.000000
In [22]:
# print ex_ants for easy copy-pasting to YAML file
proposed_ex_ants = [ant for i, ant in enumerate(ants) if np.any([col[i] > 0 for col in bar_cols.values()])]
print('ex_ants: [' + ", ".join(str(ant) for ant in proposed_ex_ants) + ']')
print(f'\nunflagged_ants: [{", ".join([str(ant) for ant in ants if ant not in proposed_ex_ants])}]')
# "golden" means no flags and good a priori status
golden_ants = ", ".join([str(ant) for ant in ants if ((ant not in proposed_ex_ants) and (a_priori_statuses[ant] in good_statuses.split(',')))])
print(f'\ngolden_ants: [{golden_ants}]')
ex_ants: [4, 5, 7, 8, 9, 10, 15, 16, 18, 19, 20, 21, 27, 28, 29, 30, 31, 32, 33, 36, 37, 38, 40, 41, 42, 45, 46, 50, 51, 52, 53, 54, 55, 56, 57, 67, 68, 69, 70, 71, 72, 73, 81, 82, 83, 84, 86, 87, 88, 90, 91, 92, 93, 94, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 116, 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130, 135, 136, 137, 138, 140, 141, 142, 143, 144, 145, 150, 155, 156, 157, 158, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 189, 190, 191, 203, 205, 206, 207, 220, 221, 222, 223, 224, 241, 242, 243, 320, 321, 323, 324, 329, 333]

unflagged_ants: [3, 17, 65, 66, 85]

golden_ants: [3, 17, 65, 66, 85]
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_2459826.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.dev9+gea58d1b
In [ ]: